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 90344 | Differences between
and this patch

Collapse All | Expand All

(-)ASTConverter.java (+3 lines)
Lines 1892-1897 Link Here
1892
		markerAnnotation.setSourceRange(start, end - start + 1);
1892
		markerAnnotation.setSourceRange(start, end - start + 1);
1893
		if (this.resolveBindings) {
1893
		if (this.resolveBindings) {
1894
			recordNodes(markerAnnotation, annotation);
1894
			recordNodes(markerAnnotation, annotation);
1895
			markerAnnotation.resolveAnnotation();
1895
		}
1896
		}
1896
		return markerAnnotation;
1897
		return markerAnnotation;
1897
	}
1898
	}
Lines 1953-1958 Link Here
1953
		normalAnnotation.setSourceRange(start, end - start + 1);
1954
		normalAnnotation.setSourceRange(start, end - start + 1);
1954
		if (this.resolveBindings) {
1955
		if (this.resolveBindings) {
1955
			recordNodes(normalAnnotation, annotation);
1956
			recordNodes(normalAnnotation, annotation);
1957
			normalAnnotation.resolveAnnotation();
1956
		}
1958
		}
1957
		return normalAnnotation;
1959
		return normalAnnotation;
1958
	}
1960
	}
Lines 2129-2134 Link Here
2129
		singleMemberAnnotation.setSourceRange(start, end - start + 1);
2131
		singleMemberAnnotation.setSourceRange(start, end - start + 1);
2130
		if (this.resolveBindings) {
2132
		if (this.resolveBindings) {
2131
			recordNodes(singleMemberAnnotation, annotation);
2133
			recordNodes(singleMemberAnnotation, annotation);
2134
			singleMemberAnnotation.resolveAnnotation();
2132
		}
2135
		}
2133
		return singleMemberAnnotation;
2136
		return singleMemberAnnotation;
2134
	}
2137
	}
(-)Annotation.java (+15 lines)
Lines 164-168 Link Here
164
	int memSize() {
164
	int memSize() {
165
		return BASE_NODE_SIZE + 1 * 4;
165
		return BASE_NODE_SIZE + 1 * 4;
166
	}
166
	}
167
	
168
	/**
169
	 * Resolves and returns the resolved annotation for this annotation.
170
	 * <p>
171
	 * Note that bindings (which includes resolved annotations) are generally unavailable unless
172
	 * requested when the AST is being built.
173
	 * </p>
174
	 * 
175
	 * @return the resolved annotation, or
176
	 *    <code>null</code> if the annotation cannot be resolved
177
	 * @since 3.2
178
	 */	
179
	public IResolvedAnnotation resolveAnnotation() {
180
	    return this.ast.getBindingResolver().resolveAnnotation(this);
181
	}
167
}
182
}
168
183
(-)BindingResolver.java (-1 / +50 lines)
Lines 17-23 Link Here
17
17
18
/**
18
/**
19
 * A binding resolver is an internal mechanism for figuring out the binding
19
 * A binding resolver is an internal mechanism for figuring out the binding
20
 * for a major declaration, type, or name reference.
20
 * for a major declaration, type, or name reference. This also handles
21
 * the creation and mapping between annotations and the ast nodes that defines them
21
 * <p>
22
 * <p>
22
 * The default implementation serves as the default binding resolver
23
 * The default implementation serves as the default binding resolver
23
 * that does no resolving whatsoever. Internal subclasses do all the real work.
24
 * that does no resolving whatsoever. Internal subclasses do all the real work.
Lines 91-96 Link Here
91
	ASTNode findDeclaringNode(String bindingKey) {
92
	ASTNode findDeclaringNode(String bindingKey) {
92
		return null;
93
		return null;
93
	}
94
	}
95
	
96
	/**
97
	 * Finds the corresponding AST node from which the given annotation instance originated.
98
	 * 
99
	 * The default implementation of this method returns <code>null</code>.
100
	 * Subclasses may reimplement.
101
	 * </p>
102
	 * 
103
	 * @param instance the dom annotation
104
	 * @return the corresponding node where the bindings is declared, 
105
	 *    or <code>null</code> if none
106
	 */
