diff -r ca063536e4a6 -r 03944ee4fac4 src/share/classes/com/sun/tools/javac/comp/Check.java --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Fri Jun 26 12:22:40 2009 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Fri Jun 26 18:51:39 2009 -0700 @@ -916,6 +916,10 @@ } } + public void visitAnnotatedType(JCAnnotatedType tree) { + tree.underlyingType.accept(this); + } + /** Default visitor method: do nothing. */ public void visitTree(JCTree tree) { @@ -1806,6 +1810,14 @@ validateAnnotation(a, s); } + /** Check the type annotations + */ + public void validateTypeAnnotations(List annotations, boolean isTypeParameter) { + if (skipAnnotations) return; + for (JCTypeAnnotation a : annotations) + validateTypeAnnotation(a, isTypeParameter); + } + /** Check an annotation of a symbol. */ public void validateAnnotation(JCAnnotation a, Symbol s) { @@ -1820,6 +1832,15 @@ } } + public void validateTypeAnnotation(JCTypeAnnotation a, boolean isTypeParameter) { + if (a.type == null) + throw new AssertionError("annotation tree hasn't been attributed yet: " + a); + validateAnnotation(a); + + if (!isTypeAnnotation(a, isTypeParameter)) + log.error(a.pos(), "annotation.type.not.applicable"); + } + /** Is s a method symbol that overrides a method in a superclass? */ boolean isOverrider(Symbol s) { if (s.kind != MTH || s.isStatic()) @@ -1838,6 +1859,25 @@ return false; } + /** Is the annotation applicable to type annotations */ + boolean isTypeAnnotation(JCTypeAnnotation a, boolean isTypeParameter) { + Attribute.Compound atTarget = + a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym); + if (atTarget == null) return true; + Attribute atValue = atTarget.member(names.value); + if (!(atValue instanceof Attribute.Array)) return true; // error recovery + Attribute.Array arr = (Attribute.Array) atValue; + for (Attribute app : arr.values) { + if (!(app instanceof Attribute.Enum)) return true; // recovery + Attribute.Enum e = (Attribute.Enum) app; + if (!isTypeParameter && e.value.name == names.TYPE_USE) + return true; + else if (isTypeParameter && e.value.name == names.TYPE_PARAMETER) + return true; + } + return false; + } + /** Is the annotation applicable to the symbol? */ boolean annotationApplicable(JCAnnotation a, Symbol s) { Attribute.Compound atTarget = @@ -1874,6 +1914,13 @@ } else if (e.value.name == names.PACKAGE) { if (s.kind == PCK) return true; } + else if (e.value.name == names.TYPE_USE) + { if (s.kind == TYP || + s.kind == VAR || + (s.kind == MTH && !s.isConstructor() && + s.type.getReturnType().tag != VOID)) + return true; + } else return true; // recovery }