8025109: Better encapsulation for AnnotatedType

Sun, 20 Oct 2013 12:01:43 -0700

author
jjg
date
Sun, 20 Oct 2013 12:01:43 -0700
changeset 2149
e5d3cd43c85e
parent 2148
c4292590fc70
child 2150
ae4f5cb78ebd

8025109: Better encapsulation for AnnotatedType
Reviewed-by: jjg
Contributed-by: wdietl@gmail.com

src/share/classes/com/sun/tools/javac/code/Symbol.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Sat Oct 19 17:43:09 2013 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Sun Oct 20 12:01:43 2013 -0700
     1.3 @@ -100,7 +100,7 @@
     1.4      /** The attributes of this symbol are contained in this
     1.5       * SymbolMetadata. The SymbolMetadata instance is NOT immutable.
     1.6       */
     1.7 -    protected SymbolMetadata annotations;
     1.8 +    protected SymbolMetadata metadata;
     1.9  
    1.10  
    1.11      /** An accessor method for the attributes of this symbol.
    1.12 @@ -108,9 +108,9 @@
    1.13       *  method to make sure that the class symbol is loaded.
    1.14       */
    1.15      public List<Attribute.Compound> getRawAttributes() {
    1.16 -        return (annotations == null)
    1.17 +        return (metadata == null)
    1.18                  ? List.<Attribute.Compound>nil()
    1.19 -                : annotations.getDeclarationAttributes();
    1.20 +                : metadata.getDeclarationAttributes();
    1.21      }
    1.22  
    1.23      /** An accessor method for the type attributes of this symbol.
    1.24 @@ -118,9 +118,9 @@
    1.25       *  method to make sure that the class symbol is loaded.
    1.26       */
    1.27      public List<Attribute.TypeCompound> getRawTypeAttributes() {
    1.28 -        return (annotations == null)
    1.29 +        return (metadata == null)
    1.30                  ? List.<Attribute.TypeCompound>nil()
    1.31 -                : annotations.getTypeAttributes();
    1.32 +                : metadata.getTypeAttributes();
    1.33      }
    1.34  
    1.35      /** Fetch a particular annotation from a symbol. */
    1.36 @@ -132,106 +132,106 @@
    1.37      }
    1.38  
    1.39      public boolean annotationsPendingCompletion() {
    1.40 -        return annotations == null ? false : annotations.pendingCompletion();
    1.41 +        return metadata == null ? false : metadata.pendingCompletion();
    1.42      }
    1.43  
    1.44      public void appendAttributes(List<Attribute.Compound> l) {
    1.45          if (l.nonEmpty()) {
    1.46 -            initedAnnos().append(l);
    1.47 +            initedMetadata().append(l);
    1.48          }
    1.49      }
    1.50  
    1.51      public void appendClassInitTypeAttributes(List<Attribute.TypeCompound> l) {
    1.52          if (l.nonEmpty()) {
    1.53 -            initedAnnos().appendClassInitTypeAttributes(l);
    1.54 +            initedMetadata().appendClassInitTypeAttributes(l);
    1.55          }
    1.56      }
    1.57  
    1.58      public void appendInitTypeAttributes(List<Attribute.TypeCompound> l) {
    1.59          if (l.nonEmpty()) {
    1.60 -            initedAnnos().appendInitTypeAttributes(l);
    1.61 +            initedMetadata().appendInitTypeAttributes(l);
    1.62          }
    1.63      }
    1.64  
    1.65      public void appendTypeAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.TypeCompound> ctx) {
    1.66 -        initedAnnos().appendTypeAttributesWithCompletion(ctx);
    1.67 +        initedMetadata().appendTypeAttributesWithCompletion(ctx);
    1.68      }
    1.69  
    1.70      public void appendUniqueTypeAttributes(List<Attribute.TypeCompound> l) {
    1.71          if (l.nonEmpty()) {
    1.72 -            initedAnnos().appendUniqueTypes(l);
    1.73 +            initedMetadata().appendUniqueTypes(l);
    1.74          }
    1.75      }
    1.76  
    1.77      public List<Attribute.TypeCompound> getClassInitTypeAttributes() {
    1.78 -        return (annotations == null)
    1.79 +        return (metadata == null)
    1.80                  ? List.<Attribute.TypeCompound>nil()
    1.81 -                : annotations.getClassInitTypeAttributes();
    1.82 +                : metadata.getClassInitTypeAttributes();
    1.83      }
    1.84  
    1.85      public List<Attribute.TypeCompound> getInitTypeAttributes() {
    1.86 -        return (annotations == null)
    1.87 +        return (metadata == null)
    1.88                  ? List.<Attribute.TypeCompound>nil()
    1.89 -                : annotations.getInitTypeAttributes();
    1.90 +                : metadata.getInitTypeAttributes();
    1.91      }
    1.92  
    1.93      public List<Attribute.Compound> getDeclarationAttributes() {
    1.94 -        return (annotations == null)
    1.95 +        return (metadata == null)
    1.96                  ? List.<Attribute.Compound>nil()
    1.97 -                : annotations.getDeclarationAttributes();
    1.98 +                : metadata.getDeclarationAttributes();
    1.99      }
   1.100  
   1.101      public boolean hasAnnotations() {
   1.102 -        return (annotations != null && !annotations.isEmpty());
   1.103 +        return (metadata != null && !metadata.isEmpty());
   1.104      }
   1.105  
   1.106      public boolean hasTypeAnnotations() {
   1.107 -        return (annotations != null && !annotations.isTypesEmpty());
   1.108 +        return (metadata != null && !metadata.isTypesEmpty());
   1.109      }
   1.110  
   1.111      public void prependAttributes(List<Attribute.Compound> l) {
   1.112          if (l.nonEmpty()) {
   1.113 -            initedAnnos().prepend(l);
   1.114 +            initedMetadata().prepend(l);
   1.115          }
   1.116      }
   1.117  
   1.118      public void resetAnnotations() {
   1.119 -        initedAnnos().reset();
   1.120 +        initedMetadata().reset();
   1.121      }
   1.122  
   1.123      public void setAttributes(Symbol other) {
   1.124 -        if (annotations != null || other.annotations != null) {
   1.125 -            initedAnnos().setAttributes(other.annotations);
   1.126 +        if (metadata != null || other.metadata != null) {
   1.127 +            initedMetadata().setAttributes(other.metadata);
   1.128          }
   1.129      }
   1.130  
   1.131      public void setDeclarationAttributes(List<Attribute.Compound> a) {
   1.132 -        if (annotations != null || a.nonEmpty()) {
   1.133 -            initedAnnos().setDeclarationAttributes(a);
   1.134 +        if (metadata != null || a.nonEmpty()) {
   1.135 +            initedMetadata().setDeclarationAttributes(a);
   1.136          }
   1.137      }
   1.138  
   1.139      public void setDeclarationAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.Compound> ctx) {
   1.140 -        initedAnnos().setDeclarationAttributesWithCompletion(ctx);
   1.141 +        initedMetadata().setDeclarationAttributesWithCompletion(ctx);
   1.142      }
   1.143  
   1.144      public void setTypeAttributes(List<Attribute.TypeCompound> a) {
   1.145 -        if (annotations != null || a.nonEmpty()) {
   1.146 -            if (annotations == null)
   1.147 -                annotations = new SymbolMetadata(this);
   1.148 -            annotations.setTypeAttributes(a);
   1.149 +        if (metadata != null || a.nonEmpty()) {
   1.150 +            if (metadata == null)
   1.151 +                metadata = new SymbolMetadata(this);
   1.152 +            metadata.setTypeAttributes(a);
   1.153          }
   1.154      }
   1.155  
   1.156 -    private SymbolMetadata initedAnnos() {
   1.157 -        if (annotations == null)
   1.158 -            annotations = new SymbolMetadata(this);
   1.159 -        return annotations;
   1.160 +    private SymbolMetadata initedMetadata() {
   1.161 +        if (metadata == null)
   1.162 +            metadata = new SymbolMetadata(this);
   1.163 +        return metadata;
   1.164      }
   1.165  
   1.166      /** This method is intended for debugging only. */
   1.167 -    public SymbolMetadata getAnnotations() {
   1.168 -        return annotations;
   1.169 +    public SymbolMetadata getMetadata() {
   1.170 +        return metadata;
   1.171      }
   1.172  
   1.173      // </editor-fold>
   1.174 @@ -862,10 +862,10 @@
   1.175          }
   1.176  
   1.177          private void mergeAttributes() {
   1.178 -            if (annotations == null &&
   1.179 -                package_info.annotations != null) {
   1.180 -                annotations = new SymbolMetadata(this);
   1.181 -                annotations.setAttributes(package_info.annotations);
   1.182 +            if (metadata == null &&
   1.183 +                package_info.metadata != null) {
   1.184 +                metadata = new SymbolMetadata(this);
   1.185 +                metadata.setAttributes(package_info.metadata);
   1.186              }
   1.187          }
   1.188  
     2.1 --- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Sat Oct 19 17:43:09 2013 +0100
     2.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Sun Oct 20 12:01:43 2013 -0700
     2.3 @@ -404,11 +404,11 @@
     2.4                  depth = depth.append(TypePathEntry.ARRAY);
     2.5                  while (arType.elemtype.hasTag(TypeTag.ARRAY)) {
     2.6                      if (arType.elemtype.isAnnotated()) {
     2.7 -                        Type.AnnotatedType aelemtype = (Type.AnnotatedType) arType.elemtype;
     2.8 +                        Type aelemtype = arType.elemtype;
     2.9                          arType = (Type.ArrayType) aelemtype.unannotatedType();
    2.10                          ArrayType prevToMod = tomodify;
    2.11                          tomodify = new Type.ArrayType(null, arType.tsym);
    2.12 -                        prevToMod.elemtype = (Type.AnnotatedType) tomodify.annotatedType(arType.elemtype.getAnnotationMirrors());
    2.13 +                        prevToMod.elemtype = tomodify.annotatedType(arType.elemtype.getAnnotationMirrors());
    2.14                      } else {
    2.15                          arType = (Type.ArrayType) arType.elemtype;
    2.16                          tomodify.elemtype = new Type.ArrayType(null, arType.tsym);
     3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Sat Oct 19 17:43:09 2013 +0100
     3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Sun Oct 20 12:01:43 2013 -0700
     3.3 @@ -4062,8 +4062,6 @@
     3.4       * Apply the annotations to the particular type.
     3.5       */
     3.6      public void annotateType(final JCTree tree, final List<JCAnnotation> annotations) {
     3.7 -        // Callers ensure this.
     3.8 -        // Assert.check(annotations != null && annotations.nonEmpty());
     3.9          annotate.typeAnnotation(new Annotate.Worker() {
    3.10              @Override
    3.11              public String toString() {

mercurial