107
	ASTNode findDeclaringNode(IResolvedAnnotation instance){
108
		return null;
109
	}
94
110
95
	/**
111
	/**
96
	 * Allows the user to get information about the given old/new pair of
112
	 * Allows the user to get information about the given old/new pair of
Lines 164-169 Link Here
164
	}
180
	}
165
	
181
	
166
	/**
182
	/**
183
	 * Return the new annotation corresponding to the given old annotation
184
	 * <p>
185
	 * The default implementation of this method returns <code>null</code>
186
	 * Subclasses may reimplement.
187
	 * </p>
188
	 * 
189
	 * @param instance the old annotation 
190
	 * @return the new DOM annotation
191
	 */
192
	IResolvedAnnotation getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance instance){
193
		return null;
194
	}
195
	
196
	/**
167
	 * Returns the compiler lookup environment used by this binding resolver.
197
	 * Returns the compiler lookup environment used by this binding resolver.
168
	 * Returns <code>null</code> if none.
198
	 * Returns <code>null</code> if none.
169
	 * 
199
	 * 
Lines 785-790 Link Here
785
	}
815
	}
786
	
816
	
787
	/**
817
	/**
818
	 * Resolves the given annotation instance and returns the DOM representation for it.
819
	 * <p>
820
	 * The implementation of {@link Annotation#resolveAnnotation()}
821
	 * forwards to this method. 
822
	 * </p>
823
	 * <p>
824
	 * The default implementation of this method returns <code>null</code>.
825
	 * Subclasses may reimplement.
826
	 * </p>
827
	 * 
828
	 * @param annotation the annotation ast node of interest
829
	 * @return the DOM annotation representation for the given ast node, or 
830
	 *    <code>null</code> if none is available
831
	 */
832
	IResolvedAnnotation resolveAnnotation(Annotation annotation){
833
		return null;
834
	}	
835
	
836
	/**
788
	 * Returns the compilation unit scope used by this binding resolver.
837
	 * Returns the compilation unit scope used by this binding resolver.
789
	 * Returns <code>null</code> if none.
838
	 * Returns <code>null</code> if none.
790
	 * 
839
	 * 
(-)CompilationUnit.java (+18 lines)
Lines 406-411 Link Here
406
	public ASTNode findDeclaringNode(IBinding binding) {
406
	public ASTNode findDeclaringNode(IBinding binding) {
407
		return this.ast.getBindingResolver().findDeclaringNode(binding);
407
		return this.ast.getBindingResolver().findDeclaringNode(binding);
408
	}
408
	}
409
	
410
	/**
411
	 * Finds the corresponding AST node in the given compilation unit from 
412
	 * which the given resolved annotation originated. Returns <code>null</code>
413
	 * if the resolved annotation does not correspond to any node in this compilation unit.
414
	 *
415
	 * This method always returns <code>null</code> when the resolved annotation
416
	 * comes from a different AST.
417
	 * 
418
	 * @param resolvedAnnotation the resolved annotation
419
	 * @return the corresponding node where the given resolved annotation is declared,
420
	 * or <code>null</code> if the resolved annotation does not correspond to a node in this
421
	 * compilation unit or if bindings were not requested when this AST was built
422
	 * @since 3.2
423
	 */
424
	public ASTNode findDeclaringNode(IResolvedAnnotation resolvedAnnotation) {
425
		return this.ast.getBindingResolver().findDeclaringNode(resolvedAnnotation);
426
	}
409
427
410
	/**
428
	/**
411
	 * Finds the corresponding AST node in the given compilation unit from 
429
	 * Finds the corresponding AST node in the given compilation unit from 
(-)DefaultBindingResolver.java (-3 / +41 lines)
Lines 90-97 Link Here
90
		Map bindingKeysToBindings;
90
		Map bindingKeysToBindings;
91
		/**
91
		/**
92
		 * This map is used to keep the correspondance between new bindings and the 
92
		 * This map is used to keep the correspondance between new bindings and the 
93
		 * compiler bindings. This is an identity map. We should only create one object
93
		 * compiler bindings as well as new annotation instances to their 
94
		 * for one binding.
94
		 * internal counterpart. 
95
		 * This is an identity map. We should only create one object
96
		 * for one binding or annotation.
97
		 * 
95
		 */
