changeset 2806:2d42e2fe1729

Patch http://cr.openjdk.java.net/~jjg/8023722/webrev.00/langtools.patch by Jon.
author wmdietl
date Wed, 28 Aug 2013 17:23:45 -0700
parents 8154df999aae
children 4eb8e0c0f3cc
files src/share/classes/com/sun/tools/javac/code/Type.java src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java src/share/classes/com/sun/tools/javac/code/Types.java src/share/classes/com/sun/tools/javac/comp/Attr.java src/share/classes/com/sun/tools/javac/comp/Lower.java src/share/classes/com/sun/tools/javadoc/AnnotatedTypeImpl.java src/share/classes/com/sun/tools/javadoc/TypeMaker.java src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java
diffstat 8 files changed, 34 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Type.java	Tue Aug 27 16:16:56 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Wed Aug 28 17:23:45 2013 -0700
@@ -219,6 +219,10 @@
     public Type baseType() {
         return this;
     }
+    
+    public Type annotatedType(List<Attribute.TypeCompound> annos) {
+        return new AnnotatedType(annos, this);
+    }
 
     public boolean isAnnotated() {
         return false;
@@ -233,7 +237,7 @@
     }
 
     @Override
-    public List<? extends Attribute.TypeCompound> getAnnotationMirrors() {
+    public List<Attribute.TypeCompound> getAnnotationMirrors() {
         return List.nil();
     }
 
@@ -1837,7 +1841,7 @@
         }
 
         @Override
