View | Details | Raw Unified | Return to bug 123470 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java (-3 / +3 lines)
Lines 6276-6282 Link Here
6276
		ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
6276
		ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
6277
		IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
6277
		IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
6278
		assertNotNull("Should not be null", binding);
6278
		assertNotNull("Should not be null", binding);
6279
		IResolvedAnnotation[] annotations = binding.getAnnotations();
6279
		IAnnotationBinding[] annotations = binding.getAnnotations();
6280
		assertNotNull("Should not be null", annotations);
6280
		assertNotNull("Should not be null", annotations);
6281
		assertEquals("Should be empty", 0, annotations.length);
6281
		assertEquals("Should be empty", 0, annotations.length);
6282
	}
6282
	}
Lines 6308-6315 Link Here
6308
		assertEquals("Wrong size", 2, modifiers.size());
6308
		assertEquals("Wrong size", 2, modifiers.size());
6309
		assertTrue("Wrong type", modifiers.get(0) instanceof NormalAnnotation);
6309
		assertTrue("Wrong type", modifiers.get(0) instanceof NormalAnnotation);
6310
		NormalAnnotation normalAnnotation = (NormalAnnotation) modifiers.get(0);
6310
		NormalAnnotation normalAnnotation = (NormalAnnotation) modifiers.get(0);
6311
		IResolvedAnnotation resolvedAnnotation = normalAnnotation.resolveAnnotation();
6311
		IAnnotationBinding annotationBinding = normalAnnotation.resolveAnnotation();
6312
		IResolvedMemberValuePair[] pairs = resolvedAnnotation.getDeclaredMemberValuePairs();
6312
		IMemberValuePairBinding[] pairs = annotationBinding.getDeclaredMemberValuePairs();
6313
		assertEquals("Wrong size", 1, pairs.length);
6313
		assertEquals("Wrong size", 1, pairs.length);
6314
		assertNotNull("Should not be null", pairs[0].getValue());
6314
		assertNotNull("Should not be null", pairs[0].getValue());
6315
	}
6315
	}
(-)dom/org/eclipse/jdt/core/dom/TypeBinding.java (-5 / +4 lines)
Lines 32-38 Link Here
32
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
32
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
33
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
33
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
34
import org.eclipse.jdt.internal.compiler.env.IDependent;
34
import org.eclipse.jdt.internal.compiler.env.IDependent;
35
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
36
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
35
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
37
import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding;
36
import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding;
38
import org.eclipse.jdt.internal.compiler.lookup.Binding;
37
import org.eclipse.jdt.internal.compiler.lookup.Binding;
Lines 75-89 Link Here
75
		this.resolver = resolver;
74
		this.resolver = resolver;
76
	}
75
	}
77
76
78
	public IResolvedAnnotation[] getAnnotations() { 
77
	public IAnnotationBinding[] getAnnotations() { 
79
		IResolvedAnnotation[] domInstances = ResolvedAnnotation.NoAnnotations;
78
		IAnnotationBinding[] domInstances = AnnotationBinding.NoAnnotations;
80
		if (this.binding.isAnnotationType() || this.binding.isClass() || this.binding.isEnum() || this.binding.isInterface()) {
79
		if (this.binding.isAnnotationType() || this.binding.isClass() || this.binding.isEnum() || this.binding.isInterface()) {
81
			org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding refType = 
80
			org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding refType = 
82
				(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) this.binding;
81
				(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) this.binding;
83
			AnnotationBinding[] internalAnnotations = refType.getAnnotations();
82
			org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] internalAnnotations = refType.getAnnotations();
84
			int length = internalAnnotations == null ? 0 : internalAnnotations.length;
83
			int length = internalAnnotations == null ? 0 : internalAnnotations.length;
85
			if (length > 0) {
84
			if (length > 0) {
86
				domInstances = new ResolvedAnnotation[length];
85
				domInstances = new AnnotationBinding[length];
87
				for (int i = 0; i < length; i++)
86
				for (int i = 0; i < length; i++)
88
					domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]);
87
					domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]);
89
			}
88
			}
(-)dom/org/eclipse/jdt/core/dom/MethodBinding.java (-10 / +9 lines)
Lines 20-26 Link Here
20
import org.eclipse.jdt.core.JavaModelException;
20
import org.eclipse.jdt.core.JavaModelException;
21
import org.eclipse.jdt.core.Signature;
21
import org.eclipse.jdt.core.Signature;
22
import org.eclipse.jdt.core.compiler.CharOperation;
22
import org.eclipse.jdt.core.compiler.CharOperation;
23
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
24
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
23
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
25
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
24
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
26
import org.eclipse.jdt.internal.compiler.lookup.MethodVerifier;
25
import org.eclipse.jdt.internal.compiler.lookup.MethodVerifier;
Lines 102-113 Link Here
102
		return name;
101
		return name;
103
	}
102
	}
104
103
105
	public IResolvedAnnotation[] getAnnotations() { 
104
	public IAnnotationBinding[] getAnnotations() { 
106
		AnnotationBinding[] annotations = this.binding.getAnnotations();
105
		org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] annotations = this.binding.getAnnotations();
107
		int length;
106
		int length;
108
		if (annotations == null || (length = annotations.length) == 0)
107
		if (annotations == null || (length = annotations.length) == 0)
109
			return ResolvedAnnotation.NoAnnotations;
108
			return AnnotationBinding.NoAnnotations;
110
		IResolvedAnnotation[] domInstances = new ResolvedAnnotation[length];
109
		IAnnotationBinding[] domInstances = new AnnotationBinding[length];
111
		for (int i = 0; i < length; i++)
110
		for (int i = 0; i < length; i++)
112
			domInstances[i] = this.resolver.getAnnotationInstance(annotations[i]);
111
			domInstances[i] = this.resolver.getAnnotationInstance(annotations[i]);
113
		return domInstances; 
112
		return domInstances; 
Lines 123-134 Link Here
123
		return declaringClass;
122
		return declaringClass;
124
	}
123
	}
125
124
126
	public IResolvedAnnotation[] getParameterAnnotations(int index) {
125
	public IAnnotationBinding[] getParameterAnnotations(int index) {
127
		AnnotationBinding[] annotations = this.binding.getParameterAnnotations(index);
126
		org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] annotations = this.binding.getParameterAnnotations(index);
128
		int length;
127
		int length;
129
		if (annotations == null || (length = annotations.length) == 0)
128
		if (annotations == null || (length = annotations.length) == 0)
130
			return ResolvedAnnotation.NoAnnotations;
129
			return AnnotationBinding.NoAnnotations;
131
		IResolvedAnnotation[] domInstances =new ResolvedAnnotation[length];
130
		IAnnotationBinding[] domInstances =new AnnotationBinding[length];
132
		for (int i = 0; i < length; i++)
131
		for (int i = 0; i < length; i++)
133
			domInstances[i] = this.resolver.getAnnotationInstance(annotations[i]);
132
			domInstances[i] = this.resolver.getAnnotationInstance(annotations[i]);
134
		return domInstances; 
133
		return domInstances; 
Lines 166-172 Link Here
166
165
167
	public Object getDefaultValue() {
166
	public Object getDefaultValue() {
168
		if (isAnnotationMember())
167
		if (isAnnotationMember())
169
			return ResolvedMemberValuePair.buildDOMValue(this.binding.getDefaultValue(), this.resolver);
168
			return MemberValuePairBinding.buildDOMValue(this.binding.getDefaultValue(), this.resolver);
170
		return null;
169
		return null;
171
	}
170
	}
172
171
(-)dom/org/eclipse/jdt/core/dom/Annotation.java (-1 / +1 lines)
Lines 175-181 Link Here
175
	 * @return the resolved annotation, or <code>null</code> if the annotation cannot be resolved
175
	 * @return the resolved annotation, or <code>null</code> if the annotation cannot be resolved
176
	 * @since 3.2
176
	 * @since 3.2
177
	 */	
177
	 */	
178
	public IResolvedAnnotation resolveAnnotation() {
178
	public IAnnotationBinding resolveAnnotation() {
179
	    return this.ast.getBindingResolver().resolveAnnotation(this);
179
	    return this.ast.getBindingResolver().resolveAnnotation(this);
180
	}
180
	}
181
}
181
}
(-)dom/org/eclipse/jdt/core/dom/ResolvedDefaultValuePair.java (-77 lines)
Removed 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.core.dom.BindingResolver;
14
import org.eclipse.jdt.core.dom.IMethodBinding;
15
import org.eclipse.jdt.core.dom.IResolvedMemberValuePair;
16
17
/**
18
 * Member value pair which compose of default values.
19
 */
