langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
changeset 31212 edf65e25e066
parent 30403 c904bbdc5ec1
child 31299 81ce5febcae8
equal deleted inserted replaced
31119:d69c968463f0 31212:edf65e25e066
    60 import static com.sun.tools.javac.code.Kinds.Kind.*;
    60 import static com.sun.tools.javac.code.Kinds.Kind.*;
    61 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
    61 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
    62 import static com.sun.tools.javac.code.TypeTag.*;
    62 import static com.sun.tools.javac.code.TypeTag.*;
    63 import static com.sun.tools.javac.code.TypeTag.WILDCARD;
    63 import static com.sun.tools.javac.code.TypeTag.WILDCARD;
    64 
    64 
       
    65 import static com.sun.tools.javac.resources.CompilerProperties.Errors.CantTypeAnnotateScoping;
       
    66 import static com.sun.tools.javac.resources.CompilerProperties.Errors.CantTypeAnnotateScoping1;
    65 import static com.sun.tools.javac.tree.JCTree.Tag.*;
    67 import static com.sun.tools.javac.tree.JCTree.Tag.*;
    66 
    68 
    67 /** Type checking helper class for the attribution phase.
    69 /** Type checking helper class for the attribution phase.
    68  *
    70  *
    69  *  <p><b>This is NOT part of any supported API.
    71  *  <p><b>This is NOT part of any supported API.
  2689 
  2691 
  2690 /* *************************************************************************
  2692 /* *************************************************************************
  2691  * Check annotations
  2693  * Check annotations
  2692  **************************************************************************/
  2694  **************************************************************************/
  2693 
  2695 
       
  2696     /** Verify that a component of a qualified type name being type annotated
       
  2697      * can indeed be legally be annotated. For example, package names and type
       
  2698      * names used to access static members cannot be annotated.
       
  2699      *
       
  2700      * @param typeComponent the component of the qualified name being annotated
       
  2701      * @param annotations the annotations
       
  2702      * @param pos diagnostic position
       
  2703      * @return true if all is swell, false otherwise.
       
  2704      */
       
  2705     boolean checkAnnotableType(Type typeComponent, List<JCAnnotation> annotations, DiagnosticPosition pos) {
       
  2706         if (typeComponent == null || typeComponent.hasTag(PACKAGE) || typeComponent.hasTag(NONE)) {
       
  2707             ListBuffer<Symbol> lb = new ListBuffer<>();
       
  2708             for (JCAnnotation annotation : annotations) {
       
  2709                 lb.append(annotation.annotationType.type.tsym);
       
  2710             }
       
  2711             List<Symbol> symbols = lb.toList();
       
  2712             log.error(pos,
       
  2713                     symbols.size() > 1 ? CantTypeAnnotateScoping(symbols)
       
  2714                             : CantTypeAnnotateScoping1(symbols.get(0)));
       
  2715             return false;
       
  2716         }
       
  2717         return true;
       
  2718     }
  2694     /**
  2719     /**
  2695      * Recursively validate annotations values
  2720      * Recursively validate annotations values
  2696      */
  2721      */
  2697     void validateAnnotationTree(JCTree tree) {
  2722     void validateAnnotationTree(JCTree tree) {
  2698         class AnnotationValidator extends TreeScanner {
  2723         class AnnotationValidator extends TreeScanner {