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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java (-5 / +10 lines)
Lines 7096-7102 Link Here
7096
		assertEquals("Wrong size", 0, annotations.length);
7096
		assertEquals("Wrong size", 0, annotations.length);
7097
	}
7097
	}
7098
	
7098
	
7099
	public void _test0227() throws JavaModelException {
7099
	public void test0227() throws JavaModelException {
7100
    	this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
7100
    	this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
7101
    	String contents =
7101
    	String contents =
7102
    		"import anno.Anno;\n" + 
7102
    		"import anno.Anno;\n" + 
Lines 7105-7111 Link Here
7105
    		"\n" + 
7105
    		"\n" + 
7106
    		"public class X extends B {\n" + 
7106
    		"public class X extends B {\n" + 
7107
    		"	@Anno(clz=IFoo.IBar.class)\n" + 
7107
    		"	@Anno(clz=IFoo.IBar.class)\n" + 
7108
    		"	public void f() {}\n" + 
7108
    			// the annotation we chase up is not this one, but the one
7109
    			// carried by B#f
7110
    		"	public void f() {}\n" +
7111
    		"   IFoo.IBar m;\n" + 
7109
    		"}";
7112
    		"}";
7110
    	class TestASTRequestor extends ASTRequestor {
7113
    	class TestASTRequestor extends ASTRequestor {
7111
    		public ArrayList asts = new ArrayList();
7114
    		public ArrayList asts = new ArrayList();
Lines 7154-7161 Link Here
7154
		assertEquals("Wrong kind", IBinding.MEMBER_VALUE_PAIR, memberValuePairBinding.getKind());
7157
		assertEquals("Wrong kind", IBinding.MEMBER_VALUE_PAIR, memberValuePairBinding.getKind());
7155
		Object value = memberValuePairBinding.getValue();
7158
		Object value = memberValuePairBinding.getValue();
7156
		assertNotNull("No value", value);
7159
		assertNotNull("No value", value);
7157
		assertTrue("not a type binding", value instanceof ITypeBinding);
7160
		assertTrue("Not a type binding", value instanceof ITypeBinding);
7158
		ITypeBinding typeBinding2 = (ITypeBinding) value;
7161
		IVariableBinding[] fields = 
7159
		assertEquals("Wrong qualified name", "intf.IFoo.IBar", typeBinding2.getQualifiedName());
7162
			declaration.resolveBinding().getDeclaredFields();
7163
		assertTrue("Bad field definition", fields != null && fields.length == 1);
7164
		assertEquals("Type binding mismatch", value, fields[0].getType());
7160
	}	
7165
	}	
7161
}
7166
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java (-1 / +1 lines)
Lines 83-89 Link Here
83
83
84
	char[] typeName = annotationInfo.getTypeName();
84
	char[] typeName = annotationInfo.getTypeName();
85
	ReferenceBinding annotationType = env.getTypeFromConstantPoolName(typeName, 1, typeName.length - 1, false);
85
	ReferenceBinding annotationType = env.getTypeFromConstantPoolName(typeName, 1, typeName.length - 1, false);
86
	return AnnotationBinding.createUnresolvedAnnotation(annotationType, pairs, env);
86
	return new UnresolvedAnnotationBinding(annotationType, pairs, env);
87
}
87
}
88
public static AnnotationBinding[] createAnnotations(IBinaryAnnotation[] annotationInfos, LookupEnvironment env) {
88
public static AnnotationBinding[] createAnnotations(IBinaryAnnotation[] annotationInfos, LookupEnvironment env) {
89
	int length = annotationInfos == null ? 0 : annotationInfos.length;
89
	int length = annotationInfos == null ? 0 : annotationInfos.length;
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/UnresolvedAnnotationBinding.java (-8 / +26 lines)
Lines 12-17 Link Here
12
12
13
public class UnresolvedAnnotationBinding extends AnnotationBinding {
13
public class UnresolvedAnnotationBinding extends AnnotationBinding {
14
	private LookupEnvironment env;
14
	private LookupEnvironment env;
15
	private boolean typeUnresolved = true;
15
16
16
UnresolvedAnnotationBinding(ReferenceBinding type, ElementValuePair[] pairs, LookupEnvironment env) {
17
UnresolvedAnnotationBinding(ReferenceBinding type, ElementValuePair[] pairs, LookupEnvironment env) {
17
	super(type, pairs);
18
	super(type, pairs);
Lines 19-38 Link Here
19
}
20
}
20
21
21
public ReferenceBinding getAnnotationType() {
22
public ReferenceBinding getAnnotationType() {
22
	// the type is resolved when requested
23
	if (this.typeUnresolved) { // the type is resolved when requested
23
	if (this.env != null) {
24
		// annotation type are never parameterized
25
		this.type = BinaryTypeBinding.resolveType(this.type, this.env, false);
24
		this.type = BinaryTypeBinding.resolveType(this.type, this.env, false);
26
		this.env = null;
25
			// annotation type are never parameterized
27
		setMethodBindings();
26
		this.typeUnresolved = false;
28
	}
27
	}
29
	return this.type;
28
	return this.type;
30
}
29
}
31
30
32
public ElementValuePair[] getElementValuePairs() {
31
public ElementValuePair[] getElementValuePairs() {
33
	if (this.env != null)
32
	if (this.env != null) {
34
		getAnnotationType(); // resolve the annotation type & method bindings of each pair
33
		if (this.typeUnresolved) {
35
34
			getAnnotationType(); // resolve the annotation type
35
		}
36
		// resolve method binding and value type (if unresolved) for each pair
37
		for (int i = this.pairs.length; --i >= 0;) {
38
			ElementValuePair pair = this.pairs[i];
39
			MethodBinding[] methods = this.type.getMethods(pair.getName());
40
			// there should be exactly one since the type is an annotation type.
41
			if (methods != null && methods.length == 1) {
42
				pair.setMethodBinding(methods[0]);
43
			} // else silently leave a null there
44
			Object value = pair.getValue();
45
			if (value instanceof UnresolvedReferenceBinding) {
46
				pair.setValue(((UnresolvedReferenceBinding) value).
47
						resolve(this.env, false));
48
							// no parameterized types in annotation values
49
			} // do nothing for UnresolvedAnnotationBinding-s, since their 
50
			  // content is only accessed through get* methods
51
		}
52
		this.env = null;
53
	}
36
	return this.pairs;
54
	return this.pairs;
37
}
55
}
38
}
56
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ElementValuePair.java (+5 lines)
Lines 95-98 Link Here
95
	// lazily set after annotation type was resolved
95
	// lazily set after annotation type was resolved
96
	this.binding = binding;
96
	this.binding = binding;
97
}
97
}
98
99
void setValue(Object value) {
100
	// can be modified after the initialization if holding an unresolved ref
101
	this.value = value;
102
}
98
}
103
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotationBinding.java (-22 / +17 lines)
Lines 16-21 Link Here
16
 * Represents JSR 175 Annotation instances in the type-system.