98
		 */
96
		Map compilerBindingsToASTBindings;
99
		Map compilerBindingsToASTBindings;
97
		
100
		
Lines 107-113 Link Here
107
	Map astNodesToBlockScope;
110
	Map astNodesToBlockScope;
108
	
111
	
109
	/**
112
	/**
110
	 * This map is used to get an ast node from its binding (new binding)
113
	 * This map is used to get an ast node from its binding (new binding) or DOM
111
	 */
114
	 */
112
	Map bindingsToAstNodes;
115
	Map bindingsToAstNodes;
113
	
116
	
Lines 183-188 Link Here
183
		return (ASTNode) this.bindingsToAstNodes.get(binding);
186
		return (ASTNode) this.bindingsToAstNodes.get(binding);
184
	}
187
	}
185
	
188
	
189
	synchronized ASTNode findDeclaringNode(IResolvedAnnotation instance)
190
	{
191
		if( instance == null ) 
192
			return null;
193
		return (ASTNode)this.bindingsToAstNodes.get(instance);
194
	}
195
	
186
	IBinding getBinding(org.eclipse.jdt.internal.compiler.lookup.Binding binding) {
196
	IBinding getBinding(org.eclipse.jdt.internal.compiler.lookup.Binding binding) {
187
		switch (binding.kind()) {
197
		switch (binding.kind()) {
188
			case Binding.PACKAGE:
198
			case Binding.PACKAGE:
Lines 351-356 Link Here
351
		return null;
361
		return null;
352
	}
362
	}
353
	
363
	
364
	synchronized IResolvedAnnotation getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance internalInstance){
365
		IResolvedAnnotation domInstance = 
366
			(IResolvedAnnotation) this.bindingTables.compilerBindingsToASTBindings.get(internalInstance);
367
		if (domInstance != null) {
368
			return domInstance;
369
		}
370
		domInstance = new ResolvedAnnotation(internalInstance, this);
371
		this.bindingTables.compilerBindingsToASTBindings.put(internalInstance, domInstance);
372
		return domInstance;
373
	}
374
	
354
	/*
375
	/*
355
	 * Method declared on BindingResolver.
376
	 * Method declared on BindingResolver.
356
	 */
377
	 */
Lines 1398-1403 Link Here
1398
		return null;
1419
		return null;
1399
	}
1420
	}
1400
	
1421
	
1422
	synchronized IResolvedAnnotation resolveAnnotation(final Annotation domASTNode)
1423
	{
1424
		Object oldNode = this.newAstToOldAst.get(domASTNode);
1425
		if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.Annotation) {
1426
			org.eclipse.jdt.internal.compiler.ast.Annotation internalAstNode = 
1427
				(org.eclipse.jdt.internal.compiler.ast.Annotation) oldNode;
1428
			
1429
			IResolvedAnnotation domAnnotation = this.getAnnotationInstance(internalAstNode.compilerAnnotation);
1430
			if (domAnnotation == null) {
1431
				return null;
1432
			}
1433
			this.bindingsToAstNodes.put(domAnnotation, domASTNode);			
1434
			return domAnnotation;
1435
		}
1436
		return null;
1437
	}
1438
	
1401
	/*
1439
	/*
1402
	 * Method declared on BindingResolver.
1440
	 * Method declared on BindingResolver.
1403
	 */
1441
	 */
(-)IBinding.java (+21 lines)
Lines 136-141 Link Here
136
	public IJavaElement getJavaElement();
136
	public IJavaElement getJavaElement();
137
	
137
	
