Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 325364 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-2 / +3 lines)
Lines 2-8 Link Here
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.jst.ws.annotations.core;singleton:=true
4
Bundle-SymbolicName: org.eclipse.jst.ws.annotations.core;singleton:=true
5
Bundle-Version: 1.0.0.qualifier
5
Bundle-Version: 1.1.0.qualifier
6
Bundle-Localization: plugin
6
Bundle-Localization: plugin
7
Bundle-RequiredExecutionEnvironment: J2SE-1.5
7
Bundle-RequiredExecutionEnvironment: J2SE-1.5
8
Bundle-Vendor: %pluginProvider
8
Bundle-Vendor: %pluginProvider
Lines 18-23 Link Here
18
Export-Package: org.eclipse.jst.ws.annotations.core,
18
Export-Package: org.eclipse.jst.ws.annotations.core,
19
 org.eclipse.jst.ws.annotations.core.initialization,
19
 org.eclipse.jst.ws.annotations.core.initialization,
20
 org.eclipse.jst.ws.annotations.core.processor,
20
 org.eclipse.jst.ws.annotations.core.processor,
21
 org.eclipse.jst.ws.annotations.core.utils
21
 org.eclipse.jst.ws.annotations.core.utils,
22
 org.eclipse.jst.ws.internal.annotations.core.utils;x-friends:="org.eclipse.jst.ws.jaxws.ui"
22
Bundle-Activator: org.eclipse.jst.ws.annotations.core.AnnotationsCorePlugin
23
Bundle-Activator: org.eclipse.jst.ws.annotations.core.AnnotationsCorePlugin
23
Bundle-ActivationPolicy: lazy
24
Bundle-ActivationPolicy: lazy
(-)src/org/eclipse/jst/ws/annotations/core/AnnotationDefinition.java (-25 / +147 lines)
Lines 19-24 Link Here
19
19
20
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IConfigurationElement;
21
import org.eclipse.core.runtime.IConfigurationElement;
22
import org.eclipse.jdt.core.IAnnotation;
23
import org.eclipse.jdt.core.IJavaProject;
24
import org.eclipse.jdt.core.IMemberValuePair;
25
import org.eclipse.jdt.core.IType;
26
import org.eclipse.jdt.core.JavaModelException;
22
import org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer;
27
import org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer;
23
28
24
/**
29
/**
Lines 46-53 Link Here
46
    private static final String RESTRICTED_TO_INTERFACE_ONLY = "INTERFACE_ONLY";
51
    private static final String RESTRICTED_TO_INTERFACE_ONLY = "INTERFACE_ONLY";
47
    private static final String RESTRICTED_TO_ENUM_ONLY = "ENUM_ONLY";
52
    private static final String RESTRICTED_TO_ENUM_ONLY = "ENUM_ONLY";
48
53
49
	private static final String ELEM_TARGET_FILTER = "targetFilter"; //$NON-NLS-1$
54
    private static final String ELEM_TARGET_FILTER = "targetFilter"; //$NON-NLS-1$
50
	private static final String ATT_TARGET = "target"; //$NON-NLS-1$
55
    private static final String ATT_TARGET = "target"; //$NON-NLS-1$
51
56
52
    private IConfigurationElement configurationElement;
57
    private IConfigurationElement configurationElement;
53
    private String category;
58
    private String category;
Lines 61-66 Link Here
61
    private boolean classOnly;
66
    private boolean classOnly;
62
    private boolean enumOnly;
67
    private boolean enumOnly;
63
68
69
    private IType annotationType;
70
    private List<ElementType> annotationTypeTargets;
71
    private IJavaProject javaProject;
72
    private Boolean deprecated;
73
64
    /**
74
    /**
65
     * Constructs an <code>AnnotationDefinition</code> using information from the
75
     * Constructs an <code>AnnotationDefinition</code> using information from the
66
     * <code>org.eclipse.jst.ws.annotations.core.annotationDefinition</code> extension point and category name.
76
     * <code>org.eclipse.jst.ws.annotations.core.annotationDefinition</code> extension point and category name.
Lines 133-148 Link Here
133
     * <code>annotation<annotation> element in the <code>org.eclipse.jst.ws.annotations.core.annotationDefinition</code>
143
     * <code>annotation<annotation> element in the <code>org.eclipse.jst.ws.annotations.core.annotationDefinition</code>
134
     * extension point.
144
     * extension point.
135
     *
145
     *
136
     * @return the annotation class
146
     * @return the annotation class or null if not found.
147
     * @deprecated As of 1.1 replaced by {@link #getAnnotationType()}
137
     */
148
     */
138
    @SuppressWarnings("unchecked")
149
    @SuppressWarnings("unchecked")
150
    @Deprecated
139
    public Class<? extends java.lang.annotation.Annotation> getAnnotationClass() {
151
    public Class<? extends java.lang.annotation.Annotation> getAnnotationClass() {
140
        if (annotationClass == null) {
152
        if (annotationClass == null) {
141
            try {
153
            try {
142
                Class<?> aClass = Class.forName(annotationClassName);
154
                Class<?> aClass = Class.forName(annotationClassName);
143
                if (aClass.isAnnotation()) {
155
                if (aClass.isAnnotation()) {
144
                    annotationClass = (Class<java.lang.annotation.Annotation>)Class.forName(
156
                    annotationClass = (Class<java.lang.annotation.Annotation>) Class.forName(annotationClassName);
145
                            annotationClassName);
146
                }
157
                }
147
            } catch(ClassNotFoundException cnfe) {
158
            } catch(ClassNotFoundException cnfe) {
148
                AnnotationsCorePlugin.log(cnfe);
159
                AnnotationsCorePlugin.log(cnfe);
Lines 152-157 Link Here
152
    }
163
    }
153
164
154
    /**
165
    /**
166
     * Returns the annotation type as specified by the <code>class</code> attribute of the
167
     * <code>annotation<annotation> element in the <code>org.eclipse.jst.ws.annotations.core.annotationDefinition</code>
168
     * extension point.
169
     * 
170
     * @return the <code>org.eclipse.jdt.core.IType</code> which represents an annotation type or null if the java project
171
     * has not been set, if the type cannot be found or if the type does not represent an annotation type.
172
     * 
173
     * @see #setJavaProject(IJavaProject)
174
     * @since 1.1
175
     */
176
    public IType getAnnotationType() {
177
        if (annotationType == null) {
178
            try {
179
                if (javaProject != null) {
180
                    IType type = javaProject.findType(annotationClassName);
181
                    if (type != null && type.isAnnotation()) {
182
                        annotationType = type;
183
                    }
184
                }
185
            } catch (JavaModelException jme) {
186
                AnnotationsCorePlugin.log(jme.getStatus());
187
            }
188
        }
189
        return annotationType;
190
    }
191
192
    /**
155
     * Returns a list of {@link ElementType} that specify the Java elements to which the annotation
193
     * Returns a list of {@link ElementType} that specify the Java elements to which the annotation
156
     * can be applied.
194
     * can be applied.
157
     * <p>
195
     * <p>
Lines 162-189 Link Here
162
     * the annotation.
200
     * the annotation.
163
     * </p>
201
     * </p>
164
     * @return a list of element types.
202
     * @return a list of element types.
203
     * @deprecated as of 1.1 replaced by {@link #getAnnotationTypeTargets()}
165
     */
204
     */
205
    @Deprecated
166
    public List<ElementType> getTargets() {
206
    public List<ElementType> getTargets() {
167
        if (targets == null) {
207
        if (targets == null) {
168
        	targets = new LinkedList<ElementType>();
208
            targets = new LinkedList<ElementType>();
169
209
170
            Class<? extends java.lang.annotation.Annotation> annotation = getAnnotationClass();
210
            Class<? extends java.lang.annotation.Annotation> annotation = getAnnotationClass();
171
            if (annotation != null) {
211
            if (annotation != null) {
172
            	Target target = annotation.getAnnotation(Target.class);
212
                Target target = annotation.getAnnotation(Target.class);
173
            	if (target != null) {
213
                if (target != null) {
174
            	    targets.addAll(Arrays.asList(target.value()));
214
                    targets.addAll(Arrays.asList(target.value()));
175
215
176
                    List<ElementType> filteredTargets = getFilteredTargets(configurationElement);
216
                    List<ElementType> filteredTargets = getFilteredTargets(configurationElement);
177
                    if (targets.containsAll(filteredTargets) && filteredTargets.size() < targets.size()) {
217
                    if (targets.containsAll(filteredTargets) && filteredTargets.size() < targets.size()) {
178
                        targets.removeAll(filteredTargets);
218
                        targets.removeAll(filteredTargets);
179
                    }
219
                    }
180
            	}
220
                }
181
            }
221
            }
182
        }
222
        }
183
        return targets;
223
        return targets;
184
    }
224
    }
185
225
186
    /**
226
    /**
227
     * Returns a list of {@link ElementType} that specify the Java elements to which the annotation can be applied.
228
     * <p>
229
     * The element types are retrieved from the annotations
230
     * {@link java.lang.annotation.Target} meta-annotation type. This list can
231
     * be filtered using the <code>targetFilter</code> element on the
232
     * <code>org.eclipse.jst.ws.annotations.core.annotationDefinition</code>
233
     * extension point when defining the annotation.
234
     * </p>
235
     * @return a list of element types or null if the java project has not been set or if the annotation type cannot be
236
     * found.
237
     * @see #setJavaProject(IJavaProject)
238
     * @since 1.1
239
     */
240
    public List<ElementType> getAnnotationTypeTargets() {
241
        if (annotationTypeTargets == null) {
242
            annotationTypeTargets = new LinkedList<ElementType>();
243
            try {
244
                IType type = getAnnotationType();
245
                if (type != null) {
246
                    IAnnotation target = type.getAnnotation(Target.class.getCanonicalName());
247
                    if (!target.exists()) {
248
                        target = type.getAnnotation(Target.class.getSimpleName());
249
                    }
250
                    if (target.exists()) {
251
                        IMemberValuePair[] memberValuePairs = target.getMemberValuePairs();
252
                        for (IMemberValuePair memberValuePair : memberValuePairs) {
253
                            Object value = memberValuePair.getValue();
254
                            if (value.getClass().isArray() && value.getClass().getComponentType().equals(String.class)) {
255
                                String[] objs = (String[]) value;
256
                                for (String obj : objs) {
257
                                    annotationTypeTargets.add(ElementType.valueOf(obj.substring(obj.lastIndexOf('.') + 1)));
258
                                }
259
                            } else {
260
                                annotationTypeTargets.add(ElementType.valueOf(value.toString().substring(value.toString().lastIndexOf('.') + 1)));
261
                            }
262
                        }
263
                    }
264
                    List<ElementType> filteredTargets = getFilteredTargets(configurationElement);
265
                    if (annotationTypeTargets.containsAll(filteredTargets) && filteredTargets.size() < annotationTypeTargets.size()) {
266
                        annotationTypeTargets.removeAll(filteredTargets);
267
                    }
268
                }
269
            } catch (JavaModelException jme) {
270
                AnnotationsCorePlugin.log(jme.getStatus());
271
            }
272
        }
273
        return annotationTypeTargets;
274
    }
275
276
    /**
187
     * Returns the annotations attribute initializer as specified in the
277
     * Returns the annotations attribute initializer as specified in the
188
     * <code>org.eclipse.jst.ws.annotations.core.annotationInitializer</code> extension point or null if no
278
     * <code>org.eclipse.jst.ws.annotations.core.annotationInitializer</code> extension point or null if no
189
     * initializer can be found.
279
     * initializer can be found.
Lines 196-203 Link Here
196
                IConfigurationElement configurationElement =
286
                IConfigurationElement configurationElement =
197
                    AnnotationsManager.getAnnotationInitializerCache().get(getAnnotationClassName());
287
                    AnnotationsManager.getAnnotationInitializerCache().get(getAnnotationClassName());
198
                if (configurationElement != null) {
288
                if (configurationElement != null) {
199
                    annotationInitializer = (IAnnotationAttributeInitializer)configurationElement
289
                    annotationInitializer = (IAnnotationAttributeInitializer)configurationElement.createExecutableExtension(ATT_CLASS);
200
                        .createExecutableExtension(ATT_CLASS);
201
                }
290
                }
202
            } catch (CoreException ce) {
291
            } catch (CoreException ce) {
203
                AnnotationsCorePlugin.log(ce.getStatus());
292
                AnnotationsCorePlugin.log(ce.getStatus());
Lines 206-222 Link Here
206
        return annotationInitializer;
295
        return annotationInitializer;
207
    }
296
    }
208
297
209
	  private List<ElementType> getFilteredTargets(IConfigurationElement configurationElement) {
298
    private List<ElementType> getFilteredTargets(IConfigurationElement configurationElement) {
210
		  List<ElementType> targets = new ArrayList<ElementType>(7);
299
        List<ElementType> targets = new ArrayList<ElementType>(7);
211
		  try {
300
        try {
212
			  IConfigurationElement[] deprecatedTargets = configurationElement.getChildren(ELEM_TARGET_FILTER);
301
            IConfigurationElement[] deprecatedTargets = configurationElement.getChildren(ELEM_TARGET_FILTER);
213
			  for (IConfigurationElement deprecatedTargetElement : deprecatedTargets) {
302
            for (IConfigurationElement deprecatedTargetElement : deprecatedTargets) {
214
				  String target = AnnotationsManager.getAttributeValue(deprecatedTargetElement, ATT_TARGET);
303
                String target = AnnotationsManager.getAttributeValue(deprecatedTargetElement, ATT_TARGET);
215
				  targets.add(ElementType.valueOf(target));
304
                targets.add(ElementType.valueOf(target));
216
			  }
305
            }
217
		  } catch (IllegalArgumentException iae) {
306
        } catch (IllegalArgumentException iae) {
218
			  AnnotationsCorePlugin.log(iae);
307
            AnnotationsCorePlugin.log(iae);
219
		  }
308
        }
220
		  return targets;
309
        return targets;
221
	  }
310
    }
311
312
    boolean isDeprecated() {
313
        if (deprecated == null) {
314
            IType type = getAnnotationType();
315
            if (type != null) {
316
                IAnnotation annotation = type.getAnnotation(Deprecated.class.getCanonicalName());
317
                if (!annotation.exists()) {
318
                    annotation = type.getAnnotation(Deprecated.class.getSimpleName());
319
                }
320
                deprecated = annotation.exists();
321
            } else {
322
                deprecated = true;
323
            }
324
        }
325
        return deprecated;
326
    }
327
328
    /**
329
     * Sets the <code>org.eclipse.jdt.core.IJavaProject</code> which is used to find the
330
     * annotation type.
331
     * 
332
     * @see {@link #getAnnotationType()}
333
     * @see {@link #getAnnotationTypeTargets()}
334
     * @since 1.1
335
     */
336
    public void setJavaProject(IJavaProject javaProject) {
337
        if (this.javaProject == null || !this.javaProject.equals(javaProject)) {
338
            this.javaProject = javaProject;
339
            this.annotationType = null;
340
            this.annotationTypeTargets = null;
341
            this.deprecated = null;
342
        }
343
    }
222
}
344
}
(-)src/org/eclipse/jst/ws/annotations/core/AnnotationsCore.java (-3 / +42 lines)
Lines 12-17 Link Here
12
12
13
import java.util.List;
13
import java.util.List;
14
14
15
import org.eclipse.jdt.core.IField;
16
import org.eclipse.jdt.core.JavaModelException;
15
import org.eclipse.jdt.core.dom.AST;
17
import org.eclipse.jdt.core.dom.AST;
16
import org.eclipse.jdt.core.dom.ArrayInitializer;
18
import org.eclipse.jdt.core.dom.ArrayInitializer;
17
import org.eclipse.jdt.core.dom.BooleanLiteral;
19
import org.eclipse.jdt.core.dom.BooleanLiteral;
Lines 174-181 Link Here
174
     * @param value an object representing the <code>enum</code> value.
176
     * @param value an object representing the <code>enum</code> value.
175
     * @return a new member value pair with the given name and value.
177
     * @return a new member value pair with the given name and value.
176
     */
178
     */
177
    public static MemberValuePair createEnumMemberValuePair(AST ast, String className, String name,
179
    public static MemberValuePair createEnumMemberValuePair(AST ast, String className, String name, Object value) {
178
            Object value) {
180
        if (value instanceof IField) {
181
            return AnnotationsCore.createMemberValuePair(ast, name, createEnumLiteral(ast, className, (IField) value));
182
        }
179
        return AnnotationsCore.createMemberValuePair(ast, name, createEnumLiteral(ast, className, value));
183
        return AnnotationsCore.createMemberValuePair(ast, name, createEnumLiteral(ast, className, value));
180
    }
184
    }
181
185
Lines 241-247 Link Here
241
     *
245
     *
242
     * @param ast the {@link AST} that will be used to create the qualified name.
246
     * @param ast the {@link AST} that will be used to create the qualified name.
243
     * @param className the fully qualified name of the enclosing class.
247
     * @param className the fully qualified name of the enclosing class.
244
     * @param value sn object representing the <code>enum</code> value.
248
     * @param value an object representing the <code>enum</code> value.
245
     * @return a new qualified name.
249
     * @return a new qualified name.
246
     */
250
     */
247
    public static QualifiedName createEnumLiteral(AST ast, String className, Object value) {
251
    public static QualifiedName createEnumLiteral(AST ast, String className, Object value) {
Lines 267-272 Link Here
267
    }
271
    }
268
272
269
    /**
273
    /**
274
     * Creates a new {@link QualifiedName} to represent an <code>enum</code> literal value.
275
     *
276
     * @param ast the {@link AST} that will be used to create the qualified name.
277
     * @param className the fully qualified name of the enclosing class.
278
     * @param value a {@link org.eclipse.jdt.core.IField} where <code>isEnumConstant()</code> is <code>true</code>.
279
     * @return a new qualified name.
280
     * @throws JavaModelException
281
     * @since 1.1
282
     */
283
    public static QualifiedName createEnumLiteral(AST ast, String className, IField enumConstant) {
284
        QualifiedName enumName = null;
285
        SimpleName enumClassName = ast.newSimpleName(enumConstant.getDeclaringType().getElementName());
286
        SimpleName enumLiteral = ast.newSimpleName(enumConstant.getElementName());
287
        try {
288
            if (enumConstant.getDeclaringType().isMember()) {
289
                Name enumEnclosingClassName = null;
290
                String enclosingClassName = enumConstant.getDeclaringType().getDeclaringType().getFullyQualifiedName();
291
                if (enclosingClassName.equals(className)) {
292
                    enumEnclosingClassName = ast.newSimpleName(enumConstant.getDeclaringType().getDeclaringType().getElementName());
293
                } else {
294
                    enumEnclosingClassName = ast.newName(enclosingClassName);
295
                }
296
                QualifiedName qualifiedName = ast.newQualifiedName(enumEnclosingClassName, enumClassName);
297
                enumName = ast.newQualifiedName(qualifiedName, enumLiteral);
298
            } else {
299
                Name qualifiedName = ast.newName(enumConstant.getDeclaringType().getFullyQualifiedName());
300
                enumName = ast.newQualifiedName(qualifiedName, enumLiteral);
301
            }
302
        } catch (JavaModelException jme) {
303
            AnnotationsCorePlugin.log(jme.getStatus());
304
        }
305
        return enumName;
306
    }
307
308
    /**
270
     * Creates a new {@link TypeLiteral}.
309
     * Creates a new {@link TypeLiteral}.
271
     *
310
     *
272
     * @param ast the {@link AST} that will be used to create the {@link TypeLiteral}.
311
     * @param ast the {@link AST} that will be used to create the {@link TypeLiteral}.
(-)src/org/eclipse/jst/ws/annotations/core/AnnotationsManager.java (-30 / +64 lines)
Lines 68-76 Link Here
68
    private static final String ATT_NAME = "name"; //$NON-NLS-1$
68
    private static final String ATT_NAME = "name"; //$NON-NLS-1$
69
    private static final String ATT_CATEGORY = "category"; //$NON-NLS-1$
69
    private static final String ATT_CATEGORY = "category"; //$NON-NLS-1$
70
70
71
    //	private static final String ELEM_TARGET_FILTER = "targetFilter"; //$NON-NLS-1$
72
    //	private static final String ATT_TARGET = "target"; //$NON-NLS-1$
73
74
    private AnnotationsManager() {
71
    private AnnotationsManager() {
75
    }
72
    }
76
73
Lines 102-107 Link Here
102
    }
99
    }
103
100
104
    /**
101
    /**
102
     * Returns a list of all the contributed annotations that target the given {@link org.eclipse.jdt.core.IJavaElement}.
103
     *
104
     * @param element one of
105
     * <li>org.eclipse.jdt.core.IPackageDeclaration</li>
106
     * <li>org.eclipse.jdt.core.IType</li>
107
     * <li>org.eclipse.jdt.core.IField</li>
108
     * <li>org.eclipse.jdt.core.IMethod</li>
109
     * <li>org.eclipse.jdt.core.ILocalVariable</li>
110
     *
111
     * @return a list of types which represent annotation types.
112
     * @since 1.1
113
     */
114
    public static List<IType> getAnnotationTypes(IJavaElement javaElement) {
115
        List<IType> annotations = new ArrayList<IType>();
116
117
        try {
118
            List<AnnotationDefinition> annotationDefinitions = getAllAnnotationsForElement(javaElement);
119
120
            filterAnnotationsList(javaElement, annotationDefinitions);
121
122
            for (AnnotationDefinition annotationDefinition : annotationDefinitions) {
123
                IType type = annotationDefinition.getAnnotationType();
124
                if (type != null) {
125
                    annotations.add(type);
126
                }
127
            }
128
        } catch (JavaModelException jme) {
129
            AnnotationsCorePlugin.log(jme.getStatus());
130
        }
131
        return annotations;
132
    }
133
134
    /**
105
     * Returns a list of all the contributed {@link java.lang.annotation.Annotation} that target the given java element type.
135
     * Returns a list of all the contributed {@link java.lang.annotation.Annotation} that target the given java element type.
106
     *
136
     *
107
     * @param element one of
137
     * @param element one of
Lines 112-118 Link Here
112
     * <li>org.eclipse.jdt.core.ILocalVariable</li>
142
     * <li>org.eclipse.jdt.core.ILocalVariable</li>
113
     *
143
     *
114
     * @return a list of annotations.
144
     * @return a list of annotations.
145
     * @deprecated As of 1.1 replaced by {@link #getAnnotationTypes(IJavaElement)}}
115
     */
146
     */
147
    @Deprecated
116
    public static List<Class<? extends Annotation>> getAnnotations(IJavaElement javaElement) {
148
    public static List<Class<? extends Annotation>> getAnnotations(IJavaElement javaElement) {
117
        List<Class<? extends Annotation>> annotations = new ArrayList<Class<? extends Annotation>>();
149
        List<Class<? extends Annotation>> annotations = new ArrayList<Class<? extends Annotation>>();
118
150
Lines 131-147 Link Here
131
    }
163
    }
132
164
133
    private static synchronized Map<String, AnnotationDefinition> getAnnotationToClassNameDefinitionMap() {
165
    private static synchronized Map<String, AnnotationDefinition> getAnnotationToClassNameDefinitionMap() {
134
135
        if (annotationClassNameToDefinitionMap == null) {
166
        if (annotationClassNameToDefinitionMap == null) {
136
            List<AnnotationDefinition> annotationDefinitions = getAnnotations();
167
            List<AnnotationDefinition> annotationDefinitions = getAnnotations();
137
168
138
            annotationClassNameToDefinitionMap = new HashMap<String, AnnotationDefinition>();
169
            annotationClassNameToDefinitionMap = new HashMap<String, AnnotationDefinition>();
139
170
140
            for (AnnotationDefinition annotationDefinition : annotationDefinitions) {
171
            for (AnnotationDefinition annotationDefinition : annotationDefinitions) {
141
            	if (annotationDefinition.getAnnotationClass() != null) {
172
                if (annotationDefinition.getAnnotationClassName() != null) {
142
                    annotationClassNameToDefinitionMap.put(annotationDefinition.getAnnotationClass()
173
                    annotationClassNameToDefinitionMap.put(annotationDefinition.getAnnotationClassName(), annotationDefinition);
143
                            .getCanonicalName(), annotationDefinition);
174
                }
144
            	}
145
            }
175
            }
146
        }
176
        }
147
        return annotationClassNameToDefinitionMap;
177
        return annotationClassNameToDefinitionMap;
Lines 195-200 Link Here
195
    }
225
    }
196
226
197
    /**
227
    /**
228
     * Returns the {@link AnnotationDefinition} for the given {@link org.eclipse.jdt.core.IType}
229
     * or null if no annotation definition can be found.
230
     *
231
     * @param annotationType an <code>org.eclipse.jdt.core.IType</code> which represents an annotation type.
232
     * @return the annotation definition for the <code>org.eclipse.jdt.core.IType</code>.
233
     * @since 1.1
234
     */
235
    public static AnnotationDefinition getAnnotationDefinitionForType(IType annotationType) {
236
        return getAnnotationToClassNameDefinitionMap().get(annotationType.getFullyQualifiedName());
237
    }
238
239
    /**
198
     * Returns the {@link IAnnotationAttributeInitializer} for the given {@link org.eclipse.jdt.core.dom.Name}
240
     * Returns the {@link IAnnotationAttributeInitializer} for the given {@link org.eclipse.jdt.core.dom.Name}
199
     * or null if none can be found.
241
     * or null if none can be found.
200
     * @param name a {@link SimpleName} or {@link QualifiedName} for the annotation to search for.
242
     * @param name a {@link SimpleName} or {@link QualifiedName} for the annotation to search for.
Lines 254-260 Link Here
254
        if (annotationCategoryCache != null) {
296
        if (annotationCategoryCache != null) {
255
            return annotationCategoryCache;
297
            return annotationCategoryCache;
256
        }
298
        }
257
258
        annotationCategoryCache = new HashMap<String, String>();
299
        annotationCategoryCache = new HashMap<String, String>();
259
300
260
        IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(
301
        IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(
Lines 274-280 Link Here
274
        if (annotationInitializerCache != null) {
315
        if (annotationInitializerCache != null) {
275
            return annotationInitializerCache;
316
            return annotationInitializerCache;
276
        }
317
        }
277
278
        annotationInitializerCache = new HashMap<String, IConfigurationElement>();
318
        annotationInitializerCache = new HashMap<String, IConfigurationElement>();
279
319
280
        IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(
320
        IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(
Lines 326-366 Link Here
326
        return ""; //$NON-NLS-1$
366
        return ""; //$NON-NLS-1$
327
    }
367
    }
328
368
329
    private static List<AnnotationDefinition> getAllAnnotationsForElement(IJavaElement javaElement)
369
    private static List<AnnotationDefinition> getAllAnnotationsForElement(IJavaElement javaElement) throws JavaModelException {
330
    throws JavaModelException {
331
332
        if (javaElement instanceof IPackageDeclaration) {
370
        if (javaElement instanceof IPackageDeclaration) {
333
            return getAnnotationsForElementType(ElementType.PACKAGE);
371
            return getAnnotationsForElementType(javaElement, ElementType.PACKAGE);
334
        }
372
        }
335
373
336
        if (javaElement instanceof IType) {
374
        if (javaElement instanceof IType) {
337
            IType type = (IType) javaElement;
375
            IType type = (IType) javaElement;
338
            if (type.isAnnotation()) {
376
            if (type.isAnnotation()) {
339
                return getAnnotationsForElementType(ElementType.ANNOTATION_TYPE);
377
                return getAnnotationsForElementType(javaElement, ElementType.ANNOTATION_TYPE);
340
            }
378
            }
341
            return getAnnotationsForElementType(ElementType.TYPE);
379
            return getAnnotationsForElementType(javaElement, ElementType.TYPE);
342
        }
380
        }
343
381
344
        if (javaElement instanceof IField) {
382
        if (javaElement instanceof IField) {
345
            return getAnnotationsForElementType(ElementType.FIELD);
383
            return getAnnotationsForElementType(javaElement, ElementType.FIELD);
346
        }
384
        }
347
385
348
        if (javaElement instanceof IMethod) {
386
        if (javaElement instanceof IMethod) {
349
            return getAnnotationsForElementType(ElementType.METHOD);
387
            return getAnnotationsForElementType(javaElement, ElementType.METHOD);
350
        }
388
        }
351
389
352
        if (javaElement instanceof ILocalVariable) {
390
        if (javaElement instanceof ILocalVariable) {
353
            return getAnnotationsForElementType(ElementType.PARAMETER);
391
            return getAnnotationsForElementType(javaElement, ElementType.PARAMETER);
354
        }
392
        }
355
393
356
        if (javaElement instanceof IAnnotation) {
394
        if (javaElement instanceof IAnnotation) {
357
            return getAnnotationsForElementType(ElementType.ANNOTATION_TYPE);
395
            return getAnnotationsForElementType(javaElement, ElementType.ANNOTATION_TYPE);
358
        }
396
        }
359
397
360
        return Collections.emptyList();
398
        return Collections.emptyList();
361
    }
399
    }
362
400
363
    private static List<AnnotationDefinition> getAnnotationsForElementType(ElementType elementType) {
401
    private static List<AnnotationDefinition> getAnnotationsForElementType(IJavaElement javaElement, ElementType elementType) {
364
        List<AnnotationDefinition> annotationDefinitions = new ArrayList<AnnotationDefinition>();
402
        List<AnnotationDefinition> annotationDefinitions = new ArrayList<AnnotationDefinition>();
365
403
366
        if (annotationCache == null) {
404
        if (annotationCache == null) {
Lines 368-375 Link Here
368
        }
406
        }
369
407
370
        for (AnnotationDefinition annotationDefinition : annotationCache) {
408
        for (AnnotationDefinition annotationDefinition : annotationCache) {
371
            if (annotationDefinition.getTargets().contains(elementType) &&
409
            annotationDefinition.setJavaProject(javaElement.getJavaProject());
372
                    !isDeprecated(annotationDefinition)) {
410
411
            if (annotationDefinition.getAnnotationTypeTargets().contains(elementType) &&
412
                    !annotationDefinition.isDeprecated()) {
373
                annotationDefinitions.add(annotationDefinition);
413
                annotationDefinitions.add(annotationDefinition);
374
            }
414
            }
375
        }
415
        }
Lines 396-402 Link Here
396
                    annotationIter.remove();
436
                    annotationIter.remove();
397
                }
437
                }
398
                if (method.isConstructor()
438
                if (method.isConstructor()
399
                        && !annotationDefinition.getTargets().contains(ElementType.CONSTRUCTOR)) {
439
                        && !annotationDefinition.getAnnotationTypeTargets().contains(ElementType.CONSTRUCTOR)) {
400
                    annotationIter.remove();
440
                    annotationIter.remove();
401
                }
441
                }
402
442
Lines 464-473 Link Here
464
        }
504
        }
465
        return false;
505
        return false;
466
    }
506
    }
467
468
    //TODO Move the Deprecated option to preferences
469
    private static boolean isDeprecated(AnnotationDefinition annotationDefinition) {
470
        Class<?> annotationClass = annotationDefinition.getAnnotationClass();
471
        return annotationClass.getAnnotation(java.lang.Deprecated.class) != null;
472
    }
473
}
507
}
(-)src/org/eclipse/jst/ws/annotations/core/initialization/AnnotationAttributeInitializer.java (-52 / +59 lines)
Lines 15-20 Link Here
15
import java.util.List;
15
import java.util.List;
16
16
17
import org.eclipse.jdt.core.IJavaElement;
17
import org.eclipse.jdt.core.IJavaElement;
18
import org.eclipse.jdt.core.IType;
18
import org.eclipse.jdt.core.dom.AST;
19
import org.eclipse.jdt.core.dom.AST;
19
import org.eclipse.jdt.core.dom.Expression;
20
import org.eclipse.jdt.core.dom.Expression;
20
import org.eclipse.jdt.core.dom.MemberValuePair;
21
import org.eclipse.jdt.core.dom.MemberValuePair;
Lines 40-98 Link Here
40
 */
41
 */
41
public abstract class AnnotationAttributeInitializer implements IAnnotationAttributeInitializer {
42
public abstract class AnnotationAttributeInitializer implements IAnnotationAttributeInitializer {
42
43
43
    protected static final String MISSING_IDENTIFER = "$missing$";
44
	protected static final String MISSING_IDENTIFER = "$missing$";
44
45
45
    protected AnnotationAttributeInitializer() {
46
	protected AnnotationAttributeInitializer() {
47
	}
46
48
47
    }
49
	/* (non-Javadoc)
48
50
	 * @see org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer#getMemberValuePairs(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.dom.AST, java.lang.Class)
49
    /* (non-Javadoc)
51
	 */
50
     * @see org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer#getMemberValuePairs(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.dom.AST, java.lang.Class)
52
	@Deprecated
51
     */
53
	public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast,  Class<? extends Annotation> annotationClass) {
52
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast,
54
		return Collections.emptyList();
53
            Class<? extends Annotation> annotationClass) {
55
	}
54
        return Collections.emptyList();
56
55
    }
57
	/**
56
58
	 * @see org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer#getMemberValuePairs(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.dom.AST, java.lang.Class)
57
    /* (non-Javadoc)
59
	 * @since 1.1
58
     * @see org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer#getCompletionProposalsForMemberValuePair(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.dom.MemberValuePair)
60
	 */
59
     */
61
	public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast, IType type) {
60
    public List<ICompletionProposal> getCompletionProposalsForMemberValuePair(IJavaElement javaElement,
62
	    return Collections.emptyList();
61
            MemberValuePair memberValuePair) {
63
    }
62
        return Collections.emptyList();
64
63
    }
65
	/* (non-Javadoc)
64
66
	 * @see org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer#getCompletionProposalsForMemberValuePair(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.dom.MemberValuePair)
65
    /* (non-Javadoc)
67
	 */
66
     * @see org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer#getCompletionProposalsForSingleMemberAnnotation(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.dom.SingleMemberAnnotation)
68
	public List<ICompletionProposal> getCompletionProposalsForMemberValuePair(IJavaElement javaElement,
67
     */
69
			MemberValuePair memberValuePair) {
68
    public List<ICompletionProposal> getCompletionProposalsForSingleMemberAnnotation(IJavaElement javaElement,
70
		return Collections.emptyList();
69
            SingleMemberAnnotation singleMemberAnnotation) {
71
	}
70
        return Collections.emptyList();
72
71
    }
73
	/* (non-Javadoc)
72
74
	 * @see org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer#getCompletionProposalsForSingleMemberAnnotation(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.dom.SingleMemberAnnotation)
73
    protected CompletionProposal createCompletionProposal(String proposal, Expression value) {
75
	 */
74
        Image image = PlatformUI.getWorkbench().getSharedImages().getImage(org.eclipse.ui.ISharedImages.IMG_OBJ_FILE);
76
	public List<ICompletionProposal> getCompletionProposalsForSingleMemberAnnotation(IJavaElement javaElement,
75
        return createCompletionProposal(proposal, value, image, proposal);
77
			SingleMemberAnnotation singleMemberAnnotation) {
76
    }
78
		return Collections.emptyList();
77
79
	}
