diff -r 756ae3791c45 -r a746587a1ff1 src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Nov 26 15:33:12 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Dec 03 18:50:26 2013 +0100 @@ -28,7 +28,6 @@ import java.util.*; import javax.lang.model.element.ElementKind; -import javax.lang.model.type.TypeKind; import javax.tools.JavaFileObject; import com.sun.source.tree.IdentifierTree; @@ -2164,11 +2163,6 @@ tree.constructor, localEnv, new ResultInfo(pkind, newMethodTemplate(syms.voidType, argtypes, typeargtypes))); - } else { - if (tree.clazz.hasTag(ANNOTATED_TYPE)) { - checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations, - tree.clazz.type.tsym); - } } if (tree.constructor != null && tree.constructor.kind == MTH) @@ -2230,21 +2224,6 @@ } } - private void checkForDeclarationAnnotations(List annotations, - Symbol sym) { - // Ensure that no declaration annotations are present. - // Note that a tree type might be an AnnotatedType with - // empty annotations, if only declaration annotations were given. - // This method will raise an error for such a type. - for (JCAnnotation ai : annotations) { - if (!ai.type.isErroneous() && - typeAnnotations.annotationType(ai.attribute, sym) == TypeAnnotations.AnnotationType.DECLARATION) { - log.error(ai.pos(), "annotation.type.not.applicable"); - } - } - } - - /** Make an attributed null check tree. */ public JCExpression makeNullCheck(JCExpression arg) { @@ -2271,10 +2250,6 @@ attribExpr(l.head, localEnv, syms.intType); owntype = new ArrayType(owntype, syms.arrayClass); } - if (tree.elemtype.hasTag(ANNOTATED_TYPE)) { - checkForDeclarationAnnotations(((JCAnnotatedType) tree.elemtype).annotations, - tree.elemtype.type.tsym); - } } else { // we are seeing an untyped aggregate { ... } // this is allowed only if the prototype is an array @@ -4419,7 +4394,7 @@ } public void visitMethodDef(JCMethodDecl tree) { if (tree.recvparam != null && - tree.recvparam.vartype.type.getKind() != TypeKind.ERROR) { + !tree.recvparam.vartype.type.isErroneous()) { checkForDeclarationAnnotations(tree.recvparam.mods.annotations, tree.recvparam.vartype.type.tsym); } @@ -4458,17 +4433,28 @@ super.visitTypeTest(tree); } public void visitNewClass(JCNewClass tree) { - if (tree.clazz.type != null) + if (tree.clazz.hasTag(ANNOTATED_TYPE)) { + checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations, + tree.clazz.type.tsym); + } + if (tree.def != null) { + checkForDeclarationAnnotations(tree.def.mods.annotations, tree.clazz.type.tsym); + } + if (tree.clazz.type != null) { validateAnnotatedType(tree.clazz, tree.clazz.type); + } super.visitNewClass(tree); } public void visitNewArray(JCNewArray tree) { - if (tree.elemtype != null && tree.elemtype.type != null) + if (tree.elemtype != null && tree.elemtype.type != null) { + if (tree.elemtype.hasTag(ANNOTATED_TYPE)) { + checkForDeclarationAnnotations(((JCAnnotatedType) tree.elemtype).annotations, + tree.elemtype.type.tsym); + } validateAnnotatedType(tree.elemtype, tree.elemtype.type); + } super.visitNewArray(tree); } - - @Override public void visitClassDef(JCClassDecl tree) { if (sigOnly) { scan(tree.mods); @@ -4483,8 +4469,6 @@ scan(member); } } - - @Override public void visitBlock(JCBlock tree) { if (!sigOnly) { scan(tree.stats); @@ -4590,6 +4574,20 @@ } } } + + private void checkForDeclarationAnnotations(List annotations, + Symbol sym) { + // Ensure that no declaration annotations are present. + // Note that a tree type might be an AnnotatedType with + // empty annotations, if only declaration annotations were given. + // This method will raise an error for such a type. + for (JCAnnotation ai : annotations) { + if (!ai.type.isErroneous() && + typeAnnotations.annotationType(ai.attribute, sym) == TypeAnnotations.AnnotationType.DECLARATION) { + log.error(ai.pos(), "annotation.type.not.applicable"); + } + } + } }; //