20
class ResolvedDefaultValuePair implements IResolvedMemberValuePair {
21
22
	private org.eclipse.jdt.internal.compiler.lookup.MethodBinding method;
23
	private Object domValue;
24
	private BindingResolver bindingResolver;
25
26
static void appendValue(Object value, StringBuffer buffer) {
27
	if (value instanceof Object[]) {
28
		Object[] values = (Object[]) value;
29
		buffer.append('{');
30
		for (int i = 0, l = values.length; i < l; i++) {
31
			if (i != 0)
32
				buffer.append(", "); //$NON-NLS-1$
33
			appendValue(values[i], buffer);
34
		}
35
		buffer.append('}');
36
	} else if (value instanceof ITypeBinding) {
37
		buffer.append(((ITypeBinding) value).getName());
38
		buffer.append(".class"); //$NON-NLS-1$
39
	} else {
40
		buffer.append(value);
41
	}
42
}
43
44
ResolvedDefaultValuePair(org.eclipse.jdt.internal.compiler.lookup.MethodBinding binding, BindingResolver resolver) {
45
	this.method = binding;
46
	this.domValue = ResolvedMemberValuePair.buildDOMValue(binding.getDefaultValue(), resolver);
47
	this.bindingResolver = resolver;
48
}
49
50
public String getName() {
51
	return new String(this.method.selector);
52
}
53
54
public IMethodBinding getMethodBinding() {
55
	return this.bindingResolver.getMethodBinding(this.method);
56
}
57
58
public Object getValue() {
59
	return this.domValue;
60
}
61
62
public boolean isDefault() {
63
	return true;
64
}
65
66
public String toString() {
67
	StringBuffer buffer = new StringBuffer();
68
	toString(buffer);
69
	return buffer.toString();
70
}
71
72
public void toString(StringBuffer buffer) {
73
	buffer.append(getName());
74
	buffer.append(" = "); //$NON-NLS-1$		
75
	appendValue(getValue(), buffer);
76
}
77
}
(-)dom/org/eclipse/jdt/core/dom/IResolvedMemberValuePair.java (-56 lines)
Removed 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 a 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
 * Returns the name of the annotation type member.
23
 * 
24
 * @return the name of the member
25
 */
26
public String getName();
27
28
/**
29
 * Returns the method binding corresponding to the named annotation type member.
30
 * 
31
 * @return the method binding for the annotation type member
32
 */
33
public IMethodBinding getMethodBinding();
34
35
/**
36
 * Returns the resolved value. Resolved values are represented as follows:
37
 * <ul>
38
 * <li>Primitive type - the equivalent boxed object</li>
39
 * <li>java.lang.Class - the <code>ITypeBinding</code> for the class object</li>
40
 * <li>java.lang.String - the string value itself</li>
41
 * <li>enum type - the <code>IVariableBinding</code> for the enum constant</li>
42
 * <li>annotation type - an <code>IResolvedAnnotation</code></li>
43
 * <li>array type - an <code>Object[]</code> whose elements are as per above
44
 * (the language only allows single dimensional arrays in annotations)</li>
45
 * </ul>
46
 * 	
47
 * @return the resolved value, or <code>null</code> if none exists
48
 */
49
public Object getValue();
50
51
/**
52
 * @return <code>true</code> iff this member value pair's value is the default value.
53
 *         Returns <code>false</code> otherwise.
54
 */
55
public boolean isDefault();
56
}
(-)dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java (-8 / +7 lines)
Lines 43-49 Link Here
43
import org.eclipse.jdt.internal.compiler.ast.ThisReference;
43
import org.eclipse.jdt.internal.compiler.ast.ThisReference;
44
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
44
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
45
import org.eclipse.jdt.internal.compiler.impl.Constant;
45
import org.eclipse.jdt.internal.compiler.impl.Constant;
46
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
47
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
46
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
48
import org.eclipse.jdt.internal.compiler.lookup.Binding;
47
import org.eclipse.jdt.internal.compiler.lookup.Binding;
49
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
48
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
Lines 178-184 Link Here
178
		return (ASTNode) this.bindingsToAstNodes.get(binding);
177
		return (ASTNode) this.bindingsToAstNodes.get(binding);
179
	}
178
	}
180
179
181
	synchronized ASTNode findDeclaringNode(IResolvedAnnotation instance) {
180
	synchronized ASTNode findDeclaringNode(IAnnotationBinding instance) {
182
		if (instance == null)
181
		if (instance == null)
183
			return null;
182
			return null;
184
		return (ASTNode) this.bindingsToAstNodes.get(instance);
183
		return (ASTNode) this.bindingsToAstNodes.get(instance);
Lines 355-367 Link Here
355
		return null;
354
		return null;
356
	}
355
	}
357
	
356
	
358
	synchronized IResolvedAnnotation getAnnotationInstance(AnnotationBinding internalInstance) {
357
	synchronized IAnnotationBinding getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding internalInstance) {
359
		if (internalInstance == null) return null;
358
		if (internalInstance == null) return null;
360
		IResolvedAnnotation domInstance = 
359
		IAnnotationBinding domInstance = 
361
			(IResolvedAnnotation) this.bindingTables.compilerBindingsToASTBindings.get(internalInstance);
360
			(IAnnotationBinding) this.bindingTables.compilerBindingsToASTBindings.get(internalInstance);
362
		if (domInstance != null)
361
		if (domInstance != null)
363
			return domInstance;
362
			return domInstance;
364
		domInstance = new ResolvedAnnotation(internalInstance, this);
363
		domInstance = new AnnotationBinding(internalInstance, this);
365
		this.bindingTables.compilerBindingsToASTBindings.put(internalInstance, domInstance);
364
		this.bindingTables.compilerBindingsToASTBindings.put(internalInstance, domInstance);
366
		return domInstance;
365
		return domInstance;
367
	}
366
	}
Lines 1550-1562 Link Here
1550
		return null;
1549
		return null;
1551
	}
1550
	}
