8025109: Better encapsulation for AnnotatedType
authorjjg
Sun, 20 Oct 2013 12:01:43 -0700
changeset 21480 9d08c2d0fafd
parent 21479 e11e5b3aec3d
child 21481 f0aeb1da97bd
8025109: Better encapsulation for AnnotatedType Reviewed-by: jjg Contributed-by: wdietl@gmail.com
langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java
langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java
langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java	Sat Oct 19 17:43:09 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java	Sun Oct 20 12:01:43 2013 -0700
@@ -100,7 +100,7 @@
     /** The attributes of this symbol are contained in this
      * SymbolMetadata. The SymbolMetadata instance is NOT immutable.
      */
-    protected SymbolMetadata annotations;
+    protected SymbolMetadata metadata;
 
 
     /** An accessor method for the attributes of this symbol.
@@ -108,9 +108,9 @@
      *  method to make sure that the class symbol is loaded.
      */
     public List<Attribute.Compound> getRawAttributes() {
-        return (annotations == null)
+        return (metadata == null)
                 ? List.<Attribute.Compound>nil()
-                : annotations.getDeclarationAttributes();
+                : metadata.getDeclarationAttributes();
     }
 
     /** An accessor method for the type attributes of this symbol.
@@ -118,9 +118,9 @@
      *  method to make sure that the class symbol is loaded.
      */
     public List<Attribute.TypeCompound> getRawTypeAttributes() {
-        return (annotations == null)
+        return (metadata == null)
                 ? List.<Attribute.TypeCompound>nil()
-                : annotations.getTypeAttributes();
+                : metadata.getTypeAttributes();
     }
 
     /** Fetch a particular annotation from a symbol. */