16
 * Represents JSR 175 Annotation instances in the type-system.
17
 */ 
17
 */ 
18
public class AnnotationBinding{
18
public class AnnotationBinding{
19
	// do not access directly - use getters instead (UnresolvedAnnotationBinding
20
	// resolves types for type and pair contents just in time)
19
	ReferenceBinding type;
21
	ReferenceBinding type;
20
	ElementValuePair[] pairs;
22
	ElementValuePair[] pairs;
21
23
Lines 74-80 Link Here
74
}
76
}
75
77
76
private static AnnotationBinding buildRetentionAnnotation(long bits, LookupEnvironment env) {
78
private static AnnotationBinding buildRetentionAnnotation(long bits, LookupEnvironment env) {
77
	ReferenceBinding retentionPolicy = env.getResolvedType(TypeConstants.JAVA_LANG_ANNOTATION_RETENTIONPOLICY, null);
79
	ReferenceBinding retentionPolicy = 
80
		env.getResolvedType(TypeConstants.JAVA_LANG_ANNOTATION_RETENTIONPOLICY, 
81
			null);
78
	Object value = null;
82
	Object value = null;
79
	if ((bits & TagBits.AnnotationRuntimeRetention) != 0)
83
	if ((bits & TagBits.AnnotationRuntimeRetention) != 0)
80
		value = retentionPolicy.getField(TypeConstants.UPPER_RUNTIME, true);
84
		value = retentionPolicy.getField(TypeConstants.UPPER_RUNTIME, true);
Lines 82-91 Link Here
82
		value = retentionPolicy.getField(TypeConstants.UPPER_CLASS, true);
86
		value = retentionPolicy.getField(TypeConstants.UPPER_CLASS, true);
83
	else if ((bits & TagBits.AnnotationSourceRetention) != 0)
87
	else if ((bits & TagBits.AnnotationSourceRetention) != 0)
84
		value = retentionPolicy.getField(TypeConstants.UPPER_SOURCE, true);
88
		value = retentionPolicy.getField(TypeConstants.UPPER_SOURCE, true);
85
89
	return (new AnnotationBinding(
86
	ReferenceBinding retention = env.getResolvedType(TypeConstants.JAVA_LANG_ANNOTATION_RETENTION, null);
90
		env.getResolvedType(TypeConstants.JAVA_LANG_ANNOTATION_RETENTION, null),
87
	ElementValuePair[] pairs = new ElementValuePair[] { new ElementValuePair(TypeConstants.VALUE, value, null) };
91
		new ElementValuePair[] { 
88
	return createUnresolvedAnnotation(retention, pairs, env);
92
			new ElementValuePair(TypeConstants.VALUE, value, null)})).
93
				setMethodBindings();
89
}
94
}
90
95
91
private static AnnotationBinding buildTargetAnnotation(long bits, LookupEnvironment env) {
96
private static AnnotationBinding buildTargetAnnotation(long bits, LookupEnvironment env) {
Lines 131-152 Link Here
131
		if ((bits & TagBits.AnnotationForType) != 0)
136
		if ((bits & TagBits.AnnotationForType) != 0)
132
			value[index++] = elementType.getField(TypeConstants.TYPE, true);
137
			value[index++] = elementType.getField(TypeConstants.TYPE, true);
133
	}
138
	}
