src/share/classes/com/sun/tools/javac/comp/Annotate.java

changeset 1755
ddb4a2bfcd82
parent 1629
f427043f8c65
child 1914
0a9f5cbe37d9
equal deleted inserted replaced
1754:0384683c64be 1755:ddb4a2bfcd82
214 * to the annotated symbol. 214 * to the annotated symbol.
215 */ 215 */
216 Attribute.Compound enterAnnotation(JCAnnotation a, 216 Attribute.Compound enterAnnotation(JCAnnotation a,
217 Type expected, 217 Type expected,
218 Env<AttrContext> env) { 218 Env<AttrContext> env) {
219 return enterAnnotation(a, expected, env, false);
220 }
221
222 Attribute.TypeCompound enterTypeAnnotation(JCAnnotation a,
223 Type expected,
224 Env<AttrContext> env) {
225 return (Attribute.TypeCompound) enterAnnotation(a, expected, env, true);
226 }
227
228 // boolean typeAnnotation determines whether the method returns
229 // a Compound (false) or TypeCompound (true).
230 Attribute.Compound enterAnnotation(JCAnnotation a,
231 Type expected,
232 Env<AttrContext> env,
233 boolean typeAnnotation) {
219 // The annotation might have had its type attributed (but not checked) 234 // The annotation might have had its type attributed (but not checked)
220 // by attr.attribAnnotationTypes during MemberEnter, in which case we do not 235 // by attr.attribAnnotationTypes during MemberEnter, in which case we do not
221 // need to do it again. 236 // need to do it again.
222 Type at = (a.annotationType.type != null ? a.annotationType.type 237 Type at = (a.annotationType.type != null ? a.annotationType.type
223 : attr.attribType(a.annotationType, env)); 238 : attr.attribType(a.annotationType, env));
224 a.type = chk.checkType(a.annotationType.pos(), at, expected); 239 a.type = chk.checkType(a.annotationType.pos(), at, expected);
225 if (a.type.isErroneous()) 240 if (a.type.isErroneous()) {
226 return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil()); 241 if (typeAnnotation) {
242 return new Attribute.TypeCompound(a.type, List.<Pair<MethodSymbol,Attribute>>nil(), null);
243 } else {
244 return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil());
245 }
246 }
227 if ((a.type.tsym.flags() & Flags.ANNOTATION) == 0) { 247 if ((a.type.tsym.flags() & Flags.ANNOTATION) == 0) {
228 log.error(a.annotationType.pos(), 248 log.error(a.annotationType.pos(),
229 "not.annotation.type", a.type.toString()); 249 "not.annotation.type", a.type.toString());
230 return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil()); 250 if (typeAnnotation) {
251 return new Attribute.TypeCompound(a.type, List.<Pair<MethodSymbol,Attribute>>nil(), null);
252 } else {
253 return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil());
254 }
231 } 255 }
232 List<JCExpression> args = a.args; 256 List<JCExpression> args = a.args;
233 if (args.length() == 1 && !args.head.hasTag(ASSIGN)) { 257 if (args.length() == 1 && !args.head.hasTag(ASSIGN)) {
234 // special case: elided "value=" assumed 258 // special case: elided "value=" assumed
235 args.head = make.at(args.head.pos). 259 args.head = make.at(args.head.pos).
264 if (!method.type.isErroneous()) 288 if (!method.type.isErroneous())
265 buf.append(new Pair<MethodSymbol,Attribute> 289 buf.append(new Pair<MethodSymbol,Attribute>
266 ((MethodSymbol)method, value)); 290 ((MethodSymbol)method, value));
267 t.type = result; 291 t.type = result;
268 } 292 }
269 // TODO: this should be a TypeCompound if "a" is a JCTypeAnnotation. 293 if (typeAnnotation) {
270 // However, how do we find the correct position? 294 if (a.attribute == null || !(a.attribute instanceof Attribute.TypeCompound)) {
271 Attribute.Compound ac = new Attribute.Compound(a.type, buf.toList()); 295 // Create a new TypeCompound
272 // TODO: is this something we want? Who would use it? 296 Attribute.TypeCompound tc = new Attribute.TypeCompound(a.type, buf.toList(), new TypeAnnotationPosition());
273 // a.attribute = ac; 297 a.attribute = tc;
274 return ac; 298 return tc;
299 } else {
300 // Use an existing TypeCompound
301 return a.attribute;
302 }
303 } else {
304 Attribute.Compound ac = new Attribute.Compound(a.type, buf.toList());
305 a.attribute = ac;
306 return ac;
307 }
275 } 308 }
276 309
277 Attribute enterAttributeValue(Type expected, 310 Attribute enterAttributeValue(Type expected,
278 JCExpression tree, 311 JCExpression tree,
279 Env<AttrContext> env) { 312 Env<AttrContext> env) {
350 return new Attribute.Enum(expected, enumerator); 383 return new Attribute.Enum(expected, enumerator);
351 } 384 }
352 if (!expected.isErroneous()) 385 if (!expected.isErroneous())
353 log.error(tree.pos(), "annotation.value.not.allowable.type"); 386 log.error(tree.pos(), "annotation.value.not.allowable.type");
354 return new Attribute.Error(attr.attribExpr(tree, env, expected)); 387 return new Attribute.Error(attr.attribExpr(tree, env, expected));
355 }
356
357 Attribute.TypeCompound enterTypeAnnotation(JCAnnotation a,
358 Type expected,
359 Env<AttrContext> env) {
360 Attribute.Compound c = enterAnnotation(a, expected, env);
361 Attribute.TypeCompound tc = new Attribute.TypeCompound(c.type, c.values, new TypeAnnotationPosition());
362 a.attribute = tc;
363 return tc;
364 } 388 }
365 389
366 /* ********************************* 390 /* *********************************
367 * Support for repeating annotations 391 * Support for repeating annotations
368 ***********************************/ 392 ***********************************/

mercurial