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.Set;
19
import java.util.Set;
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().trim());
466
                        text.setText(value.toString().trim());
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 / +287 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-36 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.ILocalVariable;
31
import org.eclipse.jdt.core.IMemberValuePair;
31
import org.eclipse.jdt.core.IMemberValuePair;
32
import org.eclipse.jdt.core.IMethod;
32
import org.eclipse.jdt.core.IMethod;
33
import org.eclipse.jdt.core.IType;
33
import org.eclipse.jdt.core.JavaModelException;
34
import org.eclipse.jdt.core.JavaModelException;
35
import org.eclipse.jdt.core.Signature;
34
import org.eclipse.jdt.core.dom.AST;
36
import org.eclipse.jdt.core.dom.AST;
35
import org.eclipse.jdt.core.dom.ASTNode;
37
import org.eclipse.jdt.core.dom.ASTNode;
36
import org.eclipse.jdt.core.dom.Annotation;
38
import org.eclipse.jdt.core.dom.Annotation;
Lines 53-58 Link Here
53
import org.eclipse.jst.ws.annotations.core.AnnotationsManager;
55
import org.eclipse.jst.ws.annotations.core.AnnotationsManager;
54
import org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer;
56
import org.eclipse.jst.ws.annotations.core.initialization.IAnnotationAttributeInitializer;
55
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;
56
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIMessages;
59
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIMessages;
57
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIPlugin;
60
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIPlugin;
58
import org.eclipse.ltk.core.refactoring.Change;
61
import org.eclipse.ltk.core.refactoring.Change;
Lines 63-68 Link Here
63
import org.eclipse.text.edits.MultiTextEdit;
66
import org.eclipse.text.edits.MultiTextEdit;
64
67
65
public class AnnotationsValuesEditingSupport extends EditingSupport {
68
public class AnnotationsValuesEditingSupport extends EditingSupport {
69
66
    private AnnotationsView annotationsView;
70
    private AnnotationsView annotationsView;
67
    private TreeViewer treeViewer;
71
    private TreeViewer treeViewer;
68
72
Lines 85-181 Link Here
85
89
86
    @Override
90
    @Override
87
    protected boolean canEdit(Object element) {
91
    protected boolean canEdit(Object element) {
88
        if (element instanceof Method) {
92
        if (element instanceof IMethod) {
89
            Method method = (Method)element;
93
            IMethod method = (IMethod) element;
90
            return (Boolean) getValue(method.getDeclaringClass());
94
            return (Boolean) getValue(method.getDeclaringType());
91
        }
95
        }
92
        return true;
96
        return true;
93
    }
97
    }
94
98
95
    @Override
99
    @Override
96
    protected CellEditor getCellEditor(Object element) {
100
    protected CellEditor getCellEditor(Object element) {
97
        if (element instanceof Class) {
101
        if (element instanceof IType) {
98
            return checkboxCellEditor;
102
            return checkboxCellEditor;
99
        }
103
        }
100
        if (element instanceof Method) {
104
        if (element instanceof IMethod) {
101
            Method method = (Method) element;
105
            try {
102
            final Class<?> returnType = method.getReturnType();
106
                IMethod method = (IMethod) element;
103
            if (returnType.isEnum()) {
107
104
                Object[] enumConstants = returnType.getEnumConstants();
108
                IType enumType = SignatureUtils.getEnumReturnType(method);
105
                String[] values = new String[enumConstants.length];
109
                if (enumType != null) {
106
                for (int i = 0; i < enumConstants.length; i++) {
110
                    comboBoxCellEditor.setItems(SignatureUtils.getEnumConstantsNames(enumType));
107
                    values[i] = enumConstants[i].toString();
111
                    return comboBoxCellEditor;
108
                }
112
                }
109
                comboBoxCellEditor.setItems(values);
113
110
                return comboBoxCellEditor;
114
                final String returnType = method.getReturnType();
111
            }
115
112
            if (returnType.equals(Boolean.TYPE)) {
116
                if (SignatureUtils.isBoolean(returnType)) {
113
                return checkboxCellEditor;
117
                    return checkboxCellEditor;
114
            }
118
                }
115
119
116
            if (returnType.equals(Class.class)) {
120
                if (SignatureUtils.isClass(returnType)) {
117
                return classDialogCellEditor;
121
                    return classDialogCellEditor;
118
            }
122
                }
119
123
120
            if (returnType.isArray()) {
124
                if (SignatureUtils.isArray(returnType)) {
121
                annotationArrayCellEditor.setMethod(method);
125
                    annotationArrayCellEditor.setMethod(method);
122
                return annotationArrayCellEditor;
126
                    return annotationArrayCellEditor;
123
            }
127
                }
124
            if (returnType.isPrimitive()) {
128
                if (SignatureUtils.isPrimitive(returnType)) {
125
                textCellEditor.setValidator(new ICellEditorValidator() {
129
                    textCellEditor.setValidator(new ICellEditorValidator() {
126
                    public String isValid(Object value) {
130
                        public String isValid(Object value) {
127
                        try {
131
                            try {
128
                            if (returnType.equals(Byte.TYPE)) {
132
                                if (returnType.charAt(0) == Signature.C_BYTE) {
129
                                Byte.parseByte((String) value);
133
                                    Byte.parseByte((String) value);
130
                            }
134
                                }
131
                            if (returnType.equals(Short.TYPE)) {
135
                                if (returnType.charAt(0) == Signature.C_SHORT) {
132
                                Short.parseShort((String) value);
136
                                    Short.parseShort((String) value);
133
                            }
137
                                }
134
                            if (returnType.equals(Integer.TYPE)) {
138
                                if (returnType.charAt(0) == Signature.C_INT) {
135
                                Integer.parseInt((String) value);
139
                                    Integer.parseInt((String) value);
136
                            }
140
                                }
137
                            if (returnType.equals(Long.TYPE)) {
141
                                if (returnType.charAt(0) == Signature.C_LONG) {
138
                                Long.parseLong((String) value);
142
                                    Long.parseLong((String) value);
139
                            }
143
                                }
140
                            if (returnType.equals(Float.TYPE)) {
144
                                if (returnType.charAt(0) == Signature.C_FLOAT) {
141
                                Float.parseFloat((String) value);
145
                                    Float.parseFloat((String) value);
142
                            }
146
                                }
143
                            if (returnType.equals(Double.TYPE)) {
147
                                if (returnType.charAt(0) == Signature.C_DOUBLE) {
144
                                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;
145
                            }
152
                            }
146
                        } catch (NumberFormatException nfe) {
153
                            return null;
147
                            return JAXWSUIMessages.ANNOTATION_EDITING_SUPPORT_NOT_VALID_MESSAGE_PREFIX
148
                            + returnType.getSimpleName();
149
                        }
154
                        }
150
                        return null;
155
                    });
151
                    }
156
                    return textCellEditor;
152
                });
157
                }
153
                return textCellEditor;
158
                return textCellEditor;
159
            } catch (JavaModelException jme) {
160
                JAXWSUIPlugin.log(jme.getStatus());
154
            }
161
            }
155
            return textCellEditor;
156
        }
162
        }
157
        return checkboxCellEditor;
163
        return checkboxCellEditor;
158
    }
164
    }
159
165
160
    @Override
166
    @Override
161
    protected Object getValue(Object element) {
167
    protected Object getValue(Object element) {
162
        if (element instanceof Class) {
168
        if (element instanceof IType) {
163
            return getValueForClass((Class<?>) element);
169
            return getValueForClass((IType) element);
164
        }
170
        }
165
        if (element instanceof Method) {
171
        if (element instanceof IMethod) {
166
            return getValueForMethod((Method) element);
172
            return getValueForMethod((IMethod) element);
167
        }
173
        }
168
        return null;
174
        return null;
169
    }
175
    }
170
176
171
    private Object getValueForClass(Class<?> aClass) {
177
    private Object getValueForClass(IType type) {
172
        if (treeViewer.getInput() instanceof IAnnotatable) {
178
        if (treeViewer.getInput() instanceof IAnnotatable) {
173
            return getValueForClass(aClass, (IAnnotatable) treeViewer.getInput());
179
            return getValueForClass(type, (IAnnotatable) treeViewer.getInput());
174
        }
180
        }
175
        return Boolean.FALSE;
181
        return Boolean.FALSE;
176
    }
182
    }
177
183
178
    private Object getValueForClass(Class<?> aClass, IAnnotatable annotatedElement) {
184
    private Object getValueForClass(IType type, IAnnotatable annotatedElement) {
179
        if (annotatedElement instanceof ILocalVariable) {
185
        if (annotatedElement instanceof ILocalVariable) {
180
            ILocalVariable localVariable = getLocalVariable(annotatedElement);
186
            ILocalVariable localVariable = getLocalVariable(annotatedElement);
181
            if (localVariable != null) {
187
            if (localVariable != null) {
Lines 187-194 Link Here
187
            for (IAnnotation annotation : annotations) {
193
            for (IAnnotation annotation : annotations) {
188
                String annotationName = annotation.getElementName();
194
                String annotationName = annotation.getElementName();
189
                if (AnnotationUtils.isAnnotationPresent((IJavaElement)annotatedElement, annotationName)
195
                if (AnnotationUtils.isAnnotationPresent((IJavaElement)annotatedElement, annotationName)
190
                        && (annotationName.equals(aClass.getSimpleName())
196
                        && (annotationName.equals(type.getElementName())
191
                                || annotationName.equals(aClass.getCanonicalName()))) {
197
                                || annotationName.equals(type.getFullyQualifiedName()))) {
192
                    return Boolean.TRUE;
198
                    return Boolean.TRUE;
193
                }
199
                }
194
            }
200
            }
Lines 198-204 Link Here
198
        return Boolean.FALSE;
204
        return Boolean.FALSE;
199
    }
205
    }
200
206
201
    private Object getValueForMethod(Method method) {
207
    private Object getValueForMethod(IMethod method) {
202
        Object value = null;
208
        Object value = null;
203
        try {
209
        try {
204
            if (treeViewer.getInput() instanceof IAnnotatable) {
210
            if (treeViewer.getInput() instanceof IAnnotatable) {
Lines 210-259 Link Here
210
        return value;
216
        return value;
211
    }
217
    }
212
218
213
    private Object getValueForMethod(Method method, IAnnotatable annotatedElement) throws JavaModelException {
219
    private Object getValueForMethod(IMethod method, IAnnotatable annotatedElement) throws JavaModelException {
214
        if (annotatedElement instanceof ILocalVariable) {
220
        if (annotatedElement instanceof ILocalVariable) {
215
            ILocalVariable localVariable = getLocalVariable(annotatedElement);
221
            ILocalVariable localVariable = getLocalVariable(annotatedElement);
216
            if (localVariable != null) {
222
            if (localVariable != null) {
217
                annotatedElement = localVariable;
223
                annotatedElement = localVariable;
218
            }
224
            }
219
        }
225
        }
220
        Class<?> returnType = method.getReturnType();
226
        String returnType = method.getReturnType();
221
        IAnnotation[] annotations = annotatedElement.getAnnotations();
227
        IAnnotation[] annotations = annotatedElement.getAnnotations();
222
        for (IAnnotation annotation : annotations) {
228
        for (IAnnotation annotation : annotations) {
223
            Class<?> declaringClass = method.getDeclaringClass();
229
            IType declaringType = method.getDeclaringType();
230
224
            String annotationName = annotation.getElementName();
231
            String annotationName = annotation.getElementName();
225
            if (annotationName.equals(declaringClass.getSimpleName())
232
            if (annotationName.equals(declaringType.getElementName())
226
                    || annotationName.equals(declaringClass.getCanonicalName())) {
233
                    || annotationName.equals(declaringType.getFullyQualifiedName())) {
227
                IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs();
234
                IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs();
228
                for (IMemberValuePair memberValuePair : memberValuePairs) {
235
                for (IMemberValuePair memberValuePair : memberValuePairs) {
229
                    if (memberValuePair.getMemberName().equals(method.getName())) {
236
                    if (memberValuePair.getMemberName().equals(method.getElementName())) {
230
                        if (returnType.equals(String.class)) {
237
                        if (SignatureUtils.isString(returnType)) {
231
                            return memberValuePair.getValue();
238
                            return memberValuePair.getValue();
232
                        }
239
                        }
233
240
234
                        if (returnType.isEnum()) {
241
                        IType enumType = SignatureUtils.getEnumReturnType(method);
242
                        if (enumType != null) {
235
                            String enumValue = memberValuePair.getValue().toString();
243
                            String enumValue = memberValuePair.getValue().toString();
236
                            String literal = enumValue.substring(enumValue.lastIndexOf(".") + 1); //$NON-NLS-1$
244
                            String literal = enumValue.substring(enumValue.lastIndexOf(".") + 1); //$NON-NLS-1$
237
                            Object[] enumConstants = method.getReturnType().getEnumConstants();
245
                            String[] enumConstants = SignatureUtils.getEnumConstantsNames(enumType);
238
                            for (int i = 0; i < enumConstants.length; i++) {
246
                            for (int i = 0; i < enumConstants.length; i++) {
239
                                if (enumConstants[i].toString().equals(literal)) {
247
                                if (enumConstants[i].equals(literal)) {
240
                                    return i;
248
                                    return i;
241
                                }
249
                                }
242
                            }
250
                            }
243
                        }
251
                        }
244
252
                        if (SignatureUtils.isClass(returnType)) {
245
                        if (returnType.equals(Class.class)) {
246
                            return memberValuePair.getValue();
253
                            return memberValuePair.getValue();
247
                        }
254
                        }
248
255
249
                        if (returnType.equals(Boolean.TYPE)) {
256
                        if (SignatureUtils.isBoolean(returnType)) {
250
                            return memberValuePair.getValue();
257
                            return memberValuePair.getValue();
251
                        }
258
                        }
252
259
253
                        if (returnType.isPrimitive()) {
260
                        if (SignatureUtils.isPrimitive(returnType)) {
254
                            return ""; //$NON-NLS-1$
261
                            return ""; //$NON-NLS-1$
255
                        }
262
                        }
256
                        if (returnType.isArray()) {
263
                        if (SignatureUtils.isArray(returnType)) {
257
                            if (memberValuePair.getValueKind() == IMemberValuePair.K_CLASS) {
264
                            if (memberValuePair.getValueKind() == IMemberValuePair.K_CLASS) {
258
                                Object[] arrayValues = (Object[])memberValuePair.getValue();
265
                                Object[] arrayValues = (Object[])memberValuePair.getValue();
259
                                for (int i = 0; i < arrayValues.length; i++) {
266
                                for (int i = 0; i < arrayValues.length; i++) {
Lines 266-293 Link Here
266
                        }
273
                        }
267
                    }
274
                    }
268
                }
275
                }
269
                return getDefaultValueForMethod(returnType);
276
                return getDefaultValueForMethod(method);
270
            }
277
            }
271
        }
278
        }
272
        return null;
279
        return null;
273
    }
280
    }
274
281
275
    private Object getDefaultValueForMethod(Class<?> returnType) {
282
    private Object getDefaultValueForMethod(IMethod method) throws JavaModelException {
276
        if (returnType.equals(String.class)) {
283
        String returnType = method.getReturnType();
284
285
        if (SignatureUtils.isString(returnType)) {
277
            return ""; //$NON-NLS-1$
286
            return ""; //$NON-NLS-1$
278
        }
287
        }
279
        if (returnType.equals(Boolean.TYPE)) {
288
289
        if (SignatureUtils.isBoolean(returnType)) {
280
            return Boolean.FALSE;
290
            return Boolean.FALSE;
281
        }
291
        }
282
        if (returnType.isEnum()) {
292
293
        if (SignatureUtils.isEnum(method)) {
283
            return -1;
294
            return -1;
284
        }
295
        }
285
        if (returnType.isPrimitive()) {
296
297
        if (SignatureUtils.isPrimitive(returnType)) {
286
            return ""; //$NON-NLS-1$
298
            return ""; //$NON-NLS-1$
287
        }
299
        }
288
        if (returnType.isArray()) {
300
301
        if (SignatureUtils.isArray(returnType)) {
289
            return new Object[] {};
302
            return new Object[] {};
290
        }
303
        }
304
291
        return null;
305
        return null;
292
    }
306
    }
293
307
Lines 310-350 Link Here
310
        }
324
        }
311
325
312
        try {
326
        try {
313
            if (element instanceof Class && ((Class<?>) element).isAnnotation()) {
327
            if (element instanceof IType && ((IType) element).isAnnotation()) {
314
                @SuppressWarnings("unchecked")
328
                setValueForClass((IType) element, (Boolean) value);
315
                Class<? extends java.lang.annotation.Annotation> annotationClass =
316
                    (Class<? extends java.lang.annotation.Annotation>) element;
317
                if (annotationClass != null) {
318
                    setValueForClass(annotationClass, (Boolean) value);
319
                }
320
            }
329
            }
321
            if (element instanceof Method) {
330
322
                setValueForMethod((Method) element, value);
331
            if (element instanceof IMethod) {
332
                setValueForMethod((IMethod) element, value);
323
            }
333
            }
324
        } catch (CoreException ce) {
334
        } catch (CoreException ce) {
325
            JAXWSUIPlugin.log(ce.getStatus());
335
            JAXWSUIPlugin.log(ce.getStatus());
326
        }
336
        }
327
    }
337
    }
328
338
329
    private void setValueForClass(Class<? extends java.lang.annotation.Annotation> annotationClass,
339
    private void setValueForClass(IType type, Boolean annotate) throws CoreException {
330
            Boolean annotate) throws CoreException {
331
        Object viewerInput = treeViewer.getInput();
340
        Object viewerInput = treeViewer.getInput();
332
341
333
        IAnnotationAttributeInitializer annotationAttributeInitializer =
342
        IAnnotationAttributeInitializer annotationAttributeInitializer =
334
            AnnotationsManager.getAnnotationDefinitionForClass(annotationClass).getAnnotationAttributeInitializer();
343
            AnnotationsManager.getAnnotationDefinitionForClass(type.getFullyQualifiedName()).getAnnotationAttributeInitializer();
335
344
336
        if (viewerInput instanceof IJavaElement) {
345
        if (viewerInput instanceof IJavaElement) {
337
            setValueForClass(annotationClass, annotate, (IJavaElement) viewerInput, annotationAttributeInitializer);
346
            setValueForClass(type, annotate, (IJavaElement) viewerInput, annotationAttributeInitializer);
338
        }
347
        }
339
    }
348
    }
340
349
341
    private Annotation getAnnotation(AST ast, Class<? extends java.lang.annotation.Annotation> annotationClass,
350
    private Annotation getAnnotation(AST ast, IType type, List<MemberValuePair> memberValuePairs) throws JavaModelException {
342
            List<MemberValuePair> memberValuePairs) {
343
344
        Annotation annotation =  null;
351
        Annotation annotation =  null;
345
        int numberOfDeclaredMethods = annotationClass.getDeclaredMethods().length;
352
        int numberOfDeclaredMethods = type.getMethods().length;
346
        if (numberOfDeclaredMethods == 0) {
353
        if (numberOfDeclaredMethods == 0) {
347
            annotation = AnnotationsCore.createMarkerAnnotation(ast, annotationClass.getSimpleName());
354
            annotation = AnnotationsCore.createMarkerAnnotation(ast, type.getElementName());
348
        } else if (numberOfDeclaredMethods == 1) {
355
        } else if (numberOfDeclaredMethods == 1) {
349
            Expression value = null;
356
            Expression value = null;
350
            if (memberValuePairs != null && memberValuePairs.size() == 1) {
357
            if (memberValuePairs != null && memberValuePairs.size() == 1) {
Lines 354-381 Link Here
354
                }
361
                }
355
            }
362
            }
356
            if (value != null) {
363
            if (value != null) {
357
                annotation = AnnotationsCore.createSingleMemberAnnotation(ast, annotationClass.getSimpleName(), value);
364
                annotation = AnnotationsCore.createSingleMemberAnnotation(ast, type.getElementName(), value);
358
            } else {
365
            } else {
359
                annotation = AnnotationsCore.createNormalAnnotation(ast, annotationClass.getSimpleName(), memberValuePairs);
366
                annotation = AnnotationsCore.createNormalAnnotation(ast, type.getElementName(), memberValuePairs);
360
            }
367
            }
361
        } else if (numberOfDeclaredMethods > 1) {
368
        } else if (numberOfDeclaredMethods > 1) {
362
            annotation = AnnotationsCore.createNormalAnnotation(ast, annotationClass.getSimpleName(), memberValuePairs);
369
            annotation = AnnotationsCore.createNormalAnnotation(ast, type.getElementName(), memberValuePairs);
363
        }
370
        }
364
371
365
        return annotation;
372
        return annotation;
366
    }
373
    }
367
374
368
    private void setValueForClass(Class<? extends java.lang.annotation.Annotation> annotationClass,
375
    private void setValueForClass(IType type, Boolean annotate, IJavaElement javaElement,
369
            Boolean annotate, IJavaElement javaElement, IAnnotationAttributeInitializer annotationAttributeInitializer)
376
            IAnnotationAttributeInitializer annotationAttributeInitializer) throws CoreException {
370
    throws CoreException {
371
        ICompilationUnit source = AnnotationUtils.getCompilationUnitFromJavaElement(javaElement);
377
        ICompilationUnit source = AnnotationUtils.getCompilationUnitFromJavaElement(javaElement);
372
        CompilationUnit compilationUnit = SharedASTProvider.getAST(source, SharedASTProvider.WAIT_YES, null);
378
        CompilationUnit compilationUnit = SharedASTProvider.getAST(source, SharedASTProvider.WAIT_YES, null);
373
        AST ast = compilationUnit.getAST();
379
        AST ast = compilationUnit.getAST();
374
380
375
        List<MemberValuePair> memberValuePairs = getMemberValuePairs(annotationAttributeInitializer, javaElement,
381
        List<MemberValuePair> memberValuePairs = getMemberValuePairs(annotationAttributeInitializer, javaElement,
376
                ast, annotationClass);
382
                ast, type);
377
383
378
        Annotation annotation = getAnnotation(ast, annotationClass, memberValuePairs);
384
        Annotation annotation = getAnnotation(ast, type, memberValuePairs);
379
385
380
        TextFileChange change = new TextFileChange("Add/Remove Annotation", (IFile) source.getResource()); //$NON-NLS-1$
386
        TextFileChange change = new TextFileChange("Add/Remove Annotation", (IFile) source.getResource()); //$NON-NLS-1$
381
        MultiTextEdit multiTextEdit = new MultiTextEdit();
387
        MultiTextEdit multiTextEdit = new MultiTextEdit();
Lines 387-393 Link Here
387
                    || javaElement.getElementType() == IJavaElement.FIELD
393
                    || javaElement.getElementType() == IJavaElement.FIELD
388
                    || javaElement.getElementType() == IJavaElement.METHOD
394
                    || javaElement.getElementType() == IJavaElement.METHOD
389
                    || javaElement.getElementType() == IJavaElement.LOCAL_VARIABLE) {
395
                    || javaElement.getElementType() == IJavaElement.LOCAL_VARIABLE) {
390
                change.addEdit(AnnotationUtils.createAddImportTextEdit(javaElement, annotationClass.getCanonicalName()));
396
                change.addEdit(AnnotationUtils.createAddImportTextEdit(javaElement, type.getFullyQualifiedName()));
391
                change.addEdit(AnnotationUtils.createAddAnnotationTextEdit(javaElement, annotation));
397
                change.addEdit(AnnotationUtils.createAddAnnotationTextEdit(javaElement, annotation));
392
            }
398
            }
393
        } else {
399
        } else {
Lines 396-420 Link Here
396
                    || javaElement.getElementType() == IJavaElement.FIELD
402
                    || javaElement.getElementType() == IJavaElement.FIELD
397
                    || javaElement.getElementType() == IJavaElement.METHOD
403
                    || javaElement.getElementType() == IJavaElement.METHOD
398
                    || javaElement.getElementType() == IJavaElement.LOCAL_VARIABLE) {
404
                    || javaElement.getElementType() == IJavaElement.LOCAL_VARIABLE) {
399
                change.addEdit(AnnotationUtils.createRemoveImportTextEdit(javaElement, annotationClass.getCanonicalName()));
405
                change.addEdit(AnnotationUtils.createRemoveImportTextEdit(javaElement, type.getFullyQualifiedName()));
400
                change.addEdit(AnnotationUtils.createRemoveAnnotationTextEdit(javaElement, annotation));
406
                change.addEdit(AnnotationUtils.createRemoveAnnotationTextEdit(javaElement, annotation));
401
            }
407
            }
402
        }
408
        }
403
        executeChange(new NullProgressMonitor(), change);
409
        executeChange(new NullProgressMonitor(), change);
404
    }
410
    }
405
411
406
    private List<MemberValuePair> getMemberValuePairs(
412
    private List<MemberValuePair> getMemberValuePairs(IAnnotationAttributeInitializer annotationAttributeInitializer,
407
            IAnnotationAttributeInitializer annotationAttributeInitializer, IJavaElement javaElement, AST ast,
413
            IJavaElement javaElement, AST ast, IType type) {
408
            Class<?extends java.lang.annotation.Annotation> annotationClass) {
409
        if (annotationAttributeInitializer != null) {
414
        if (annotationAttributeInitializer != null) {
410
            return annotationAttributeInitializer.getMemberValuePairs(javaElement, ast, annotationClass);
415
            List<MemberValuePair> memberValuePairs = annotationAttributeInitializer.getMemberValuePairs(javaElement, ast, type);
416
            if (memberValuePairs.size() > 0) {
417
                return memberValuePairs;
418
            } else {
419
                return annotationAttributeInitializer.getMemberValuePairs(javaElement, ast,
420
                        AnnotationsManager.getAnnotationDefinitionForType(type).getAnnotationClass());
421
            }
411
        }
422
        }
412
        return Collections.emptyList();
423
        return Collections.emptyList();
413
    }
424
    }
414
425
415
426
    private void setValueForMethod(IMethod method, Object value) throws CoreException {
416
    private void setValueForMethod(Method method, Object value) throws CoreException {
427
        if (value instanceof String) {
417
        if (((Boolean) getValue(method.getDeclaringClass())).booleanValue()) {
428
            Object currentValue = getValue(method);
429
            if (currentValue != null && currentValue instanceof String) {
430
                if (((String) value).equals(currentValue)) {
431
                    return;
432
                }
433
            }
434
        }
435
        if (((Boolean) getValue(method.getDeclaringType())).booleanValue()) {
418
            Object viewerInput = treeViewer.getInput();
436
            Object viewerInput = treeViewer.getInput();
419
            if (viewerInput instanceof IAnnotatable) {
437
            if (viewerInput instanceof IAnnotatable) {
420
                setValueForMethod(method, value, (IJavaElement) viewerInput);
438
                setValueForMethod(method, value, (IJavaElement) viewerInput);
Lines 422-428 Link Here
422
        }
440
        }
423
    }
441
    }
424
442
425
    private void setValueForMethod(Method method, Object value, IJavaElement javaElement) throws CoreException {
443
    private void setValueForMethod(IMethod method, Object value, IJavaElement javaElement) throws CoreException {
426
        ICompilationUnit source = AnnotationUtils.getCompilationUnitFromJavaElement(javaElement);
444
        ICompilationUnit source = AnnotationUtils.getCompilationUnitFromJavaElement(javaElement);
427
        CompilationUnit compilationUnit = SharedASTProvider.getAST(source, SharedASTProvider.WAIT_YES, null);
445
        CompilationUnit compilationUnit = SharedASTProvider.getAST(source, SharedASTProvider.WAIT_YES, null);
428
        AST ast = compilationUnit.getAST();
446
        AST ast = compilationUnit.getAST();
Lines 435-448 Link Here
435
        for (Annotation annotation : annotations) {
453
        for (Annotation annotation : annotations) {
436
            if (annotation instanceof NormalAnnotation) {
454
            if (annotation instanceof NormalAnnotation) {
437
                NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
455
                NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
438
                Class<?> declaringClass = method.getDeclaringClass();
456
                IType declaringType = method.getDeclaringType();
439
                String annotationName = normalAnnotation.getTypeName().getFullyQualifiedName();
457
                String annotationName = normalAnnotation.getTypeName().getFullyQualifiedName();
440
                if (annotationName.equals(declaringClass.getSimpleName()) || annotationName.equals(declaringClass.getCanonicalName())) {
458
                if (annotationName.equals(declaringType.getElementName()) || annotationName.equals(declaringType.getFullyQualifiedName())) {
441
                    @SuppressWarnings("unchecked")
459
                    @SuppressWarnings("unchecked")
442
                    List<MemberValuePair> memberValuePairs = normalAnnotation.values();
460
                    List<MemberValuePair> memberValuePairs = normalAnnotation.values();
443
                    boolean hasMemberValuePair = false;
461
                    boolean hasMemberValuePair = false;
444
                    for (MemberValuePair memberValuePair : memberValuePairs) {
462
                    for (MemberValuePair memberValuePair : memberValuePairs) {
445
                        if (memberValuePair.getName().getIdentifier().equals(method.getName())) {
463
                        if (memberValuePair.getName().getIdentifier().equals(method.getElementName())) {
446
                            ASTNode memberValue = getMemberValuePairValue(ast, method, value);
464
                            ASTNode memberValue = getMemberValuePairValue(ast, method, value);
447
                            if (memberValue != null) {
465
                            if (memberValue != null) {
448
                                change.addEdit(AnnotationUtils.createUpdateMemberValuePairTextEdit(memberValuePair, memberValue));
466
                                change.addEdit(AnnotationUtils.createUpdateMemberValuePairTextEdit(memberValuePair, memberValue));
Lines 461-469 Link Here
461
                }
479
                }
462
            } else if (annotation instanceof SingleMemberAnnotation) {
480
            } else if (annotation instanceof SingleMemberAnnotation) {
463
                SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) annotation;
481
                SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) annotation;
464
                Class<?> declaringClass = method.getDeclaringClass();
482
                IType declaringType = method.getDeclaringType();
465
                String annotationName = singleMemberAnnotation.getTypeName().getFullyQualifiedName();
483
                String annotationName = singleMemberAnnotation.getTypeName().getFullyQualifiedName();
466
                if (annotationName.equals(declaringClass.getSimpleName()) || annotationName.equals(declaringClass.getCanonicalName())) {
484
                if (annotationName.equals(declaringType.getElementName()) || annotationName.equals(declaringType.getFullyQualifiedName())) {
467
                    MemberValuePair memberValuePair = getMemberValuePair(ast, method, value);
485
                    MemberValuePair memberValuePair = getMemberValuePair(ast, method, value);
468
                    if (memberValuePair != null) {
486
                    if (memberValuePair != null) {
469
                        change.addEdit(AnnotationUtils.createUpdateSingleMemberAnnotationTextEdit(singleMemberAnnotation, memberValuePair.getValue()));
487
                        change.addEdit(AnnotationUtils.createUpdateSingleMemberAnnotationTextEdit(singleMemberAnnotation, memberValuePair.getValue()));
Lines 477-552 Link Here
477
        executeChange(new NullProgressMonitor(), change);
495
        executeChange(new NullProgressMonitor(), change);
478
    }
496
    }
479
497
480
    private ASTNode getMemberValuePairValue(AST ast, Method method, Object value) {
498
    private MemberValuePair getMemberValuePair(AST ast, IMethod method, Object value) throws JavaModelException {
481
        Class<?> returnType = method.getReturnType();
499
        String returnType = method.getReturnType();
482
        if (returnType.equals(String.class)) {
500
        if (SignatureUtils.isString(returnType)) {
483
            return AnnotationsCore.createStringLiteral(ast, value.toString());
501
            return AnnotationsCore.createStringMemberValuePair(ast, method.getElementName(), (String) value);
484
        }
502
        }
485
        if (returnType.equals(Boolean.TYPE)) {
503
        if (SignatureUtils.isBoolean(returnType)) {
486
            return AnnotationsCore.createBooleanLiteral(ast, ((Boolean) value).booleanValue());
504
            return AnnotationsCore.createBooleanMemberValuePair(ast, method.getElementName(), (Boolean) value);
505
        }
506
507
        if (SignatureUtils.isPrimitive(returnType)) {
508
            if (returnType.charAt(0) == Signature.C_BYTE
509
                    || returnType.charAt(0) == Signature.C_SHORT
510
                    || returnType.charAt(0) == Signature.C_INT
511
                    || returnType.charAt(0) == Signature.C_LONG
512
                    || returnType.charAt(0) == Signature.C_FLOAT
513
                    || returnType.charAt(0) == Signature.C_DOUBLE) {
514
                return AnnotationsCore.createNumberMemberValuePair(ast, method.getElementName(), value.toString());
515
            }
487
        }
516
        }
488
        if (returnType.isPrimitive()
517
489
                && (returnType.equals(Byte.TYPE) || returnType.equals(Short.TYPE)
518
        if (SignatureUtils.isArray(returnType)) {
490
                        || returnType.equals(Integer.TYPE) || returnType.equals(Long.TYPE)
519
            IType componentType = getComponentType(method);
491
                        || returnType.equals(Float.TYPE) || returnType.equals(Double.TYPE))) {
520
            if (componentType != null) {
492
            return AnnotationsCore.createNumberLiteral(ast, value.toString());
521
                if (componentType.isAnnotation()) {
493
        }
522
                    return createArrayMemberValuePair(ast, method, (Object[]) value);
494
        if (returnType.isArray()) {
523
                } else {
495
            if (method.getReturnType().getComponentType().isAnnotation()) {
524
                    return AnnotationsCore.createArrayMemberValuePair(ast, method.getElementName(), (Object[]) value);
496
                return createArrayValueLiteral(ast, method, (Object[]) value);
525
                }
497
            } else {
498
                return AnnotationsCore.createArrayValueLiteral(ast, (Object[]) value);
499
            }
526
            }
500
        }
527
        }
501
528
502
        if (returnType.equals(Class.class)) {
529
        if (SignatureUtils.isClass(returnType)) {
503
            return AnnotationsCore.createTypeLiteral(ast, value.toString());
530
            return AnnotationsCore.createTypeMemberValuePair(ast, method.getElementName(), value.toString());
504
        }
531
        }
505
532
506
        if (returnType.isEnum()) {
533
        IType enumType = SignatureUtils.getEnumReturnType(method);
534
        if (enumType != null) {
507
            int selected = ((Integer) value).intValue();
535
            int selected = ((Integer) value).intValue();
508
            if (selected != -1) {
536
            if (selected != -1) {
509
                return AnnotationsCore.createEnumLiteral(ast, method.getDeclaringClass().getCanonicalName(),
537
                if (enumType.isMember()) {
510
                        method.getReturnType().getEnumConstants()[selected]);
538
                    return AnnotationsCore.createEnumMemberValuePair(ast, enumType.getDeclaringType().getFullyQualifiedName(),
539
                            method.getElementName(), SignatureUtils.getEnumConstants(enumType)[selected]);
540
                } else {
541
                    return AnnotationsCore.createEnumMemberValuePair(ast, enumType.getFullyQualifiedName(),
542
                            method.getElementName(), SignatureUtils.getEnumConstants(enumType)[selected]);
543
                }
511
            }
544
            }
512
        }
545
        }
513
        return null;
546
        return null;
514
    }
547
    }
515
548
516
    private MemberValuePair getMemberValuePair(AST ast, Method method, Object value) {
549
    private ASTNode getMemberValuePairValue(AST ast, IMethod method, Object value) throws JavaModelException {
517
        Class<?> returnType = method.getReturnType();
550
        String returnType = method.getReturnType();
518
        if (returnType.equals(String.class)) {
551
        if (SignatureUtils.isString(returnType)) {
519
            return AnnotationsCore.createStringMemberValuePair(ast, method.getName(), (String) value);
552
            return AnnotationsCore.createStringLiteral(ast, value.toString());
520
        }
553
        }
521
        if (returnType.equals(Boolean.TYPE)) {
554
522
            return AnnotationsCore.createBooleanMemberValuePair(ast, method.getName(), (Boolean) value);
555
        if (SignatureUtils.isBoolean(returnType)) {
523
        }
556
            return AnnotationsCore.createBooleanLiteral(ast, ((Boolean) value).booleanValue());
524
        if (returnType.isPrimitive()
557
        }
525
                && (returnType.equals(Byte.TYPE) || returnType.equals(Short.TYPE)
558
526
                        || returnType.equals(Integer.TYPE) || returnType.equals(Long.TYPE)
559
        if (SignatureUtils.isPrimitive(returnType)) {
527
                        || returnType.equals(Float.TYPE) || returnType.equals(Double.TYPE))) {
560
            if (returnType.charAt(0) == Signature.C_BYTE
528
            return AnnotationsCore.createNumberMemberValuePair(ast, method.getName(), value.toString());
561
                    || returnType.charAt(0) == Signature.C_SHORT
529
        }
562
                    || returnType.charAt(0) == Signature.C_INT
530
        if (returnType.isArray()) {
563
                    || returnType.charAt(0) == Signature.C_LONG
531
            if (method.getReturnType().getComponentType().isAnnotation()) {
564
                    || returnType.charAt(0) == Signature.C_FLOAT
532
                return createArrayMemberValuePair(ast, method, (Object[]) value);
565
                    || returnType.charAt(0) == Signature.C_DOUBLE) {
533
            } else {
566
                return AnnotationsCore.createNumberLiteral(ast, value.toString());
534
                return AnnotationsCore.createArrayMemberValuePair(ast, method.getName(), (Object[]) value);
567
            }
568
        }
569
570
        if (SignatureUtils.isArray(returnType)) {
571
            IType componentType = getComponentType(method);
572
            if (componentType != null) {
573
                if (componentType.isAnnotation()) {
574
                    return createArrayValueLiteral(ast, method, (Object[]) value);
575
                } else {
576
                    return AnnotationsCore.createArrayValueLiteral(ast, (Object[]) value);
577
                }
535
            }
578
            }
536
        }
579
        }
537
580
538
        if (returnType.equals(Class.class)) {
581
        if (SignatureUtils.isClass(returnType)) {
539
            return AnnotationsCore.createTypeMemberValuePair(ast, method.getName(), value.toString());
582
            return AnnotationsCore.createTypeLiteral(ast, value.toString());
540
        }
583
        }
541
584
542
        if (returnType.isEnum()) {
585
586
        IType enumType = SignatureUtils.getEnumReturnType(method);
587
        if (enumType != null) {
543
            int selected = ((Integer) value).intValue();
588
            int selected = ((Integer) value).intValue();
544
            if (selected != -1) {
589
            if (selected != -1) {
545
                return AnnotationsCore.createEnumMemberValuePair(ast,
590
                if (enumType.isMember()) {
546
                        method.getDeclaringClass().getCanonicalName(), method.getName(), method.getReturnType()
591
                    return AnnotationsCore.createEnumLiteral(ast, enumType.getDeclaringType().getFullyQualifiedName(),
547
                        .getEnumConstants()[selected]);
592
                            SignatureUtils.getEnumConstants(enumType)[selected]);
593
                } else {
594
                    return AnnotationsCore.createEnumLiteral(ast, enumType.getFullyQualifiedName(),
595
                            SignatureUtils.getEnumConstants(enumType)[selected]);
596
                }
548
            }
597
            }
549
        }
598
        }
599
550
        return null;
600
        return null;
551
    }
601
    }
552
602
Lines 578-642 Link Here
578
        annotationsView.refreshLabels();
628
        annotationsView.refreshLabels();
579
    }
629
    }
580
630
581
    private MemberValuePair createArrayMemberValuePair(AST ast, Method method, Object[] values) {
631
    private MemberValuePair createArrayMemberValuePair(AST ast, IMethod method, Object[] values) throws JavaModelException {
582
        return AnnotationsCore.createMemberValuePair(ast, method.getName(), createArrayValueLiteral(ast,
632
        return AnnotationsCore.createMemberValuePair(ast, method.getElementName(), createArrayValueLiteral(ast,
583
                method, values));
633
                method, values));
584
    }
634
    }
585
635
586
    @SuppressWarnings("unchecked")
636
    private IType getComponentType(IMethod method) throws JavaModelException {
587
    private ArrayInitializer createArrayValueLiteral(AST ast, Method method, Object[] values) {
637
        String returnType = method.getReturnType();
638
        if (SignatureUtils.isArray(returnType)) {
639
            String elementType = Signature.getElementType(returnType);
640
            IType declaringType = method.getDeclaringType();
641
            IJavaProject javaProject = declaringType.getJavaProject();
642
            if (javaProject != null) {
643
                return javaProject.findType(Signature.toString(elementType));
644
            }
645
        }
646
        return null;
647
    }
648
649
    private ArrayInitializer createArrayValueLiteral(AST ast, IMethod method, Object[] values) throws JavaModelException {
588
        ArrayInitializer arrayInitializer = ast.newArrayInitializer();
650
        ArrayInitializer arrayInitializer = ast.newArrayInitializer();
589
        for (Object value : values) {
651
        for (Object value : values) {
590
            if (value instanceof List) {
652
            if (value instanceof List<?>) {
591
                Class<? extends java.lang.annotation.Annotation> annotationClass =
653
                IType componentType = getComponentType(method);
592
                    (Class<? extends java.lang.annotation.Annotation>) method.getReturnType().getComponentType();
654
                if (componentType != null) {
593
655
594
                List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
656
                    List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
595
657
                    @SuppressWarnings("unchecked")
596
                List<Map<String, Object>> valuesList = (List<Map<String, Object>>) value;
658
                    List<Map<String, Object>> valuesList = (List<Map<String, Object>>) value;
597
                Iterator<Map<String, Object>> valuesIterator = valuesList.iterator();
659
                    Iterator<Map<String, Object>> valuesIterator = valuesList.iterator();
598
                while (valuesIterator.hasNext()) {
660
                    while (valuesIterator.hasNext()) {
599
                    Map<String, Object> annotationMap = valuesIterator.next();
661
                        Map<String, Object> annotationMap = valuesIterator.next();
600
                    Set<Entry<String, Object>> entrySet = annotationMap.entrySet();
662
                        Set<Entry<String, Object>> entrySet = annotationMap.entrySet();
601
                    Iterator<Map.Entry<String, Object>> iterator = entrySet.iterator();
663
                        Iterator<Map.Entry<String, Object>> iterator = entrySet.iterator();
602
                    while (iterator.hasNext()) {
664
                        while (iterator.hasNext()) {
603
                        Map.Entry<java.lang.String, Object> entry = iterator.next();
665
                            Map.Entry<java.lang.String, Object> entry = iterator.next();
604
                        String memberName = entry.getKey();
666
                            String memberName = entry.getKey();
605
                        try {
667
                            try {
606
                            Method annotationMethod = annotationClass.getMethod(memberName, new Class[0]);
668
                                IMethod annotationMethod = componentType.getMethod(memberName, new String[] {});
607
                            if (annotationMethod != null) {
669
                                if (annotationMethod != null) {
608
                                Object memberValue = entry.getValue();
670
                                    Object memberValue = entry.getValue();
609
                                Class<?> returnType = annotationMethod.getReturnType();
671
                                    String returnType = annotationMethod.getReturnType();
610
                                if (returnType.equals(String.class)) {
672
                                    if (SignatureUtils.isString(returnType)) {
611
                                    memberValuePairs.add(AnnotationsCore.createStringMemberValuePair(ast, memberName,
673
                                        memberValuePairs.add(AnnotationsCore.createStringMemberValuePair(ast, memberName,
612
                                            memberValue.toString()));
674
                                                memberValue.toString()));
613
                                }
614
                                if (returnType.equals(Boolean.TYPE)) {
615
                                    memberValuePairs.add(AnnotationsCore.createBooleanMemberValuePair(ast, memberName,
616
                                            (Boolean) memberValue));
617
                                }
618
                                if (returnType.equals(Class.class)) {
619
                                    String className = memberValue.toString();
620
                                    if (className.endsWith(".class")) {
621
                                        className = className.substring(0, className.lastIndexOf("."));
622
                                    }
675
                                    }
623
                                    memberValuePairs.add(AnnotationsCore.createMemberValuePair(ast, memberName,
676
                                    if (SignatureUtils.isBoolean(returnType)) {
624
                                            AnnotationsCore.createTypeLiteral(ast, className)));
677
                                        memberValuePairs.add(AnnotationsCore.createBooleanMemberValuePair(ast, memberName,
678
                                                (Boolean) memberValue));
679
                                    }
680
                                    if (SignatureUtils.isClass(returnType)) {
681
                                        String className = memberValue.toString();
682
                                        if (className.endsWith(".class")) {
683
                                            className = className.substring(0, className.lastIndexOf("."));
684
                                        }
685
                                        memberValuePairs.add(AnnotationsCore.createMemberValuePair(ast, memberName,
686
                                                AnnotationsCore.createTypeLiteral(ast, className)));
687
                                    }
688
                                    //                                if (returnType.isPrimitive()) {
689
                                    //                                    memberValuePairs.add(getNumberMemberValuePair(ast, memberName, memberValue));
690
                                    //                                }
625
                                }
691
                                }
626
                                //                                if (returnType.isPrimitive()) {
627
                                //                                    memberValuePairs.add(getNumberMemberValuePair(ast, memberName, memberValue));
628
                                //                                }
629
                            }
630
692
631
                        } catch (SecurityException se) {
693
                            } catch (SecurityException se) {
632
                            AnnotationsCorePlugin.log(se);
694
                                AnnotationsCorePlugin.log(se);
633
                        } catch (NoSuchMethodException nsme) {
695
                            }
634
                            AnnotationsCorePlugin.log(nsme);
635
                        }
696
                        }
636
                    }
697
                    }
698
                    arrayInitializer.expressions().add(AnnotationsCore.createNormalAnnotation(ast, componentType.getFullyQualifiedName(),
699
                            memberValuePairs));
637
                }
700
                }
638
                arrayInitializer.expressions().add(AnnotationsCore.createNormalAnnotation(ast, annotationClass.getCanonicalName(),
639
                        memberValuePairs));
640
            }
701
            }
641
        }
702
        }
642
        return arrayInitializer;
703
        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 134-146 Link Here
134
        annotationTreeViewer.setComparator(new ViewerComparator() {
133
        annotationTreeViewer.setComparator(new ViewerComparator() {
135
            @Override
134
            @Override
136
            public int compare(Viewer viewer, Object obj1, Object obj2) {
135
            public int compare(Viewer viewer, Object obj1, Object obj2) {
137
                if (obj1 instanceof Class<?> && ((Class<?>) obj1).isAnnotation()
136
                if (obj1 instanceof IType && obj2 instanceof IType) {
138
                        && obj2 instanceof Class<?> && ((Class<?>) obj2).isAnnotation()) {
137
                    return ((IType) obj1).getFullyQualifiedName().compareTo(
139
                    return ((Class<? extends java.lang.annotation.Annotation>) obj1).getCanonicalName().compareTo(
138
                            ((IType) obj2).getFullyQualifiedName());
140
                            ((Class<? extends java.lang.annotation.Annotation>) obj2).getCanonicalName());
141
                }
139
                }
142
                if (obj1 instanceof Method && obj2 instanceof Method) {
140
                if (obj1 instanceof IMethod && obj2 instanceof IMethod) {
143
                    return ((Method)obj1).getName().compareTo(((Method)obj2).getName());
141
                    return ((IMethod) obj1).getElementName().compareTo(((IMethod) obj2).getElementName());
144
                }
142
                }
145
                return super.compare(viewer, obj1, obj2);
143
                return super.compare(viewer, obj1, obj2);
146
            }
144
            }
(-)src/org/eclipse/jst/ws/internal/jaxws/ui/views/AnnotationsViewCategoryFilter.java (-5 / +3 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.dialogs.IDialogSettings;
17
import org.eclipse.jface.dialogs.IDialogSettings;
18
import org.eclipse.jface.viewers.StructuredViewer;
18
import org.eclipse.jface.viewers.StructuredViewer;
19
import org.eclipse.jface.viewers.Viewer;
19
import org.eclipse.jface.viewers.Viewer;
Lines 38-46 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
            }
Lines 77-81 Link Here
77
        IDialogSettings settings = JAXWSUIPlugin.getDefault().getDialogSettings();
76
        IDialogSettings settings = JAXWSUIPlugin.getDefault().getDialogSettings();
78
        settings.put(TAG_CATEGORY_NAME, categories.toArray(new String[categories.size()]));
77
        settings.put(TAG_CATEGORY_NAME, categories.toArray(new String[categories.size()]));
79
    }
78
    }
80
81
}
79
}
(-)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