1552
1551
1553
	synchronized IResolvedAnnotation resolveAnnotation(final Annotation domASTNode) {
1552
	synchronized IAnnotationBinding resolveAnnotation(final Annotation domASTNode) {
1554
		Object oldNode = this.newAstToOldAst.get(domASTNode);
1553
		Object oldNode = this.newAstToOldAst.get(domASTNode);
1555
		if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.Annotation) {
1554
		if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.Annotation) {
1556
			org.eclipse.jdt.internal.compiler.ast.Annotation internalAstNode = 
1555
			org.eclipse.jdt.internal.compiler.ast.Annotation internalAstNode = 
1557
				(org.eclipse.jdt.internal.compiler.ast.Annotation) oldNode;
1556
				(org.eclipse.jdt.internal.compiler.ast.Annotation) oldNode;
1558
			
1557
			
1559
			IResolvedAnnotation domAnnotation = this.getAnnotationInstance(internalAstNode.getCompilerAnnotation());
1558
			IAnnotationBinding domAnnotation = this.getAnnotationInstance(internalAstNode.getCompilerAnnotation());
1560
			if (domAnnotation == null)
1559
			if (domAnnotation == null)
1561
				return null;
1560
				return null;
1562
			this.bindingsToAstNodes.put(domAnnotation, domASTNode);			
1561
			this.bindingsToAstNodes.put(domAnnotation, domASTNode);			
(-)dom/org/eclipse/jdt/core/dom/ResolvedMemberValuePair.java (-120 lines)
Removed 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.AnnotationBinding;
15
import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair;
16
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
17
18
/**
19
 * Internal class.
20
 */
21
class ResolvedMemberValuePair implements IResolvedMemberValuePair {
22
	static final ResolvedMemberValuePair[] NoPair = new ResolvedMemberValuePair[0];
23
	private static final Object NoValue = new Object();
24
	private static final Object[] EmptyArray = new Object[0];
25
26
	private ElementValuePair internalPair;
27
	private Object value = null;
28
	private BindingResolver bindingResolver;
29
30
static Object buildDOMValue(final Object internalObject, BindingResolver resolver) {
31
	if (internalObject == null)
32
		return null;
33
34
	if (internalObject instanceof Constant) {
35
		Constant constant = (Constant) internalObject;
36
		switch (constant.typeID()) {
37
			case TypeIds.T_boolean:
38
				return Boolean.valueOf(constant.booleanValue());
39
			case TypeIds.T_byte:
40
				return new Byte(constant.byteValue());
41
			case TypeIds.T_char:
42
				return new Character(constant.charValue());
43
			case TypeIds.T_double:
44
				return new Double(constant.doubleValue());
45
			case TypeIds.T_float:
46
				return new Float(constant.floatValue());
47
			case TypeIds.T_int:
48
				return new Integer(constant.intValue());
49
			case TypeIds.T_long:
50
				return new Long(constant.longValue());
51
			case TypeIds.T_short:
52
				return new Short(constant.shortValue());
53
			case TypeIds.T_JavaLangString:
54
				return constant.stringValue();
55
		}
56
	} else if (internalObject instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
57
		return resolver.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) internalObject);
58
	} else if (internalObject instanceof AnnotationBinding) {
59
		return resolver.getAnnotationInstance((AnnotationBinding) internalObject);
60
	} else if (internalObject instanceof org.eclipse.jdt.internal.compiler.lookup.FieldBinding) {
61
		return resolver.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding) internalObject);
62
	} else if (internalObject instanceof Object[]) {
63
		Object[] elements = (Object[]) internalObject;
64
		int length = elements.length;
65
		Object[] values = length == 0 ? EmptyArray : new Object[length];
66
		for (int i = 0; i < length; i++)
67
			values[i] = buildDOMValue(elements[i], resolver);
68
		return values;
69
	}
70
	throw new IllegalStateException(internalObject.toString()); // should never get here
71
}
72
73
ResolvedMemberValuePair(ElementValuePair pair, BindingResolver resolver) {
74
	this.internalPair = pair;
75
	this.bindingResolver = resolver;
76
}
77
78
public IMethodBinding getMethodBinding() {
79
	return this.bindingResolver.getMethodBinding(this.internalPair.getMethodBinding());
80
}
81
82
public String getName() {
83
	if (this.internalPair == null)
84
		return null;
85
	final char[] membername = this.internalPair.getName();
86
	return membername == null ? null : new String(membername);
87
}
88
89
public Object getValue() {
90
	if (value == null)
91
		init();
92
	return value == NoValue ? null : this.value;
93
}
94
95
private void init() {
96
	this.value = buildDOMValue(this.internalPair.getValue(), this.bindingResolver);
97
	if (this.value == null)
98
		this.value = NoValue;
99
}
100
101
char[] internalName() {
102
	return this.internalPair == null ? null : this.internalPair.getName();
103
}
104
105
public boolean isDefault() {
106
	return false;
107
}
108
109
public String toString() {
110
	StringBuffer buffer = new StringBuffer();
111
	toString(buffer);
112
	return buffer.toString();
113
}
114
115
public void toString(StringBuffer buffer) {
116
	buffer.append(getName());
117
	buffer.append(" = "); //$NON-NLS-1$		
118
	ResolvedDefaultValuePair.appendValue(getValue(), buffer);
119
}
120
}
(-)dom/org/eclipse/jdt/core/dom/CompilationUnit.java (-3 / +3 lines)
Lines 330-343 Link Here
330
	 * This method always returns <code>null</code> when the resolved annotation
330
	 * This method always returns <code>null</code> when the resolved annotation
331
	 * comes from a different AST.
331
	 * comes from a different AST.
332
	 * 
332
	 * 
333
	 * @param resolvedAnnotation the resolved annotation
333
	 * @param annotationBinding the resolved annotation
334
	 * @return the corresponding node where the given resolved annotation is declared,
334
	 * @return the corresponding node where the given resolved annotation is declared,
335
	 * or <code>null</code> if the resolved annotation does not correspond to a node in this
335
	 * or <code>null</code> if the resolved annotation does not correspond to a node in this
336
	 * compilation unit or if bindings were not requested when this AST was built
336
	 * compilation unit or if bindings were not requested when this AST was built
337
	 * @since 3.2
337
	 * @since 3.2
338
	 */
338
	 */
339
	public ASTNode findDeclaringNode(IResolvedAnnotation resolvedAnnotation) {
339
	public ASTNode findDeclaringNode(IAnnotationBinding annotationBinding) {
340
		return this.ast.getBindingResolver().findDeclaringNode(resolvedAnnotation);
340
		return this.ast.getBindingResolver().findDeclaringNode(annotationBinding);
341
	}
341
	}
342
342
343
	/**
343
	/**
(-)dom/org/eclipse/jdt/core/dom/PackageBinding.java (-15 / +14 lines)
Lines 25-31 Link Here
25
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
25
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
26
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
26
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
27
import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding;
27
import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding;
28
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
29
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
28
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
30
import org.eclipse.jdt.internal.core.NameLookup;
29
import org.eclipse.jdt.internal.core.NameLookup;
31
import org.eclipse.jdt.internal.core.SearchableEnvironment;
30
import org.eclipse.jdt.internal.core.SearchableEnvironment;
Lines 49-66 Link Here
49
		this.resolver = resolver;
48
		this.resolver = resolver;
50
	}
49
	}
51
50
52
	public IResolvedAnnotation[] getAnnotations() {
51
	public IAnnotationBinding[] getAnnotations() {
53
		try {
52
		try {
54
			INameEnvironment nameEnvironment = this.binding.environment.nameEnvironment; 
53
			INameEnvironment nameEnvironment = this.binding.environment.nameEnvironment; 
55
			if (!(nameEnvironment instanceof SearchableEnvironment))
54
			if (!(nameEnvironment instanceof SearchableEnvironment))
56
				return ResolvedAnnotation.NoAnnotations;
55
				return AnnotationBinding.NoAnnotations;
57
			NameLookup nameLookup = ((SearchableEnvironment) nameEnvironment).nameLookup;
56
			NameLookup nameLookup = ((SearchableEnvironment) nameEnvironment).nameLookup;
58
			if (nameLookup == null)
57
			if (nameLookup == null)
59
				return ResolvedAnnotation.NoAnnotations;
58
				return AnnotationBinding.NoAnnotations;
60
			final String pkgName = getName();
59
			final String pkgName = getName();
61
			IPackageFragment[] pkgs = nameLookup.findPackageFragments(pkgName, false/*exact match*/);
60
			IPackageFragment[] pkgs = nameLookup.findPackageFragments(pkgName, false/*exact match*/);
62
			if (pkgs == null)
61
			if (pkgs == null)
63
				return ResolvedAnnotation.NoAnnotations;
62
				return AnnotationBinding.NoAnnotations;
