363 } |
363 } |
364 if (tree.hasTag(ANNOTATION)) { //error recovery |
364 if (tree.hasTag(ANNOTATION)) { //error recovery |
365 if (!expected.isErroneous()) |
365 if (!expected.isErroneous()) |
366 log.error(tree.pos(), "annotation.not.valid.for.type", expected); |
366 log.error(tree.pos(), "annotation.not.valid.for.type", expected); |
367 enterAnnotation((JCAnnotation)tree, syms.errType, env); |
367 enterAnnotation((JCAnnotation)tree, syms.errType, env); |
368 return new Attribute.Error(original); |
368 return new Attribute.Error(((JCAnnotation)tree).annotationType.type); |
369 } |
369 } |
370 if (expected.isPrimitive() || types.isSameType(expected, syms.stringType)) { |
370 if (expected.isPrimitive() || types.isSameType(expected, syms.stringType)) { |
371 Type result = attr.attribExpr(tree, env, expected); |
371 Type result = attr.attribExpr(tree, env, expected); |
372 if (result.isErroneous()) |
372 if (result.isErroneous()) |
373 return new Attribute.Error(expected); |
373 return new Attribute.Error(result.getOriginalType()); |
374 if (result.constValue() == null) { |
374 if (result.constValue() == null) { |
375 log.error(tree.pos(), "attribute.value.must.be.constant"); |
375 log.error(tree.pos(), "attribute.value.must.be.constant"); |
376 return new Attribute.Error(expected); |
376 return new Attribute.Error(expected); |
377 } |
377 } |
378 result = cfolder.coerce(result, expected); |
378 result = cfolder.coerce(result, expected); |
379 return new Attribute.Constant(expected, result.constValue()); |
379 return new Attribute.Constant(expected, result.constValue()); |
380 } |
380 } |
381 if (expected.tsym == syms.classType.tsym) { |
381 if (expected.tsym == syms.classType.tsym) { |
382 Type result = attr.attribExpr(tree, env, expected); |
382 Type result = attr.attribExpr(tree, env, expected); |
383 if (result.isErroneous()) { |
383 if (result.isErroneous()) { |
384 // Does it look like a class literal? |
384 // Does it look like an unresolved class literal? |
385 if (TreeInfo.name(tree) == names._class) { |
385 if (TreeInfo.name(tree) == names._class && |
|
386 ((JCFieldAccess) tree).selected.type.isErroneous()) { |
386 Name n = (((JCFieldAccess) tree).selected).type.tsym.flatName(); |
387 Name n = (((JCFieldAccess) tree).selected).type.tsym.flatName(); |
387 return new Attribute.UnresolvedClass(expected, |
388 return new Attribute.UnresolvedClass(expected, |
388 types.createErrorType(n, |
389 types.createErrorType(n, |
389 syms.unknownSymbol, syms.classType)); |
390 syms.unknownSymbol, syms.classType)); |
390 } else { |
391 } else { |
391 return new Attribute.Error(expected); |
392 return new Attribute.Error(result.getOriginalType()); |
392 } |
393 } |
393 } |
394 } |
394 |
395 |
395 // Class literals look like field accesses of a field named class |
396 // Class literals look like field accesses of a field named class |
396 // at the tree level |
397 // at the tree level |
397 if (TreeInfo.name(tree) != names._class) { |
398 if (TreeInfo.name(tree) != names._class) { |
398 log.error(tree.pos(), "annotation.value.must.be.class.literal"); |
399 log.error(tree.pos(), "annotation.value.must.be.class.literal"); |
399 return new Attribute.Error(expected); |
400 return new Attribute.Error(syms.errType); |
400 } |
401 } |
401 return new Attribute.Class(types, |
402 return new Attribute.Class(types, |
402 (((JCFieldAccess) tree).selected).type); |
403 (((JCFieldAccess) tree).selected).type); |
403 } |
404 } |
404 if (expected.hasTag(CLASS) && |
405 if (expected.hasTag(CLASS) && |
405 (expected.tsym.flags() & Flags.ENUM) != 0) { |
406 (expected.tsym.flags() & Flags.ENUM) != 0) { |
406 attr.attribExpr(tree, env, expected); |
407 Type result = attr.attribExpr(tree, env, expected); |
407 Symbol sym = TreeInfo.symbol(tree); |
408 Symbol sym = TreeInfo.symbol(tree); |
408 if (sym == null || |
409 if (sym == null || |
409 TreeInfo.nonstaticSelect(tree) || |
410 TreeInfo.nonstaticSelect(tree) || |
410 sym.kind != Kinds.VAR || |
411 sym.kind != Kinds.VAR || |
411 (sym.flags() & Flags.ENUM) == 0) { |
412 (sym.flags() & Flags.ENUM) == 0) { |
412 log.error(tree.pos(), "enum.annotation.must.be.enum.constant"); |
413 log.error(tree.pos(), "enum.annotation.must.be.enum.constant"); |
413 return new Attribute.Error(expected); |
414 return new Attribute.Error(result.getOriginalType()); |
414 } |
415 } |
415 VarSymbol enumerator = (VarSymbol) sym; |
416 VarSymbol enumerator = (VarSymbol) sym; |
416 return new Attribute.Enum(expected, enumerator); |
417 return new Attribute.Enum(expected, enumerator); |
417 } |
418 } |
418 //error recovery: |
419 //error recovery: |