138
	/**
138
	/**
139
	 * Return the resolved annotations associated with this binding.
140
	 * <ul>
141
	 * <li>Package bindings - these are annotations on a package declaration.
142
	 * </li>
143
	 * <li>Type bindings - these are annotations on a class, interface, enum,
144
	 * or annotation type declaration. The result is the same regardless of
145
	 * whether the type is parameterized.</li>
146
	 * <li>Method bindings - these are annotations on a method or constructor
147
	 * declaration. The result is the same regardless of whether the method is
148
	 * parameterized.</li>
149
	 * <li>Variable bindings - these are annotations on a field, enum constant,
150
	 * or formal parameter declaration.</li>
151
	 * </ul>
152
	 * 
153
	 * @return the list of resolved annotations, or the empty list if there are no
154
	 * annotations associated with the object for which this is the binding
155
	 * @since 3.2
156
	 */
157
	public IResolvedAnnotation[] getAnnotations();
158
	
159
	/**
139
	 * Returns the key for this binding.
160
	 * Returns the key for this binding.
140
	 * <p>
161
	 * <p>
141
	 * Within a connected cluster of bindings (for example, all bindings 
162
	 * Within a connected cluster of bindings (for example, all bindings 
(-)IMethodBinding.java (-3 / +49 lines)
Lines 42-49 Link Here
42
	 * @return <code>true</code> if this is the binding for a constructor,
42
	 * @return <code>true</code> if this is the binding for a constructor,
43
	 *    and <code>false</code> if this is the binding for a method
43
	 *    and <code>false</code> if this is the binding for a method
44
	 */ 
44
	 */ 
45
	public boolean isConstructor();
45
	public boolean isConstructor();	
46
46
	
47
	/**
47
	/**
48
	 * Returns whether this binding is known to be a compiler-generated 
48
	 * Returns whether this binding is known to be a compiler-generated 
49
	 * default constructor. 
49
	 * default constructor. 
Lines 237-243 Link Here
237
	 *
237
	 *
238
	 * @return <code>true</code> if this method binding represents a 
238
	 * @return <code>true</code> if this method binding represents a 
239
	 * an instance of a generic method corresponding to a raw
239
	 * an instance of a generic method corresponding to a raw
240
	 * method reference, and <code>false</code> otherwise
240
	 * method reference, ad <code>false</code> otherwise
241
	 * @see #getMethodDeclaration()
241
	 * @see #getMethodDeclaration()
242
	 * @see #getTypeArguments()
242
	 * @see #getTypeArguments()
243
	 * @since 3.1
243
	 * @since 3.1
Lines 266-271 Link Here
266
	public boolean isVarargs();
266
	public boolean isVarargs();
267
	
267
	
268
	/**
268
	/**
269
	 * Return whether this is the binding for an annotation type member.
270
	 * 
271
	 * @return <code>true</code> iff this is the binding for an annotation type member
272
	 *         and <code>false</code> otherwise
273
	 * @since 3.2
274
	 */
275
	public boolean isAnnotationMember();
276
277
	/**
278
	 * Return the resolved default value of an annotation type member, 
279
	 * or <code>null</code> if the member has no default value, or if this
280
	 * is not the binding for an annotation type member.
281
	 * <p>
282
	 * Resolved values are represented as follows (same as for
283
	 * {@link IResolvedMemberValuePair#getValue()}):
284
	 * <ul>
285
	 * <li>Primitive type - the equivalent boxed object</li>
286
	 * <li>java.lang.Class - the <code>ITypeBinding</code> for the class object</li>
287
	 * <li>java.lang.String - the string value itself</li>
288
	 * <li>enum type - the <code>IVariableBinding</code> for the enum constant</li>
289
	 * <li>annotation type - an <code>IResolvedAnnotation</code></li>
290
	 * <li>array type - an <code>Object[]</code> whose elements are as per above
291
	 * (the language only allows single dimensional arrays in annotations)</li>
292
	 * </ul>
293
	 * 
294
	 * @return the default value of this annotation type member, or <code>null</code>
295
	 * if none or not applicable
296
	 * @since 3.2
297
	 */