64
63
65
			for (int i = 0, len = pkgs.length; i < len; i++) {
64
			for (int i = 0, len = pkgs.length; i < len; i++) {
66
				int fragType = pkgs[i].getKind();
65
				int fragType = pkgs[i].getKind();
Lines 80-93 Link Here
80
							if (pkgDecl != null) {
79
							if (pkgDecl != null) {
81
								List annos = pkgDecl.annotations();
80
								List annos = pkgDecl.annotations();
82
								if (annos == null || annos.isEmpty())
81
								if (annos == null || annos.isEmpty())
83
									return ResolvedAnnotation.NoAnnotations; 
82
									return AnnotationBinding.NoAnnotations; 
84
								IResolvedAnnotation[] result = new IResolvedAnnotation[annos.size()];
83
								IAnnotationBinding[] result = new IAnnotationBinding[annos.size()];
85
								int index=0;
84
								int index=0;
86
		 						for (Iterator it = annos.iterator(); it.hasNext(); index++) {
85
		 						for (Iterator it = annos.iterator(); it.hasNext(); index++) {
87
									result[index] = ((Annotation) it.next()).resolveAnnotation();
86
									result[index] = ((Annotation) it.next()).resolveAnnotation();
88
									// not resolving bindings
87
									// not resolving bindings
89
									if (result[index] == null)
88
									if (result[index] == null)
90
										return ResolvedAnnotation.NoAnnotations;							
89
										return AnnotationBinding.NoAnnotations;							
91
								}
90
								}
92
								return result;
91
								return result;
93
							}
92
							}
Lines 99-123 Link Here
99
						if (answer != null && answer.isBinaryType()) {
98
						if (answer != null && answer.isBinaryType()) {
100
							IBinaryType type = answer.getBinaryType();
99
							IBinaryType type = answer.getBinaryType();
101
							IBinaryAnnotation[] binaryAnnotations = type.getAnnotations();
100
							IBinaryAnnotation[] binaryAnnotations = type.getAnnotations();
102
							AnnotationBinding[] binaryInstances =
101
							org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] binaryInstances =
103
								BinaryTypeBinding.createAnnotations(binaryAnnotations, this.binding.environment);
102
								BinaryTypeBinding.createAnnotations(binaryAnnotations, this.binding.environment);
104
							AnnotationBinding[] allInstances =
103
							org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] allInstances =
105
								AnnotationBinding.addStandardAnnotations(binaryInstances, type.getTagBits(), this.binding.environment);
104
								org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding.addStandardAnnotations(binaryInstances, type.getTagBits(), this.binding.environment);
106
							int total = allInstances.length;
105
							int total = allInstances.length;
107
							IResolvedAnnotation[] domInstances = new ResolvedAnnotation[total];
106
							IAnnotationBinding[] domInstances = new AnnotationBinding[total];
108
							for (int a = 0; a < total; a++) {
107
							for (int a = 0; a < total; a++) {
109
								domInstances[a] = this.resolver.getAnnotationInstance(allInstances[a]);
108
								domInstances[a] = this.resolver.getAnnotationInstance(allInstances[a]);
110
								if (domInstances[a] == null) // not resolving binding
109
								if (domInstances[a] == null) // not resolving binding
111
									return ResolvedAnnotation.NoAnnotations; 
110
									return AnnotationBinding.NoAnnotations; 
112
							}
111
							}
113
							return domInstances;
112
							return domInstances;
114
						}
113
						}
115
				}	
114
				}	
116
			}		
115
			}		
117
		} catch(JavaModelException e) {
116
		} catch(JavaModelException e) {
118
			return ResolvedAnnotation.NoAnnotations;
117
			return AnnotationBinding.NoAnnotations;
119
		}		
118
		}		
120
		return ResolvedAnnotation.NoAnnotations;
119
		return AnnotationBinding.NoAnnotations;
121
	}
120
	}
122
121
123
	/*
122
	/*
(-)dom/org/eclipse/jdt/core/dom/IMethodBinding.java (-3 / +3 lines)
Lines 93-105 Link Here
93
	 * is not the binding for an annotation type member.
93
	 * is not the binding for an annotation type member.
94
	 * <p>
94
	 * <p>
95
	 * Resolved values are represented as follows (same as for
95
	 * Resolved values are represented as follows (same as for
96
	 * {@link IResolvedMemberValuePair#getValue()}):
96
	 * {@link IMemberValuePairBinding#getValue()}):
97
	 * <ul>
97
	 * <ul>
98
	 * <li>Primitive type - the equivalent boxed object</li>
98
	 * <li>Primitive type - the equivalent boxed object</li>
99
	 * <li>java.lang.Class - the <code>ITypeBinding</code> for the class object</li>
99
	 * <li>java.lang.Class - the <code>ITypeBinding</code> for the class object</li>
100
	 * <li>java.lang.String - the string value itself</li>
100
	 * <li>java.lang.String - the string value itself</li>
101
	 * <li>enum type - the <code>IVariableBinding</code> for the enum constant</li>
101
	 * <li>enum type - the <code>IVariableBinding</code> for the enum constant</li>
102
	 * <li>annotation type - an <code>IResolvedAnnotation</code></li>
102
	 * <li>annotation type - an <code>IAnnotationBinding</code></li>
103
	 * <li>array type - an <code>Object[]</code> whose elements are as per above
103
	 * <li>array type - an <code>Object[]</code> whose elements are as per above
104
	 * (the language only allows single dimensional arrays in annotations)</li>
104
	 * (the language only allows single dimensional arrays in annotations)</li>
105
	 * </ul>
105
	 * </ul>
Lines 122-128 Link Here
122
	 * not a valid index
122
	 * not a valid index
123
	 * @since 3.2
123
	 * @since 3.2
124
	 */
124
	 */
125
	public IResolvedAnnotation[] getParameterAnnotations(int paramIndex);
125
	public IAnnotationBinding[] getParameterAnnotations(int paramIndex);
126
126
127
	/**
127
	/**
128
	 * Returns a list of type bindings representing the formal parameter types,
128
	 * Returns a list of type bindings representing the formal parameter types,
(-)dom/org/eclipse/jdt/core/dom/BindingResolver.java (-4 / +3 lines)
Lines 11-17 Link Here
11
11
12
package org.eclipse.jdt.core.dom;
12
package org.eclipse.jdt.core.dom;
13
13
14
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
15
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
14
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
16
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
15
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
17
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
16
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
Lines 105-111 Link Here
105
	 * @return the corresponding node where the bindings is declared, 
104
	 * @return the corresponding node where the bindings is declared, 
106
	 *    or <code>null</code> if none
105
	 *    or <code>null</code> if none
107
	 */
106
	 */
108
	ASTNode findDeclaringNode(IResolvedAnnotation instance) {
107
	ASTNode findDeclaringNode(IAnnotationBinding instance) {
109
		return null;
108
		return null;
110
	}
109
	}
111
110
Lines 190-196 Link Here
190
	 * @param instance the old annotation 
189
	 * @param instance the old annotation 
191
	 * @return the new DOM annotation
190
	 * @return the new DOM annotation
192
	 */
191
	 */
193
	IResolvedAnnotation getAnnotationInstance(AnnotationBinding instance) {
192
	IAnnotationBinding getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding instance) {
194
		return null;
193
		return null;
195
	}
194
	}
196
195
Lines 830-836 Link Here
830
	 * @return the DOM annotation representation for the given ast node, or 
829
	 * @return the DOM annotation representation for the given ast node, or 
831
	 *    <code>null</code> if none is available
830
	 *    <code>null</code> if none is available
832
	 */
831
	 */
833
	IResolvedAnnotation resolveAnnotation(Annotation annotation) {
832
	IAnnotationBinding resolveAnnotation(Annotation annotation) {
834
		return null;
833
		return null;
835
	}
834
	}
836
835
(-)dom/org/eclipse/jdt/core/dom/ResolvedAnnotation.java (-91 lines)
Removed 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.lookup.AnnotationBinding;
14
import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair;
15
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
16
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
17
import org.eclipse.jdt.internal.compiler.util.*;
18
19
/**
20
 * Internal class
21
 */
