# HG changeset patch # User jjg # Date 1382295703 25200 # Node ID e5d3cd43c85e8781e891e2a0835650697d27a448 # Parent c4292590fc700ddcdce980cd6622e004bd388c41 8025109: Better encapsulation for AnnotatedType Reviewed-by: jjg Contributed-by: wdietl@gmail.com diff -r c4292590fc70 -r e5d3cd43c85e src/share/classes/com/sun/tools/javac/code/Symbol.java --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Sat Oct 19 17:43:09 2013 +0100 +++ b/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 getRawAttributes() { - return (annotations == null) + return (metadata == null) ? List.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 getRawTypeAttributes() { - return (annotations == null) + return (metadata == null) ? List.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 l) { if (l.nonEmpty()) { - initedAnnos().append(l); + initedMetadata().append(l); } } public void appendClassInitTypeAttributes(List l) { if (l.nonEmpty()) { - initedAnnos().appendClassInitTypeAttributes(l); + initedMetadata().appendClassInitTypeAttributes(l); } } public void appendInitTypeAttributes(List l) { if (l.nonEmpty()) { - initedAnnos().appendInitTypeAttributes(l); + initedMetadata().appendInitTypeAttributes(l); } } public void appendTypeAttributesWithCompletion(final Annotate.AnnotateRepeatedContext ctx) { - initedAnnos().appendTypeAttributesWithCompletion(ctx); + initedMetadata().appendTypeAttributesWithCompletion(ctx); } public void appendUniqueTypeAttributes(List l) { if (l.nonEmpty()) { - initedAnnos().appendUniqueTypes(l); + initedMetadata().appendUniqueTypes(l); } } public List getClassInitTypeAttributes() { - return (annotations == null) + return (metadata == null) ? List.nil() - : annotations.getClassInitTypeAttributes(); + : metadata.getClassInitTypeAttributes(); } public List getInitTypeAttributes() { - return (annotations == null) + return (metadata == null) ? List.nil() - : annotations.getInitTypeAttributes(); + : metadata.getInitTypeAttributes(); } public List getDeclarationAttributes() { - return (annotations == null) + return (metadata == null) ? List.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 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 a) { - if (annotations != null || a.nonEmpty()) { - initedAnnos().setDeclarationAttributes(a); + if (metadata != null || a.nonEmpty()) { + initedMetadata().setDeclarationAttributes(a); } } public void setDeclarationAttributesWithCompletion(final Annotate.AnnotateRepeatedContext ctx) { - initedAnnos().setDeclarationAttributesWithCompletion(ctx); + initedMetadata().setDeclarationAttributesWithCompletion(ctx); } public void setTypeAttributes(List 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; } // @@ -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); } } diff -r c4292590fc70 -r e5d3cd43c85e src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java --- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Sat Oct 19 17:43:09 2013 +0100 +++ b/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); diff -r c4292590fc70 -r e5d3cd43c85e src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Sat Oct 19 17:43:09 2013 +0100 +++ b/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 annotations) { - // Callers ensure this. - // Assert.check(annotations != null && annotations.nonEmpty()); annotate.typeAnnotation(new Annotate.Worker() { @Override public String toString() {