298
	public Object getDefaultValue();
299
	
300
	/**
269
	 * Returns whether this method overrides the given method,
301
	 * Returns whether this method overrides the given method,
270
	 * as specified in section 6.4.2 of <em>The Java Language 
302
	 * as specified in section 6.4.2 of <em>The Java Language 
271
	 * Specification, Second Edition</em> (JLS2).
303
	 * Specification, Second Edition</em> (JLS2).
Lines 276-279 Link Here
276
	 * @since 3.1
308
	 * @since 3.1
277
	 */
309
	 */
278
	public boolean overrides(IMethodBinding method);
310
	public boolean overrides(IMethodBinding method);
311
		
312
	/**
313
	 * Return the resolved annotations of a parameter of this method.
314
	 * The result returned is the same regardless of whether 
315
	 * this is a parameterized method.
316
	 * 
317
	 * @param paramIndex the index of the parameter of interest
318
	 * @return the resolved annotations of the <code>paramIndex</code>th parameter,
319
	 * or an empty list if there are none
320
	 * @throws ArrayIndexOutOfBoundsException if <code>paramIndex</code> is 
321
	 * not a valid index
322
	 * @since 3.2
323
	 */
324
	public IResolvedAnnotation[] getParameterAnnotations(int paramIndex);
279
}
325
}
(-)MethodBinding.java (+42 lines)
Lines 383-389 Link Here
383
		MethodVerifier methodVerifier = lookupEnvironment.methodVerifier();
383
		MethodVerifier methodVerifier = lookupEnvironment.methodVerifier();
384
		return methodVerifier.doesMethodOverride(this.binding, otherCompilerBinding);
384
		return methodVerifier.doesMethodOverride(this.binding, otherCompilerBinding);
385
	}
385
	}
386
	
387
	public IResolvedAnnotation[] getAnnotations(){ 
388
		final org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance[] internalAnnotations =
389
			this.binding.getAnnotations();				
390
		final int len = internalAnnotations == null ?  0 : internalAnnotations.length;
391
		IResolvedAnnotation[] domInstances = ResolvedAnnotation.NoAnnotations;
392
		if( len > 0 ){
393
			domInstances = new ResolvedAnnotation[len];
394
			for( int i=0; i<len; i++ ){
395
				domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]);
396
			}
397
		}
398
		return domInstances; 
399
	}
400
	
401
	public IResolvedAnnotation[] getParameterAnnotations(int index){
402
		// this line may through <code>ArrayIndexOutOfBoundException()</code> if 
403
		// <code>index</code> is invalid
404
		final org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance[] internalAnnotations =
405
			this.binding.getParameterAnnotations(index);
406
		final int len = internalAnnotations == null ?  0 : internalAnnotations.length;
407
		IResolvedAnnotation[] domInstances = ResolvedAnnotation.NoAnnotations;
408
		if( len > 0 ){
409
			domInstances = new ResolvedAnnotation[len];
410
			for( int i=0; i<len; i++ ){
411
				domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]); 
412
			}
413
		}
414
		return domInstances; 
415
	}
416
	
417
	public boolean isAnnotationMember()
418
	{ return this.binding instanceof org.eclipse.jdt.internal.compiler.lookup.AnnotationMethodBinding; }
386
419
420
	public Object getDefaultValue()
421
	{ 
422
		if( isAnnotationMember() ){
423
			final Object internalObject = 
424
				((org.eclipse.jdt.internal.compiler.lookup.AnnotationMethodBinding)this.binding).getDefaultValue();
425
			return ResolvedMemberValuePair.buildDOMValue(internalObject, this.binding.returnType, this.resolver);
426
		}
427
		return null;
428
	}