22
class ResolvedAnnotation implements IResolvedAnnotation {
23
	static final ResolvedAnnotation[] NoAnnotations = new ResolvedAnnotation[0];
24
	private AnnotationBinding internalAnnotation;
25
	private BindingResolver bindingResolver;
26
27
	ResolvedAnnotation(AnnotationBinding annotation, BindingResolver resolver) {
28
		if (annotation == null)
29
			throw new IllegalStateException();
30
		internalAnnotation = annotation;
31
		bindingResolver = resolver;
32
	}
33
34
	public ITypeBinding getAnnotationType() {
35
		ITypeBinding binding = this.bindingResolver.getTypeBinding(this.internalAnnotation.getAnnotationType());
36
		if (binding == null || !binding.isAnnotation())
37
			return null;
38
		return binding;
39
	}
40
41
	public IResolvedMemberValuePair[] getDeclaredMemberValuePairs() {
42
		ElementValuePair[] internalPairs = this.internalAnnotation.getElementValuePairs();
43
		int length = internalPairs.length;
44
		IResolvedMemberValuePair[] pairs = length == 0 ? ResolvedMemberValuePair.NoPair : new ResolvedMemberValuePair[length];
45
		for (int i = 0; i < length; i++)
46
			pairs[i] = new ResolvedMemberValuePair(internalPairs[i], this.bindingResolver);
47
		return pairs;
48
	}
49
50
	public IResolvedMemberValuePair[] getAllMemberValuePairs() {
51
		IResolvedMemberValuePair[] pairs = getDeclaredMemberValuePairs();
52
		ReferenceBinding typeBinding = this.internalAnnotation.getAnnotationType();
53
		if (typeBinding == null) return pairs;
54
		MethodBinding[] methods = typeBinding.methods();
55
		int methodLength = methods == null ? 0 : methods.length;
56
		if (methodLength == 0) return pairs;
57
58
		int declaredLength = pairs.length;
59
		if (declaredLength == methodLength)
60
			return pairs;
61
62
		HashtableOfObject table = new HashtableOfObject(declaredLength);
63
		for (int i = 0; i < declaredLength; i++)
64
			table.put(((ResolvedMemberValuePair) pairs[i]).internalName(), pairs[i]);
65
66
		// handle case of more methods than declared members
67
		IResolvedMemberValuePair[] allPairs = new  IResolvedMemberValuePair[methodLength];
68
		for (int i = 0; i < methodLength; i++) {
69
			Object pair = table.get(methods[i].selector);
70
			allPairs[i] = pair == null ? new ResolvedDefaultValuePair(methods[i], this.bindingResolver) : (IResolvedMemberValuePair) pair;
71
		}
72
		return allPairs;
73
	}
74
75
	public String toString() {
76
		ITypeBinding type = getAnnotationType();
77
		final StringBuffer buffer = new StringBuffer();
78
		buffer.append('@');
79
		if (type != null)
80
			buffer.append(type.getName());
81
		buffer.append('(');
82
		IResolvedMemberValuePair[] pairs = getDeclaredMemberValuePairs();
83
		for (int i = 0, len = pairs.length; i < len; i++) {
84
			if (i != 0)
85
				buffer.append(", "); //$NON-NLS-1$
86
			buffer.append(pairs[i].toString());
87
		}
88
		buffer.append(')');
89
		return buffer.toString();
90
	}
91
}
(-)dom/org/eclipse/jdt/core/dom/IBinding.java (-7 / +40 lines)
Lines 68-73 Link Here
68
	public static final int METHOD = 4;
68
	public static final int METHOD = 4;
69
69
70
	/**
70
	/**
71
	 * Kind constant (value 5) indicating an annotation binding.
72
	 * Bindings of this kind can be safely cast to <code>IAnnotationBinding</code>.
73
	 * 
74
	 * @see #getKind()
75
	 * @see IAnnotationBinding
76
	 * @since 3.2
77
	 */
78
	public static final int ANNOTATION = 5;
79
80
	/**
81
	 * Kind constant (value 6) indicating a member value pair binding.
82
	 * Bindings of this kind can be safely cast to <code>IMemberValuePairBinding</code>.
83
	 * 
84
	 * @see #getKind()
85
	 * @see IMemberValuePairBinding
86
	 * @since 3.2
87
	 */
88
	public static final int MEMBER_VALUE_PAIR = 6;
89
90
	/**
71
	 * Return the resolved annotations associated with this binding.
91
	 * Return the resolved annotations associated with this binding.
72
	 * <ul>
92
	 * <ul>
73
	 * <li>Package bindings - these are annotations on a package declaration.
93
	 * <li>Package bindings - these are annotations on a package declaration.
Lines 80-101 Link Here
80
	 * parameterized.</li>
100
	 * parameterized.</li>
81
	 * <li>Variable bindings - these are annotations on a field, enum constant,
101
	 * <li>Variable bindings - these are annotations on a field, enum constant,
82
	 * or formal parameter declaration.</li>
102
	 * or formal parameter declaration.</li>
103
	 * <li>Annotation bindings - an empty array is always returned</li>
104
	 * <li>Member value pair bindings - an empty array is always returned<li>
83
	 * </ul>
105
	 * </ul>
84
	 * 
106
	 * 
85
	 * @return the list of resolved annotations, or the empty list if there are no
107
	 * @return the list of resolved annotations, or the empty list if there are no
86
	 * annotations associated with the object
108
	 * annotations associated with the object
87
	 * @since 3.2
109
	 * @since 3.2
88
	 */
110
	 */
89
	public IResolvedAnnotation[] getAnnotations();
111
	public IAnnotationBinding[] getAnnotations();
90
112
91
	/**
113
	/**
92
	 * Returns the kind of bindings this is.
114
	 * Returns the kind of bindings this is. That is one of the kind constants:
93
	 * 
115
	 * <code>PACKAGE</code>,
94
	 * @return one of the kind constants:
95
	 * 	<code>PACKAGE</code>,
96
	 * 	<code>TYPE</code>,
116
	 * 	<code>TYPE</code>,
97
	 * 	<code>VARIABLE</code>,
117
	 * 	<code>VARIABLE</code>,
98
	 * 	or <code>METHOD</code>.
118
	 * 	<code>METHOD</code>,
119
	 * 	<code>ANNOTATION</code>,
120
	 * or <code>MEMBER_VALUE_PAIR</code>.
121
	 * <p>
122
	 * Note that additional kinds might be added in the
123
	 * future, so clients should not assume this list is exhaustive and 
124
	 * should program defensively, e.g. by having a reasonable default
125
	 * in a switch statement.
126
	 * </p>
127
	 * @return one of the kind constants
99
	 */
128
	 */
100
	public int getKind();
129
	public int getKind();
101
	
130
	
Lines 166-173 Link Here
166
	 * <li>the "length" field of an array type</li>
195
	 * <li>the "length" field of an array type</li>
167
	 * <li>the default constructor of a source class</li>
196
	 * <li>the default constructor of a source class</li>
168
	 * <li>the constructor of an anonymous class</li>
197
	 * <li>the constructor of an anonymous class</li>
198
	 * <li>member value pairs</li>
169
	 * </ul>
199
	 * </ul>
170
	 * For all other kind of type, method, variable, and package bindings,
200
	 * For all other kind of type, method, variable, annotation and package bindings,
171
	 * this method returns non-<code>null</code>.
201
	 * this method returns non-<code>null</code>.
172
	 * </p>
202
	 * </p>
173
	 * 
203
	 * 
Lines 231-236 Link Here
231
	 * type</li>
261
	 * type</li>
232
	 * </ul>
262
	 * </ul>
233
	 * </p>
263
	 * </p>
264
	 * <p>Note that the key for annotation bindings and member value pair bindings is
265
	 * not yet implemented. This returns <code>null</code> for these 2 kinds of bindings.
266
	 * </p>
234
	 * 
267
	 * 
235
	 * @return the key for this binding
268
	 * @return the key for this binding
