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 |
} |