387
	/* 
429
	/* 
388
	 * For debugging purpose only.
430
	 * For debugging purpose only.
389
	 * @see java.lang.Object#toString()
431
	 * @see java.lang.Object#toString()
(-)PackageBinding.java (+5 lines)
Lines 148-153 Link Here
148
		}
148
		}
149
	}
149
	}
150
	
150
	
151
	public IResolvedAnnotation[] getAnnotations() {
152
		// TODO Auto-generated method stub
153
		throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
154
	}
155
151
	/* 
156
	/* 
152
	 * For debugging purpose only.
157
	 * For debugging purpose only.
153
	 * @see java.lang.Object#toString()
158
	 * @see java.lang.Object#toString()
(-)TypeBinding.java (+21 lines)
Lines 1029-1034 Link Here
1029
		return methodBinding.isDefaultAbstract() || methodBinding.isSynthetic() || (methodBinding.isConstructor() && isInterface());
1029
		return methodBinding.isDefaultAbstract() || methodBinding.isSynthetic() || (methodBinding.isConstructor() && isInterface());
1030
	}
1030
	}
1031
	
1031
	
1032
	public IResolvedAnnotation[] getAnnotations(){ 
1033
		if( this.binding.isAnnotationType() || this.binding.isClass() ||
1034
		    this.binding.isEnum() || this.binding.isInterface() ){
1035
			final org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding refType = 
1036
				(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding)this.binding;
1037
			final org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance[] 
1038
				internalAnnotations = refType.getAnnotations();
1039
			
1040
			final int len = internalAnnotations == null ? 0 : internalAnnotations.length;
1041
			IResolvedAnnotation[] domInstances = ResolvedAnnotation.NoAnnotations;
1042
			if( len > 0 ){
1043
				domInstances = new ResolvedAnnotation[len];
1044
				for( int i=0; i<len; i++ ){
1045
					domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]);					
1046
				}
1047
			}
1048
			return domInstances;
1049
		}
1050
		return null;
1051
	}
1052
	
1032
	/* 
1053
	/* 
1033
	 * For debugging purpose only.
1054
	 * For debugging purpose only.
1034
	 * @see java.lang.Object#toString()
1055
	 * @see java.lang.Object#toString()
(-)VariableBinding.java (+17 lines)
Lines 289-294 Link Here
289
		}
289
		}
290
		return false;
290
		return false;
291
	}
291
	}
292
	
293
	public IResolvedAnnotation[] getAnnotations()
294
	{ 
295
		final org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance[] internalAnnotations =
296
			this.binding.getAnnotations();
297
		// the variable is not an enum constant nor a field nor an argument.
298
		if( internalAnnotations == null ) return null;
299
		final int len = internalAnnotations.length;
300
		IResolvedAnnotation[] domInstances = ResolvedAnnotation.NoAnnotations;
301
		if( len > 0 ){
302
			domInstances = new ResolvedAnnotation[len];
303
			for( int i=0; i<len; i++ ){
304
				domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]);
305
			}
306
		}
307
		return domInstances;                                                                  
308
	}
292
309
293
	/* 
310
	/* 
294
	 * For debugging purpose only.
311
	 * For debugging purpose only.
(-)IResolvedAnnotation.java (+53 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.dom;
12
13
/**
14
 * Represents an resolved annotation. Resolved annotation are computed along with other
15
 * bindings; they correspond to {@link Annotation} nodes.
16
 * 
17
 * @since 3.2
18
 */