@@ -132,106 +132,106 @@
     }
 
     public boolean annotationsPendingCompletion() {
-        return annotations == null ? false : annotations.pendingCompletion();
+        return metadata == null ? false : metadata.pendingCompletion();
     }
 
     public void appendAttributes(List<Attribute.Compound> l) {
         if (l.nonEmpty()) {
-            initedAnnos().append(l);
+            initedMetadata().append(l);
         }
     }
 
     public void appendClassInitTypeAttributes(List<Attribute.TypeCompound> l) {
         if (l.nonEmpty()) {
-            initedAnnos().appendClassInitTypeAttributes(l);
+            initedMetadata().appendClassInitTypeAttributes(l);
         }
     }
 
     public void appendInitTypeAttributes(List<Attribute.TypeCompound> l) {
         if (l.nonEmpty()) {
-            initedAnnos().appendInitTypeAttributes(l);
+            initedMetadata().appendInitTypeAttributes(l);
         }
     }
 
     public void appendTypeAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.TypeCompound> ctx) {
-        initedAnnos().appendTypeAttributesWithCompletion(ctx);
+        initedMetadata().appendTypeAttributesWithCompletion(ctx);
     }
 
     public void appendUniqueTypeAttributes(List<Attribute.TypeCompound> l) {
         if (l.nonEmpty()) {
-            initedAnnos().appendUniqueTypes(l);
+            initedMetadata().appendUniqueTypes(l);
         }
     }
 
     public List<Attribute.TypeCompound> getClassInitTypeAttributes() {
-        return (annotations == null)
+        return (metadata == null)
                 ? List.<Attribute.TypeCompound>nil()
-                : annotations.getClassInitTypeAttributes();
+                : metadata.getClassInitTypeAttributes();
     }
 
     public List<Attribute.TypeCompound> getInitTypeAttributes() {
-        return (annotations == null)
+        return (metadata == null)
                 ? List.<Attribute.TypeCompound>nil()
-                : annotations.getInitTypeAttributes();
+                : metadata.getInitTypeAttributes();
     }
 
     public List<Attribute.Compound> getDeclarationAttributes() {
-        return (annotations == null)
+        return (metadata == null)
                 ? List.<Attribute.Compound>nil()
-                : annotations.getDeclarationAttributes();
+                : metadata.getDeclarationAttributes();
     }
 
     public boolean hasAnnotations() {
-        return (annotations != null && !annotations.isEmpty());
+        return (metadata != null && !metadata.isEmpty());
     }
 
     public boolean hasTypeAnnotations() {
-        return (annotations != null && !annotations.isTypesEmpty());
+        return (metadata != null && !metadata.isTypesEmpty());
     }
 
     public void prependAttributes(List<Attribute.Compound> l) {
         if (l.nonEmpty()) {
-            initedAnnos().prepend(l);
+            initedMetadata().prepend(l);
         }
     }
 
     public void resetAnnotations() {
-        initedAnnos().reset();
+        initedMetadata().reset();
     }
 
     public void setAttributes(Symbol other) {
-        if (annotations != null || other.annotations != null) {
-            initedAnnos().setAttributes(other.annotations);
+        if (metadata != null || other.metadata != null) {
+            initedMetadata().setAttributes(other.metadata);
         }
     }
 
     public void setDeclarationAttributes(List<Attribute.Compound> a) {
-        if (annotations != null || a.nonEmpty()) {
-            initedAnnos().setDeclarationAttributes(a);
+        if (metadata != null || a.nonEmpty()) {
+            initedMetadata().setDeclarationAttributes(a);
         }
     }
 
     public void setDeclarationAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.Compound> ctx) {
-        initedAnnos().setDeclarationAttributesWithCompletion(ctx);
+        initedMetadata().setDeclarationAttributesWithCompletion(ctx);
     }
 
     public void setTypeAttributes(List<Attribute.TypeCompound> a) {
-        if (annotations != null || a.nonEmpty()) {
-            if (annotations == null)
-                annotations = new SymbolMetadata(this);
-            annotations.setTypeAttributes(a);
+        if (metadata != null || a.nonEmpty()) {
+            if (metadata == null)
+                metadata = new SymbolMetadata(this);
+            metadata.setTypeAttributes(a);
         }
     }
 
-    private SymbolMetadata initedAnnos() {
-        if (annotations == null)
-            annotations = new SymbolMetadata(this);
-        return annotations;
+    private SymbolMetadata initedMetadata() {
+        if (metadata == null)
+            metadata = new SymbolMetadata(this);
+        return metadata;
     }
 
     /** This method is intended for debugging only. */
-    public SymbolMetadata getAnnotations() {
-        return annotations;
+    public SymbolMetadata getMetadata() {
+        return metadata;
     }
 
     // </editor-fold>
@@ -862,10 +862,10 @@
         }
 
         private void mergeAttributes() {
-            if (annotations == null &&
-                package_info.annotations != null) {
-                annotations = new SymbolMetadata(this);
-                annotations.setAttributes(package_info.annotations);
+            if (metadata == null &&
+                package_info.metadata != null) {
+                metadata = new SymbolMetadata(this);
+                metadata.setAttributes(package_info.metadata);
             }
         }
 
--- a/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Sat Oct 19 17:43:09 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Sun Oct 20 12:01:43 2013 -0700
@@ -404,11 +404,11 @@
                 depth = depth.append(TypePathEntry.ARRAY);
                 while (arType.elemtype.hasTag(TypeTag.ARRAY)) {
                     if (arType.elemtype.isAnnotated()) {
-                        Type.AnnotatedType aelemtype = (Type.AnnotatedType) arType.elemtype;
+                        Type aelemtype = arType.elemtype;
                         arType = (Type.ArrayType) aelemtype.unannotatedType();
                         ArrayType prevToMod = tomodify;
                         tomodify = new Type.ArrayType(null, arType.tsym);
-                        prevToMod.elemtype = (Type.AnnotatedType) tomodify.annotatedType(arType.elemtype.getAnnotationMirrors());
+                        prevToMod.elemtype = tomodify.annotatedType(arType.elemtype.getAnnotationMirrors());
                     } else {
                         arType = (Type.ArrayType) arType.elemtype;
                         tomodify.elemtype = new Type.ArrayType(null, arType.tsym);
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java	Sat Oct 19 17:43:09 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java	Sun Oct 20 12:01:43 2013 -0700
@@ -4062,8 +4062,6 @@
      * Apply the annotations to the particular type.
      */
     public void annotateType(final JCTree tree, final List<JCAnnotation> annotations) {
-        // Callers ensure this.
-        // Assert.check(annotations != null && annotations.nonEmpty());
         annotate.typeAnnotation(new Annotate.Worker() {
             @Override
             public String toString() {