78
    protected CompletionProposal createCompletionProposal(String proposal, Expression value, Image image,
80
79
            String displayString) {
81
	protected CompletionProposal createCompletionProposal(String proposal, Expression value) {
80
        int replacementOffset = value.getStartPosition();
82
		Image image = PlatformUI.getWorkbench().getSharedImages().getImage(org.eclipse.ui.ISharedImages.IMG_OBJ_FILE);
81
        int replacementLength = 0;
83
		return createCompletionProposal(proposal, value, image, proposal);
82
        if (value.toString().equals(MISSING_IDENTIFER)) {
84
	}
83
            if (proposal.charAt(0) != '\"') {
85
84
                proposal = "\"" + proposal;
86
	protected CompletionProposal createCompletionProposal(String proposal, Expression value, Image image, String displayString) {
85
            }
87
		int replacementOffset = value.getStartPosition();
86
            if (proposal.charAt(proposal.length() - 1) != '\"') {
88
		int replacementLength = 0;
87
                proposal = proposal + "\"";
89
		if (value.toString().equals(MISSING_IDENTIFER)) {
88
            }
90
			if (proposal.charAt(0) != '\"') {
89
        } else {
91
				proposal = "\"" + proposal;
90
            replacementOffset += 1;
92
			}
91
            replacementLength = value.getLength() - 2;
93
			if (proposal.charAt(proposal.length() - 1) != '\"') {
92
        }
94
				proposal = proposal + "\"";
93
95
			}
94
        return new CompletionProposal(proposal, replacementOffset, replacementLength, proposal.length(),
96
		} else {
95
                image, displayString, null, null);
97
			replacementOffset += 1;
96
    }
98
			replacementLength = value.getLength() - 2;
99
		}
100
101
		return new CompletionProposal(proposal, replacementOffset, replacementLength, proposal.length(),
102
				image, displayString, null, null);
103
	}
97
104
98
}
105
}
(-)src/org/eclipse/jst/ws/annotations/core/initialization/DefaultsAnnotationAttributeInitializer.java (-4 / +84 lines)
Lines 15-24 Link Here
15
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.List;
16
import java.util.List;
17
17
18
import org.eclipse.jdt.core.IField;
18
import org.eclipse.jdt.core.IJavaElement;
19
import org.eclipse.jdt.core.IJavaElement;
20
import org.eclipse.jdt.core.IMemberValuePair;
21
import org.eclipse.jdt.core.IMethod;
22
import org.eclipse.jdt.core.IType;
23
import org.eclipse.jdt.core.JavaModelException;
24
import org.eclipse.jdt.core.Signature;
19
import org.eclipse.jdt.core.dom.AST;
25
import org.eclipse.jdt.core.dom.AST;
20
import org.eclipse.jdt.core.dom.MemberValuePair;
26
import org.eclipse.jdt.core.dom.MemberValuePair;
21
import org.eclipse.jst.ws.annotations.core.AnnotationsCore;
27
import org.eclipse.jst.ws.annotations.core.AnnotationsCore;
28
import org.eclipse.jst.ws.annotations.core.AnnotationsCorePlugin;
29
import org.eclipse.jst.ws.internal.annotations.core.utils.SignatureUtils;
22
30
23
/**
31
/**
24
 * Constructs {@link MemberValuePair} from the defaults found in the given {@link java.lang.annotation.Annotation}.
32
 * Constructs {@link MemberValuePair} from the defaults found in the given {@link java.lang.annotation.Annotation}.
Lines 40-52 Link Here
40
     *  @see org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer#getMemberValuePairs(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.dom.AST, java.lang.Class)
48
     *  @see org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer#getMemberValuePairs(org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.dom.AST, java.lang.Class)
41
     */
49
     */
42
    @Override
50
    @Override
43
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast,
51
    @Deprecated
44
            Class<? extends Annotation> annotationClass) {
52
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast, Class<? extends Annotation> annotationClass) {
45
        return getMemberValuePairs(ast, annotationClass);
53
        return getMemberValuePairs(ast, annotationClass);
46
    }
54
    }
47
55
48
    private List<MemberValuePair> getMemberValuePairs(AST ast,
56
    @Override
49
            Class<? extends Annotation> annotationClass) {
57
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast, IType type) {
58
        return interalGetMemberValuePairs(javaElement, ast, type);
59
    }
60
61
    private List<MemberValuePair> interalGetMemberValuePairs(IJavaElement javaElement, AST ast, IType type) {
62
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
63
64
        try {
65
            IMethod[] methods = type.getMethods();
66
            for (IMethod method : methods) {
67
                String name = method.getElementName();
68
                String returnType = method.getReturnType();
69
                IMemberValuePair defaultValue = method.getDefaultValue();
70
                if (defaultValue != null) {
71
                    if (SignatureUtils.isString(returnType)) {
72
                        memberValuePairs.add(AnnotationsCore.createStringMemberValuePair(ast,
73
                                name, defaultValue.getValue().toString()));
74
                    }
75
76
                    if (SignatureUtils.isBoolean(returnType)) {
77
                        memberValuePairs.add(AnnotationsCore.createBooleanMemberValuePair(ast,
78
                                name, Boolean.parseBoolean(defaultValue.getValue().toString())));
79
                    }
80
81
                    int signatureKind = Signature.getTypeSignatureKind(returnType);
82
                    if (signatureKind == Signature.BASE_TYPE_SIGNATURE) {
83
                        if (returnType.charAt(0) == Signature.C_BYTE
84
                                || returnType.charAt(0) == Signature.C_SHORT
85
                                || returnType.charAt(0) == Signature.C_INT
86
                                || returnType.charAt(0) == Signature.C_LONG
87
                                || returnType.charAt(0) == Signature.C_FLOAT
88
                                || returnType.charAt(0) == Signature.C_DOUBLE) {
89
                            memberValuePairs.add(AnnotationsCore.createNumberMemberValuePair(ast, name, defaultValue.getValue().toString()));
90
                        }
91
                    }
92
93
                    if (SignatureUtils.isArray(returnType)) {
94
                        memberValuePairs.add(AnnotationsCore.createArrayMemberValuePair(ast, method.getElementName(),
95
                                (Object[]) defaultValue.getValue()));
96
                    }
97
98
                    if (SignatureUtils.isEnum(method)) {
99
                        if (defaultValue.getValueKind() == IMemberValuePair.K_QUALIFIED_NAME) {
100
                            String value = defaultValue.getValue().toString();
101
                            String enumName = value.substring(0, value.lastIndexOf("."));
102
                            String constant = value.substring(value.lastIndexOf(".") + 1, value.length());
103
                            IType enumType = javaElement.getJavaProject().findType(enumName);
104
                            if (enumType != null && enumType.isEnum()) {
105
                                IField[] fields = enumType.getFields();
106
                                for (IField field : fields) {
107
                                    if (field.isEnumConstant() && field.getElementName().equals(constant)) {
108
                                        memberValuePairs.add(AnnotationsCore.createEnumMemberValuePair(ast,
109
                                                method.getDeclaringType().getFullyQualifiedName(), name, field));
110
                                    }
111
                                }
112
                            }
113
                        }
114
                    }
115
116
                    if (SignatureUtils.isClass(returnType)) {
117
                        memberValuePairs.add(AnnotationsCore.createTypeMemberValuePair(ast, name,
118
                                defaultValue.getValue()));
119
                    }
120
                }
121
            }
122
        } catch (JavaModelException jme) {
123
            AnnotationsCorePlugin.log(jme.getStatus());
124
        }
125
126
        return memberValuePairs;
127
    }
128
129
    private List<MemberValuePair> getMemberValuePairs(AST ast, Class<? extends Annotation> annotationClass) {
50
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
130
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
51
131
52
        Method[] declaredMethods = annotationClass.getDeclaredMethods();
132
        Method[] declaredMethods = annotationClass.getDeclaredMethods();
(-)src/org/eclipse/jst/ws/annotations/core/initialization/IAnnotationAttributeInitializer.java (+13 lines)
Lines 13-18 Link Here
13
import java.util.List;
13
import java.util.List;
14
14
15
import org.eclipse.jdt.core.IJavaElement;
15
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.core.IType;
16
import org.eclipse.jdt.core.dom.AST;
17
import org.eclipse.jdt.core.dom.AST;
17
import org.eclipse.jdt.core.dom.MemberValuePair;
18
import org.eclipse.jdt.core.dom.MemberValuePair;
18
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
19
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
Lines 38-48 Link Here
38
     * @param annotationClass the {@link java.lang.annotation.Annotation} class which may be
39
     * @param annotationClass the {@link java.lang.annotation.Annotation} class which may be
39
     * used to query the declared members of the annotation type and the members default values.
40
     * used to query the declared members of the annotation type and the members default values.
40
     * @return a list of member value pairs.
41
     * @return a list of member value pairs.
42
     * @deprecated as of 1.1 replaced by {@link IAnnotationAttributeInitializer2#getMemberValuePairs(IJavaElement, AST, IType)}
41
     */
43
     */
44
    @Deprecated
42
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast,
45
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast,
43
            Class<? extends java.lang.annotation.Annotation> annotationClass);
46
            Class<? extends java.lang.annotation.Annotation> annotationClass);
44
47
45
    /**
48
    /**
49
     * Returns a list of {@link MemberValuePair} that may be added to a {@link NormalAnnotation}.
50
     * @param javaElement the java element on which the annotation is declared.
51
     * @param ast the <code>AST</code> with which to create the member value pairs.
52
     * @param type the {@link org.eclipse.jdt.core.IType} which represents an annotation type,.
53
     * @return a list of member value pairs.
54
     * @since 1.1
55
     */
