--- old/src/share/classes/com/sun/tools/javac/code/Type.java 2013-08-27 12:08:41.554296536 -0700 +++ new/src/share/classes/com/sun/tools/javac/code/Type.java 2013-08-27 12:08:41.490296536 -0700 @@ -219,6 +219,10 @@ public Type baseType() { return this; } + + public Type annotatedType(List annos) { + return new AnnotatedType(annos, this); + } public boolean isAnnotated() { return false; @@ -233,7 +237,7 @@ } @Override - public List getAnnotationMirrors() { + public List getAnnotationMirrors() { return List.nil(); } @@ -1837,7 +1841,7 @@ } @Override - public List getAnnotationMirrors() { + public List 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 --- old/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java 2013-08-27 12:08:41.870296538 -0700 +++ new/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java 2013-08-27 12:08:41.802296538 -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 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 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 s) { - return new AnnotatedType(s, t); + return t.annotatedType(s); } @Override @@ -585,12 +574,12 @@ @Override public Type visitTypeVar(TypeVar t, List s) { - return new AnnotatedType(s, t); + return t.annotatedType(s); } @Override public Type visitCapturedType(CapturedType t, List s) { - return new AnnotatedType(s, t); + return t.annotatedType(s); } @Override @@ -607,12 +596,12 @@ @Override public Type visitErrorType(ErrorType t, List s) { - return new AnnotatedType(s, t); + return t.annotatedType(s); } @Override public Type visitType(Type t, List s) { - return new AnnotatedType(s, t); + return t.annotatedType(s); } }; --- old/src/share/classes/com/sun/tools/javac/code/Types.java 2013-08-27 12:08:42.182296541 -0700 +++ new/src/share/classes/com/sun/tools/javac/code/Types.java 2013-08-27 12:08:42.114296539 -0700 @@ -2216,7 +2216,7 @@ // on the bound. erased = ((AnnotatedType)erased).underlyingType; } - return new AnnotatedType(t.typeAnnotations, erased); + return erased.annotatedType(t.typeAnnotations); } }; --- old/src/share/classes/com/sun/tools/javac/comp/Attr.java 2013-08-27 12:08:42.518296544 -0700 +++ new/src/share/classes/com/sun/tools/javac/comp/Attr.java 2013-08-27 12:08:42.450296543 -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.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.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 annotations) { + public void annotateType(final Type type, final List annotations) { + Assert.check(type instanceof AnnotatedType); if (annotations.isEmpty()) return; annotate.typeAnnotation(new Annotate.Annotator() { @@ -4084,7 +4085,7 @@ @Override public void enterAnnotation() { List compounds = fromAnnotations(annotations); - type.typeAnnotations = compounds; + ((AnnotatedType) type).typeAnnotations = compounds; } }); } --- old/src/share/classes/com/sun/tools/javac/comp/Lower.java 2013-08-27 12:08:42.874296546 -0700 +++ new/src/share/classes/com/sun/tools/javac/comp/Lower.java 2013-08-27 12:08:42.802296546 -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; --- old/src/share/classes/com/sun/tools/javadoc/AnnotatedTypeImpl.java 2013-08-27 12:08:43.214296549 -0700 +++ new/src/share/classes/com/sun/tools/javadoc/AnnotatedTypeImpl.java 2013-08-27 12:08:43.146296548 -0700 @@ -50,7 +50,7 @@ */ @Override public AnnotationDesc[] annotations() { - List tas = ((com.sun.tools.javac.code.Type.AnnotatedType)type).typeAnnotations; + List 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 --- old/src/share/classes/com/sun/tools/javadoc/TypeMaker.java 2013-08-27 12:08:43.498296551 -0700 +++ new/src/share/classes/com/sun/tools/javadoc/TypeMaker.java 2013-08-27 12:08:43.430296550 -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: --- old/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java 2013-08-27 12:08:43.786296553 -0700 +++ new/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java 2013-08-27 12:08:43.718296553 -0700 @@ -140,7 +140,7 @@ if (!type.isAnnotated()) { return new AnnotationDesc[0]; } - List tas = ((com.sun.tools.javac.code.Type.AnnotatedType) type).typeAnnotations; + List tas = type.getAnnotationMirrors(); AnnotationDesc res[] = new AnnotationDesc[tas.length()]; int i = 0; for (Attribute.Compound a : tas) {