-        public List<? extends Attribute.TypeCompound> getAnnotationMirrors() {
+        public List<Attribute.TypeCompound> getAnnotationMirrors() {
             return typeAnnotations;
         }
 
@@ -1970,10 +1974,8 @@
         public TypeMirror getComponentType()     { return ((ArrayType)underlyingType).getComponentType(); }
 
         // The result is an ArrayType, but only in the model sense, not the Type sense.
-        public AnnotatedType makeVarargs() {
-            AnnotatedType atype = new AnnotatedType(((ArrayType)underlyingType).makeVarargs());
-            atype.typeAnnotations = this.typeAnnotations;
-            return atype;
+        public Type makeVarargs() {
+            return ((ArrayType) underlyingType).makeVarargs().annotatedType(typeAnnotations);
         }
 
         @Override
--- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Tue Aug 27 16:16:56 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Wed Aug 28 17:23:45 2013 -0700
@@ -360,25 +360,15 @@
                 return type;
             }
             if (type.hasTag(TypeTag.ARRAY)) {
+                Type.ArrayType arType = (Type.ArrayType) type.unannotatedType();
+                Type.ArrayType tomodify = new Type.ArrayType(null, arType.tsym);
                 Type toreturn;
-                Type.ArrayType tomodify;
-                Type.ArrayType arType;
-                {
-                    Type touse = type;
-                    if (type.isAnnotated()) {
-                        Type.AnnotatedType atype = (Type.AnnotatedType)type;
-                        toreturn = new Type.AnnotatedType(atype.underlyingType);
-                        ((Type.AnnotatedType)toreturn).typeAnnotations = atype.typeAnnotations;
-                        touse = atype.underlyingType;
-                        arType = (Type.ArrayType) touse;
-                        tomodify = new Type.ArrayType(null, arType.tsym);
-                        ((Type.AnnotatedType)toreturn).underlyingType = tomodify;
-                    } else {
-                        arType = (Type.ArrayType) touse;
-                        tomodify = new Type.ArrayType(null, arType.tsym);
-                        toreturn = tomodify;
-                    }
+                if (type.isAnnotated()) {
+                    toreturn = tomodify.annotatedType(type.getAnnotationMirrors());
+                } else {
+                    toreturn = tomodify;
                 }
+                
                 JCArrayTypeTree arTree = arrayTypeTree(typetree);
 
                 ListBuffer<TypePathEntry> depth = ListBuffer.lb();
@@ -386,9 +376,8 @@
                 while (arType.elemtype.hasTag(TypeTag.ARRAY)) {
                     if (arType.elemtype.isAnnotated()) {
                         Type.AnnotatedType aelemtype = (Type.AnnotatedType) arType.elemtype;
-                        Type.AnnotatedType newAT = new Type.AnnotatedType(aelemtype.underlyingType);
+                        Type.AnnotatedType newAT = (Type.AnnotatedType) aelemtype.underlyingType.annotatedType(arType.elemtype.getAnnotationMirrors());
                         tomodify.elemtype = newAT;
-                        newAT.typeAnnotations = aelemtype.typeAnnotations;
                         arType = (Type.ArrayType) aelemtype.underlyingType;
                         tomodify = new Type.ArrayType(null, arType.tsym);
                         newAT.underlyingType = tomodify;
@@ -542,7 +531,7 @@
                     // assert that t.constValue() == null?
                     if (t == stopAt ||
                         t.getEnclosingType() == Type.noType) {
-                        return new AnnotatedType(s, t);
+                        return t.annotatedType(s);
                     } else {
                         ClassType ret = new ClassType(t.getEnclosingType().accept(this, s),
                                 t.typarams_field, t.tsym);
@@ -557,12 +546,12 @@
 
                 @Override
                 public Type visitAnnotatedType(AnnotatedType t, List<TypeCompound> s) {
-                    return new AnnotatedType(t.typeAnnotations, t.underlyingType.accept(this, s));
+                    return t.underlyingType.accept(this, s).annotatedType(t.typeAnnotations);
                 }
 
                 @Override
                 public Type visitWildcardType(WildcardType t, List<TypeCompound> s) {
-                    return new AnnotatedType(s, t);
+                    return t.annotatedType(s);
                 }
 
                 @Override
@@ -585,12 +574,12 @@
 
                 @Override
                 public Type visitTypeVar(TypeVar t, List<TypeCompound> s) {
-                    return new AnnotatedType(s, t);
+                    return t.annotatedType(s);
                 }
 
                 @Override
                 public Type visitCapturedType(CapturedType t, List<TypeCompound> s) {
-                    return new AnnotatedType(s, t);
+                    return t.annotatedType(s);
                 }
 
                 @Override
@@ -607,12 +596,12 @@
 
                 @Override
                 public Type visitErrorType(ErrorType t, List<TypeCompound> s) {
-                    return new AnnotatedType(s, t);
+                    return t.annotatedType(s);
                 }
 
                 @Override
                 public Type visitType(Type t, List<TypeCompound> s) {
-                    return new AnnotatedType(s, t);
+                    return t.annotatedType(s);
                 }
             };
 
--- a/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Aug 27 16:16:56 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Wed Aug 28 17:23:45 2013 -0700
@@ -2216,7 +2216,7 @@
                     // on the bound.
                     erased = ((AnnotatedType)erased).underlyingType;
                 }
-                return new AnnotatedType(t.typeAnnotations, erased);
+                return erased.annotatedType(t.typeAnnotations);
             }
         };
 
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Aug 27 16:16:56 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Aug 28 17:23:45 2013 -0700
@@ -3962,7 +3962,7 @@
         TypeVar typeVar = (TypeVar) tree.type;
 
         if (tree.annotations != null && tree.annotations.nonEmpty()) {
-            AnnotatedType antype = new AnnotatedType(typeVar);
+            Type antype = typeVar.annotatedType(List.<Attribute.TypeCompound>nil());
             annotateType(antype, tree.annotations);
             tree.type = antype;
         }
@@ -4065,7 +4065,7 @@
     public void visitAnnotatedType(JCAnnotatedType tree) {
         Type underlyingType = attribType(tree.getUnderlyingType(), env);
         this.attribAnnotationTypes(tree.annotations, env);
-        AnnotatedType antype = new AnnotatedType(underlyingType);
+        Type antype = underlyingType.annotatedType(List.<Attribute.TypeCompound>nil());
         annotateType(antype, tree.annotations);
         result = tree.type = antype;
     }
@@ -4073,7 +4073,8 @@
     /**
      * Apply the annotations to the particular type.
      */
-    public void annotateType(final AnnotatedType type, final List<JCAnnotation> annotations) {
+    public void annotateType(final Type type, final List<JCAnnotation> annotations) {
+        Assert.check(type instanceof AnnotatedType);
         if (annotations.isEmpty())
             return;
         annotate.typeAnnotation(new Annotate.Annotator() {
@@ -4084,7 +4085,7 @@
             @Override
             public void enterAnnotation() {
                 List<Attribute.TypeCompound> compounds = fromAnnotations(annotations);
-                type.typeAnnotations = compounds;
+                ((AnnotatedType) type).typeAnnotations = compounds;
             }
         });
     }
--- a/src/share/classes/com/sun/tools/javac/comp/Lower.java	Tue Aug 27 16:16:56 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java	Wed Aug 28 17:23:45 2013 -0700
@@ -2812,8 +2812,7 @@
             } else {
                 // Create a new AnnotatedType to have the correct tag.
                 AnnotatedType oldat = (AnnotatedType) tree.type;
-                tree.type = new AnnotatedType(tree.underlyingType.type);
-                ((AnnotatedType) tree.type).typeAnnotations = oldat.typeAnnotations;
+                tree.type = tree.underlyingType.type.annotatedType(oldat.typeAnnotations);
             }
         }
         result = tree;
--- a/src/share/classes/com/sun/tools/javadoc/AnnotatedTypeImpl.java	Tue Aug 27 16:16:56 2013 -0700
+++ b/src/share/classes/com/sun/tools/javadoc/AnnotatedTypeImpl.java	Wed Aug 28 17:23:45 2013 -0700
@@ -50,7 +50,7 @@
      */
     @Override
     public AnnotationDesc[] annotations() {
-        List<TypeCompound> tas = ((com.sun.tools.javac.code.Type.AnnotatedType)type).typeAnnotations;
+        List<? extends TypeCompound> tas = type.getAnnotationMirrors();
         if (tas == null ||
                 tas.isEmpty()) {
             return new AnnotationDesc[0];
@@ -65,7 +65,7 @@
 
     @Override
     public com.sun.javadoc.Type underlyingType() {
-        return TypeMaker.getType(env, ((com.sun.tools.javac.code.Type.AnnotatedType)type).underlyingType, true, false);
+        return TypeMaker.getType(env, type.unannotatedType(), true, false);
     }
 
     @Override
--- a/src/share/classes/com/sun/tools/javadoc/TypeMaker.java	Tue Aug 27 16:16:56 2013 -0700
+++ b/src/share/classes/com/sun/tools/javadoc/TypeMaker.java	Wed Aug 28 17:23:45 2013 -0700
@@ -143,8 +143,7 @@
     static String getTypeString(DocEnv env, Type t, boolean full) {
         // TODO: should annotations be included here?
         if (t.isAnnotated()) {
-            Type.AnnotatedType at = (Type.AnnotatedType)t;
-            t = at.underlyingType;
+            t = t.unannotatedType();
         }
         switch (t.getTag()) {
         case ARRAY:
--- a/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java	Tue Aug 27 16:16:56 2013 -0700
+++ b/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java	Wed Aug 28 17:23:45 2013 -0700
@@ -140,7 +140,7 @@
         if (!type.isAnnotated()) {
             return new AnnotationDesc[0];
         }
-        List<TypeCompound> tas = ((com.sun.tools.javac.code.Type.AnnotatedType) type).typeAnnotations;
+        List<? extends TypeCompound> tas = type.getAnnotationMirrors();
         AnnotationDesc res[] = new AnnotationDesc[tas.length()];
         int i = 0;
         for (Attribute.Compound a : tas) {