56
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast, IType type);
57
58
    /**
46
     * Used to provide a list of {@link ICompletionProposal} for a {@link MemberValuePair} value.
59
     * Used to provide a list of {@link ICompletionProposal} for a {@link MemberValuePair} value.
47
     * @param javaElement the java element on which the annotation is declared.
60
     * @param javaElement the java element on which the annotation is declared.
48
     * @param memberValuePair the member value pair in which content assist was invoked.
61
     * @param memberValuePair the member value pair in which content assist was invoked.
(-)src/org/eclipse/jst/ws/annotations/core/utils/AnnotationUtils.java (-1 / +2 lines)
Lines 317-325 Link Here
317
        final String annotationSimpleName = qualifiedName.substring(qualifiedName.lastIndexOf(".") + 1);
317
        final String annotationSimpleName = qualifiedName.substring(qualifiedName.lastIndexOf(".") + 1);
318
        final List<String> occurences = new ArrayList<String>();
318
        final List<String> occurences = new ArrayList<String>();
319
        AnnotationDefinition annotationDefinition = AnnotationsManager.getAnnotationDefinitionForClass(qualifiedName);
319
        AnnotationDefinition annotationDefinition = AnnotationsManager.getAnnotationDefinitionForClass(qualifiedName);
320
        annotationDefinition.setJavaProject(javaElement.getJavaProject());
320
        List<ElementType> elementTypes = Collections.emptyList();
321
        List<ElementType> elementTypes = Collections.emptyList();
321
        if (annotationDefinition != null) {
322
        if (annotationDefinition != null) {
322
            elementTypes = annotationDefinition.getTargets();
323
            elementTypes = annotationDefinition.getAnnotationTypeTargets();
323
        }
324
        }
324
        for (ElementType elementType : elementTypes) {
325
        for (ElementType elementType : elementTypes) {
325
            if (elementType == ElementType.PACKAGE) {
326
            if (elementType == ElementType.PACKAGE) {
(-)src/org/eclipse/jst/ws/internal/annotations/core/utils/SignatureUtils.java (+124 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Shane Clarke.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Shane Clarke - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jst.ws.internal.annotations.core.utils;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.jdt.core.IField;
17
import org.eclipse.jdt.core.IMethod;
18
import org.eclipse.jdt.core.IType;
19
import org.eclipse.jdt.core.JavaModelException;
20
import org.eclipse.jdt.core.Signature;
21
22
public final class SignatureUtils {
23
24
    private SignatureUtils() {
25
    }
26
27
    public static boolean isString(String returnType) {
28
        int signatureKind = Signature.getTypeSignatureKind(returnType);
29
        if (signatureKind == Signature.CLASS_TYPE_SIGNATURE) {
30
            if (returnType.charAt(0) == Signature.C_RESOLVED) {
31
                return Signature.toString(returnType).equals(java.lang.String.class.getCanonicalName());
32
            }
33
            if (returnType.charAt(0) == Signature.C_UNRESOLVED) {
34
                return Signature.toString(returnType).equals(java.lang.String.class.getSimpleName());
35
            }
36
        }
37
        return false;
38
    }
39
40
    public static boolean isClass(String returnType) {
41
        int signatureKind = Signature.getTypeSignatureKind(returnType);
42
        if (signatureKind == Signature.CLASS_TYPE_SIGNATURE) {
43
            if (returnType.charAt(0) == Signature.C_RESOLVED) {
44
                returnType = Signature.getTypeErasure(returnType);
45
                return Signature.toString(returnType).equals(java.lang.Class.class.getCanonicalName());
46
            }
47
            if (returnType.charAt(0) == Signature.C_UNRESOLVED) {
48
                returnType = Signature.getTypeErasure(returnType);
49
                return Signature.toString(returnType).equals(java.lang.Class.class.getSimpleName());
50
            }
51
        }
52
        return false;
53
    }
54
55
    public static boolean isBoolean(String returnType) {
56
        int signatureKind = Signature.getTypeSignatureKind(returnType);
57
        if (signatureKind == Signature.CLASS_TYPE_SIGNATURE) {
58
            if (returnType.charAt(0) == Signature.C_RESOLVED) {
59
                return Signature.toString(returnType).equals(java.lang.Boolean.class.getCanonicalName());
60
            }
61
            if (returnType.charAt(0) == Signature.C_UNRESOLVED) {
62
                return Signature.toString(returnType).equals(java.lang.Boolean.class.getSimpleName());
63
            }
64
        }
65
        if (signatureKind == Signature.BASE_TYPE_SIGNATURE) {
66
            return returnType.charAt(0) == Signature.C_BOOLEAN;
67
        }
68
        return false;
69
    }
70
71
    public static boolean isArray(String returnType) {
72
        return Signature.getTypeSignatureKind(returnType) == Signature.ARRAY_TYPE_SIGNATURE;
73
    }
74
75
    public static boolean isPrimitive(String returnType) {
76
        return Signature.getTypeSignatureKind(returnType) == Signature.BASE_TYPE_SIGNATURE;
77
    }
78
79
    public static boolean isEnum(IMethod method) throws JavaModelException {
80
        return getEnumReturnType(method) != null;
81
    }
82
83
    public static IType getEnumReturnType(IMethod method) throws JavaModelException {
84
        String returnType = method.getReturnType();
85
        int signatureKind = Signature.getTypeSignatureKind(returnType);
86
        if (signatureKind == Signature.CLASS_TYPE_SIGNATURE) {
87
            if (returnType.charAt(0) == Signature.C_RESOLVED) {
88
                IType type = method.getJavaProject().findType(Signature.toString(returnType));
89
                if (type != null && type.isEnum()) {
90
                    return type;
91
                }
92
            }
93
        }
94
        return null;
95
    }
96
97
    public static String[] getEnumConstantsNames(IType enumType) throws JavaModelException {
98
        if (enumType.isEnum()) {
99
            List<String> enumConstants = new ArrayList<String>();
100
            IField[] fields = getEnumConstants(enumType);
101
            for (IField field : fields) {
102
                enumConstants.add(field.getElementName());
103
            }
104
            return enumConstants.toArray(new String[enumConstants.size()]);
105
        }
106
        return new String[] {};
107
    }
108
109
    public static IField[] getEnumConstants(IType enumType) throws JavaModelException {
110
        if (enumType.isEnum()) {
111
            List<IField> enumConstants = new ArrayList<IField>();
112
            IField[] fields = enumType.getFields();
113
            for (IField field : fields) {
114
                if (field.isEnumConstant()) {
115
                    enumConstants.add(field);
116
                }
117
            }
118
            return enumConstants.toArray(new IField[enumConstants.size()]);
119
        }
120
        return new IField[] {};
121
    }
122
123
124
}
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 46-52 Link Here
46
 org.eclipse.ui.console;bundle-version="[3.3.0,4.0.0)",
46
 org.eclipse.ui.console;bundle-version="[3.3.0,4.0.0)",
47
 org.eclipse.emf.ecore;bundle-version="[2.4.0,3.0.0)",
47
 org.eclipse.emf.ecore;bundle-version="[2.4.0,3.0.0)",
48
 org.eclipse.jdt.apt.core;bundle-version="[3.3.100,4.0.0)",
48
 org.eclipse.jdt.apt.core;bundle-version="[3.3.100,4.0.0)",
49
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.1.0)",
49
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.2.0)",
50
 org.eclipse.jst.ws.jaxws.core;bundle-version="[1.0.0,1.1.0)",
50
 org.eclipse.jst.ws.jaxws.core;bundle-version="[1.0.0,1.1.0)",
51
 org.eclipse.wst.command.env.core;bundle-version="[1.0.204,1.1.0)",
51
 org.eclipse.wst.command.env.core;bundle-version="[1.0.204,1.1.0)",
52
 javax.jws;bundle-version="[2.0.0,2.1.0)",
52
 javax.jws;bundle-version="[2.0.0,2.1.0)",
(-)src/org/eclipse/jst/ws/internal/cxf/core/utils/CXFModelUtils.java (-8 / +10 lines)
Lines 40-45 Link Here
40
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
40
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
41
import org.eclipse.jdt.ui.CodeStyleConfiguration;
41
import org.eclipse.jdt.ui.CodeStyleConfiguration;
42
import org.eclipse.jdt.ui.SharedASTProvider;
42
import org.eclipse.jdt.ui.SharedASTProvider;
43
import org.eclipse.jst.ws.annotations.core.AnnotationDefinition;
43
import org.eclipse.jst.ws.annotations.core.AnnotationsCore;
44
import org.eclipse.jst.ws.annotations.core.AnnotationsCore;
44
import org.eclipse.jst.ws.annotations.core.AnnotationsManager;
45
import org.eclipse.jst.ws.annotations.core.AnnotationsManager;
45
import org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer;
46
import org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer;
Lines 124-136 Link Here
124
        } else {
125
        } else {
125
            List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
126
            List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
126
127
127
            IAnnotationAttributeInitializer annotationAttributeInitializer =
128
            AnnotationDefinition annotationDefinition = AnnotationsManager.getAnnotationDefinitionForClass(WebService.class.getCanonicalName());
128
                AnnotationsManager.getAnnotationDefinitionForClass(WebService.class).
129
            IAnnotationAttributeInitializer annotationAttributeInitializer = annotationDefinition.getAnnotationAttributeInitializer();
129
                getAnnotationAttributeInitializer();
130
130
131
            IType annotationType = annotationDefinition.getAnnotationType();
131
            if (annotationAttributeInitializer != null) {
132
            if (annotationAttributeInitializer != null) {
132
                memberValuePairs = annotationAttributeInitializer.getMemberValuePairs(type, ast,
133
                memberValuePairs = annotationAttributeInitializer.getMemberValuePairs(type, ast, annotationType);
133
                        WebService.class);
134
            }
134
            }
135
135
136
            if (model.isUseServiceEndpointInterface() && type.isClass()) {
136
            if (model.isUseServiceEndpointInterface() && type.isClass()) {
Lines 218-228 Link Here
218
218
219
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
219
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
220
220
221
        IAnnotationAttributeInitializer annotationAttributeInitializer = AnnotationsManager
221
        AnnotationDefinition annotationDefinition = AnnotationsManager.getAnnotationDefinitionForClass(annotationClass.getCanonicalName());
222
        .getAnnotationDefinitionForClass(annotationClass).getAnnotationAttributeInitializer();
222
        IAnnotationAttributeInitializer annotationAttributeInitializer = annotationDefinition.getAnnotationAttributeInitializer();
223
224
        IType annotationType = annotationDefinition.getAnnotationType();
223
225
224
        if (annotationAttributeInitializer != null) {
226
        if (annotationAttributeInitializer != null) {
225
            memberValuePairs = annotationAttributeInitializer.getMemberValuePairs(javaElement, ast, annotationClass);
227
            memberValuePairs = annotationAttributeInitializer.getMemberValuePairs(javaElement, ast, annotationType);
226
        }
228
        }
227
229
228
        return AnnotationsCore.createNormalAnnotation(ast, annotationClass.getSimpleName(), memberValuePairs);
230
        return AnnotationsCore.createNormalAnnotation(ast, annotationClass.getSimpleName(), memberValuePairs);
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 23-29 Link Here
23
 org.eclipse.jst.j2ee;bundle-version="[1.1.100,1.2.0)",
23
 org.eclipse.jst.j2ee;bundle-version="[1.1.100,1.2.0)",
24
 org.eclipse.jst.j2ee.core;bundle-version="[1.1.0,1.3.0)",
24
 org.eclipse.jst.j2ee.core;bundle-version="[1.1.0,1.3.0)",
25
 org.eclipse.text;bundle-version="[3.4.0,4.0.0)",
25
 org.eclipse.text;bundle-version="[3.4.0,4.0.0)",
26
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.1.0)",
26
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.2.0)",
27
 org.eclipse.jst.ws.jaxws.core;bundle-version="[1.0.0,1.1.0)",
27
 org.eclipse.jst.ws.jaxws.core;bundle-version="[1.0.0,1.1.0)",
28
 org.eclipse.emf.ecore;bundle-version="[2.4.0,3.0.0)",
28
 org.eclipse.emf.ecore;bundle-version="[2.4.0,3.0.0)",
29
 org.eclipse.jem;bundle-version="[2.0.0,2.1.0)",
29
 org.eclipse.jem;bundle-version="[2.0.0,2.1.0)",
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 29-35 Link Here
29
 org.eclipse.jst.ws.creation.ui;bundle-version="[1.0.305,1.1.0)",
29
 org.eclipse.jst.ws.creation.ui;bundle-version="[1.0.305,1.1.0)",
30
 org.eclipse.jst.ws;bundle-version="[1.0.304,1.1.0)",
30
 org.eclipse.jst.ws;bundle-version="[1.0.304,1.1.0)",
31
 org.eclipse.ltk.core.refactoring;bundle-version="[3.4.0,4.0.0)",
31
 org.eclipse.ltk.core.refactoring;bundle-version="[3.4.0,4.0.0)",
32
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.1.0)",
32
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.2.0)",
33
 org.eclipse.jst.ws.jaxws.core;bundle-version="[1.0.0,1.1.0)",
33
 org.eclipse.jst.ws.jaxws.core;bundle-version="[1.0.0,1.1.0)",
34
 org.eclipse.emf.common;bundle-version="[2.4.0,3.0.0)",
34
 org.eclipse.emf.common;bundle-version="[2.4.0,3.0.0)",
35
 javax.wsdl;bundle-version="[1.6.2,1.7.0)",
35
 javax.wsdl;bundle-version="[1.6.2,1.7.0)",
(-)META-INF/MANIFEST.MF (-5 / +2 lines)
Lines 6-16 Link Here
6
Bundle-Version: 1.0.0.qualifier
6
Bundle-Version: 1.0.0.qualifier
7
Bundle-ClassPath: .
7
Bundle-ClassPath: .
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
9
Eclipse-RegisterBuddy: org.eclipse.jst.ws.annotations.core
10
Bundle-RequiredExecutionEnvironment: J2SE-1.5
9
Bundle-RequiredExecutionEnvironment: J2SE-1.5
11
Bundle-Activator: org.eclipse.jst.ws.internal.jaxb.core.JAXBCorePlugin
10
Bundle-Activator: org.eclipse.jst.ws.internal.jaxb.core.JAXBCorePlugin
12
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)"
11
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
13
Export-Package: org.eclipse.jst.ws.internal.jaxb.core
12
 org.eclipse.jst.ws.annotations.core;bundle-version="1.1.0"
14
Import-Package: javax.xml.bind.annotation;version="[2.1.0,2.2.0)",
15
 javax.xml.bind.annotation.adapters;version="[2.1.0,2.2.0)"
16
Bundle-ActivationPolicy: lazy
13
Bundle-ActivationPolicy: lazy
(-)plugin.xml (-10 / +1 lines)
Lines 17-31 Link Here
17
            category="jaxb.category"
17
            category="jaxb.category"
18
            class="javax.xml.bind.annotation.XmlAccessorType"
18
            class="javax.xml.bind.annotation.XmlAccessorType"
19
            name="XmlAccessorType"/>
19
            name="XmlAccessorType"/>
20
      
21
      <!-- TODO Reinstate when XmlAdapter issue is solved
22
      <annotation
23
            category="jaxb.category"
24
            class="javax.xml.bind.annotation.adapters.XmlAdapter"
25
            name="XmlAdapter">
26
      </annotation>
27
      -->
28
      
29
      <annotation
20
      <annotation
30
            category="jaxb.category"
21
            category="jaxb.category"
31
            class="javax.xml.bind.annotation.XmlAnyAttribute"
22
            class="javax.xml.bind.annotation.XmlAnyAttribute"
Lines 177-181 Link Here
177
            name="XmlValue">
168
            name="XmlValue">
178
      </annotation>
169
      </annotation>
179
   </extension>
170
   </extension>
180
   
171
181
</plugin>
172
</plugin>
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 14-20 Link Here
14
 org.eclipse.jdt.launching;bundle-version="[3.4.0,4.0.0)",
14
 org.eclipse.jdt.launching;bundle-version="[3.4.0,4.0.0)",
15
 org.eclipse.ltk.core.refactoring;bundle-version="[3.4.0,4.0.0)",
15
 org.eclipse.ltk.core.refactoring;bundle-version="[3.4.0,4.0.0)",
16
 org.eclipse.ltk.ui.refactoring;bundle-version="[3.4.0,4.0.0)",
16
 org.eclipse.ltk.ui.refactoring;bundle-version="[3.4.0,4.0.0)",
17
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.1.0)",
17
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.2.0)",
18
 org.eclipse.jdt.apt.core;bundle-version="[3.3.100,4.0.0)",
18
 org.eclipse.jdt.apt.core;bundle-version="[3.3.100,4.0.0)",
19
 org.eclipse.text;bundle-version="[3.4.0,4.0.0)",
19
 org.eclipse.text;bundle-version="[3.4.0,4.0.0)",
20
 org.eclipse.jdt.ui;bundle-version="[3.4.0,4.0.0)"
20
 org.eclipse.jdt.ui;bundle-version="[3.4.0,4.0.0)"
(-)META-INF/MANIFEST.MF (-2 / +1 lines)
Lines 6-12 Link Here
6
Bundle-Version: 1.0.100.qualifier
6
Bundle-Version: 1.0.100.qualifier
7
Bundle-ClassPath: .
7
Bundle-ClassPath: .
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
9
Eclipse-RegisterBuddy: org.eclipse.jst.ws.annotations.core
10
Bundle-RequiredExecutionEnvironment: J2SE-1.5
9
Bundle-RequiredExecutionEnvironment: J2SE-1.5
11
Bundle-Activator: org.eclipse.jst.ws.internal.jaxws.core.JAXWSCorePlugin
10
Bundle-Activator: org.eclipse.jst.ws.internal.jaxws.core.JAXWSCorePlugin
12
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
11
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
Lines 14-20 Link Here
14
 org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)",
13
 org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)",
15
 org.eclipse.jdt.apt.core;bundle-version="[3.3.100,4.0.0)",
14
 org.eclipse.jdt.apt.core;bundle-version="[3.3.100,4.0.0)",
16
 org.eclipse.core.filesystem;bundle-version="[1.2.0,2.0.0)",
15
 org.eclipse.core.filesystem;bundle-version="[1.2.0,2.0.0)",
17
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.1.0)",
16
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.2.0)",
18
 javax.wsdl;bundle-version="[1.6.2,1.7.0)",
17
 javax.wsdl;bundle-version="[1.6.2,1.7.0)",
19
 javax.xml.soap;bundle-version="[1.2.0,1.3.0)",
18
 javax.xml.soap;bundle-version="[1.2.0,1.3.0)",
20
 org.apache.xerces;bundle-version="[2.9.0,3.0.0)",
19
 org.apache.xerces;bundle-version="[2.9.0,3.0.0)",
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 14-20 Link Here
14
 org.eclipse.jdt.launching;bundle-version="[3.4.0,4.0.0)",
14
 org.eclipse.jdt.launching;bundle-version="[3.4.0,4.0.0)",
15
 org.eclipse.ltk.core.refactoring;bundle-version="[3.4.0,4.0.0)",
15
 org.eclipse.ltk.core.refactoring;bundle-version="[3.4.0,4.0.0)",
16
 org.eclipse.ltk.ui.refactoring;bundle-version="[3.4.0,4.0.0)",
16
 org.eclipse.ltk.ui.refactoring;bundle-version="[3.4.0,4.0.0)",
17
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.1.0)",
17
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.2.0)",
18
 org.eclipse.jdt.apt.core;bundle-version="[3.3.100,4.0.0)",
18
 org.eclipse.jdt.apt.core;bundle-version="[3.3.100,4.0.0)",
19
 org.eclipse.text;bundle-version="[3.4.0,4.0.0)",
19
 org.eclipse.text;bundle-version="[3.4.0,4.0.0)",
20
 org.eclipse.jdt.ui;bundle-version="[3.4.0,4.0.0)"
20
 org.eclipse.jdt.ui;bundle-version="[3.4.0,4.0.0)"
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 17-23 Link Here
17
 org.eclipse.ltk.core.refactoring;bundle-version="[3.4.0,4.0.0)",
17
 org.eclipse.ltk.core.refactoring;bundle-version="[3.4.0,4.0.0)",
18
 org.eclipse.ui.editors;bundle-version="[3.4.0,4.0.0)",
18
 org.eclipse.ui.editors;bundle-version="[3.4.0,4.0.0)",
19
 org.eclipse.jdt.launching;bundle-version="[3.4.0,4.0.0)",
19
 org.eclipse.jdt.launching;bundle-version="[3.4.0,4.0.0)",
20
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.1.0)",
20
 org.eclipse.jst.ws.annotations.core;bundle-version="[1.0.0,1.2.0)",
21
 org.eclipse.jdt.apt.core;bundle-version="[3.3.100,4.0.0)",
21
 org.eclipse.jdt.apt.core;bundle-version="[3.3.100,4.0.0)",
22
 org.eclipse.jst.ws.jaxws.dom.runtime;bundle-version="[1.0.0,1.1.0)",
22
 org.eclipse.jst.ws.jaxws.dom.runtime;bundle-version="[1.0.0,1.1.0)",
23
 org.eclipse.emf.ecore;bundle-version="[2.4.0,3.0.0)"
23
 org.eclipse.emf.ecore;bundle-version="[2.4.0,3.0.0)"
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/annotations/initialization/BindingTypeAttributeInitializer.java (-4 / +5 lines)
Lines 11-24 Link Here
11
package org.eclipse.jst.ws.internal.jaxws.ui.annotations.initialization;
11
package org.eclipse.jst.ws.internal.jaxws.ui.annotations.initialization;
12
12
13
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.VALUE;
13
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.VALUE;
14
import java.lang.annotation.Annotation;
14
15
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.HashMap;
16
import java.util.HashMap;
17
import java.util.Iterator;
17
import java.util.Iterator;
18
import java.util.List;
18
import java.util.List;
19
import java.util.Map;
19
import java.util.Map;
20
20
import javax.xml.ws.http.HTTPBinding;
21
import javax.xml.ws.http.HTTPBinding;
21
import javax.xml.ws.soap.SOAPBinding;
22
import javax.xml.ws.soap.SOAPBinding;
23
22
import org.eclipse.jdt.core.IJavaElement;
24
import org.eclipse.jdt.core.IJavaElement;
23
import org.eclipse.jdt.core.IType;
25
import org.eclipse.jdt.core.IType;
24
import org.eclipse.jdt.core.dom.AST;
26
import org.eclipse.jdt.core.dom.AST;
Lines 49-58 Link Here
49
        JAXWSUIPlugin.getDefault().getImageRegistry().put(HTTP_BINDING,
51
        JAXWSUIPlugin.getDefault().getImageRegistry().put(HTTP_BINDING,
50
                JAXWSUIPlugin.getImageDescriptor("icons/obj16/httpbinding_obj.gif").createImage()); //$NON-NLS-1$
52
                JAXWSUIPlugin.getImageDescriptor("icons/obj16/httpbinding_obj.gif").createImage()); //$NON-NLS-1$
51
    }
53
    }
52
54
    
53
    @Override
55
    @Override
54
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast,
56
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast, IType annotationType) {
55
            Class<? extends Annotation> annotationClass) {
56
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
57
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
57
        if (javaElement.getElementType() == IJavaElement.TYPE) {
58
        if (javaElement.getElementType() == IJavaElement.TYPE) {
58
            MemberValuePair value = AnnotationsCore.createStringMemberValuePair(ast, VALUE, getDefault()); //$NON-NLS-1$
59
            MemberValuePair value = AnnotationsCore.createStringMemberValuePair(ast, VALUE, getDefault()); //$NON-NLS-1$
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/annotations/initialization/RequestWrapperAttributeInitializer.java (-4 / +2 lines)
Lines 17-23 Link Here
17
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.OPERATION_NAME;
17
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.OPERATION_NAME;
18
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.TARGET_NAMESPACE;
18
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.TARGET_NAMESPACE;
19
19
20
import java.lang.annotation.Annotation;
21
import java.util.ArrayList;
20
import java.util.ArrayList;
22
import java.util.List;
21
import java.util.List;
23
22
Lines 40-49 Link Here
40
import org.eclipse.jst.ws.jaxws.core.utils.JDTUtils;
39
import org.eclipse.jst.ws.jaxws.core.utils.JDTUtils;
41
40
42
public class RequestWrapperAttributeInitializer extends AnnotationAttributeInitializer {
41
public class RequestWrapperAttributeInitializer extends AnnotationAttributeInitializer {
43
42
    
44
    @Override
43
    @Override
45
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast,
44
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast, IType annotationType) {
46
            Class<? extends Annotation> annotationClass) {
47
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
45
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
48
        if (javaElement.getElementType() == IJavaElement.METHOD) {
46
        if (javaElement.getElementType() == IJavaElement.METHOD) {
49
            IMethod method = (IMethod) javaElement;
47
            IMethod method = (IMethod) javaElement;
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/annotations/initialization/SOAPBindingAttributeInitializer.java (-4 / +3 lines)
Lines 14-20 Link Here
14
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.STYLE;
14
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.STYLE;
15
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.USE;
15
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.USE;
16
16
17
import java.lang.annotation.Annotation;
18
import java.util.ArrayList;
17
import java.util.ArrayList;
19
import java.util.List;
18
import java.util.List;
20
19
Lines 24-39 Link Here
24
import javax.jws.soap.SOAPBinding.Use;
23
import javax.jws.soap.SOAPBinding.Use;
25
24
26
import org.eclipse.jdt.core.IJavaElement;
25
import org.eclipse.jdt.core.IJavaElement;
26
import org.eclipse.jdt.core.IType;
27
import org.eclipse.jdt.core.dom.AST;
27
import org.eclipse.jdt.core.dom.AST;
28
import org.eclipse.jdt.core.dom.MemberValuePair;
28
import org.eclipse.jdt.core.dom.MemberValuePair;
29
import org.eclipse.jst.ws.annotations.core.AnnotationsCore;
29
import org.eclipse.jst.ws.annotations.core.AnnotationsCore;
30
import org.eclipse.jst.ws.annotations.core.initialization.AnnotationAttributeInitializer;
30
import org.eclipse.jst.ws.annotations.core.initialization.AnnotationAttributeInitializer;
31
31
32
public class SOAPBindingAttributeInitializer extends AnnotationAttributeInitializer {
32
public class SOAPBindingAttributeInitializer extends AnnotationAttributeInitializer {
33
33
    
34
    @Override
34
    @Override
35
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast,
35
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast, IType annotationType) {
36
            Class<? extends Annotation> annotationClass) {
37
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
36
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
38
37
39
        MemberValuePair styleValuePair = AnnotationsCore.createEnumMemberValuePair(ast,
38
        MemberValuePair styleValuePair = AnnotationsCore.createEnumMemberValuePair(ast,
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/annotations/initialization/WebMethodAttributeInitializer.java (-12 / +8 lines)
Lines 13-19 Link Here
13
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.ACTION;
13
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.ACTION;
14
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.OPERATION_NAME;
14
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.OPERATION_NAME;
15
15
16
import java.lang.annotation.Annotation;
17
import java.util.ArrayList;
16
import java.util.ArrayList;
18
import java.util.List;
17
import java.util.List;
19
18
Lines 30-51 Link Here
30
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIPlugin;
29
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIPlugin;
31
30
32
public class WebMethodAttributeInitializer extends AnnotationAttributeInitializer {
31
public class WebMethodAttributeInitializer extends AnnotationAttributeInitializer {
33
    
32
        
34
    @Override
33
    @Override
35
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast,
34
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast, IType annotationType) {
36
            Class<? extends Annotation> annotationClass) {
37
35
38
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
36
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
39
37
40
        if (javaElement.getElementType() == IJavaElement.METHOD) {
38
        if (javaElement.getElementType() == IJavaElement.METHOD) {
41
            IMethod method = (IMethod) javaElement;
39
            IMethod method = (IMethod) javaElement;
42
            IType type = method.getCompilationUnit().findPrimaryType();
43
            
40
            
44
            MemberValuePair operationValuePair = AnnotationsCore.createStringMemberValuePair(ast, 
41
            MemberValuePair operationValuePair = AnnotationsCore.createStringMemberValuePair(ast, 
45
                    OPERATION_NAME, getOperationNameValue(type, method));
42
                    OPERATION_NAME, getOperationNameValue(method));
46
43
47
            MemberValuePair actionValuePair = AnnotationsCore.createStringMemberValuePair(ast, 
44
            MemberValuePair actionValuePair = AnnotationsCore.createStringMemberValuePair(ast, 
48
                    ACTION, getActionValue(type, method));
45
                    ACTION, getActionValue(method));
49
46
50
            memberValuePairs.add(operationValuePair);
47
            memberValuePairs.add(operationValuePair);
51
            memberValuePairs.add(actionValuePair);
48
            memberValuePairs.add(actionValuePair);
Lines 61-77 Link Here
61
        
58
        
62
        if (javaElement.getElementType() == IJavaElement.METHOD) {
59
        if (javaElement.getElementType() == IJavaElement.METHOD) {
63
            IMethod method = (IMethod) javaElement;
60
            IMethod method = (IMethod) javaElement;
64
            IType type = method.getCompilationUnit().findPrimaryType();
65
            
61
            
66
            String memberValuePairName = memberValuePair.getName().getIdentifier();
62
            String memberValuePairName = memberValuePair.getName().getIdentifier();
67
63
68
            if (memberValuePairName.equals(OPERATION_NAME)) {
64
            if (memberValuePairName.equals(OPERATION_NAME)) {
69
                completionProposals.add(createCompletionProposal(getOperationNameValue(type, method), 
65
                completionProposals.add(createCompletionProposal(getOperationNameValue(method), 
70
                		memberValuePair.getValue()));
66
                		memberValuePair.getValue()));
71
            }
67
            }
72
            
68
            
73
            if (memberValuePairName.equals(ACTION)) {
69
            if (memberValuePairName.equals(ACTION)) {
74
                completionProposals.add(createCompletionProposal(getActionValue(type, method),
70
                completionProposals.add(createCompletionProposal(getActionValue(method),
75
                		memberValuePair.getValue()));
71
                		memberValuePair.getValue()));
76
            }
72
            }
77
73
Lines 79-85 Link Here
79
        return completionProposals;
75
        return completionProposals;
80
    }
76
    }
81
77
82
    private String getOperationNameValue(IType type, IMethod method) {
78
    private String getOperationNameValue(IMethod method) {
83
        try {
79
        try {
84
            return method.getElementName() + JAXWSUtils.accountForOverloadedMethods(method);
80
            return method.getElementName() + JAXWSUtils.accountForOverloadedMethods(method);
85
        } catch (JavaModelException jme) {
81
        } catch (JavaModelException jme) {
Lines 88-94 Link Here
88
        return ""; //$NON-NLS-1$
84
        return ""; //$NON-NLS-1$
89
    }
85
    }
90
    
86
    
91
    private String getActionValue(IType type, IMethod method) {
87
    private String getActionValue(IMethod method) {
92
        try {
88
        try {
93
            String methodName = method.getElementName();
89
            String methodName = method.getElementName();
94
            return "urn:" + methodName.substring(0, 1).toUpperCase()  //$NON-NLS-1$
90
            return "urn:" + methodName.substring(0, 1).toUpperCase()  //$NON-NLS-1$
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/annotations/initialization/WebParamAttributeInitializer.java (-4 / +2 lines)
Lines 17-23 Link Here
17
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.PART_NAME;
17
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.PART_NAME;
18
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.TARGET_NAMESPACE;
18
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.TARGET_NAMESPACE;
19
19
20
import java.lang.annotation.Annotation;
21
import java.util.ArrayList;
20
import java.util.ArrayList;
22
import java.util.Arrays;
21
import java.util.Arrays;
23
import java.util.List;
22
import java.util.List;
Lines 43-52 Link Here
43
import org.eclipse.jst.ws.jaxws.core.utils.JDTUtils;
42
import org.eclipse.jst.ws.jaxws.core.utils.JDTUtils;
44
43
45
public class WebParamAttributeInitializer extends AnnotationAttributeInitializer {
44
public class WebParamAttributeInitializer extends AnnotationAttributeInitializer {
46
45
    
47
    @Override
46
    @Override
48
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement,
47
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast, IType annotationType) {
49
            AST ast, Class<? extends Annotation> annotationClass) {
50
48
51
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
49
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
52
50
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/annotations/initialization/WebResultAttributeInitializer.java (-3 / +1 lines)
Lines 18-24 Link Here
18
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.RETURN;
18
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.RETURN;
19
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.TARGET_NAMESPACE;
19
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.TARGET_NAMESPACE;
20
20
21
import java.lang.annotation.Annotation;
22
import java.util.ArrayList;
21
import java.util.ArrayList;
23
import java.util.List;
22
import java.util.List;
24
23
Lines 47-54 Link Here
47
public class WebResultAttributeInitializer extends AnnotationAttributeInitializer {
46
public class WebResultAttributeInitializer extends AnnotationAttributeInitializer {
48
    
47
    
49
    @Override
48
    @Override
50
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast,
49
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast, IType annotationType) {
51
            Class<? extends Annotation> annotationClass) {
52
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
50
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
53
51
54
        if (javaElement.getElementType() == IJavaElement.METHOD) {
52
        if (javaElement.getElementType() == IJavaElement.METHOD) {
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/annotations/initialization/WebServiceAttributeInitializer.java (-3 / +1 lines)
Lines 18-24 Link Here
18
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.SERVICE_SUFFIX;
18
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.SERVICE_SUFFIX;
19
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.TARGET_NAMESPACE;
19
import static org.eclipse.jst.ws.internal.jaxws.core.utils.JAXWSUtils.TARGET_NAMESPACE;
20
20
21
import java.lang.annotation.Annotation;
22
import java.util.ArrayList;
21
import java.util.ArrayList;
23
import java.util.Collections;
22
import java.util.Collections;
24
import java.util.List;
23
import java.util.List;
Lines 40-47 Link Here
40
public class WebServiceAttributeInitializer extends AnnotationAttributeInitializer {
39
public class WebServiceAttributeInitializer extends AnnotationAttributeInitializer {
41
40
42
    @Override
41
    @Override
43
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast,
42
    public List<MemberValuePair> getMemberValuePairs(IJavaElement javaElement, AST ast, IType annotationType) {
44
            Class<? extends Annotation> annotationClass) {
45
        
43
        
46
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
44
        List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
47
        if (javaElement.getElementType() == IJavaElement.TYPE) {
45
        if (javaElement.getElementType() == IJavaElement.TYPE) {
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/views/AnnotationArrayCellEditor.java (-220 / +256 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
12
12
13
import java.lang.reflect.Method;
14
import java.util.ArrayList;
13
import java.util.ArrayList;
15
import java.util.HashMap;
14
import java.util.HashMap;
16
import java.util.Iterator;
15
import java.util.Iterator;
Lines 20-28 Link Here
20
import java.util.Map.Entry;
19
import java.util.Map.Entry;
21
20
22
import org.eclipse.jdt.core.IAnnotation;
21
import org.eclipse.jdt.core.IAnnotation;
22
import org.eclipse.jdt.core.IJavaProject;
23
import org.eclipse.jdt.core.IMemberValuePair;
23
import org.eclipse.jdt.core.IMemberValuePair;
24
import org.eclipse.jdt.core.IMethod;
24
import org.eclipse.jdt.core.IType;
25
import org.eclipse.jdt.core.IType;
25
import org.eclipse.jdt.core.JavaModelException;
26
import org.eclipse.jdt.core.JavaModelException;
27
import org.eclipse.jdt.core.Signature;
26
import org.eclipse.jdt.core.search.SearchEngine;
28
import org.eclipse.jdt.core.search.SearchEngine;
27
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
29
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
28
import org.eclipse.jdt.ui.ISharedImages;
30
import org.eclipse.jdt.ui.ISharedImages;
Lines 39-44 Link Here
39
import org.eclipse.jface.viewers.TableViewer;
41
import org.eclipse.jface.viewers.TableViewer;
40
import org.eclipse.jface.viewers.Viewer;
42
import org.eclipse.jface.viewers.Viewer;
41
import org.eclipse.jface.window.Window;
43
import org.eclipse.jface.window.Window;
44
import org.eclipse.jst.ws.internal.annotations.core.utils.SignatureUtils;
42
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIMessages;
45
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIMessages;
43
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIPlugin;
46
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIPlugin;
44
import org.eclipse.swt.SWT;
47
import org.eclipse.swt.SWT;
Lines 59-65 Link Here
59
import org.eclipse.ui.dialogs.SelectionStatusDialog;
62
import org.eclipse.ui.dialogs.SelectionStatusDialog;
60
63
61
public class AnnotationArrayCellEditor extends DialogCellEditor {
64
public class AnnotationArrayCellEditor extends DialogCellEditor {
62
    private Method method;
65
    private IMethod method;
63
    private Object[] values;
66
    private Object[] values;
64
67
65
    private List<Object> originalValues;
68
    private List<Object> originalValues;
Lines 89-95 Link Here
89
        return values;
92
        return values;
90
    }
93
    }
91
94
92
    public void setMethod(Method method) {
95
    public void setMethod(IMethod method) {
93
        this.method = method;
96
        this.method = method;
94
        if (updatedValues != null) {
97
        if (updatedValues != null) {
95
            updatedValues.clear();
98
            updatedValues.clear();
Lines 184-446 Link Here
184
        protected Control createDialogArea(Composite parent) {
187
        protected Control createDialogArea(Composite parent) {
185
            Composite mainComposite = (Composite) super.createDialogArea(parent);
188
            Composite mainComposite = (Composite) super.createDialogArea(parent);
186
189
187
            GridLayout gridLayout = new GridLayout(3, false);
190
            try {
188
            mainComposite.setLayout(gridLayout);
191
                GridLayout gridLayout = new GridLayout(3, false);
189
192
                mainComposite.setLayout(gridLayout);
190
            GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, false, false);
191
            gridData.widthHint = 800;
192
            mainComposite.setLayoutData(gridData);
193
194
            Composite typeComposite = new Composite(mainComposite, SWT.NONE);
195
            gridLayout = new GridLayout(3, false);
196
            typeComposite.setLayout(gridLayout);
197
            gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
198
            typeComposite.setLayoutData(gridData);
199
200
            final Class<?> componentType = method.getReturnType().getComponentType();
201
            if (componentType.isAnnotation()) {
202
                Label compontTypeLabel = new Label(typeComposite, SWT.NONE);
203
                compontTypeLabel.setText("@" + componentType.getName()); //$NON-NLS-1$
204
                gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
205
                gridData.horizontalSpan = 3;
206
                compontTypeLabel.setLayoutData(gridData);
207
193
208
                Method[] methods = componentType.getDeclaredMethods();
194
                GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, false, false);
209
                for (Method method : methods) {
195
                gridData.widthHint = 800;
210
                    Label label = new Label(typeComposite, SWT.NONE);
196
                mainComposite.setLayoutData(gridData);
211
                    label.setText(method.getName() + ":"); //$NON-NLS-1$
197
212
                    createEntryFields(method, typeComposite);
198
                Composite typeComposite = new Composite(mainComposite, SWT.NONE);
199
                gridLayout = new GridLayout(3, false);
200
                typeComposite.setLayout(gridLayout);
201
                gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
202
                typeComposite.setLayoutData(gridData);
203
204
                final IType componentType = getComponentType(method);
205
                if (componentType != null) {
206
                    if (componentType.isAnnotation()) {
207
                        Label compontTypeLabel = new Label(typeComposite, SWT.NONE);
208
                        compontTypeLabel.setText("@" + componentType.getFullyQualifiedName()); //$NON-NLS-1$
209
                        gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
210
                        gridData.horizontalSpan = 3;
211
                        compontTypeLabel.setLayoutData(gridData);
212
213
                        IMethod[] methods = componentType.getMethods();
214
                        for (IMethod method : methods) {
215
                            Label label = new Label(typeComposite, SWT.NONE);
216
                            label.setText(method.getElementName() + ":"); //$NON-NLS-1$
217
                            createEntryFields(method, typeComposite);
218
                        }
219
                    } else {
220
                        Label label = new Label(typeComposite, SWT.NONE);
221
                        label.setText(Signature.getSimpleName(Signature.toString(method.getReturnType())));
222
                        createEntryFields(method, typeComposite);
223
                    }
213
                }
224
                }
214
            } else {
225
215
                Label label = new Label(typeComposite, SWT.NONE);
226
                Composite buttonComposite = new Composite(mainComposite, SWT.NONE);
216
                label.setText(method.getReturnType().getSimpleName());
227
                gridLayout = new GridLayout(1, false);
217
                createEntryFields(method, typeComposite);
228
                buttonComposite.setLayout(gridLayout);
218
            }
229
219
230
                addButton = new Button(buttonComposite, SWT.PUSH);
220
            Composite buttonComposite = new Composite(mainComposite, SWT.NONE);
231
                addButton.setText(JAXWSUIMessages.ANNOTATION_ARRAY_CELL_EDITOR_ADD_LABEL);
221
            gridLayout = new GridLayout(1, false);
232
                addButton.addSelectionListener(new SelectionAdapter() {
222
            buttonComposite.setLayout(gridLayout);
233
                    @Override
223
234
                    public void widgetSelected(SelectionEvent event) {
224
            addButton = new Button(buttonComposite, SWT.PUSH);
235
                        try {
225
            addButton.setText(JAXWSUIMessages.ANNOTATION_ARRAY_CELL_EDITOR_ADD_LABEL);
236
                            Set<Entry<String, Control>> entrySet = controls.entrySet();
226
            addButton.addSelectionListener(new SelectionAdapter() {
237
                            Iterator<Map.Entry<String, Control>> iterator = entrySet.iterator();
227
                @Override
238
                            List<Map<String, Object>> aList = new ArrayList<Map<String,Object>>();
228
                public void widgetSelected(SelectionEvent event) {
239
                            while (iterator.hasNext()) {
229
                    Set<Entry<String, Control>> entrySet = controls.entrySet();
240
                                Map.Entry<String, Control> entry = iterator.next();
230
                    Iterator<Map.Entry<String, Control>> iterator = entrySet.iterator();
241
                                if (entry.getValue() instanceof Text) {
231
                    List<Map<String, Object>> aList = new ArrayList<Map<String,Object>>();
242
                                    Text textField = (Text) entry.getValue();
232
                    while (iterator.hasNext()) {
243
                                    IMethod methodAA = (IMethod) textField.getData();
233
                        Map.Entry<String, Control> entry = iterator.next();
244
                                    if (textField.getText().trim().length() > 0) {
234
                        if (entry.getValue() instanceof Text) {
245
                                        if (componentType != null && componentType.isAnnotation())  {
235
                            Text textField = (Text) entry.getValue();
246
                                            Map<String, Object> memberValuePairs = new HashMap<String, Object>();
236
                            Method method = (Method) textField.getData();
247
                                            memberValuePairs.put(methodAA.getElementName(), textField.getText());
237
                            if (textField.getText().trim().length() > 0) {
248
                                            aList.add(memberValuePairs);
238
                                if (componentType.isAnnotation()) {
249
                                        } else {
239
                                    Map<String, Object> memberValuePairs = new HashMap<String, Object>();
250
                                            updatedValues.add(textField.getText());
240
                                    memberValuePairs.put(method.getName(), textField.getText());
251
                                        }
241
                                    aList.add(memberValuePairs);
252
                                    }
242
                                } else {
253
                                }
243
                                    updatedValues.add(textField.getText());
254
                                if (entry.getValue() instanceof Button) {
255
                                    Button button = (Button) entry.getValue();
256
                                    IMethod methodVV = (IMethod) button.getData();
257
                                    if (componentType != null && componentType.isAnnotation()) {
258
                                        Map<String, Object> memberValuePairs = new HashMap<String, Object>();
259
                                        memberValuePairs.put(methodVV.getElementName(), button.getSelection());
260
                                        aList.add(memberValuePairs);
261
                                    } else {
262
                                        updatedValues.add(button.getSelection());
263
                                    }
244
                                }
264
                                }
245
                            }
265
                            }
246
                        }
266
                            if (aList.size() > 0) {
247
                        if (entry.getValue() instanceof Button) {
267
                                updatedValues.add(aList);
248
                            Button button = (Button) entry.getValue();
249
                            Method method = (Method) button.getData();
250
                            if (componentType.isAnnotation()) {
251
                                Map<String, Object> memberValuePairs = new HashMap<String, Object>();
252
                                memberValuePairs.put(method.getName(), button.getSelection());
253
                                aList.add(memberValuePairs);
254
                            } else {
255
                                updatedValues.add(button.getSelection());
256
                            }
268
                            }
269
                            arrayValuesTableViewer.refresh();
270
                        } catch (JavaModelException jme) {
271
                            JAXWSUIPlugin.log(jme.getStatus());
257
                        }
272
                        }
273
                    }
274
                });
275
                gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
276
                addButton.setLayoutData(gridData);
258
277
278
                removeButton = new Button(buttonComposite, SWT.PUSH);
279
                removeButton.setText(JAXWSUIMessages.ANNOTATION_ARRAY_CELL_EDITOR_REMOVE_LABEL);
280
                removeButton.addSelectionListener(new SelectionAdapter() {
281
                    @Override
282
                    public void widgetSelected(SelectionEvent event) {
283
                        ISelection selection = arrayValuesTableViewer.getSelection();
284
                        if (selection != null && !selection.isEmpty()) {
285
                            int index = arrayValuesTable.getSelectionIndex();
286
                            updatedValues.remove(index);
287
                            arrayValuesTableViewer.refresh();
288
                        }
259
                    }
289
                    }
260
                    if (aList.size() > 0) {
290
                });
261
                        updatedValues.add(aList);
291
                gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
292
                removeButton.setLayoutData(gridData);
293
294
                upButton = new Button(buttonComposite, SWT.PUSH);
295
                upButton.setText(JAXWSUIMessages.ANNOTATION_ARRAY_CELL_EDITOR_UP_LABEL);
296
                upButton.addSelectionListener(new SelectionAdapter() {
297
                    @Override
298
                    public void widgetSelected(SelectionEvent e) {
299
                        moveSelectedElememtUp(getSelectedElement(), getTableViewer());
262
                    }
300
                    }
263
                    arrayValuesTableViewer.refresh();
301
                });
264
                }
302
265
            });
303
                gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
266
            gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
304
                upButton.setLayoutData(gridData);
267
            addButton.setLayoutData(gridData);
305
268
306
                downButton = new Button(buttonComposite, SWT.PUSH);
269
            removeButton = new Button(buttonComposite, SWT.PUSH);
307
                downButton.setText(JAXWSUIMessages.ANNOTATION_ARRAY_CELL_EDITOR_DOWN_LABEL);
270
            removeButton.setText(JAXWSUIMessages.ANNOTATION_ARRAY_CELL_EDITOR_REMOVE_LABEL);
308
                downButton.addSelectionListener(new SelectionAdapter() {
271
            removeButton.addSelectionListener(new SelectionAdapter() {
309
                    @Override
272
                @Override
310
                    public void widgetSelected(SelectionEvent e) {
273
                public void widgetSelected(SelectionEvent event) {
311
                        moveSelectedElememtDown(getSelectedElement(), getTableViewer());
274
                    ISelection selection = arrayValuesTableViewer.getSelection();
275
                    if (selection != null && !selection.isEmpty()) {
276
                        int index = arrayValuesTable.getSelectionIndex();
277
                        updatedValues.remove(index);
278
                        arrayValuesTableViewer.refresh();
279
                    }
312
                    }
280
                }
313
                });
281
            });
314
                gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
282
            gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
315
                downButton.setLayoutData(gridData);
283
            removeButton.setLayoutData(gridData);
284
285
            upButton = new Button(buttonComposite, SWT.PUSH);
286
            upButton.setText(JAXWSUIMessages.ANNOTATION_ARRAY_CELL_EDITOR_UP_LABEL);
287
            upButton.addSelectionListener(new SelectionAdapter() {
288
                @Override
289
                public void widgetSelected(SelectionEvent e) {
290
                    moveSelectedElememtUp(getSelectedElement(), getTableViewer());
291
                }
292
            });
293
316
294
            gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
317
                Composite valuesComposite = new Composite(mainComposite, SWT.NONE);
295
            upButton.setLayoutData(gridData);
318
                gridLayout = new GridLayout(1, false);
319
                valuesComposite.setLayout(gridLayout);
320
                gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
321
                gridData.widthHint = 200;
322
                valuesComposite.setLayoutData(gridData);
296
323
297
            downButton = new Button(buttonComposite, SWT.PUSH);
324
                Label valuesLabel = new Label(valuesComposite, SWT.NONE);
298
            downButton.setText(JAXWSUIMessages.ANNOTATION_ARRAY_CELL_EDITOR_DOWN_LABEL);
325
                valuesLabel.setText(method.getElementName() + ":"); //$NON-NLS-1$
299
            downButton.addSelectionListener(new SelectionAdapter() {
326
300
                @Override
327
                arrayValuesTableViewer = new TableViewer(valuesComposite, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
301
                public void widgetSelected(SelectionEvent e) {
328
                arrayValuesTableViewer.setLabelProvider(new LabelProvider() {
302
                    moveSelectedElememtDown(getSelectedElement(), getTableViewer());
329
                    @Override
303
                }
330
                    public String getText(Object element) {
304
            });
331
                        if (element instanceof List<?>) {
305
            gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
332
                            String annotationName = componentType.getElementName();
306
            downButton.setLayoutData(gridData);
333
                            annotationName += "("; //$NON-NLS-1$
307
334
                            @SuppressWarnings("unchecked")
308
            Composite valuesComposite = new Composite(mainComposite, SWT.NONE);
335
                            List<Map<String, Object>> valuesList = (List<Map<String, Object>>) element;
309
            gridLayout = new GridLayout(1, false);
336
                            Iterator<Map<String, Object>> valuesIterator = valuesList.iterator();
310
            valuesComposite.setLayout(gridLayout);
337
                            while (valuesIterator.hasNext()) {
311
            gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
338
                                Map<String, Object> valuesMap = valuesIterator.next();
312
            gridData.widthHint = 200;
339
                                Set<Entry<String, Object>> entrySet = valuesMap.entrySet();
313
            valuesComposite.setLayoutData(gridData);
340
                                Iterator<Map.Entry<String, Object>> iterator = entrySet.iterator();
314
341
                                while (iterator.hasNext()) {
315
            Label valuesLabel = new Label(valuesComposite, SWT.NONE);
342
                                    Map.Entry<String, Object> entry = iterator.next();
316
            valuesLabel.setText(method.getName() + ":"); //$NON-NLS-1$
343
                                    Object value = entry.getValue();
317
344
                                    boolean isString = value instanceof String && !value.toString().endsWith(".class"); //$NON-NLS-1$
318
            arrayValuesTableViewer = new TableViewer(valuesComposite, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL
345
                                    if (isString) {
319
                    | SWT.H_SCROLL);
346
                                        annotationName += entry.getKey() + "=\"" + value + "\""; //$NON-NLS-1$ //$NON-NLS-2$
320
            arrayValuesTableViewer.setLabelProvider(new LabelProvider() {
347
                                    } else {
321
                @Override
348
                                        annotationName += entry.getKey() + "=" + value; //$NON-NLS-1$
322
                public String getText(Object element) {
349
                                    }
323
                    if (element instanceof List<?>) {
350
                                }
324
                        String annotationName = method.getReturnType().getComponentType().getSimpleName();
351
                                if (valuesIterator.hasNext()) {
325
                        annotationName += "("; //$NON-NLS-1$
352
                                    annotationName += ", "; //$NON-NLS-1$
326
                        List<Map<String, Object>> valuesList = (List<Map<String, Object>>)element;
327
                        Iterator<Map<String, Object>> valuesIterator = valuesList.iterator();
328
                        while (valuesIterator.hasNext()) {
329
                            Map<String, Object> valuesMap = valuesIterator.next();
330
                            Set<Entry<String, Object>> entrySet = valuesMap.entrySet();
331
                            Iterator<Map.Entry<String, Object>> iterator = entrySet.iterator();
332
                            while (iterator.hasNext()) {
333
                                Map.Entry<String, Object> entry = iterator.next();
334
                                Object value = entry.getValue();
335
                                boolean isString = value instanceof String && !value.toString().
336
                                endsWith(".class"); //$NON-NLS-1$
337
                                if (isString) {
338
                                    annotationName += entry.getKey() + "=\"" + value + "\""; //$NON-NLS-1$ //$NON-NLS-2$
339
                                } else {
340
                                    annotationName += entry.getKey() + "=" + value; //$NON-NLS-1$
341
                                }
353
                                }
342
                            }
354
                            }
343
                            if (valuesIterator.hasNext()) {
355
                            return annotationName += ")"; //$NON-NLS-1$
344
                                annotationName += ", "; //$NON-NLS-1$
345
                            }
346
                        }
356
                        }
347
                        return annotationName += ")"; //$NON-NLS-1$
357
                        return element.toString();
348
                    }
358
                    }
349
                    return element.toString();
350
                }
351
359
352
                @Override
360
                    @Override
353
                public Image getImage(Object element) {
361
                    public Image getImage(Object element) {
354
                    Class<?> returnType = method.getReturnType();
362
                        try {
355
                    if (returnType.getComponentType().isAnnotation()) {
363
                            if (componentType != null && componentType.isAnnotation()) {
356
                        return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_ANNOTATION);
364
                                return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_ANNOTATION);
357
                    } if (returnType.equals(Class.class)) {
365
                            } else if (SignatureUtils.isClass(method.getReturnType())) {
358
                        return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_CLASS);
366
                                return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_CLASS);
359
                    } else {
367
                            } else {
360
                        return PlatformUI.getWorkbench().getSharedImages().getImage(
368
                                return PlatformUI.getWorkbench().getSharedImages().getImage(
361
                                org.eclipse.ui.ISharedImages.IMG_OBJ_FILE);
369
                                        org.eclipse.ui.ISharedImages.IMG_OBJ_FILE);
370
                            }
371
                        } catch (JavaModelException jme) {
372
                            JAXWSUIPlugin.log(jme.getStatus());
373
                        }
374
                        return null;
362
                    }
375
                    }
363
                }
376
                });
364
            });
365
377
366
            arrayValuesTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
378
                arrayValuesTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
367
                public void selectionChanged(SelectionChangedEvent event) {
379
                    public void selectionChanged(SelectionChangedEvent event) {
368
                    int index = arrayValuesTable.getSelectionIndex();
380
                        int index = arrayValuesTable.getSelectionIndex();
369
                    int itemCount = arrayValuesTable.getItemCount();
381
                        int itemCount = arrayValuesTable.getItemCount();
370
382
371
                    if (index == 0 && itemCount <= 1) {
383
                        if (index == 0 && itemCount <= 1) {
372
                        upButton.setEnabled(false);
384
                            upButton.setEnabled(false);
373
                        downButton.setEnabled(false);
385
                            downButton.setEnabled(false);
374
                    }
386
                        }
375
387
376
                    if (index == 0 && itemCount > 1) {
388
                        if (index == 0 && itemCount > 1) {
377
                        upButton.setEnabled(false);
389
                            upButton.setEnabled(false);
378
                        downButton.setEnabled(true);
390
                            downButton.setEnabled(true);
379
                    }
391
                        }
380
392
381
                    if (index > 0 && index < itemCount - 1) {
393
                        if (index > 0 && index < itemCount - 1) {
382
                        upButton.setEnabled(true);
394
                            upButton.setEnabled(true);
383
                        downButton.setEnabled(true);
395
                            downButton.setEnabled(true);
384
                    }
396
                        }
385
397
386
                    if (index > 0 && index == itemCount - 1) {
398
                        if (index > 0 && index == itemCount - 1) {
387
                        upButton.setEnabled(true);
399
                            upButton.setEnabled(true);
388
                        downButton.setEnabled(false);
400
                            downButton.setEnabled(false);
389
                    }
401
                        }
390
402
391
                    if (index != -1) {
403
                        if (index != -1) {
392
                        removeButton.setEnabled(true);
404
                            removeButton.setEnabled(true);
393
                    } else {
405
                        } else {
394
                        removeButton.setEnabled(false);
406
                            removeButton.setEnabled(false);
407
                        }
395
                    }
408
                    }
396
                }
409
                });
397
            });
398
410
399
            arrayValuesTableViewer.setContentProvider(new ArrayValuesContentProvider());
411
                arrayValuesTableViewer.setContentProvider(new ArrayValuesContentProvider());
400
412
401
            arrayValuesTable = arrayValuesTableViewer.getTable();
413
                arrayValuesTable = arrayValuesTableViewer.getTable();
402
            gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
414
                gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
403
            arrayValuesTable.setLayoutData(gridData);
415
                arrayValuesTable.setLayoutData(gridData);
404
416
405
            arrayValuesTableViewer.setInput(values);
417
                arrayValuesTableViewer.setInput(values);
406
418
407
            upButton.setEnabled(false);
419
                upButton.setEnabled(false);
408
            downButton.setEnabled(false);
420
                downButton.setEnabled(false);
409
            removeButton.setEnabled(false);
421
                removeButton.setEnabled(false);
422
            } catch (JavaModelException jme) {
423
                jme.printStackTrace();
424
            }
410
425
411
            return mainComposite;
426
            return mainComposite;
412
        }
427
        }
413
428
414
        public void createEntryFields(Method method, Composite typeComposite) {
429
        private IType getComponentType(IMethod method) throws JavaModelException {
430
            String returnType = method.getReturnType();
431
            if (SignatureUtils.isArray(returnType)) {
432
                String elementType = Signature.getElementType(returnType);
433
                IType declaringType = method.getDeclaringType();
434
                IJavaProject javaProject = declaringType.getJavaProject();
435
                if (javaProject != null) {
436
                    return javaProject.findType(Signature.toString(elementType));
437
                }
438
            }
439
            return null;
440
        }
441
442
        private void createEntryFields(IMethod method, Composite typeComposite) throws JavaModelException {
415
            //TODO Handle ENUMS
443
            //TODO Handle ENUMS
416
            Class<?> returnType = method.getReturnType();
444
            String returnType = method.getReturnType();
417
            Object defaultValue = method.getDefaultValue();
445
            IMemberValuePair defaultValue = method.getDefaultValue();
418
            GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
446
            GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
419
            //String or String[]
447
            //String or String[]
420
            if (returnType.equals(String.class) || returnType.isArray() && returnType.getComponentType().equals(String.class)) {
448
            if (SignatureUtils.isString(returnType) || SignatureUtils.isArray(returnType) && SignatureUtils.isString(Signature.getElementType(returnType))) {
421
                Text text = new Text(typeComposite, SWT.BORDER);
449
                Text text = new Text(typeComposite, SWT.BORDER);
422
                text.setData(method);
450
                text.setData(method);
423
                gridData.horizontalSpan = 2;
451
                gridData.horizontalSpan = 2;
424
                text.setLayoutData(gridData);
452
                text.setLayoutData(gridData);
425
                if (defaultValue != null) {
453
                if (defaultValue != null) {
426
                    if (defaultValue instanceof String[] && ((String[]) defaultValue).length == 1) {
454
                    Object value = defaultValue.getValue();
427
                        String[] values = (String[]) defaultValue;
455
                    if (value instanceof Object[]) {
428
                        text.setText(values[0]);
456
                        Object[] values = (Object[]) value;
457
                        if (values.length == 1) {
458
                            text.setText(values[0].toString());
459
                        }
460
                    } else if (value instanceof String[]) {
461
                        String[] values = (String[]) value;
462
                        if (values.length == 1) {
463
                            text.setText(values[0]);
464
                        }
429
                    } else {
465
                    } else {
430
                        text.setText(defaultValue.toString());
466
                        text.setText(value.toString());
431
                    }
467
                    }
432
                }
468
                }
433
                controls.put(method.getName(), text);
469
                controls.put(method.getElementName(), text);
434
            }
470
            }
435
            //Class or Class[]
471
            //Class or Class[]
436
            if (returnType.equals(Class.class) || returnType.isArray() && returnType.getComponentType().equals(Class.class)) {
472
            if (SignatureUtils.isClass(returnType) || SignatureUtils.isArray(returnType) && SignatureUtils.isClass(Signature.getElementType(returnType))) {
437
                final Text text = new Text(typeComposite, SWT.BORDER);
473
                final Text text = new Text(typeComposite, SWT.BORDER);
438
                text.setData(method);
474
                text.setData(method);
439
                gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
475
                gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
440
                text.setLayoutData(gridData);
476
                text.setLayoutData(gridData);
441
                if (defaultValue != null) {
477
                if (defaultValue != null && defaultValue.getValueKind() == IMemberValuePair.K_CLASS) {
442
                    Class<?> classValue = (Class<?>)defaultValue;
478
                    Object value = defaultValue.getValue();
443
                    text.setText(classValue.getCanonicalName() + ".class"); //$NON-NLS-1$
479
                    text.setText(value + ".class"); //$NON-NLS-1$
444
                }
480
                }
445
                Button browseClassButton = new Button(typeComposite, SWT.PUSH);
481
                Button browseClassButton = new Button(typeComposite, SWT.PUSH);
446
                browseClassButton.setText(getBrowseButtonLabel());
482
                browseClassButton.setText(getBrowseButtonLabel());
Lines 462-480 Link Here
462
                    }
498
                    }
463
                });
499
                });
464
                browse_button_count++;
500
                browse_button_count++;
465
                controls.put(method.getName(), text);
501
                controls.put(method.getElementName(), text);
466
            }
502
            }
467
503
468
            //Boolean
504
            //Boolean
469
            if (returnType.equals(Boolean.TYPE)) {
505
            if (SignatureUtils.isBoolean(returnType)) {
470
                Button checkbox = new Button(typeComposite, SWT.CHECK);
506
                Button checkbox = new Button(typeComposite, SWT.CHECK);
471
                checkbox.setData(method);
507
                checkbox.setData(method);
472
                gridData.horizontalSpan = 2;
508
                gridData.horizontalSpan = 2;
473
                checkbox.setLayoutData(gridData);
509
                checkbox.setLayoutData(gridData);
474
                if (defaultValue != null) {
510
                if (defaultValue != null) {
475
                    checkbox.setSelection((Boolean)defaultValue);
511
                    checkbox.setSelection((Boolean) defaultValue.getValue());
476
                }
512
                }
477
                controls.put(method.getName(), checkbox);
513
                controls.put(method.getElementName(), checkbox);
478
            }
514
            }
479
        }
515
        }
480
516
Lines 497-503 Link Here
497
            }
533
            }
498
        }
534
        }
499
535
500
        public Object getSelectedElement() {
536
        private Object getSelectedElement() {
501
            IStructuredSelection selection= (IStructuredSelection) arrayValuesTableViewer.getSelection();
537
            IStructuredSelection selection= (IStructuredSelection) arrayValuesTableViewer.getSelection();
502
            return selection.getFirstElement();
538
            return selection.getFirstElement();
503
        }
539
        }
Lines 506-512 Link Here
506
            return arrayValuesTableViewer;
542
            return arrayValuesTableViewer;
507
        }
543
        }
508
544
509
        public void moveSelectedElememtUp(Object selected, TableViewer tableViewer) {
545
        private void moveSelectedElememtUp(Object selected, TableViewer tableViewer) {
510
            int selectionIndex = tableViewer.getTable().getSelectionIndex();
546
            int selectionIndex = tableViewer.getTable().getSelectionIndex();
511
            if (selectionIndex > 0) {
547
            if (selectionIndex > 0) {
512
                updatedValues.remove(selected);
548
                updatedValues.remove(selected);
Lines 518-524 Link Here
518
            }
554
            }
519
        }
555
        }
520
556
521
        public void moveSelectedElememtDown(Object selected, TableViewer tableViewer) {
557
        private void moveSelectedElememtDown(Object selected, TableViewer tableViewer) {
522
            int selectionIndex = tableViewer.getTable().getSelectionIndex();
558
            int selectionIndex = tableViewer.getTable().getSelectionIndex();
523
            int itemCount = tableViewer.getTable().getItemCount();
559
            int itemCount = tableViewer.getTable().getItemCount();
524
            if (selectionIndex < itemCount - 1) {
560
            if (selectionIndex < itemCount - 1) {
Lines 547-553 Link Here
547
            }
583
            }
548
        }
584
        }
549
585
550
        public SelectionDialog getClassSelectionDialog() {
586
        private SelectionDialog getClassSelectionDialog() {
551
            try {
587
            try {
552
                return JavaUI.createTypeDialog(getShell(), PlatformUI.getWorkbench().getProgressService(),
588
                return JavaUI.createTypeDialog(getShell(), PlatformUI.getWorkbench().getProgressService(),
553
                        SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_CLASSES,
589
                        SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_CLASSES,
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/views/AnnotationsColumnLabelProvider.java (-8 / +8 lines)
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
12
12
13
import java.lang.reflect.Method;
13
import org.eclipse.jdt.core.IMethod;
14
14
import org.eclipse.jdt.core.IType;
15
import org.eclipse.jdt.ui.ISharedImages;
15
import org.eclipse.jdt.ui.ISharedImages;
16
import org.eclipse.jdt.ui.JavaUI;
16
import org.eclipse.jdt.ui.JavaUI;
17
import org.eclipse.jface.viewers.ColumnLabelProvider;
17
import org.eclipse.jface.viewers.ColumnLabelProvider;
Lines 22-43 Link Here
22
22
23
    @Override
23
    @Override
24
    public String getText(Object element) {
24
    public String getText(Object element) {
25
        if (element instanceof Class) {
25
        if (element instanceof IType) {
26
            return ((Class<?>)element).getName();
26
            return ((IType) element).getFullyQualifiedName();
27
        }
27
        }
28
        
28
        
29
        if (element instanceof Method) {
29
        if (element instanceof IMethod) {
30
            return ((Method)element).getName();
30
            return ((IMethod) element).getElementName();
31
        }
31
        }
32
        return ""; //$NON-NLS-1$
32
        return ""; //$NON-NLS-1$
33
    }
33
    }
34
34
35
    @Override
35
    @Override
36
    public Image getImage(Object element) {
36
    public Image getImage(Object element) {
37
        if (element instanceof Class) {
37
        if (element instanceof IType) {
38
            return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_ANNOTATION);
38
            return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_ANNOTATION);
39
        }
39
        }
40
        if (element instanceof Method) {
40
        if (element instanceof IMethod) {
41
            return PlatformUI.getWorkbench().getSharedImages().getImage(
41
            return PlatformUI.getWorkbench().getSharedImages().getImage(
42
                    org.eclipse.ui.ISharedImages.IMG_OBJ_FILE);
42
                    org.eclipse.ui.ISharedImages.IMG_OBJ_FILE);
43
        }
43
        }
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/views/AnnotationsValuesColumnLabelProvider.java (-40 / +47 lines)
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
12
12
13
import java.lang.reflect.Method;
14
import java.util.List;
13
import java.util.List;
15
14
16
import org.eclipse.jdt.core.IJavaElement;
15
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.core.IMethod;
17
import org.eclipse.jdt.core.IType;
17
import org.eclipse.jdt.core.JavaModelException;
18
import org.eclipse.jdt.core.JavaModelException;
19
import org.eclipse.jdt.core.Signature;
18
import org.eclipse.jdt.core.dom.Annotation;
20
import org.eclipse.jdt.core.dom.Annotation;
19
import org.eclipse.jdt.core.dom.ArrayInitializer;
21
import org.eclipse.jdt.core.dom.ArrayInitializer;
20
import org.eclipse.jdt.core.dom.BooleanLiteral;
22
import org.eclipse.jdt.core.dom.BooleanLiteral;
Lines 25-30 Link Here
25
import org.eclipse.jface.viewers.ColumnLabelProvider;
27
import org.eclipse.jface.viewers.ColumnLabelProvider;
26
import org.eclipse.jface.viewers.TreeViewer;
28
import org.eclipse.jface.viewers.TreeViewer;
27
import org.eclipse.jst.ws.annotations.core.utils.AnnotationUtils;
29
import org.eclipse.jst.ws.annotations.core.utils.AnnotationUtils;
30
import org.eclipse.jst.ws.internal.annotations.core.utils.SignatureUtils;
28
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIPlugin;
31
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIPlugin;
29
import org.eclipse.swt.graphics.Image;
32
import org.eclipse.swt.graphics.Image;
30
33
Lines 43-55 Link Here
43
46
44
    @Override
47
    @Override
45
    public String getText(Object element) {
48
    public String getText(Object element) {
46
        if (element instanceof Method) {
49
        if (element instanceof IMethod) {
47
            return getTextForMethod((Method)element);
50
            try {
51
                return getTextForMethod((IMethod) element);
52
            } catch (JavaModelException jme) {
53
                JAXWSUIPlugin.log(jme.getStatus());
54
            }
48
        }
55
        }
49
        return ""; //$NON-NLS-1$
56
        return ""; //$NON-NLS-1$
50
    }
57
    }
51
58
52
    private String getTextForMethod(Method method) {
59
    private String getTextForMethod(IMethod method) throws JavaModelException {
53
        if (annotationTreeViewer.getInput() instanceof IJavaElement) {
60
        if (annotationTreeViewer.getInput() instanceof IJavaElement) {
54
            IJavaElement javaElement = (IJavaElement) annotationTreeViewer.getInput();
61
            IJavaElement javaElement = (IJavaElement) annotationTreeViewer.getInput();
55
            if (javaElement.exists()) {
62
            if (javaElement.exists()) {
Lines 59-105 Link Here
59
        return ""; //$NON-NLS-1$
66
        return ""; //$NON-NLS-1$
60
    }
67
    }
61
68
62
    private String getTextForMethod(Method method, IJavaElement annotatedElement) {
69
    private String getTextForMethod(IMethod method, IJavaElement annotatedElement) throws JavaModelException {
63
        List<Annotation> annotations = AnnotationUtils.getAnnotations(annotatedElement);
70
        List<Annotation> annotations = AnnotationUtils.getAnnotations(annotatedElement);
64
        for (Annotation annotation : annotations) {
71
        for (Annotation annotation : annotations) {
65
            String annotationName = AnnotationUtils.getAnnotationName(annotation);
72
            String annotationName = AnnotationUtils.getAnnotationName(annotation);
66
            Class<?> declaringClass = method.getDeclaringClass();
73
            IType type = method.getDeclaringType();
67
            if (annotationName.equals(declaringClass.getSimpleName())
74
            if (type != null && annotationName.equals(type.getElementName())
68
                    || annotationName.equals(declaringClass.getCanonicalName())) {
75
                    || annotationName.equals(type.getFullyQualifiedName())) {
69
                if (annotation.isNormalAnnotation()) {
76
                if (annotation.isNormalAnnotation()) {
70
                    NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
77
                    NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
71
                    @SuppressWarnings("unchecked")
78
                    @SuppressWarnings("unchecked")
72
                    List<MemberValuePair> memberValuePairs = normalAnnotation.values();
79
                    List<MemberValuePair> memberValuePairs = normalAnnotation.values();
73
                    for (MemberValuePair memberValuePair : memberValuePairs) {
80
                    for (MemberValuePair memberValuePair : memberValuePairs) {
74
                        if (memberValuePair.getName().getIdentifier().equals(method.getName())) {
81
                        if (memberValuePair.getName().getIdentifier().equals(method.getElementName())) {
75
                            return getTextForMethod(method.getReturnType(), memberValuePair.getValue());
82
                            return getTextForMethod(method, memberValuePair.getValue());
76
                        }
83
                        }
77
                    }
84
                    }
78
                } else if (annotation.isSingleMemberAnnotation()) {
85
                } else if (annotation.isSingleMemberAnnotation()) {
79
                    SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) annotation;
86
                    SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) annotation;
80
                    return getTextForMethod(method.getReturnType(), singleMemberAnnotation.getValue());
87
                    return getTextForMethod(method, singleMemberAnnotation.getValue());
81
                }
88
                }
82
            }
89
            }
83
        }
90
        }
84
        return ""; //$NON-NLS-1$
91
        return ""; //$NON-NLS-1$
85
    }
92
    }
86
93
87
    private String getTextForMethod(Class<?> returnType, Expression expression) {
94
    private String getTextForMethod(IMethod method, Expression expression) throws JavaModelException {
88
        if (returnType.equals(String.class)) {
95
        String returnType = method.getReturnType();
96
97
        if (SignatureUtils.isString(returnType) || SignatureUtils.isClass(returnType)) {
89
            return expression.toString();
98
            return expression.toString();
90
        }
99
        }
91
100
92
        if (returnType.equals(Class.class)) {
101
        if (SignatureUtils.isEnum(method)) {
93
            return expression.toString() + ".class"; //$NON-NLS-1$
102
            String enumValue = expression.toString();
103
            return enumValue.substring(enumValue.lastIndexOf(".") + 1); //$NON-NLS-1$
94
        }
104
        }
95
        if (returnType.isPrimitive() && (returnType.equals(Byte.TYPE)
105
96
                || returnType.equals(Short.TYPE) || returnType.equals(Integer.TYPE)
106
        if (SignatureUtils.isPrimitive(returnType) && (returnType.charAt(0) == Signature.C_BYTE
97
                || returnType.equals(Long.TYPE)  || returnType.equals(Float.TYPE)
107
                || returnType.charAt(0) == Signature.C_SHORT || returnType.charAt(0) == Signature.C_INT
98
                || returnType.equals(Double.TYPE))) {
108
                || returnType.charAt(0) == Signature.C_LONG  || returnType.charAt(0) == Signature.C_FLOAT
109
                || returnType.charAt(0) == Signature.C_DOUBLE)) {
99
            return expression.toString();
110
            return expression.toString();
100
        }
111
        }
101
112
102
        if (returnType.isArray() && expression instanceof ArrayInitializer) {
113
        if (SignatureUtils.isArray(returnType) && expression instanceof ArrayInitializer) {
103
            ArrayInitializer arrayInitializer = (ArrayInitializer) expression;
114
            ArrayInitializer arrayInitializer = (ArrayInitializer) expression;
104
            if (arrayInitializer.expressions().size() > 0) {
115
            if (arrayInitializer.expressions().size() > 0) {
105
                return "[]{...}"; //$NON-NLS-1$
116
                return "[]{...}"; //$NON-NLS-1$
Lines 107-127 Link Here
107
                return "[]{}"; //$NON-NLS-1$
118
                return "[]{}"; //$NON-NLS-1$
108
            }
119
            }
109
        }
120
        }
110
        if (returnType.isEnum()) {
111
            String enumValue = expression.toString();
112
            return enumValue.substring(enumValue.lastIndexOf(".") + 1); //$NON-NLS-1$
113
        }
114
        return ""; //$NON-NLS-1$
121
        return ""; //$NON-NLS-1$
115
    }
122
    }
116
123
117
    @Override
124
    @Override
118
    public Image getImage(Object element) {
125
    public Image getImage(Object element) {
119
        try {
126
        try {
120
            if (element instanceof Class) {
127
            if (element instanceof IType) {
121
                return getImageForClass((Class<?>) element);
128
                return getImageForClass((IType) element);
122
            }
129
            }
123
            if (element instanceof Method) {
130
            if (element instanceof IMethod) {
124
                return getImageForMethod((Method) element);
131
                return getImageForMethod((IMethod) element);
125
            }
132
            }
126
        } catch (JavaModelException jme) {
133
        } catch (JavaModelException jme) {
127
            JAXWSUIPlugin.log(jme.getStatus());
134
            JAXWSUIPlugin.log(jme.getStatus());
Lines 129-158 Link Here
129
        return null;
136
        return null;
130
    }
137
    }
131
138
132
    private Image getImageForClass(Class<?> aClass) throws JavaModelException {
139
    private Image getImageForClass(IType type) throws JavaModelException {
133
        if (annotationTreeViewer.getInput() instanceof IJavaElement) {
140
        if (annotationTreeViewer.getInput() instanceof IJavaElement) {
134
            IJavaElement javaElement = (IJavaElement) annotationTreeViewer.getInput();
141
            IJavaElement javaElement = (IJavaElement) annotationTreeViewer.getInput();
135
            if (javaElement.exists()) {
142
            if (javaElement.exists()) {
136
                return getImageForClass(aClass, javaElement);
143
                return getImageForClass(type, javaElement);
137
            }
144
            }
138
        }
145
        }
139
        return null;
146
        return null;
140
    }
147
    }
141
148
142
    private Image getImageForClass(Class<?> aClass, IJavaElement javaElement) throws JavaModelException {
149
    private Image getImageForClass(IType type, IJavaElement javaElement) throws JavaModelException {
143
        List<Annotation> annotations = AnnotationUtils.getAnnotations(javaElement);
150
        List<Annotation> annotations = AnnotationUtils.getAnnotations(javaElement);
144
        for (Annotation annotation : annotations) {
151
        for (Annotation annotation : annotations) {
145
            String annotationName = AnnotationUtils.getAnnotationName(annotation);
152
            String annotationName = AnnotationUtils.getAnnotationName(annotation);
146
            if (annotationName.equals(aClass.getSimpleName()) ||
153
            if (annotationName.equals(type.getElementName()) ||
147
                    annotationName.equals(aClass.getCanonicalName())) {
154
                    annotationName.equals(type.getFullyQualifiedName())) {
148
                return true_image;
155
                return true_image;
149
            }
156
            }
150
        }
157
        }
151
        return false_image;
158
        return false_image;
152
    }
159
    }
153
160
154
    private Image getImageForMethod(Method method) throws JavaModelException {
161
    private Image getImageForMethod(IMethod method) throws JavaModelException {
155
        if (method.getReturnType().equals(Boolean.TYPE) && annotationTreeViewer.getInput() instanceof IJavaElement) {
162
        if (SignatureUtils.isBoolean(method.getReturnType()) && annotationTreeViewer.getInput() instanceof IJavaElement) {
156
            IJavaElement javaElement = (IJavaElement) annotationTreeViewer.getInput();
163
            IJavaElement javaElement = (IJavaElement) annotationTreeViewer.getInput();
157
            if (javaElement.exists()) {
164
            if (javaElement.exists()) {
158
                return getImageForMethod(method, javaElement);
165
                return getImageForMethod(method, javaElement);
Lines 161-179 Link Here
161
        return null;
168
        return null;
162
    }
169
    }
163
170
164
    private Image getImageForMethod(Method method, IJavaElement javaElement) throws JavaModelException {
171
    private Image getImageForMethod(IMethod method, IJavaElement javaElement) throws JavaModelException {
165
        List<Annotation> annotations = AnnotationUtils.getAnnotations(javaElement);
172
        List<Annotation> annotations = AnnotationUtils.getAnnotations(javaElement);
166
        for (Annotation annotation : annotations) {
173
        for (Annotation annotation : annotations) {
167
            String annotationName = AnnotationUtils.getAnnotationName(annotation);
174
            String annotationName = AnnotationUtils.getAnnotationName(annotation);
168
            Class<?> declaringClass = method.getDeclaringClass();
175
            IType declaringType = method.getDeclaringType();
169
            if (annotationName.equals(declaringClass.getSimpleName())
176
            if (declaringType != null && annotationName.equals(declaringType.getElementName())
170
                    || annotationName.equals(declaringClass.getCanonicalName())) {
177
                    || annotationName.equals(declaringType.getFullyQualifiedName())) {
171
                if (annotation.isNormalAnnotation()) {
178
                if (annotation.isNormalAnnotation()) {
172
                    NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
179
                    NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
173
                    @SuppressWarnings("unchecked")
180
                    @SuppressWarnings("unchecked")
174
                    List<MemberValuePair> memberValuePairs = normalAnnotation.values();
181
                    List<MemberValuePair> memberValuePairs = normalAnnotation.values();
175
                    for (MemberValuePair memberValuePair : memberValuePairs) {
182
                    for (MemberValuePair memberValuePair : memberValuePairs) {
176
                        if (memberValuePair.getName().getIdentifier().equals(method.getName())
183
                        if (memberValuePair.getName().getIdentifier().equals(method.getElementName())
177
                                && memberValuePair.getValue() instanceof BooleanLiteral) {
184
                                && memberValuePair.getValue() instanceof BooleanLiteral) {
178
                            if (((BooleanLiteral) memberValuePair.getValue()).booleanValue()) {
185
                            if (((BooleanLiteral) memberValuePair.getValue()).booleanValue()) {
179
                                return true_image;
186
                                return true_image;
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/views/AnnotationsValuesEditingSupport.java (-226 / +315 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
12
12
13
import java.lang.reflect.Method;
14
import java.util.ArrayList;
13
import java.util.ArrayList;
15
import java.util.Collections;
14
import java.util.Collections;
16
import java.util.Iterator;
15
import java.util.Iterator;
Lines 27-34 Link Here
27
import org.eclipse.jdt.core.IAnnotation;
26
import org.eclipse.jdt.core.IAnnotation;
28
import org.eclipse.jdt.core.ICompilationUnit;
27
import org.eclipse.jdt.core.ICompilationUnit;
29
import org.eclipse.jdt.core.IJavaElement;
28
import org.eclipse.jdt.core.IJavaElement;
29
import org.eclipse.jdt.core.IJavaProject;
30
import org.eclipse.jdt.core.ILocalVariable;
30
import org.eclipse.jdt.core.IMemberValuePair;
31
import org.eclipse.jdt.core.IMemberValuePair;
32
import org.eclipse.jdt.core.IMethod;
33
import org.eclipse.jdt.core.IType;
31
import org.eclipse.jdt.core.JavaModelException;
34
import org.eclipse.jdt.core.JavaModelException;
35
import org.eclipse.jdt.core.Signature;
32
import org.eclipse.jdt.core.dom.AST;
36
import org.eclipse.jdt.core.dom.AST;
33
import org.eclipse.jdt.core.dom.ASTNode;
37
import org.eclipse.jdt.core.dom.ASTNode;
34
import org.eclipse.jdt.core.dom.Annotation;
38
import org.eclipse.jdt.core.dom.Annotation;
Lines 51-56 Link Here
51
import org.eclipse.jst.ws.annotations.core.AnnotationsManager;
55
import org.eclipse.jst.ws.annotations.core.AnnotationsManager;
52
import org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer;
56
import org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer;
53
import org.eclipse.jst.ws.annotations.core.utils.AnnotationUtils;
57
import org.eclipse.jst.ws.annotations.core.utils.AnnotationUtils;
58
import org.eclipse.jst.ws.internal.annotations.core.utils.SignatureUtils;
54
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIMessages;
59
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIMessages;
55
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIPlugin;
60
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIPlugin;
56
import org.eclipse.ltk.core.refactoring.Change;
61
import org.eclipse.ltk.core.refactoring.Change;
Lines 61-66 Link Here
61
import org.eclipse.text.edits.MultiTextEdit;
66
import org.eclipse.text.edits.MultiTextEdit;
62
67
63
public class AnnotationsValuesEditingSupport extends EditingSupport {
68
public class AnnotationsValuesEditingSupport extends EditingSupport {
69
64
    private AnnotationsView annotationsView;
70
    private AnnotationsView annotationsView;
65
    private TreeViewer treeViewer;
71
    private TreeViewer treeViewer;
66
72
Lines 83-186 Link Here
83
89
84
    @Override
90
    @Override
85
    protected boolean canEdit(Object element) {
91
    protected boolean canEdit(Object element) {
86
        if (element instanceof Method) {
92
        if (element instanceof IMethod) {
87
            Method method = (Method)element;
93
            IMethod method = (IMethod) element;
88
            return (Boolean) getValue(method.getDeclaringClass());
94
            return (Boolean) getValue(method.getDeclaringType());
89
        }
95
        }
90
        return true;
96
        return true;
91
    }
97
    }
92
98
93
    @Override
99
    @Override
94
    protected CellEditor getCellEditor(Object element) {
100
    protected CellEditor getCellEditor(Object element) {
95
        if (element instanceof Class) {
101
        if (element instanceof IType) {
96
            return checkboxCellEditor;
102
            return checkboxCellEditor;
97
        }
103
        }
98
        if (element instanceof Method) {
104
        if (element instanceof IMethod) {
99
            Method method = (Method) element;
105
            try {
100
            final Class<?> returnType = method.getReturnType();
106
                IMethod method = (IMethod) element;
101
            if (returnType.isEnum()) {
107
102
                Object[] enumConstants = returnType.getEnumConstants();
108
                IType enumType = SignatureUtils.getEnumReturnType(method);
103
                String[] values = new String[enumConstants.length];
109
                if (enumType != null) {
104
                for (int i = 0; i < enumConstants.length; i++) {
110
                    comboBoxCellEditor.setItems(SignatureUtils.getEnumConstantsNames(enumType));
105
                    values[i] = enumConstants[i].toString();
111
                    return comboBoxCellEditor;
106
                }
112
                }
107
                comboBoxCellEditor.setItems(values);
113
108
                return comboBoxCellEditor;
114
                final String returnType = method.getReturnType();
109
            }
115
110
            if (returnType.equals(Boolean.TYPE)) {
116
                if (SignatureUtils.isBoolean(returnType)) {
111
                return checkboxCellEditor;
117
                    return checkboxCellEditor;
112
            }
118
                }
113
119
114
            if (returnType.equals(Class.class)) {
120
                if (SignatureUtils.isClass(returnType)) {
115
                return classDialogCellEditor;
121
                    return classDialogCellEditor;
116
            }
122
                }
117
123
118
            if (returnType.isArray()) {
124
                if (SignatureUtils.isArray(returnType)) {
119
                annotationArrayCellEditor.setMethod(method);
125
                    annotationArrayCellEditor.setMethod(method);
120
                return annotationArrayCellEditor;
126
                    return annotationArrayCellEditor;
121
            }
127
                }
122
            if (returnType.isPrimitive()) {
128
                if (SignatureUtils.isPrimitive(returnType)) {
123
                textCellEditor.setValidator(new ICellEditorValidator() {
129
                    textCellEditor.setValidator(new ICellEditorValidator() {
124
                    public String isValid(Object value) {
130
                        public String isValid(Object value) {
125
                        try {
131
                            try {
126
                            if (returnType.equals(Byte.TYPE)) {
132
                                if (returnType.charAt(0) == Signature.C_BYTE) {
127
                                Byte.parseByte((String) value);
133
                                    Byte.parseByte((String) value);
128
                            }
134
                                }
129
                            if (returnType.equals(Short.TYPE)) {
135
                                if (returnType.charAt(0) == Signature.C_SHORT) {
130
                                Short.parseShort((String) value);
136
                                    Short.parseShort((String) value);
131
                            }
137
                                }
132
                            if (returnType.equals(Integer.TYPE)) {
138
                                if (returnType.charAt(0) == Signature.C_INT) {
133
                                Integer.parseInt((String) value);
139
                                    Integer.parseInt((String) value);
134
                            }
140
                                }
135
                            if (returnType.equals(Long.TYPE)) {
141
                                if (returnType.charAt(0) == Signature.C_LONG) {
136
                                Long.parseLong((String) value);
142
                                    Long.parseLong((String) value);
137
                            }
143
                                }
138
                            if (returnType.equals(Float.TYPE)) {
144
                                if (returnType.charAt(0) == Signature.C_FLOAT) {
139
                                Float.parseFloat((String) value);
145
                                    Float.parseFloat((String) value);
140
                            }
146
                                }
141
                            if (returnType.equals(Double.TYPE)) {
147
                                if (returnType.charAt(0) == Signature.C_DOUBLE) {
142
                                Double.parseDouble((String) value);
148
                                    Double.parseDouble((String) value);
149
                                }
150
                            } catch (NumberFormatException nfe) {
151
                                return JAXWSUIMessages.ANNOTATION_EDITING_SUPPORT_NOT_VALID_MESSAGE_PREFIX + value;
143
                            }
152
                            }
144
                        } catch (NumberFormatException nfe) {
153
                            return null;
145
                            return JAXWSUIMessages.ANNOTATION_EDITING_SUPPORT_NOT_VALID_MESSAGE_PREFIX
146
                            + returnType.getSimpleName();
147
                        }
154
                        }
148
                        return null;
155
                    });
149
                    }
156
                    return textCellEditor;
150
                });
157
                }
151
                return textCellEditor;
158
                return textCellEditor;
159
            } catch (JavaModelException jme) {
160
                JAXWSUIPlugin.log(jme.getStatus());
152
            }
161
            }
153
            return textCellEditor;
154
        }
162
        }
155
        return checkboxCellEditor;
163
        return checkboxCellEditor;
156
    }
164
    }
157
165
158
    @Override
166
    @Override
159
    protected Object getValue(Object element) {
167
    protected Object getValue(Object element) {
160
        if (element instanceof Class) {
168
        if (element instanceof IType) {
161
            return getValueForClass((Class<?>) element);
169
            return getValueForClass((IType) element);
162
        }
170
        }
163
        if (element instanceof Method) {
171
        if (element instanceof IMethod) {
164
            return getValueForMethod((Method) element);
172
            return getValueForMethod((IMethod) element);
165
        }
173
        }
166
        return null;
174
        return null;
167
    }
175
    }
168
176
169
    private Object getValueForClass(Class<?> aClass) {
177
    private Object getValueForClass(IType type) {
170
        if (treeViewer.getInput() instanceof IAnnotatable) {
178
        if (treeViewer.getInput() instanceof IAnnotatable) {
171
            return getValueForClass(aClass, (IAnnotatable) treeViewer.getInput());
179
            return getValueForClass(type, (IAnnotatable) treeViewer.getInput());
172
        }
180
        }
173
        return Boolean.FALSE;
181
        return Boolean.FALSE;
174
    }
182
    }
175
183
176
    private Object getValueForClass(Class<?> aClass, IAnnotatable annotatedElement) {
184
    private Object getValueForClass(IType type, IAnnotatable annotatedElement) {
185
        if (annotatedElement instanceof ILocalVariable) {
186
            ILocalVariable localVariable = getLocalVariable(annotatedElement);
187
            if (localVariable != null) {
188
                annotatedElement = localVariable;
189
            }
190
        }
177
        try {
191
        try {
178
            IAnnotation[] annotations = annotatedElement.getAnnotations();
192
            IAnnotation[] annotations = annotatedElement.getAnnotations();
179
            for (IAnnotation annotation : annotations) {
193
            for (IAnnotation annotation : annotations) {
180
                String annotationName = annotation.getElementName();
194
                String annotationName = annotation.getElementName();
181
                if (AnnotationUtils.isAnnotationPresent((IJavaElement)annotatedElement, annotationName)
195
                if (AnnotationUtils.isAnnotationPresent((IJavaElement)annotatedElement, annotationName)
182
                        && (annotationName.equals(aClass.getSimpleName())
196
                        && (annotationName.equals(type.getElementName())
183
                                || annotationName.equals(aClass.getCanonicalName()))) {
197
                                || annotationName.equals(type.getFullyQualifiedName()))) {
184
                    return Boolean.TRUE;
198
                    return Boolean.TRUE;
185
                }
199
                }
186
            }
200
            }
Lines 190-196 Link Here
190
        return Boolean.FALSE;
204
        return Boolean.FALSE;
191
    }
205
    }
192
206
193
    private Object getValueForMethod(Method method) {
207
    private Object getValueForMethod(IMethod method) {
194
        Object value = null;
208
        Object value = null;
195
        try {
209
        try {
196
            if (treeViewer.getInput() instanceof IAnnotatable) {
210
            if (treeViewer.getInput() instanceof IAnnotatable) {
Lines 202-245 Link Here
202
        return value;
216
        return value;
203
    }
217
    }
204
218
205
    private Object getValueForMethod(Method method, IAnnotatable annotatedElement) throws JavaModelException {
219
    private ILocalVariable getLocalVariable(IAnnotatable annotatedElement) {
206
        Class<?> returnType = method.getReturnType();
220
        if (annotatedElement instanceof ILocalVariable) {
221
            ILocalVariable localVariable = (ILocalVariable) annotatedElement;
222
            if (localVariable.getParent() instanceof IMethod) {
223
                IMethod parent = (IMethod) localVariable.getParent();
224
                localVariable = AnnotationUtils.getLocalVariable(parent, localVariable.getElementName());
225
                if (localVariable != null) {
226
                    return localVariable;
227
                }
228
            }
229
        }
230
        return null;
231
    }
232
233
    private Object getValueForMethod(IMethod method, IAnnotatable annotatedElement) throws JavaModelException {
234
        String returnType = method.getReturnType();
235
        if (annotatedElement instanceof ILocalVariable) {
236
            ILocalVariable localVariable = getLocalVariable(annotatedElement);
237
            if (localVariable != null) {
238
                annotatedElement = localVariable;
239
            }
240
        }
207
        IAnnotation[] annotations = annotatedElement.getAnnotations();
241
        IAnnotation[] annotations = annotatedElement.getAnnotations();
208
        for (IAnnotation annotation : annotations) {
242
        for (IAnnotation annotation : annotations) {
209
            Class<?> declaringClass = method.getDeclaringClass();
243
            IType declaringType = method.getDeclaringType();
244
210
            String annotationName = annotation.getElementName();
245
            String annotationName = annotation.getElementName();
211
            if (annotationName.equals(declaringClass.getSimpleName())
246
            if (annotationName.equals(declaringType.getElementName())
212
                    || annotationName.equals(declaringClass.getCanonicalName())) {
247
                    || annotationName.equals(declaringType.getFullyQualifiedName())) {
213
                IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs();
248
                IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs();
214
                for (IMemberValuePair memberValuePair : memberValuePairs) {
249
                for (IMemberValuePair memberValuePair : memberValuePairs) {
215
                    if (memberValuePair.getMemberName().equals(method.getName())) {
250
                    if (memberValuePair.getMemberName().equals(method.getElementName())) {
216
                        if (returnType.equals(String.class)) {
251
                        if (SignatureUtils.isString(returnType)) {
217
                            return memberValuePair.getValue();
252
                            return memberValuePair.getValue();
218
                        }
253
                        }
219
254
220
                        if (returnType.isEnum()) {
255
                        IType enumType = SignatureUtils.getEnumReturnType(method);
256
                        if (enumType != null) {
221
                            String enumValue = memberValuePair.getValue().toString();
257
                            String enumValue = memberValuePair.getValue().toString();
222
                            String literal = enumValue.substring(enumValue.lastIndexOf(".") + 1); //$NON-NLS-1$
258
                            String literal = enumValue.substring(enumValue.lastIndexOf(".") + 1); //$NON-NLS-1$
223
                            Object[] enumConstants = method.getReturnType().getEnumConstants();
259
                            String[] enumConstants = SignatureUtils.getEnumConstantsNames(enumType);
224
                            for (int i = 0; i < enumConstants.length; i++) {
260
                            for (int i = 0; i < enumConstants.length; i++) {
225
                                if (enumConstants[i].toString().equals(literal)) {
261
                                if (enumConstants[i].equals(literal)) {
226
                                    return i;
262
                                    return i;
227
                                }
263
                                }
228
                            }
264
                            }
229
                        }
265
                        }
230
266
                        if (SignatureUtils.isClass(returnType)) {
231
                        if (returnType.equals(Class.class)) {
232
                            return memberValuePair.getValue();
267
                            return memberValuePair.getValue();
233
                        }
268
                        }
234
269
235
                        if (returnType.equals(Boolean.TYPE)) {
270
                        if (SignatureUtils.isBoolean(returnType)) {
236
                            return memberValuePair.getValue();
271
                            return memberValuePair.getValue();
237
                        }
272
                        }
238
273
239
                        if (returnType.isPrimitive()) {
274
                        if (SignatureUtils.isPrimitive(returnType)) {
240
                            return ""; //$NON-NLS-1$
275
                            return ""; //$NON-NLS-1$
241
                        }
276
                        }
242
                        if (returnType.isArray()) {
277
                        if (SignatureUtils.isArray(returnType)) {
243
                            if (memberValuePair.getValueKind() == IMemberValuePair.K_CLASS) {
278
                            if (memberValuePair.getValueKind() == IMemberValuePair.K_CLASS) {
244
                                Object[] arrayValues = (Object[])memberValuePair.getValue();
279
                                Object[] arrayValues = (Object[])memberValuePair.getValue();
245
                                for (int i = 0; i < arrayValues.length; i++) {
280
                                for (int i = 0; i < arrayValues.length; i++) {
Lines 252-279 Link Here
252
                        }
287
                        }
253
                    }
288
                    }
254
                }
289
                }
255
                return getDefaultValueForMethod(returnType);
290
                return getDefaultValueForMethod(method);
256
            }
291
            }
257
        }
292
        }
258
        return null;
293
        return null;
259
    }
294
    }
260
295
261
    private Object getDefaultValueForMethod(Class<?> returnType) {
296
    private Object getDefaultValueForMethod(IMethod method) throws JavaModelException {
262
        if (returnType.equals(String.class)) {
297
        String returnType = method.getReturnType();
298
299
        if (SignatureUtils.isString(returnType)) {
263
            return ""; //$NON-NLS-1$
300
            return ""; //$NON-NLS-1$
264
        }
301
        }
265
        if (returnType.equals(Boolean.TYPE)) {
302
303
        if (SignatureUtils.isBoolean(returnType)) {
266
            return Boolean.FALSE;
304
            return Boolean.FALSE;
267
        }
305
        }
268
        if (returnType.isEnum()) {
306
307
        if (SignatureUtils.isEnum(method)) {
269
            return -1;
308
            return -1;
270
        }
309
        }
271
        if (returnType.isPrimitive()) {
310
311
        if (SignatureUtils.isPrimitive(returnType)) {
272
            return ""; //$NON-NLS-1$
312
            return ""; //$NON-NLS-1$
273
        }
313
        }
274
        if (returnType.isArray()) {
314
315
        if (SignatureUtils.isArray(returnType)) {
275
            return new Object[] {};
316
            return new Object[] {};
276
        }
317
        }
318
277
        return null;
319
        return null;
278
    }
320
    }
279
321
Lines 284-324 Link Here
284
        }
326
        }
285
327
286
        try {
328
        try {
287
            if (element instanceof Class && ((Class<?>) element).isAnnotation()) {
329
            if (element instanceof IType && ((IType) element).isAnnotation()) {
288
                @SuppressWarnings("unchecked")
330
                setValueForClass((IType) element, (Boolean) value);
289
                Class<? extends java.lang.annotation.Annotation> annotationClass =
290
                    (Class<? extends java.lang.annotation.Annotation>) element;
291
                if (annotationClass != null) {
292
                    setValueForClass(annotationClass, (Boolean) value);
293
                }
294
            }
331
            }
295
            if (element instanceof Method) {
332
296
                setValueForMethod((Method) element, value);
333
            if (element instanceof IMethod) {
334
                setValueForMethod((IMethod) element, value);
297
            }
335
            }
298
        } catch (CoreException ce) {
336
        } catch (CoreException ce) {
299
            JAXWSUIPlugin.log(ce.getStatus());
337
            JAXWSUIPlugin.log(ce.getStatus());
300
        }
338
        }
301
    }
339
    }
302
340
303
    private void setValueForClass(Class<? extends java.lang.annotation.Annotation> annotationClass,
341
    private void setValueForClass(IType type, Boolean annotate) throws CoreException {
304
            Boolean annotate) throws CoreException {
305
        Object viewerInput = treeViewer.getInput();
342
        Object viewerInput = treeViewer.getInput();
306
343
307
        IAnnotationAttributeInitializer annotationAttributeInitializer =
344
        IAnnotationAttributeInitializer annotationAttributeInitializer =
308
            AnnotationsManager.getAnnotationDefinitionForClass(annotationClass).getAnnotationAttributeInitializer();
345
            AnnotationsManager.getAnnotationDefinitionForClass(type.getFullyQualifiedName()).getAnnotationAttributeInitializer();
309
346
310
        if (viewerInput instanceof IJavaElement) {
347
        if (viewerInput instanceof IJavaElement) {
311
            setValueForClass(annotationClass, annotate, (IJavaElement) viewerInput, annotationAttributeInitializer);
348
            setValueForClass(type, annotate, (IJavaElement) viewerInput, annotationAttributeInitializer);
312
        }
349
        }
313
    }
350
    }
314
351
315
    private Annotation getAnnotation(AST ast, Class<? extends java.lang.annotation.Annotation> annotationClass,
352
    private Annotation getAnnotation(AST ast, IType type, List<MemberValuePair> memberValuePairs) throws JavaModelException {
316
            List<MemberValuePair> memberValuePairs) {
317
318
        Annotation annotation =  null;
353
        Annotation annotation =  null;
319
        int numberOfDeclaredMethods = annotationClass.getDeclaredMethods().length;
354
        int numberOfDeclaredMethods = type.getMethods().length;
320
        if (numberOfDeclaredMethods == 0) {
355
        if (numberOfDeclaredMethods == 0) {
321
            annotation = AnnotationsCore.createMarkerAnnotation(ast, annotationClass.getSimpleName());
356
            annotation = AnnotationsCore.createMarkerAnnotation(ast, type.getElementName());
322
        } else if (numberOfDeclaredMethods == 1) {
357
        } else if (numberOfDeclaredMethods == 1) {
323
            Expression value = null;
358
            Expression value = null;
324
            if (memberValuePairs != null && memberValuePairs.size() == 1) {
359
            if (memberValuePairs != null && memberValuePairs.size() == 1) {
Lines 328-355 Link Here
328
                }
363
                }
329
            }
364
            }
330
            if (value != null) {
365
            if (value != null) {
331
                annotation = AnnotationsCore.createSingleMemberAnnotation(ast, annotationClass.getSimpleName(), value);
366
                annotation = AnnotationsCore.createSingleMemberAnnotation(ast, type.getElementName(), value);
332
            } else {
367
            } else {
333
                annotation = AnnotationsCore.createNormalAnnotation(ast, annotationClass.getSimpleName(), memberValuePairs);
368
                annotation = AnnotationsCore.createNormalAnnotation(ast, type.getElementName(), memberValuePairs);
334
            }
369
            }
335
        } else if (numberOfDeclaredMethods > 1) {
370
        } else if (numberOfDeclaredMethods > 1) {
336
            annotation = AnnotationsCore.createNormalAnnotation(ast, annotationClass.getSimpleName(), memberValuePairs);
371
            annotation = AnnotationsCore.createNormalAnnotation(ast, type.getElementName(), memberValuePairs);
337
        }
372
        }
338
373
339
        return annotation;
374
        return annotation;
340
    }
375
    }
341
376
342
    private void setValueForClass(Class<? extends java.lang.annotation.Annotation> annotationClass,
377
    private void setValueForClass(IType type, Boolean annotate, IJavaElement javaElement,
343
            Boolean annotate, IJavaElement javaElement, IAnnotationAttributeInitializer annotationAttributeInitializer)
378
            IAnnotationAttributeInitializer annotationAttributeInitializer) throws CoreException {
344
    throws CoreException {
345
        ICompilationUnit source = AnnotationUtils.getCompilationUnitFromJavaElement(javaElement);
379
        ICompilationUnit source = AnnotationUtils.getCompilationUnitFromJavaElement(javaElement);
346
        CompilationUnit compilationUnit = SharedASTProvider.getAST(source, SharedASTProvider.WAIT_YES, null);
380
        CompilationUnit compilationUnit = SharedASTProvider.getAST(source, SharedASTProvider.WAIT_YES, null);
347
        AST ast = compilationUnit.getAST();
381
        AST ast = compilationUnit.getAST();
348
382
349
        List<MemberValuePair> memberValuePairs = getMemberValuePairs(annotationAttributeInitializer, javaElement,
383
        List<MemberValuePair> memberValuePairs = getMemberValuePairs(annotationAttributeInitializer, javaElement,
350
                ast, annotationClass);
384
                ast, type);
351
385
352
        Annotation annotation = getAnnotation(ast, annotationClass, memberValuePairs);
386
        Annotation annotation = getAnnotation(ast, type, memberValuePairs);
353
387
354
        TextFileChange change = new TextFileChange("Add/Remove Annotation", (IFile) source.getResource()); //$NON-NLS-1$
388
        TextFileChange change = new TextFileChange("Add/Remove Annotation", (IFile) source.getResource()); //$NON-NLS-1$
355
        MultiTextEdit multiTextEdit = new MultiTextEdit();
389
        MultiTextEdit multiTextEdit = new MultiTextEdit();
Lines 361-368 Link Here
361
                    || javaElement.getElementType() == IJavaElement.FIELD
395
                    || javaElement.getElementType() == IJavaElement.FIELD
362
                    || javaElement.getElementType() == IJavaElement.METHOD
396
                    || javaElement.getElementType() == IJavaElement.METHOD
363
                    || javaElement.getElementType() == IJavaElement.LOCAL_VARIABLE) {
397
                    || javaElement.getElementType() == IJavaElement.LOCAL_VARIABLE) {
398
                change.addEdit(AnnotationUtils.createAddImportTextEdit(javaElement, type.getFullyQualifiedName()));
364
                change.addEdit(AnnotationUtils.createAddAnnotationTextEdit(javaElement, annotation));
399
                change.addEdit(AnnotationUtils.createAddAnnotationTextEdit(javaElement, annotation));
365
                change.addEdit(AnnotationUtils.createAddImportTextEdit(javaElement, annotationClass.getCanonicalName()));
366
            }
400
            }
367
        } else {
401
        } else {
368
            if (javaElement.getElementType() == IJavaElement.PACKAGE_DECLARATION
402
            if (javaElement.getElementType() == IJavaElement.PACKAGE_DECLARATION
Lines 371-394 Link Here
371
                    || javaElement.getElementType() == IJavaElement.METHOD
405
                    || javaElement.getElementType() == IJavaElement.METHOD
372
                    || javaElement.getElementType() == IJavaElement.LOCAL_VARIABLE) {
406
                    || javaElement.getElementType() == IJavaElement.LOCAL_VARIABLE) {
373
                change.addEdit(AnnotationUtils.createRemoveAnnotationTextEdit(javaElement, annotation));
407
                change.addEdit(AnnotationUtils.createRemoveAnnotationTextEdit(javaElement, annotation));
374
                change.addEdit(AnnotationUtils.createRemoveImportTextEdit(javaElement, annotationClass.getCanonicalName()));
408
                change.addEdit(AnnotationUtils.createRemoveImportTextEdit(javaElement, type.getFullyQualifiedName()));
375
            }
409
            }
376
        }
410
        }
377
        executeChange(new NullProgressMonitor(), change);
411
        executeChange(new NullProgressMonitor(), change);
378
    }
412
    }
379
413
380
    private List<MemberValuePair> getMemberValuePairs(
414
    private List<MemberValuePair> getMemberValuePairs(IAnnotationAttributeInitializer annotationAttributeInitializer,
381
            IAnnotationAttributeInitializer annotationAttributeInitializer, IJavaElement javaElement, AST ast,
415
            IJavaElement javaElement, AST ast, IType type) {
382
            Class<?extends java.lang.annotation.Annotation> annotationClass) {
383
        if (annotationAttributeInitializer != null) {
416
        if (annotationAttributeInitializer != null) {
384
            return annotationAttributeInitializer.getMemberValuePairs(javaElement, ast, annotationClass);
417
            List<MemberValuePair> memberValuePairs = annotationAttributeInitializer.getMemberValuePairs(javaElement, ast, type);
418
            if (memberValuePairs.size() > 0) {
419
                return memberValuePairs;
420
            } else {
421
                return annotationAttributeInitializer.getMemberValuePairs(javaElement, ast,
422
                        AnnotationsManager.getAnnotationDefinitionForType(type).getAnnotationClass());
423
            }
385
        }
424
        }
386
        return Collections.emptyList();
425
        return Collections.emptyList();
387
    }
426
    }
388
427
389
428
    private void setValueForMethod(IMethod method, Object value) throws CoreException {
390
    private void setValueForMethod(Method method, Object value) throws CoreException {
429
        if (value instanceof String) {
391
        if (((Boolean) getValue(method.getDeclaringClass())).booleanValue()) {
430
            Object currentValue = getValue(method);
431
            if (currentValue != null && currentValue instanceof String) {
432
                if (((String) value).equals(currentValue)) {
433
                    return;
434
                }
435
            }
436
        }
437
        if (((Boolean) getValue(method.getDeclaringType())).booleanValue()) {
392
            Object viewerInput = treeViewer.getInput();
438
            Object viewerInput = treeViewer.getInput();
393
            if (viewerInput instanceof IAnnotatable) {
439
            if (viewerInput instanceof IAnnotatable) {
394
                setValueForMethod(method, value, (IJavaElement) viewerInput);
440
                setValueForMethod(method, value, (IJavaElement) viewerInput);
Lines 396-402 Link Here
396
        }
442
        }
397
    }
443
    }
398
444
399
    private void setValueForMethod(Method method, Object value, IJavaElement javaElement) throws CoreException {
445
    private void setValueForMethod(IMethod method, Object value, IJavaElement javaElement) throws CoreException {
400
        ICompilationUnit source = AnnotationUtils.getCompilationUnitFromJavaElement(javaElement);
446
        ICompilationUnit source = AnnotationUtils.getCompilationUnitFromJavaElement(javaElement);
401
        CompilationUnit compilationUnit = SharedASTProvider.getAST(source, SharedASTProvider.WAIT_YES, null);
447
        CompilationUnit compilationUnit = SharedASTProvider.getAST(source, SharedASTProvider.WAIT_YES, null);
402
        AST ast = compilationUnit.getAST();
448
        AST ast = compilationUnit.getAST();
Lines 409-422 Link Here
409
        for (Annotation annotation : annotations) {
455
        for (Annotation annotation : annotations) {
410
            if (annotation instanceof NormalAnnotation) {
456
            if (annotation instanceof NormalAnnotation) {
411
                NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
457
                NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
412
                Class<?> declaringClass = method.getDeclaringClass();
458
                IType declaringType = method.getDeclaringType();
413
                String annotationName = normalAnnotation.getTypeName().getFullyQualifiedName();
459
                String annotationName = normalAnnotation.getTypeName().getFullyQualifiedName();
414
                if (annotationName.equals(declaringClass.getSimpleName()) || annotationName.equals(declaringClass.getCanonicalName())) {
460
                if (annotationName.equals(declaringType.getElementName()) || annotationName.equals(declaringType.getFullyQualifiedName())) {
415
                    @SuppressWarnings("unchecked")
461
                    @SuppressWarnings("unchecked")
416
                    List<MemberValuePair> memberValuePairs = normalAnnotation.values();
462
                    List<MemberValuePair> memberValuePairs = normalAnnotation.values();
417
                    boolean hasMemberValuePair = false;
463
                    boolean hasMemberValuePair = false;
418
                    for (MemberValuePair memberValuePair : memberValuePairs) {
464
                    for (MemberValuePair memberValuePair : memberValuePairs) {
419
                        if (memberValuePair.getName().getIdentifier().equals(method.getName())) {
465
                        if (memberValuePair.getName().getIdentifier().equals(method.getElementName())) {
420
                            ASTNode memberValue = getMemberValuePairValue(ast, method, value);
466
                            ASTNode memberValue = getMemberValuePairValue(ast, method, value);
421
                            if (memberValue != null) {
467
                            if (memberValue != null) {
422
                                change.addEdit(AnnotationUtils.createUpdateMemberValuePairTextEdit(memberValuePair, memberValue));
468
                                change.addEdit(AnnotationUtils.createUpdateMemberValuePairTextEdit(memberValuePair, memberValue));
Lines 435-443 Link Here
435
                }
481
                }
436
            } else if (annotation instanceof SingleMemberAnnotation) {
482
            } else if (annotation instanceof SingleMemberAnnotation) {
437
                SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) annotation;
483
                SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) annotation;
438
                Class<?> declaringClass = method.getDeclaringClass();
484
                IType declaringType = method.getDeclaringType();
439
                String annotationName = singleMemberAnnotation.getTypeName().getFullyQualifiedName();
485
                String annotationName = singleMemberAnnotation.getTypeName().getFullyQualifiedName();
440
                if (annotationName.equals(declaringClass.getSimpleName()) || annotationName.equals(declaringClass.getCanonicalName())) {
486
                if (annotationName.equals(declaringType.getElementName()) || annotationName.equals(declaringType.getFullyQualifiedName())) {
441
                    MemberValuePair memberValuePair = getMemberValuePair(ast, method, value);
487
                    MemberValuePair memberValuePair = getMemberValuePair(ast, method, value);
442
                    if (memberValuePair != null) {
488
                    if (memberValuePair != null) {
443
                        change.addEdit(AnnotationUtils.createUpdateSingleMemberAnnotationTextEdit(singleMemberAnnotation, memberValuePair.getValue()));
489
                        change.addEdit(AnnotationUtils.createUpdateSingleMemberAnnotationTextEdit(singleMemberAnnotation, memberValuePair.getValue()));
Lines 451-526 Link Here
451
        executeChange(new NullProgressMonitor(), change);
497
        executeChange(new NullProgressMonitor(), change);
452
    }
498
    }
453
499
454
    private ASTNode getMemberValuePairValue(AST ast, Method method, Object value) {
500
    private MemberValuePair getMemberValuePair(AST ast, IMethod method, Object value) throws JavaModelException {
455
        Class<?> returnType = method.getReturnType();
501
        String returnType = method.getReturnType();
456
        if (returnType.equals(String.class)) {
502
        if (SignatureUtils.isString(returnType)) {
457
            return AnnotationsCore.createStringLiteral(ast, value.toString());
503
            return AnnotationsCore.createStringMemberValuePair(ast, method.getElementName(), (String) value);
458
        }
504
        }
459
        if (returnType.equals(Boolean.TYPE)) {
505
        if (SignatureUtils.isBoolean(returnType)) {
460
            return AnnotationsCore.createBooleanLiteral(ast, ((Boolean) value).booleanValue());
506
            return AnnotationsCore.createBooleanMemberValuePair(ast, method.getElementName(), (Boolean) value);
507
        }
508
509
        if (SignatureUtils.isPrimitive(returnType)) {
510
            if (returnType.charAt(0) == Signature.C_BYTE
511
                    || returnType.charAt(0) == Signature.C_SHORT
512
                    || returnType.charAt(0) == Signature.C_INT
513
                    || returnType.charAt(0) == Signature.C_LONG
514
                    || returnType.charAt(0) == Signature.C_FLOAT
515
                    || returnType.charAt(0) == Signature.C_DOUBLE) {
516
                return AnnotationsCore.createNumberMemberValuePair(ast, method.getElementName(), value.toString());
517
            }
461
        }
518
        }
462
        if (returnType.isPrimitive()
519
463
                && (returnType.equals(Byte.TYPE) || returnType.equals(Short.TYPE)
520
        if (SignatureUtils.isArray(returnType)) {
464
                        || returnType.equals(Integer.TYPE) || returnType.equals(Long.TYPE)
521
            IType componentType = getComponentType(method);
465
                        || returnType.equals(Float.TYPE) || returnType.equals(Double.TYPE))) {
522
            if (componentType != null) {
466
            return AnnotationsCore.createNumberLiteral(ast, value.toString());
523
                if (componentType.isAnnotation()) {
467
        }
524
                    return createArrayMemberValuePair(ast, method, (Object[]) value);
468
        if (returnType.isArray()) {
525
                } else {
469
            if (method.getReturnType().getComponentType().isAnnotation()) {
526
                    return AnnotationsCore.createArrayMemberValuePair(ast, method.getElementName(), (Object[]) value);
470
                return createArrayValueLiteral(ast, method, (Object[]) value);
527
                }
471
            } else {
472
                return AnnotationsCore.createArrayValueLiteral(ast, (Object[]) value);
473
            }
528
            }
474
        }
529
        }
475
530
476
        if (returnType.equals(Class.class)) {
531
        if (SignatureUtils.isClass(returnType)) {
477
            return AnnotationsCore.createTypeLiteral(ast, value.toString());
532
            return AnnotationsCore.createTypeMemberValuePair(ast, method.getElementName(), value.toString());
478
        }
533
        }
479
534
480
        if (returnType.isEnum()) {
535
        IType enumType = SignatureUtils.getEnumReturnType(method);
536
        if (enumType != null) {
481
            int selected = ((Integer) value).intValue();
537
            int selected = ((Integer) value).intValue();
482
            if (selected != -1) {
538
            if (selected != -1) {
483
                return AnnotationsCore.createEnumLiteral(ast, method.getDeclaringClass().getCanonicalName(),
539
                if (enumType.isMember()) {
484
                        method.getReturnType().getEnumConstants()[selected]);
540
                    return AnnotationsCore.createEnumMemberValuePair(ast, enumType.getDeclaringType().getFullyQualifiedName(),
541
                            method.getElementName(), SignatureUtils.getEnumConstants(enumType)[selected]);
542
                } else {
543
                    return AnnotationsCore.createEnumMemberValuePair(ast, enumType.getFullyQualifiedName(),
544
                            method.getElementName(), SignatureUtils.getEnumConstants(enumType)[selected]);
545
                }
485
            }
546
            }
486
        }
547
        }
487
        return null;
548
        return null;
488
    }
549
    }
489
550
490
    private MemberValuePair getMemberValuePair(AST ast, Method method, Object value) {
551
    private ASTNode getMemberValuePairValue(AST ast, IMethod method, Object value) throws JavaModelException {
491
        Class<?> returnType = method.getReturnType();
552
        String returnType = method.getReturnType();
492
        if (returnType.equals(String.class)) {
553
        if (SignatureUtils.isString(returnType)) {
493
            return AnnotationsCore.createStringMemberValuePair(ast, method.getName(), (String) value);
554
            return AnnotationsCore.createStringLiteral(ast, value.toString());
494
        }
555
        }
495
        if (returnType.equals(Boolean.TYPE)) {
556
496
            return AnnotationsCore.createBooleanMemberValuePair(ast, method.getName(), (Boolean) value);
557
        if (SignatureUtils.isBoolean(returnType)) {
497
        }
558
            return AnnotationsCore.createBooleanLiteral(ast, ((Boolean) value).booleanValue());
498
        if (returnType.isPrimitive()
559
        }
499
                && (returnType.equals(Byte.TYPE) || returnType.equals(Short.TYPE)
560
500
                        || returnType.equals(Integer.TYPE) || returnType.equals(Long.TYPE)
561
        if (SignatureUtils.isPrimitive(returnType)) {
501
                        || returnType.equals(Float.TYPE) || returnType.equals(Double.TYPE))) {
562
            if (returnType.charAt(0) == Signature.C_BYTE
502
            return AnnotationsCore.createNumberMemberValuePair(ast, method.getName(), value.toString());
563
                    || returnType.charAt(0) == Signature.C_SHORT
503
        }
564
                    || returnType.charAt(0) == Signature.C_INT
504
        if (returnType.isArray()) {
565
                    || returnType.charAt(0) == Signature.C_LONG
505
            if (method.getReturnType().getComponentType().isAnnotation()) {
566
                    || returnType.charAt(0) == Signature.C_FLOAT
506
                return createArrayMemberValuePair(ast, method, (Object[]) value);
567
                    || returnType.charAt(0) == Signature.C_DOUBLE) {
507
            } else {
568
                return AnnotationsCore.createNumberLiteral(ast, value.toString());
508
                return AnnotationsCore.createArrayMemberValuePair(ast, method.getName(), (Object[]) value);
509
            }
569
            }
510
        }
570
        }
511
571
512
        if (returnType.equals(Class.class)) {
572
        if (SignatureUtils.isArray(returnType)) {
513
            return AnnotationsCore.createTypeMemberValuePair(ast, method.getName(), value.toString());
573
            IType componentType = getComponentType(method);
574
            if (componentType != null) {
575
                if (componentType.isAnnotation()) {
576
                    return createArrayValueLiteral(ast, method, (Object[]) value);
577
                } else {
578
                    return AnnotationsCore.createArrayValueLiteral(ast, (Object[]) value);
579
                }
580
            }
581
        }
582
583
        if (SignatureUtils.isClass(returnType)) {
584
            return AnnotationsCore.createTypeLiteral(ast, value.toString());
514
        }
585
        }
515
586
516
        if (returnType.isEnum()) {
587
588
        IType enumType = SignatureUtils.getEnumReturnType(method);
589
        if (enumType != null) {
517
            int selected = ((Integer) value).intValue();
590
            int selected = ((Integer) value).intValue();
518
            if (selected != -1) {
591
            if (selected != -1) {
519
                return AnnotationsCore.createEnumMemberValuePair(ast,
592
                if (enumType.isMember()) {
520
                        method.getDeclaringClass().getCanonicalName(), method.getName(), method.getReturnType()
593
                    return AnnotationsCore.createEnumLiteral(ast, enumType.getDeclaringType().getFullyQualifiedName(),
521
                        .getEnumConstants()[selected]);
594
                            SignatureUtils.getEnumConstants(enumType)[selected]);
595
                } else {
596
                    return AnnotationsCore.createEnumLiteral(ast, enumType.getFullyQualifiedName(),
597
                            SignatureUtils.getEnumConstants(enumType)[selected]);
598
                }
522
            }
599
            }
523
        }
600
        }
601
524
        return null;
602
        return null;
525
    }
603
    }
526
604
Lines 552-616 Link Here
552
        annotationsView.refreshLabels();
630
        annotationsView.refreshLabels();
553
    }
631
    }
554
632
555
    private MemberValuePair createArrayMemberValuePair(AST ast, Method method, Object[] values) {
633
    private MemberValuePair createArrayMemberValuePair(AST ast, IMethod method, Object[] values) throws JavaModelException {
556
        return AnnotationsCore.createMemberValuePair(ast, method.getName(), createArrayValueLiteral(ast,
634
        return AnnotationsCore.createMemberValuePair(ast, method.getElementName(), createArrayValueLiteral(ast,
557
                method, values));
635
                method, values));
558
    }
636
    }
559
637
560
    @SuppressWarnings("unchecked")
638
    private IType getComponentType(IMethod method) throws JavaModelException {
561
    private ArrayInitializer createArrayValueLiteral(AST ast, Method method, Object[] values) {
639
        String returnType = method.getReturnType();
640
        if (SignatureUtils.isArray(returnType)) {
641
            String elementType = Signature.getElementType(returnType);
642
            IType declaringType = method.getDeclaringType();
643
            IJavaProject javaProject = declaringType.getJavaProject();
644
            if (javaProject != null) {
645
                return javaProject.findType(Signature.toString(elementType));
646
            }
647
        }
648
        return null;
649
    }
650
651
    private ArrayInitializer createArrayValueLiteral(AST ast, IMethod method, Object[] values) throws JavaModelException {
562
        ArrayInitializer arrayInitializer = ast.newArrayInitializer();
652
        ArrayInitializer arrayInitializer = ast.newArrayInitializer();
563
        for (Object value : values) {
653
        for (Object value : values) {
564
            if (value instanceof List) {
654
            if (value instanceof List<?>) {
565
                Class<? extends java.lang.annotation.Annotation> annotationClass =
655
                IType componentType = getComponentType(method);
566
                    (Class<? extends java.lang.annotation.Annotation>) method.getReturnType().getComponentType();
656
                if (componentType != null) {
567
657
568
                List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
658
                    List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
569
659
                    @SuppressWarnings("unchecked")
570
                List<Map<String, Object>> valuesList = (List<Map<String, Object>>) value;
660
                    List<Map<String, Object>> valuesList = (List<Map<String, Object>>) value;
571
                Iterator<Map<String, Object>> valuesIterator = valuesList.iterator();
661
                    Iterator<Map<String, Object>> valuesIterator = valuesList.iterator();
572
                while (valuesIterator.hasNext()) {
662
                    while (valuesIterator.hasNext()) {
573
                    Map<String, Object> annotationMap = valuesIterator.next();
663
                        Map<String, Object> annotationMap = valuesIterator.next();
574
                    Set<Entry<String, Object>> entrySet = annotationMap.entrySet();
664
                        Set<Entry<String, Object>> entrySet = annotationMap.entrySet();
575
                    Iterator<Map.Entry<String, Object>> iterator = entrySet.iterator();
665
                        Iterator<Map.Entry<String, Object>> iterator = entrySet.iterator();
576
                    while (iterator.hasNext()) {
666
                        while (iterator.hasNext()) {
577
                        Map.Entry<java.lang.String, Object> entry = iterator.next();
667
                            Map.Entry<java.lang.String, Object> entry = iterator.next();
578
                        String memberName = entry.getKey();
668
                            String memberName = entry.getKey();
579
                        try {
669
                            try {
580
                            Method annotationMethod = annotationClass.getMethod(memberName, new Class[0]);
670
                                IMethod annotationMethod = componentType.getMethod(memberName, new String[] {});
581
                            if (annotationMethod != null) {
671
                                if (annotationMethod != null) {
582
                                Object memberValue = entry.getValue();
672
                                    Object memberValue = entry.getValue();
583
                                Class<?> returnType = annotationMethod.getReturnType();
673
                                    String returnType = annotationMethod.getReturnType();
584
                                if (returnType.equals(String.class)) {
674
                                    if (SignatureUtils.isString(returnType)) {
585
                                    memberValuePairs.add(AnnotationsCore.createStringMemberValuePair(ast, memberName,
675
                                        memberValuePairs.add(AnnotationsCore.createStringMemberValuePair(ast, memberName,
586
                                            memberValue.toString()));
676
                                                memberValue.toString()));
587
                                }
677
                                    }
588
                                if (returnType.equals(Boolean.TYPE)) {
678
                                    if (SignatureUtils.isBoolean(returnType)) {
589
                                    memberValuePairs.add(AnnotationsCore.createBooleanMemberValuePair(ast, memberName,
679
                                        memberValuePairs.add(AnnotationsCore.createBooleanMemberValuePair(ast, memberName,
590
                                            (Boolean) memberValue));
680
                                                (Boolean) memberValue));
591
                                }
681
                                    }
592
                                if (returnType.equals(Class.class)) {
682
                                    if (SignatureUtils.isClass(returnType)) {
593
                                    String className = memberValue.toString();
683
                                        String className = memberValue.toString();
594
                                    if (className.endsWith(".class")) {
684
                                        if (className.endsWith(".class")) {
595
                                        className = className.substring(0, className.lastIndexOf("."));
685
                                            className = className.substring(0, className.lastIndexOf("."));
686
                                        }
687
                                        memberValuePairs.add(AnnotationsCore.createMemberValuePair(ast, memberName,
688
                                                AnnotationsCore.createTypeLiteral(ast, className)));
596
                                    }
689
                                    }
597
                                    memberValuePairs.add(AnnotationsCore.createMemberValuePair(ast, memberName,
690
                                    //                                if (returnType.isPrimitive()) {
598
                                            AnnotationsCore.createTypeLiteral(ast, className)));
691
                                    //                                    memberValuePairs.add(getNumberMemberValuePair(ast, memberName, memberValue));
692
                                    //                                }
599
                                }
693
                                }
600
                                //                                if (returnType.isPrimitive()) {
601
                                //                                    memberValuePairs.add(getNumberMemberValuePair(ast, memberName, memberValue));
602
                                //                                }
603
                            }
604
694
605
                        } catch (SecurityException se) {
695
                            } catch (SecurityException se) {
606
                            AnnotationsCorePlugin.log(se);
696
                                AnnotationsCorePlugin.log(se);
607
                        } catch (NoSuchMethodException nsme) {
697
                            }
608
                            AnnotationsCorePlugin.log(nsme);
609
                        }
698
                        }
610
                    }
699
                    }
700
                    arrayInitializer.expressions().add(AnnotationsCore.createNormalAnnotation(ast, componentType.getFullyQualifiedName(),
701
                            memberValuePairs));
611
                }
702
                }
612
                arrayInitializer.expressions().add(AnnotationsCore.createNormalAnnotation(ast, annotationClass.getCanonicalName(),
613
                        memberValuePairs));
614
            }
703
            }
615
        }
704
        }
616
        return arrayInitializer;
705
        return arrayInitializer;
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/views/AnnotationsView.java (-7 / +5 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
12
12
13
import java.lang.reflect.Method;
14
import java.util.ArrayList;
13
import java.util.ArrayList;
15
import java.util.List;
14
import java.util.List;
16
15
Lines 136-148 Link Here
136
        annotationTreeViewer.setComparator(new ViewerComparator() {
135
        annotationTreeViewer.setComparator(new ViewerComparator() {
137
            @Override
136
            @Override
138
            public int compare(Viewer viewer, Object obj1, Object obj2) {
137
            public int compare(Viewer viewer, Object obj1, Object obj2) {
139
                if (obj1 instanceof Class<?> && ((Class<?>) obj1).isAnnotation()
138
                if (obj1 instanceof IType && obj2 instanceof IType) {
140
                        && obj2 instanceof Class<?> && ((Class<?>) obj2).isAnnotation()) {
139
                    return ((IType) obj1).getFullyQualifiedName().compareTo(
141
                    return ((Class<? extends java.lang.annotation.Annotation>) obj1).getCanonicalName().compareTo(
140
                            ((IType) obj2).getFullyQualifiedName());
142
                            ((Class<? extends java.lang.annotation.Annotation>) obj2).getCanonicalName());
143
                }
141
                }
144
                if (obj1 instanceof Method && obj2 instanceof Method) {
142
                if (obj1 instanceof IMethod && obj2 instanceof IMethod) {
145
                    return ((Method)obj1).getName().compareTo(((Method)obj2).getName());
143
                    return ((IMethod) obj1).getElementName().compareTo(((IMethod) obj2).getElementName());
146
                }
144
                }
147
                return super.compare(viewer, obj1, obj2);
145
                return super.compare(viewer, obj1, obj2);
148
            }
146
            }
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/views/AnnotationsViewCategoryFilter.java (-5 / +4 lines)
Lines 10-19 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
12
12
13
import java.lang.annotation.Annotation;
14
import java.util.ArrayList;
13
import java.util.ArrayList;
15
import java.util.List;
14
import java.util.List;
16
15
16
import org.eclipse.jdt.core.IType;
17
import org.eclipse.jface.viewers.StructuredViewer;
17
import org.eclipse.jface.viewers.StructuredViewer;
18
import org.eclipse.jface.viewers.Viewer;
18
import org.eclipse.jface.viewers.Viewer;
19
import org.eclipse.jface.viewers.ViewerFilter;
19
import org.eclipse.jface.viewers.ViewerFilter;
Lines 38-50 Link Here
38
38
39
    @Override
39
    @Override
40
    public boolean select(Viewer viewer, Object parentElement, Object element) {
40
    public boolean select(Viewer viewer, Object parentElement, Object element) {
41
        if (element instanceof Class && ((Class<?>) element).isAnnotation()) {
41
    	if (element instanceof IType) {
42
            AnnotationDefinition annotationDefinition = AnnotationsManager.
42
    		AnnotationDefinition annotationDefinition = AnnotationsManager.getAnnotationDefinitionForType((IType) element);
43
                getAnnotationDefinitionForClass((Class<? extends Annotation>)element);
44
            if (annotationDefinition != null) {
43
            if (annotationDefinition != null) {
45
                return !categories.contains(annotationDefinition.getCategory());
44
                return !categories.contains(annotationDefinition.getCategory());
46
            }
45
            }
47
        }
46
    	}
48
        return true;
47
        return true;
49
    }
48
    }
50
49
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/views/AnnotationsViewContentProvider.java (-29 / +40 lines)
Lines 11-53 Link Here
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
11
package org.eclipse.jst.ws.internal.jaxws.ui.views;
12
12
13
import org.eclipse.jdt.core.IJavaElement;
13
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.jdt.core.IType;
15
import org.eclipse.jdt.core.JavaModelException;
14
import org.eclipse.jface.viewers.ITreeContentProvider;
16
import org.eclipse.jface.viewers.ITreeContentProvider;
15
import org.eclipse.jface.viewers.Viewer;
17
import org.eclipse.jface.viewers.Viewer;
16
import org.eclipse.jst.ws.annotations.core.AnnotationsManager;
18
import org.eclipse.jst.ws.annotations.core.AnnotationsManager;
19
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIPlugin;
17
20
18
public class AnnotationsViewContentProvider implements ITreeContentProvider {
21
public class AnnotationsViewContentProvider implements ITreeContentProvider {
19
22
20
	public Object[] getChildren(Object parentElement) {
23
    public Object[] getChildren(Object parentElement) {
21
		if (parentElement instanceof Class) {
24
        if (parentElement instanceof IType) {
22
			return ((Class<?>)parentElement).getDeclaredMethods();
25
            try {
23
		}
26
                return ((IType) parentElement).getMethods();
24
		return new Object[] {};
27
            } catch (JavaModelException jme) {
25
	}
28
                JAXWSUIPlugin.log(jme.getStatus());
26
29
            }
27
	public Object getParent(Object element) {
30
        }
28
		return null;
31
        return new Object[] {};
29
	}
32
    }
30
33
31
	public boolean hasChildren(Object element) {
34
    public Object getParent(Object element) {
32
		if (element instanceof Class) {
35
        return null;
33
			return ((Class<?>)element).getDeclaredMethods().length > 0;
36
    }
34
		}
37
35
		return false;
38
    public boolean hasChildren(Object element) {
36
	}
39
        if (element instanceof IType) {
37
40
            try {
38
	public Object[] getElements(Object inputElement) {
41
                return ((IType) element).getMethods().length > 0;
39
		if (inputElement != null && inputElement instanceof IJavaElement && ((IJavaElement) inputElement).exists()) {
42
            } catch (JavaModelException jme) {
40
			IJavaElement javaElement = (IJavaElement) inputElement;
43
                JAXWSUIPlugin.log(jme.getStatus());
41
			return AnnotationsManager.getAnnotations(javaElement).toArray();
44
            }
42
		}
45
        }
43
		return new Object[] {};
46
        return false;
44
	}
47
    }
48
49
    public Object[] getElements(Object inputElement) {
50
        if (inputElement != null && inputElement instanceof IJavaElement && ((IJavaElement) inputElement).exists()) {
51
            IJavaElement javaElement = (IJavaElement) inputElement;
52
            return AnnotationsManager.getAnnotationTypes(javaElement).toArray();
53
        }
54
        return new Object[] {};
55
    }
45
56
46
	public void dispose() {
57
    public void dispose() {
47
58
48
	}
59
    }
49
60
50
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
61
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
51
	}
62
    }
52
63
53
}
64
}
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/views/ClassDialogCellEditor.java (-1 / +1 lines)
Lines 56-62 Link Here
56
    
56
    
57
    @Override
57
    @Override
58
    protected void updateContents(Object value) {
58
    protected void updateContents(Object value) {
59
        if (value != null) {
59
        if (value != null && value.toString().trim().length() > 0) {
60
            getDefaultLabel().setText(value.toString() + ".class"); //$NON-NLS-1$
60
            getDefaultLabel().setText(value.toString() + ".class"); //$NON-NLS-1$
61
        } else {
61
        } else {
62
            getDefaultLabel().setText(""); //$NON-NLS-1$
62
            getDefaultLabel().setText(""); //$NON-NLS-1$

Return to bug 325364