19
public interface IResolvedAnnotation 
20
{
21
	/**
22
	 * Returns the type of the annotation. The resulting type binding will always
23
	 * return <code>true</code>	to <code>ITypeBinding.isAnnotation()</code>.
24
	 * 
25
	 * @return the type of the annotation
26
	 */
27
	ITypeBinding getAnnotationType();
28
	
29
	/**
30
	 * Returns the list of declared member value pairs for this annotation.
31
	 * Returns an empty list for a <code>MarkerAnnotation</code>, a one element
32
	 * list for a <code>SingleMemberAnnotation</code>, and one entry for each
33
	 * of the explicitly listed values in a <code>NormalAnnotation</code>.
34
	 * <p>
35
	 * Note that the list only includes entries for annotation type members that are
36
	 * explicitly mentioned in the annotation. The list does not include any 
37
	 * annotation type members with default values that are merely implied.
38
	 * Use {@link #getAllMemberValuePairs()} to get those as well.
39
	 * </p>
40
	 * 
41
	 * @return a possibly empty list of resolved member value pairs
42
	 */
43
	IResolvedMemberValuePair[] getDeclaredMemberValuePairs();
44
	
45
	/**
46
	 * Returns the complete list of member value pairs for this annotation, including
47
	 * ones explicitly listed in the annotation as well as entries for 
48
	 * annotation type members with default values that are implied.
49
	 * 
50
	 * @return a possibly empty list of resolved member value pairs
51
	 */
52
	IResolvedMemberValuePair[] getAllMemberValuePairs();
53
}
(-)IResolvedMemberValuePair.java (+51 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.dom;
12
13
/**
14
 * Represents an resolved instance of an annotation's member value pair.
15
 * Resolved annotation are computed along with other bindings; these objects
16
 * correspond to {@link MemberValuePair} nodes.
17
 * 
18
 * @since 3.2
19
 */
20
public interface IResolvedMemberValuePair 
21
{
22
	/**
23
	 * Returns the name of the annotation type member.
24
	 * 
25
	 * @return the name of the member
26
	 */
27
	public String getName();
28
	
29
	/**
30
	 * Returns the method binding corresponding to the named annotation type member.
31
	 * 
32
	 * @return the method binding for the annotation type member
33
	 */
34
	public IMethodBinding getMemberBinding();
35
	
36
	/**
37
	 * Returns the resolved value. Resolved values are represented as follows:
38
	 * <ul>
39
	 * <li>Primitive type - the equivalent boxed object</li>
40
	 * <li>java.lang.Class - the <code>ITypeBinding</code> for the class object</li>
41
	 * <li>java.lang.String - the string value itself</li>
42
	 * <li>enum type - the <code>IVariableBinding</code> for the enum constant</li>
43
	 * <li>annotation type - an <code>IResolvedAnnotation</code></li>
44
	 * <li>array type - an <code>Object[]</code> whose elements are as per above
45
	 * (the language only allows single dimensional arrays in annotations)</li>
46
	 * </ul>
47
	 * 	
48
	 * @return the resolved value, or <code>null</code> if none exists
49
	 */
50
	public Object getValue();
51
}
(-)ResolvedAnnotation.java (+51 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.dom;
12
13
/**
14
 * Internal class
15
 */
16
class ResolvedAnnotation implements IResolvedAnnotation 
17
{	
18
	static final ResolvedAnnotation[] NoAnnotations = new ResolvedAnnotation[0];
19
	private final org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance internalAnnotation;
20
	private final BindingResolver bindingResolver;
21
	
22
	ResolvedAnnotation(org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance anno, 
23
	  				   BindingResolver resolver )
24
	{
25
		internalAnnotation = anno;
26
		bindingResolver = resolver;
27
	}
28
	
29
	public ITypeBinding getAnnotationType() {
30
		final ITypeBinding binding = 
31
			this.bindingResolver.getTypeBinding(this.internalAnnotation.getAnnotationType());
32
		return binding.isAnnotation() ? binding : null;
33
	}
34
	
35
	public IResolvedMemberValuePair[] getDeclaredMemberValuePairs() {
36
		final org.eclipse.jdt.internal.compiler.lookup.IElementValuePair[] internalPair =
37
			this.internalAnnotation.getElementValuePairs();
38
		final int len = internalPair.length;
39
		IResolvedMemberValuePair[] pairs = ResolvedMemberValuePair.NoPair;
40
		for( int i=0; i<len; i++ ){
41
			pairs[i] = new ResolvedMemberValuePair(internalPair[i],this.bindingResolver);
42
		}
43
		return pairs;
44
	}
45
	
46
	public IResolvedMemberValuePair[] getAllMemberValuePairs() {
47
		// TODO missing implementation
48
		throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
49
	}
50
	
51
}
(-)ResolvedMemberValuePair.java (+109 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 BEA Systems, Inc.
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
 *    tyeung@bea.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.dom;
12
13
import org.eclipse.jdt.internal.compiler.impl.Constant;
14
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
15
16
/**
17
 * Internal class.
18
 */
19
class ResolvedMemberValuePair implements IResolvedMemberValuePair
20
{	
21
	static final ResolvedMemberValuePair[] NoPair = new ResolvedMemberValuePair[0]; 
22
	private static final Object NoValue = new Object();
23
	private final org.eclipse.jdt.internal.compiler.lookup.IElementValuePair internalPair;
24
	private Object value = null; 
25
	private final BindingResolver bindingResolver;
26
	
27
	ResolvedMemberValuePair(final org.eclipse.jdt.internal.compiler.lookup.IElementValuePair pair, 
28
					 BindingResolver resolver)
29
	{	
30
		this.internalPair = pair;
31
		this.bindingResolver = resolver;		
32
	}
33
	
34
	private void init()
35
	{
36
		final org.eclipse.jdt.internal.compiler.lookup.TypeBinding type = this.internalPair.getType();
37
		this.value =  buildDOMValue(this.internalPair.getValue(), type, this.bindingResolver);
38
		if( this.value == null )
39
			this.value = NoValue;
40
	}
41
	
42
	static Object buildDOMValue(final Object internalObject, 
43
			  				    org.eclipse.jdt.internal.compiler.lookup.TypeBinding type,
44
			  				    BindingResolver resolver)
45
	{
46
		if( internalObject == null || type == null ) return null;
47
		switch(type.id)
48
		{
49
		case TypeIds.T_boolean:
50
			return new Boolean( ((Constant)internalObject).booleanValue() );			
51
		case TypeIds.T_byte:
52
			return new Byte( ((Constant)internalObject).byteValue() );			
53
		case TypeIds.T_char:
54
			return new Character( ((Constant)internalObject).charValue() );
55
		case TypeIds.T_double:
56
			return new Double( ((Constant)internalObject).doubleValue() );			
57
		case TypeIds.T_float:
58
			return new Float( ((Constant)internalObject).floatValue() );
59
		case TypeIds.T_int:
60
			return new Integer( ((Constant)internalObject).intValue() );			
61
		case TypeIds.T_long:
62
			return new Long( ((Constant)internalObject).longValue() );			
63
		case TypeIds.T_short:
64
			return new Short( ((Constant)internalObject).shortValue() );
65
		case TypeIds.T_JavaLangString:
66
			return internalObject;
67
		case TypeIds.T_JavaLangClass:
68
			return resolver.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)internalObject);
69
		}	
70
		
71
		if( type.isAnnotationType() ){
72
			return new ResolvedAnnotation(
73
					(org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance)internalObject, 
74
					resolver);
75
		}
76
		else if( type.isEnum() ){
77
			return resolver.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding)internalObject);
78
		}
79
		else if( type.isArrayType() ){
80
			final Object[] iElements = (Object[])internalObject;
81
			final int len = iElements.length;
82
			Object[] values = null;
83
			if( len > 0){
84
				final org.eclipse.jdt.internal.compiler.lookup.TypeBinding elementType =
85
					((org.eclipse.jdt.internal.compiler.lookup.ArrayBinding)type).leafComponentType;
86
				values = new Object[len];
87
				for( int i=0; i<len; i++ ){
88
					values[i] = buildDOMValue(iElements[i], elementType, resolver);
89
				}
90
			}
91
		}
92
		throw new IllegalStateException(); // should never get here.		
93
	}
94
	
95
	public String getName() {
96
		final char[] membername = this.internalPair.getMemberName();
97
		return membername == null ? null : new String(membername);
98
	}
99
	
100
	public IMethodBinding getMemberBinding() {
101
		return this.bindingResolver.getMethodBinding(this.internalPair.getMethodBinding());
102
	}
103
	
104
	public Object getValue() {
105
		if( value == null )
106
			init();
107
		return value == NoValue ? null : this.value;
108
	}	
109
}

Return to bug 90344