134
139
	return (new AnnotationBinding(target,
135
	ElementValuePair[] pairs = new ElementValuePair[] { new ElementValuePair(TypeConstants.VALUE, value, null) };
140
				new ElementValuePair[] { 
136
	return createUnresolvedAnnotation(target, pairs, env);
141
					new ElementValuePair(TypeConstants.VALUE, value, null)}).
137
}
142
						setMethodBindings());
138
139
public static AnnotationBinding createUnresolvedAnnotation(ReferenceBinding type, ElementValuePair[] pairs, LookupEnvironment env) {
140
	// if type is unresolved then answer a lazy instance that will resolve the type & fault in the method of each pair when requested
141
	if (type instanceof UnresolvedReferenceBinding)
142
		return new UnresolvedAnnotationBinding(type, pairs, env);
143
144
	AnnotationBinding newInstance = new AnnotationBinding(type, pairs);
145
	newInstance.setMethodBindings();
146
	return newInstance;
147
}
143
}
148
144
149
150
public AnnotationBinding(ReferenceBinding type, ElementValuePair[] pairs) {
145
public AnnotationBinding(ReferenceBinding type, ElementValuePair[] pairs) {
151
	this.type = type;
146
	this.type = type;
152
	this.pairs = pairs;
147
	this.pairs = pairs;
Lines 164-172 Link Here
164
	return this.pairs;
159
	return this.pairs;
165
}
160
}
166
161
167
protected void setMethodBindings() {
162
private AnnotationBinding setMethodBindings() {
168
	// set the method bindings of each element value pair
163
	// set the method bindings of each element value pair
169
	if (this.type == null) return;
170
	for (int i = this.pairs.length; --i >= 0;) {
164
	for (int i = this.pairs.length; --i >= 0;) {
171
		ElementValuePair pair = this.pairs[i];
165
		ElementValuePair pair = this.pairs[i];
172
		MethodBinding[] methods = this.type.getMethods(pair.getName());
166
		MethodBinding[] methods = this.type.getMethods(pair.getName());
Lines 174-178 Link Here
174
		if (methods != null && methods.length == 1)
168
		if (methods != null && methods.length == 1)
175
			pair.setMethodBinding(methods[0]);
169
			pair.setMethodBinding(methods[0]);
176
	}
170
	}
171
	return this;
177
}
172
}
178
}
173
}

Return to bug 155115