langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java
changeset 14804 f93a8d60b9a4
parent 14359 d4099818ab70
child 14961 e731935052af
equal deleted inserted replaced
14803:88347e495d34 14804:f93a8d60b9a4
    24  */
    24  */
    25 
    25 
    26 package com.sun.tools.javac.comp;
    26 package com.sun.tools.javac.comp;
    27 
    27 
    28 import java.util.Map;
    28 import java.util.Map;
    29 
       
    30 import com.sun.tools.javac.util.*;
    29 import com.sun.tools.javac.util.*;
    31 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
    30 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
    32 import com.sun.tools.javac.code.*;
    31 import com.sun.tools.javac.code.*;
    33 import com.sun.tools.javac.code.Symbol.*;
    32 import com.sun.tools.javac.code.Symbol.*;
    34 import com.sun.tools.javac.tree.*;
    33 import com.sun.tools.javac.tree.*;
   169          * for the container.
   168          * for the container.
   170          *
   169          *
   171          * @param repeatingAnnotations a List of repeating annotations
   170          * @param repeatingAnnotations a List of repeating annotations
   172          * @return a new Attribute.Compound that is the container for the repeatingAnnotations
   171          * @return a new Attribute.Compound that is the container for the repeatingAnnotations
   173          */
   172          */
   174         public Attribute.Compound processRepeatedAnnotations(List<Attribute.Compound> repeatingAnnotations) {
   173         public Attribute.Compound processRepeatedAnnotations(List<Attribute.Compound> repeatingAnnotations, Symbol sym) {
   175             return Annotate.this.processRepeatedAnnotations(repeatingAnnotations, this);
   174             return Annotate.this.processRepeatedAnnotations(repeatingAnnotations, this, sym);
   176         }
   175         }
   177 
   176 
   178         /**
   177         /**
   179          * Queue the Annotator a on the repeating annotations queue of the
   178          * Queue the Annotator a on the repeating annotations queue of the
   180          * Annotate instance this context belongs to.
   179          * Annotate instance this context belongs to.
   337     /* Process repeated annotations. This method returns the
   336     /* Process repeated annotations. This method returns the
   338      * synthesized container annotation or null IFF all repeating
   337      * synthesized container annotation or null IFF all repeating
   339      * annotation are invalid.  This method reports errors/warnings.
   338      * annotation are invalid.  This method reports errors/warnings.
   340      */
   339      */
   341     private Attribute.Compound processRepeatedAnnotations(List<Attribute.Compound> annotations,
   340     private Attribute.Compound processRepeatedAnnotations(List<Attribute.Compound> annotations,
   342             AnnotateRepeatedContext ctx) {
   341                                                           AnnotateRepeatedContext ctx,
       
   342                                                           Symbol on) {
   343         Attribute.Compound firstOccurrence = annotations.head;
   343         Attribute.Compound firstOccurrence = annotations.head;
   344         List<Attribute> repeated = List.nil();
   344         List<Attribute> repeated = List.nil();
   345         Type origAnnoType;
   345         Type origAnnoType = null;
   346         Type arrayOfOrigAnnoType = null;
   346         Type arrayOfOrigAnnoType = null;
   347         Type targetContainerType = null;
   347         Type targetContainerType = null;
   348         MethodSymbol containerValueSymbol = null;
   348         MethodSymbol containerValueSymbol = null;
   349 
   349 
   350         Assert.check(!annotations.isEmpty() &&
   350         Assert.check(!annotations.isEmpty() &&
   388             Pair<MethodSymbol, Attribute> p =
   388             Pair<MethodSymbol, Attribute> p =
   389                     new Pair<MethodSymbol, Attribute>(containerValueSymbol,
   389                     new Pair<MethodSymbol, Attribute>(containerValueSymbol,
   390                                                       new Attribute.Array(arrayOfOrigAnnoType, repeated));
   390                                                       new Attribute.Array(arrayOfOrigAnnoType, repeated));
   391             annoTree = m.Annotation(new Attribute.Compound(targetContainerType,
   391             annoTree = m.Annotation(new Attribute.Compound(targetContainerType,
   392                     List.of(p)));
   392                     List.of(p)));
       
   393 
       
   394             if (!chk.annotationApplicable(annoTree, on))
       
   395                 log.error(annoTree.pos(), "invalid.containedby.annotation.incompatible.target", targetContainerType, origAnnoType);
       
   396 
       
   397             if (!chk.validateAnnotationDeferErrors(annoTree))
       
   398                 log.error(annoTree.pos(), "duplicate.annotation.invalid.repeated", origAnnoType);
       
   399 
   393             Attribute.Compound c = enterAnnotation(annoTree,
   400             Attribute.Compound c = enterAnnotation(annoTree,
   394                                                    targetContainerType,
   401                                                    targetContainerType,
   395                                                    ctx.env);
   402                                                    ctx.env);
   396             return c;
   403             return c;
   397         } else {
   404         } else {
   408 
   415 
   409         // Fetch the ContainedBy annotation from the current
   416         // Fetch the ContainedBy annotation from the current
   410         // annotation's declaration, or null if it has none
   417         // annotation's declaration, or null if it has none
   411         Attribute.Compound ca = origAnnoDecl.attribute(syms.containedByType.tsym);
   418         Attribute.Compound ca = origAnnoDecl.attribute(syms.containedByType.tsym);
   412         if (ca == null) { // has no ContainedBy annotation
   419         if (ca == null) { // has no ContainedBy annotation
   413             log.error(pos, "duplicate.annotation.missing.container", origAnnoType);
   420             log.error(pos, "duplicate.annotation.missing.container", origAnnoType, syms.containedByType);
   414             return null;
   421             return null;
   415         }
   422         }
   416 
   423 
   417         return filterSame(extractContainingType(ca, pos, origAnnoDecl),
   424         return filterSame(extractContainingType(ca, pos, origAnnoDecl),
   418                           origAnnoType);
   425                           origAnnoType);