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

changeset 2210
a746587a1ff1
parent 2206
8acb838c9b79
child 2222
8832b6048e65
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Nov 26 15:33:12 2013 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Dec 03 18:50:26 2013 +0100
     1.3 @@ -28,7 +28,6 @@
     1.4  import java.util.*;
     1.5  
     1.6  import javax.lang.model.element.ElementKind;
     1.7 -import javax.lang.model.type.TypeKind;
     1.8  import javax.tools.JavaFileObject;
     1.9  
    1.10  import com.sun.source.tree.IdentifierTree;
    1.11 @@ -2164,11 +2163,6 @@
    1.12                      tree.constructor,
    1.13                      localEnv,
    1.14                      new ResultInfo(pkind, newMethodTemplate(syms.voidType, argtypes, typeargtypes)));
    1.15 -            } else {
    1.16 -                if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
    1.17 -                    checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations,
    1.18 -                            tree.clazz.type.tsym);
    1.19 -                }
    1.20              }
    1.21  
    1.22              if (tree.constructor != null && tree.constructor.kind == MTH)
    1.23 @@ -2230,21 +2224,6 @@
    1.24                  }
    1.25              }
    1.26  
    1.27 -    private void checkForDeclarationAnnotations(List<? extends JCAnnotation> annotations,
    1.28 -            Symbol sym) {
    1.29 -        // Ensure that no declaration annotations are present.
    1.30 -        // Note that a tree type might be an AnnotatedType with
    1.31 -        // empty annotations, if only declaration annotations were given.
    1.32 -        // This method will raise an error for such a type.
    1.33 -        for (JCAnnotation ai : annotations) {
    1.34 -            if (!ai.type.isErroneous() &&
    1.35 -                typeAnnotations.annotationType(ai.attribute, sym) == TypeAnnotations.AnnotationType.DECLARATION) {
    1.36 -                log.error(ai.pos(), "annotation.type.not.applicable");
    1.37 -            }
    1.38 -        }
    1.39 -    }
    1.40 -
    1.41 -
    1.42      /** Make an attributed null check tree.
    1.43       */
    1.44      public JCExpression makeNullCheck(JCExpression arg) {
    1.45 @@ -2271,10 +2250,6 @@
    1.46                  attribExpr(l.head, localEnv, syms.intType);
    1.47                  owntype = new ArrayType(owntype, syms.arrayClass);
    1.48              }
    1.49 -            if (tree.elemtype.hasTag(ANNOTATED_TYPE)) {
    1.50 -                checkForDeclarationAnnotations(((JCAnnotatedType) tree.elemtype).annotations,
    1.51 -                        tree.elemtype.type.tsym);
    1.52 -            }
    1.53          } else {
    1.54              // we are seeing an untyped aggregate { ... }
    1.55              // this is allowed only if the prototype is an array
    1.56 @@ -4419,7 +4394,7 @@
    1.57          }
    1.58          public void visitMethodDef(JCMethodDecl tree) {
    1.59              if (tree.recvparam != null &&
    1.60 -                    tree.recvparam.vartype.type.getKind() != TypeKind.ERROR) {
    1.61 +                    !tree.recvparam.vartype.type.isErroneous()) {
    1.62                  checkForDeclarationAnnotations(tree.recvparam.mods.annotations,
    1.63                          tree.recvparam.vartype.type.tsym);
    1.64              }
    1.65 @@ -4458,17 +4433,28 @@
    1.66              super.visitTypeTest(tree);
    1.67          }
    1.68          public void visitNewClass(JCNewClass tree) {
    1.69 -            if (tree.clazz.type != null)
    1.70 +            if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
    1.71 +                checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations,
    1.72 +                        tree.clazz.type.tsym);
    1.73 +            }
    1.74 +            if (tree.def != null) {
    1.75 +                checkForDeclarationAnnotations(tree.def.mods.annotations, tree.clazz.type.tsym);
    1.76 +            }
    1.77 +            if (tree.clazz.type != null) {
    1.78                  validateAnnotatedType(tree.clazz, tree.clazz.type);
    1.79 +            }
    1.80              super.visitNewClass(tree);
    1.81          }
    1.82          public void visitNewArray(JCNewArray tree) {
    1.83 -            if (tree.elemtype != null && tree.elemtype.type != null)
    1.84 +            if (tree.elemtype != null && tree.elemtype.type != null) {
    1.85 +                if (tree.elemtype.hasTag(ANNOTATED_TYPE)) {
    1.86 +                    checkForDeclarationAnnotations(((JCAnnotatedType) tree.elemtype).annotations,
    1.87 +                            tree.elemtype.type.tsym);
    1.88 +                }
    1.89                  validateAnnotatedType(tree.elemtype, tree.elemtype.type);
    1.90 +            }
    1.91              super.visitNewArray(tree);
    1.92          }
    1.93 -
    1.94 -        @Override
    1.95          public void visitClassDef(JCClassDecl tree) {
    1.96              if (sigOnly) {
    1.97                  scan(tree.mods);
    1.98 @@ -4483,8 +4469,6 @@
    1.99                  scan(member);
   1.100              }
   1.101          }
   1.102 -
   1.103 -        @Override
   1.104          public void visitBlock(JCBlock tree) {
   1.105              if (!sigOnly) {
   1.106                  scan(tree.stats);
   1.107 @@ -4590,6 +4574,20 @@
   1.108                  }
   1.109              }
   1.110          }
   1.111 +
   1.112 +        private void checkForDeclarationAnnotations(List<? extends JCAnnotation> annotations,
   1.113 +                Symbol sym) {
   1.114 +            // Ensure that no declaration annotations are present.
   1.115 +            // Note that a tree type might be an AnnotatedType with
   1.116 +            // empty annotations, if only declaration annotations were given.
   1.117 +            // This method will raise an error for such a type.
   1.118 +            for (JCAnnotation ai : annotations) {
   1.119 +                if (!ai.type.isErroneous() &&
   1.120 +                        typeAnnotations.annotationType(ai.attribute, sym) == TypeAnnotations.AnnotationType.DECLARATION) {
   1.121 +                    log.error(ai.pos(), "annotation.type.not.applicable");
   1.122 +                }
   1.123 +            }
   1.124 +        }
   1.125      };
   1.126  
   1.127      // <editor-fold desc="post-attribution visitor">

mercurial