236
	 */
269
	 */
(-)dom/org/eclipse/jdt/core/dom/VariableBinding.java (-5 / +4 lines)
Lines 16-22 Link Here
16
import org.eclipse.jdt.core.util.IModifierConstants;
16
import org.eclipse.jdt.core.util.IModifierConstants;
17
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
17
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
18
import org.eclipse.jdt.internal.compiler.impl.Constant;
18
import org.eclipse.jdt.internal.compiler.impl.Constant;
19
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
20
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
19
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
21
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
20
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
22
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
21
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
Lines 43-54 Link Here
43
		this.binding = binding;
42
		this.binding = binding;
44
	}
43
	}
45
44
46
	public IResolvedAnnotation[] getAnnotations() { 
45
	public IAnnotationBinding[] getAnnotations() { 
47
		AnnotationBinding[] internalAnnotations = this.binding.getAnnotations();
46
		org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] internalAnnotations = this.binding.getAnnotations();
48
		// the variable is not an enum constant nor a field nor an argument.
47
		// the variable is not an enum constant nor a field nor an argument.
49
		int length = internalAnnotations == null ? 0 : internalAnnotations.length;
48
		int length = internalAnnotations == null ? 0 : internalAnnotations.length;
50
		IResolvedAnnotation[] domInstances =
49
		IAnnotationBinding[] domInstances =
51
			length == 0 ? ResolvedAnnotation.NoAnnotations : new ResolvedAnnotation[length];
50
			length == 0 ? AnnotationBinding.NoAnnotations : new AnnotationBinding[length];
52
		for (int i = 0; i < length; i++)
51
		for (int i = 0; i < length; i++)
53
			domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]);
52
			domInstances[i] = this.resolver.getAnnotationInstance(internalAnnotations[i]);
54
		return domInstances;                                                                  
53
		return domInstances;                                                                  
(-)dom/org/eclipse/jdt/core/dom/IResolvedAnnotation.java (-52 lines)
Removed 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
 * Returns the type of the annotation. The resulting type binding will always
22
 * return <code>true</code>	to <code>ITypeBinding.isAnnotation()</code>.
23
 * 
24
 * @return the type of the annotation
25
 */
26
ITypeBinding getAnnotationType();
27
28
/**
29
 * Returns the list of declared member value pairs for this annotation.
30
 * Returns an empty list for a <code>MarkerAnnotation</code>, a one element
31
 * list for a <code>SingleMemberAnnotation</code>, and one entry for each
32
 * of the explicitly listed values in a <code>NormalAnnotation</code>.
33
 * <p>
34
 * Note that the list only includes entries for annotation type members that are
35
 * explicitly mentioned in the annotation. The list does not include any 
36
 * annotation type members with default values that are merely implied.
37
 * Use {@link #getAllMemberValuePairs()} to get those as well.
38
 * </p>
39
 * 
40
 * @return a possibly empty list of resolved member value pairs
41
 */
42
IResolvedMemberValuePair[] getDeclaredMemberValuePairs();
43
44
/**
45
 * Returns the complete list of member value pairs for this annotation, including
46
 * ones explicitly listed in the annotation as well as entries for 
47
 * annotation type members with default values that are implied.
48
 * 
49
 * @return a possibly empty list of resolved member value pairs
50
 */
51
IResolvedMemberValuePair[] getAllMemberValuePairs();
52
}
(-)dom/org/eclipse/jdt/core/dom/IAnnotationBinding.java (+66 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
 *    IBM Corporation - changed interface to extend IBinding
11
 *    IBM Corporation - renamed from IResolvedAnnotation to IAnnotationBinding
12
 *******************************************************************************/
13
package org.eclipse.jdt.core.dom;
14
15
/**
16
 * Represents an resolved annotation. Resolved annotation are computed along with other
17
 * bindings; they correspond to {@link Annotation} nodes.
18
 * <p>
19
 * This interface is not intended to be implemented by clients.
20
 * </p>
21
 * 
22
 * @since 3.2
23
 */
24
public interface IAnnotationBinding extends IBinding {
25
26
	/**
27
	 * Returns the complete list of member value pairs for this annotation, including
28
	 * ones explicitly listed in the annotation as well as entries for 
29
	 * annotation type members with default values that are implied.
30
	 * 
31
	 * @return a possibly empty list of resolved member value pairs
32
	 */
33
	IMemberValuePairBinding[] getAllMemberValuePairs();
34
	
35
	/**
36
	 * Returns the type of the annotation. The resulting type binding will always
37
	 * return <code>true</code>	to <code>ITypeBinding.isAnnotation()</code>.
38
	 * 
39
	 * @return the type of the annotation
40
	 */
41
	ITypeBinding getAnnotationType();
42
	
43
	/**
44
	 * Returns the list of declared member value pairs for this annotation.
45
	 * Returns an empty list for a <code>MarkerAnnotation</code>, a one element
46
	 * list for a <code>SingleMemberAnnotation</code>, and one entry for each
47
	 * of the explicitly listed values in a <code>NormalAnnotation</code>.
48
	 * <p>
49
	 * Note that the list only includes entries for annotation type members that are
50
	 * explicitly mentioned in the annotation. The list does not include any 
51
	 * annotation type members with default values that are merely implied.
52
	 * Use {@link #getAllMemberValuePairs()} to get those as well.
53
	 * </p>
54
	 * 
55
	 * @return a possibly empty list of resolved member value pairs
56
	 */
57
	IMemberValuePairBinding[] getDeclaredMemberValuePairs();
58
	
59
	/**
60
	 * Returns the name of the annotation type.
61
	 * 
62
	 * @return the name of the annotation type
63
	 */
64
	public String getName();
65
	
66
}
(-)dom/org/eclipse/jdt/core/dom/IMemberValuePairBinding.java (+61 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
 *    IBM Corporation - changed interface to extend IBinding
11
 *    IBM Corporation - renamed from IResolvedMemberValuePair to IMemberValuePairBinding
12
 *******************************************************************************/
13
package org.eclipse.jdt.core.dom;
14
15
/**
16
 * Represents a resolved instance of an annotation's member value pair.
17
 * Resolved annotation are computed along with other bindings; these objects
18
 * correspond to {@link MemberValuePair} nodes.
19
 * <p>
20
 * This interface is not intended to be implemented by clients.
21
 * </p>
22
 * 
23
 * @since 3.2
24
 */
25
public interface IMemberValuePairBinding extends IBinding {
26
/**
27
 * Returns the name of the annotation type member.
28
 * 
29
 * @return the name of the member
30
 */
31
public String getName();
32
33
/**
34
 * Returns the method binding corresponding to the named annotation type member.
35
 * 
36
 * @return the method binding for the annotation type member
37
 */
38
public IMethodBinding getMethodBinding();
39
40
/**
41
 * Returns the resolved value. Resolved values are represented as follows:
42
 * <ul>
43
 * <li>Primitive type - the equivalent boxed object</li>
44
 * <li>java.lang.Class - the <code>ITypeBinding</code> for the class object</li>
45
 * <li>java.lang.String - the string value itself</li>
46
 * <li>enum type - the <code>IVariableBinding</code> for the enum constant</li>
47
 * <li>annotation type - an <code>IAnnotationBinding</code></li>
48
 * <li>array type - an <code>Object[]</code> whose elements are as per above
49
 * (the language only allows single dimensional arrays in annotations)</li>
50
 * </ul>
51
 * 	
52
 * @return the resolved value, or <code>null</code> if none exists
53
 */
54
public Object getValue();
55
56
/**
57
 * @return <code>true</code> iff this member value pair's value is the default value.
58
 *         Returns <code>false</code> otherwise.
59
 */
60
public boolean isDefault();
61
}
(-)dom/org/eclipse/jdt/core/dom/DefaultValuePairBinding.java (+123 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
 *    IBM Corporation - implemented methods from IBinding
11
 *    IBM Corporation - renamed from ResolvedDefaultValuePair to DefaultValuePairBinding
12
 *******************************************************************************/
13
package org.eclipse.jdt.core.dom;
14
15
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.core.dom.BindingResolver;
17
import org.eclipse.jdt.core.dom.IMethodBinding;
18
import org.eclipse.jdt.core.dom.IMemberValuePairBinding;
19
20
/**
21
 * Member value pair which compose of default values.
22
 */
23
class DefaultValuePairBinding implements IMemberValuePairBinding {
24
25
	private org.eclipse.jdt.internal.compiler.lookup.MethodBinding method;
26
	private Object domValue;
27
	private BindingResolver bindingResolver;
28
29
	static void appendValue(Object value, StringBuffer buffer) {
30
		if (value instanceof Object[]) {
31
			Object[] values = (Object[]) value;
32
			buffer.append('{');
33
			for (int i = 0, l = values.length; i < l; i++) {
34
				if (i != 0)
35
					buffer.append(", "); //$NON-NLS-1$
36
				appendValue(values[i], buffer);
37
			}
38
			buffer.append('}');
39
		} else if (value instanceof ITypeBinding) {
40
			buffer.append(((ITypeBinding) value).getName());
41
			buffer.append(".class"); //$NON-NLS-1$
42
		} else {
43
			buffer.append(value);
44
		}
45
	}
46
	
47
	DefaultValuePairBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding binding, BindingResolver resolver) {
48
		this.method = binding;
49
		this.domValue = MemberValuePairBinding.buildDOMValue(binding.getDefaultValue(), resolver);
50
		this.bindingResolver = resolver;
51
	}
52
	
53
	public IAnnotationBinding[] getAnnotations() {
54
		return AnnotationBinding.NoAnnotations;
55
	}
56
57
	public IJavaElement getJavaElement() {
58
		return null;
59
	}
60
	
61
	public String getKey() {
62
		// TODO when implementing, update spec in IBinding
63
		return null;
64
	}
65
66
	public int getKind() {
67
		return IBinding.MEMBER_VALUE_PAIR;
68
	}
69
70
	public IMethodBinding getMethodBinding() {
71
		return this.bindingResolver.getMethodBinding(this.method);
72
	}
73
	
74
	public int getModifiers() {
75
		return -1;
76
	}
77
78
	public String getName() {
79
		return new String(this.method.selector);
80
	}
81
	
82
	public Object getValue() {
83
		return this.domValue;
84
	}
85
	
86
	public boolean isDefault() {
87
		return true;
88
	}
89
	
90
	public boolean isDeprecated() {
91
		return false;
92
	}
93
	
94
	public boolean isEqualTo(IBinding binding) {
95
		if (this == binding)
96
			return true;
97
		if (binding.getKind() != IBinding.MEMBER_VALUE_PAIR)
98
			return false;
99
		IMemberValuePairBinding other = (IMemberValuePairBinding) binding;
100
		if (!getMethodBinding().isEqualTo(other.getMethodBinding()))
101
			return false;
102
		Object value = getValue();
103
		if (value == null)
104
			return other.getValue() == null;
105
		return value.equals(other.getValue());
106
	}
107
108
	public boolean isSynthetic() {
109
		return false;
110
	}
111
112
	public String toString() {
113
		StringBuffer buffer = new StringBuffer();
114
		toString(buffer);
115
		return buffer.toString();
116
	}
117
	
118
	public void toString(StringBuffer buffer) {
119
		buffer.append(getName());
120
		buffer.append(" = "); //$NON-NLS-1$		
121
		appendValue(getValue(), buffer);
122
	}
123
}
(-)dom/org/eclipse/jdt/core/dom/AnnotationBinding.java (+153 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
 *    IBM Corporation - implemented methods from IBinding
11
 *    IBM Corporation - renamed from ResolvedAnnotation to AnnotationBinding
12
 *******************************************************************************/
13
package org.eclipse.jdt.core.dom;
14
15
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair;
17
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
18
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
19
import org.eclipse.jdt.internal.compiler.util.*;
20
21
/**
22
 * Internal class
23
 */
24
class AnnotationBinding implements IAnnotationBinding {
25
	static final AnnotationBinding[] NoAnnotations = new AnnotationBinding[0];
26
	private org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding internalAnnotation;
27
	private BindingResolver bindingResolver;
28
29
	AnnotationBinding(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding annotation, BindingResolver resolver) {
30
		if (annotation == null)
31
			throw new IllegalStateException();
32
		internalAnnotation = annotation;
33
		bindingResolver = resolver;
34
	}
35
	
36
	public IAnnotationBinding[] getAnnotations() {
37
		return NoAnnotations;
38
	}
39
40
	public ITypeBinding getAnnotationType() {
41
		ITypeBinding binding = this.bindingResolver.getTypeBinding(this.internalAnnotation.getAnnotationType());
42
		if (binding == null || !binding.isAnnotation())
43
			return null;
44
		return binding;
45
	}
46
	
47
	public IMemberValuePairBinding[] getDeclaredMemberValuePairs() {
48
		ElementValuePair[] internalPairs = this.internalAnnotation.getElementValuePairs();
49
		int length = internalPairs.length;
50
		IMemberValuePairBinding[] pairs = length == 0 ? MemberValuePairBinding.NoPair : new MemberValuePairBinding[length];
51
		for (int i = 0; i < length; i++)
52
			pairs[i] = new MemberValuePairBinding(internalPairs[i], this.bindingResolver);
53
		return pairs;
54
	}
55
56
	public IMemberValuePairBinding[] getAllMemberValuePairs() {
57
		IMemberValuePairBinding[] pairs = getDeclaredMemberValuePairs();
58
		ReferenceBinding typeBinding = this.internalAnnotation.getAnnotationType();
59
		if (typeBinding == null) return pairs;
60
		MethodBinding[] methods = typeBinding.methods();
61
		int methodLength = methods == null ? 0 : methods.length;
62
		if (methodLength == 0) return pairs;
63
64
		int declaredLength = pairs.length;
65
		if (declaredLength == methodLength)
66
			return pairs;
67
68
		HashtableOfObject table = new HashtableOfObject(declaredLength);
69
		for (int i = 0; i < declaredLength; i++)
70
			table.put(((MemberValuePairBinding) pairs[i]).internalName(), pairs[i]);
71
72
		// handle case of more methods than declared members
73
		IMemberValuePairBinding[] allPairs = new  IMemberValuePairBinding[methodLength];
74
		for (int i = 0; i < methodLength; i++) {
75
			Object pair = table.get(methods[i].selector);
76
			allPairs[i] = pair == null ? new DefaultValuePairBinding(methods[i], this.bindingResolver) : (IMemberValuePairBinding) pair;
77
		}
78
		return allPairs;
79
	}
80
	
81
	public IJavaElement getJavaElement() {
82
		ITypeBinding annotationType = getAnnotationType();
83
		if (annotationType == null)
84
			return null;
85
		return annotationType.getJavaElement();
86
	}
87
88
	public String getKey() {
89
		// TODO when implementing, update spec in IBinding
90
		return null;
91
	}
92
93
	public int getKind() {
94
		return IBinding.ANNOTATION;
95
	}
96
97
	public int getModifiers() {
98
		return -1;
99
	}
100
101
	public String getName() {
102
		ITypeBinding annotationType = getAnnotationType();
103
		if (annotationType == null)
104
			return new String(this.internalAnnotation.getAnnotationType().sourceName());
105
		else
106
			return annotationType.getName();
107
	}
108
	
109
	public boolean isDeprecated() {
110
		return false;
111
	}
112
	
113
	public boolean isEqualTo(IBinding binding) {
114
		if (this == binding)
115
			return true;
116
		if (binding.getKind() != IBinding.ANNOTATION)
117
			return false;
118
		IAnnotationBinding other = (IAnnotationBinding) binding;
119
		if (!getAnnotationType().isEqualTo(other.getAnnotationType()))
120
			return false;
121
		IMemberValuePairBinding[] memberValuePairs = getDeclaredMemberValuePairs();
122
		IMemberValuePairBinding[] otherMemberValuePairs = other.getDeclaredMemberValuePairs();
123
		if (memberValuePairs.length != otherMemberValuePairs.length)
124
			return false;
125
		for (int i = 0, length = memberValuePairs.length; i < length; i++) {
126
			if (!memberValuePairs[i].isEqualTo(otherMemberValuePairs[i]))
127
				return false;
128
		}
129
		return true;
130
	}
131
	
132
	public boolean isSynthetic() {
133
		return false;
134
	}
135
136
	public String toString() {
137
		ITypeBinding type = getAnnotationType();
138
		final StringBuffer buffer = new StringBuffer();
139
		buffer.append('@');
140
		if (type != null)
141
			buffer.append(type.getName());
142
		buffer.append('(');
143
		IMemberValuePairBinding[] pairs = getDeclaredMemberValuePairs();
144
		for (int i = 0, len = pairs.length; i < len; i++) {
145
			if (i != 0)
146
				buffer.append(", "); //$NON-NLS-1$
147
			buffer.append(pairs[i].toString());
148
		}
149
		buffer.append(')');
150
		return buffer.toString();
151
	}
152
	
153
}
(-)dom/org/eclipse/jdt/core/dom/MemberValuePairBinding.java (+164 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
 *    IBM Corporation - implemented methods from IBinding
11
 *    IBM Corporation - renamed from ResolvedMemberValuePair to MemberValuePairBinding
12
 *******************************************************************************/
13
package org.eclipse.jdt.core.dom;
14
15
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.internal.compiler.impl.Constant;
17
import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair;
18
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
19
20
/**
21
 * Internal class.
22
 */
23
class MemberValuePairBinding implements IMemberValuePairBinding {
24
	static final MemberValuePairBinding[] NoPair = new MemberValuePairBinding[0];
25
	private static final Object NoValue = new Object();
26
	private static final Object[] EmptyArray = new Object[0];
27
28
	private ElementValuePair internalPair;
29
	private Object value = null;
30
	private BindingResolver bindingResolver;
31
32
	static Object buildDOMValue(final Object internalObject, BindingResolver resolver) {
33
		if (internalObject == null)
34
			return null;
35
	
36
		if (internalObject instanceof Constant) {
37
			Constant constant = (Constant) internalObject;
38
			switch (constant.typeID()) {
39
				case TypeIds.T_boolean:
40
					return Boolean.valueOf(constant.booleanValue());
41
				case TypeIds.T_byte:
42
					return new Byte(constant.byteValue());
43
				case TypeIds.T_char:
44
					return new Character(constant.charValue());
45
				case TypeIds.T_double:
46
					return new Double(constant.doubleValue());
47
				case TypeIds.T_float:
48
					return new Float(constant.floatValue());
49
				case TypeIds.T_int:
50
					return new Integer(constant.intValue());
51
				case TypeIds.T_long:
52
					return new Long(constant.longValue());
53
				case TypeIds.T_short:
54
					return new Short(constant.shortValue());
55
				case TypeIds.T_JavaLangString:
56
					return constant.stringValue();
57
			}
58
		} else if (internalObject instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
59
			return resolver.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) internalObject);
60
		} else if (internalObject instanceof org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding) {
61
			return resolver.getAnnotationInstance((org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding) internalObject);
62
		} else if (internalObject instanceof org.eclipse.jdt.internal.compiler.lookup.FieldBinding) {
63
			return resolver.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding) internalObject);
64
		} else if (internalObject instanceof Object[]) {
65
			Object[] elements = (Object[]) internalObject;
66
			int length = elements.length;
67
			Object[] values = length == 0 ? EmptyArray : new Object[length];
68
			for (int i = 0; i < length; i++)
69
				values[i] = buildDOMValue(elements[i], resolver);
70
			return values;
71
		}
72
		throw new IllegalStateException(internalObject.toString()); // should never get here
73
	}
74
	
75
	MemberValuePairBinding(ElementValuePair pair, BindingResolver resolver) {
76
		this.internalPair = pair;
77
		this.bindingResolver = resolver;
78
	}
79
	
80
	public IAnnotationBinding[] getAnnotations() {
81
		return AnnotationBinding.NoAnnotations;
82
	}
83
84
	public IJavaElement getJavaElement() {
85
		return null;
86
	}
87
		
88
	public String getKey() {
89
		// TODO when implementing, update spec in IBinding
90
		return null;
91
	}
92
93
	public int getKind() {
94
		return IBinding.MEMBER_VALUE_PAIR;
95
	}
96
97
	public IMethodBinding getMethodBinding() {
98
		return this.bindingResolver.getMethodBinding(this.internalPair.getMethodBinding());
99
	}
100
	
101
	public int getModifiers() {
102
		return -1;
103
	}
104
105
	public String getName() {
106
		if (this.internalPair == null)
107
			return null;
108
		final char[] membername = this.internalPair.getName();
109
		return membername == null ? null : new String(membername);
110
	}
111
	
112
	public Object getValue() {
113
		if (value == null)
114
			init();
115
		return value == NoValue ? null : this.value;
116
	}
117
	
118
	private void init() {
119
		this.value = buildDOMValue(this.internalPair.getValue(), this.bindingResolver);
120
		if (this.value == null)
121
			this.value = NoValue;
122
	}
123
	
124
	char[] internalName() {
125
		return this.internalPair == null ? null : this.internalPair.getName();
126
	}
127
	
128
	public boolean isDefault() {
129
		return false;
130
	}
131
	
132
	public boolean isDeprecated() {
133
		return false;
134
	}
135
136
	public boolean isEqualTo(IBinding binding) {
137
		if (this == binding)
138
			return true;
139
		if (binding.getKind() != IBinding.MEMBER_VALUE_PAIR)
140
			return false;
141
		IMemberValuePairBinding other = (IMemberValuePairBinding) binding;
142
		if (!getMethodBinding().isEqualTo(other.getMethodBinding()))
143
			return false;
144
		if (this.value == null)
145
			return other.getValue() == null;
146
		return this.value.equals(other.getValue());
147
	}
148
149
	public boolean isSynthetic() {
150
		return false;
151
	}
152
153
	public String toString() {
154
		StringBuffer buffer = new StringBuffer();
155
		toString(buffer);
156
		return buffer.toString();
157
	}
158
	
159
	public void toString(StringBuffer buffer) {
160
		buffer.append(getName());
161
		buffer.append(" = "); //$NON-NLS-1$		
162
		DefaultValuePairBinding.appendValue(getValue(), buffer);
163
	}
164
}
(-)src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java (-1 / +1 lines)
Lines 368-374 Link Here
368
						ITypeBinding typeBinding = typeDecl.resolveBinding();
368
						ITypeBinding typeBinding = typeDecl.resolveBinding();
369
						if (typeBinding == null) continue;
369
						if (typeBinding == null) continue;
370
						typeBinding = typeBinding.getAnnotations()[0].getAnnotationType();
370
						typeBinding = typeBinding.getAnnotations()[0].getAnnotationType();
371
						IResolvedAnnotation targetValue = typeBinding.getAnnotations()[0];
371
						IAnnotationBinding targetValue = typeBinding.getAnnotations()[0];
372
						IMethodBinding method = targetValue.getDeclaredMemberValuePairs()[0].getMethodBinding();
372
						IMethodBinding method = targetValue.getDeclaredMemberValuePairs()[0].getMethodBinding();
373
						if (!"value".equals(method.getName()))
373
						if (!"value".equals(method.getName()))
374
							problems.add(new ParticipantProblem("method " + method.getName() + " not found", file.getName()));
374
							problems.add(new ParticipantProblem("method " + method.getName() + " not found", file.getName()));

Return to bug 123470