From 39458a8b2740c7dbf2a6583f5e62c3a48bea58b0 Mon Sep 17 00:00:00 2001 From: jfranck Date: Sun, 16 Dec 2012 11:09:36 +0100 Subject: [PATCH] 8005098: Provide isSynthesized() information on Attribute.Compound Reviewed-by: jjg --- make/build.properties | 2 +- .../com/sun/tools/javac/code/Attribute.java | 15 +++++++++ .../com/sun/tools/javac/code/Symbol.java | 33 ++++++++++++++----- .../com/sun/tools/javac/comp/Annotate.java | 1 + .../com/sun/tools/javac/jvm/ClassWriter.java | 10 +++--- .../com/sun/tools/javac/tree/TreeMaker.java | 4 +-- .../com/sun/tools/javadoc/PackageDocImpl.java | 4 +-- .../com/sun/tools/javadoc/ParameterImpl.java | 4 +-- .../tools/javadoc/ProgramElementDocImpl.java | 4 +-- 9 files changed, 54 insertions(+), 23 deletions(-) diff --git a/make/build.properties b/make/build.properties index 78bc7175..912342dc 100644 --- a/make/build.properties +++ b/make/build.properties @@ -68,7 +68,7 @@ javac.no.jdk.warnings = -XDignore.symbol.file=true # set the following to -version to verify the versions of javac being used javac.version.opt = # in time, there should be no exceptions to -Xlint:all -javac.lint.opts = -Xlint:all,-deprecation -Werror +javac.lint.opts = -Xlint:all -Werror # options for the task for javac #javadoc.jls3.url=http://java.sun.com/docs/books/jls/ diff --git a/src/share/classes/com/sun/tools/javac/code/Attribute.java b/src/share/classes/com/sun/tools/javac/code/Attribute.java index f827006a..9ecb23d8 100644 --- a/src/share/classes/com/sun/tools/javac/code/Attribute.java +++ b/src/share/classes/com/sun/tools/javac/code/Attribute.java @@ -60,6 +60,9 @@ public abstract class Attribute implements AnnotationValue { throw new UnsupportedOperationException(); } + public boolean isSynthesized() { + return false; + } /** The value for an annotation element of primitive type or String. */ public static class Constant extends Attribute { @@ -136,6 +139,18 @@ public abstract class Attribute implements AnnotationValue { * access this attribute. */ public final List> values; + + private boolean synthesized = false; + + @Override + public boolean isSynthesized() { + return synthesized; + } + + public void setSynthesized(boolean synthesized) { + this.synthesized = synthesized; + } + public Compound(Type type, List> values) { super(type); diff --git a/src/share/classes/com/sun/tools/javac/code/Symbol.java b/src/share/classes/com/sun/tools/javac/code/Symbol.java index b8e90d62..2f3f84ab 100644 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java @@ -83,13 +83,13 @@ public abstract class Symbol implements Element { * Attributes of class symbols should be accessed through the accessor * method to make sure that the class symbol is loaded. */ - public List getAnnotationMirrors() { - return Assert.checkNonNull(annotations.getAttributes()); + public List getRawAttributes() { + return annotations.getAttributes(); } /** Fetch a particular annotation from a symbol. */ public Attribute.Compound attribute(Symbol anno) { - for (Attribute.Compound a : getAnnotationMirrors()) { + for (Attribute.Compound a : getRawAttributes()) { if (a.type.tsym == anno) return a; } return null; @@ -446,6 +446,14 @@ public abstract class Symbol implements Element { return name; } + /** + * This is the implementation for {@code + * javax.lang.model.element.Element.getAnnotationMirrors()}. + */ + public final List getAnnotationMirrors() { + return getRawAttributes(); + } + /** * @deprecated this method should never be used by javac internally. */ @@ -662,15 +670,21 @@ public abstract class Symbol implements Element { return flags_field; } - public List getAnnotationMirrors() { + @Override + public List getRawAttributes() { if (completer != null) complete(); if (package_info != null && package_info.completer != null) { package_info.complete(); - if (annotations.isEmpty()) { - annotations.setAttributes(package_info.annotations); + mergeAttributes(); } + return super.getRawAttributes(); + } + + private void mergeAttributes() { + if (annotations.isEmpty() && + !package_info.annotations.isEmpty()) { + annotations.setAttributes(package_info.annotations); } - return Assert.checkNonNull(annotations.getAttributes()); } /** A package "exists" if a type or package that exists has @@ -770,9 +784,10 @@ public abstract class Symbol implements Element { return members_field; } - public List getAnnotationMirrors() { + @Override + public List getRawAttributes() { if (completer != null) complete(); - return Assert.checkNonNull(annotations.getAttributes()); + return super.getRawAttributes(); } public Type erasure(Types types) { diff --git a/src/share/classes/com/sun/tools/javac/comp/Annotate.java b/src/share/classes/com/sun/tools/javac/comp/Annotate.java index ab5d49c3..b9807d91 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Annotate.java +++ b/src/share/classes/com/sun/tools/javac/comp/Annotate.java @@ -400,6 +400,7 @@ public class Annotate { Attribute.Compound c = enterAnnotation(annoTree, targetContainerType, ctx.env); + c.setSynthesized(true); return c; } else { return null; // errors should have been reported elsewhere diff --git a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java index 2a16d194..f67e0d3b 100644 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java @@ -721,7 +721,7 @@ public class ClassWriter extends ClassFile { endAttr(alenIdx); acount++; } - acount += writeJavaAnnotations(sym.getAnnotationMirrors()); + acount += writeJavaAnnotations(sym.getRawAttributes()); return acount; } @@ -732,7 +732,7 @@ public class ClassWriter extends ClassFile { boolean hasVisible = false; boolean hasInvisible = false; if (m.params != null) for (VarSymbol s : m.params) { - for (Attribute.Compound a : s.getAnnotationMirrors()) { + for (Attribute.Compound a : s.getRawAttributes()) { switch (types.getRetention(a)) { case SOURCE: break; case CLASS: hasInvisible = true; break; @@ -748,7 +748,7 @@ public class ClassWriter extends ClassFile { databuf.appendByte(m.params.length()); for (VarSymbol s : m.params) { ListBuffer buf = new ListBuffer(); - for (Attribute.Compound a : s.getAnnotationMirrors()) + for (Attribute.Compound a : s.getRawAttributes()) if (types.getRetention(a) == RetentionPolicy.RUNTIME) buf.append(a); databuf.appendChar(buf.length()); @@ -763,7 +763,7 @@ public class ClassWriter extends ClassFile { databuf.appendByte(m.params.length()); for (VarSymbol s : m.params) { ListBuffer buf = new ListBuffer(); - for (Attribute.Compound a : s.getAnnotationMirrors()) + for (Attribute.Compound a : s.getRawAttributes()) if (types.getRetention(a) == RetentionPolicy.CLASS) buf.append(a); databuf.appendChar(buf.length()); @@ -1636,7 +1636,7 @@ public class ClassWriter extends ClassFile { } acount += writeFlagAttrs(c.flags()); - acount += writeJavaAnnotations(c.getAnnotationMirrors()); + acount += writeJavaAnnotations(c.getRawAttributes()); acount += writeEnclosingMethodAttribute(c); acount += writeExtraClassAttributes(c); diff --git a/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java b/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java index ce69edbe..27a2d74f 100644 --- a/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java +++ b/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java @@ -684,7 +684,7 @@ public class TreeMaker implements JCTree.Factory { public JCVariableDecl VarDef(VarSymbol v, JCExpression init) { return (JCVariableDecl) new JCVariableDecl( - Modifiers(v.flags(), Annotations(v.getAnnotationMirrors())), + Modifiers(v.flags(), Annotations(v.getRawAttributes())), v.name, Type(v.type), init, @@ -800,7 +800,7 @@ public class TreeMaker implements JCTree.Factory { public JCMethodDecl MethodDef(MethodSymbol m, Type mtype, JCBlock body) { return (JCMethodDecl) new JCMethodDecl( - Modifiers(m.flags(), Annotations(m.getAnnotationMirrors())), + Modifiers(m.flags(), Annotations(m.getRawAttributes())), m.name, Type(mtype.getReturnType()), TypeParams(mtype.getTypeArguments()), diff --git a/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java b/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java index 1068f803..bc54bef6 100644 --- a/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java +++ b/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java @@ -288,9 +288,9 @@ public class PackageDocImpl extends DocImpl implements PackageDoc { * Return an empty array if there are none. */ public AnnotationDesc[] annotations() { - AnnotationDesc res[] = new AnnotationDesc[sym.getAnnotationMirrors().length()]; + AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()]; int i = 0; - for (Attribute.Compound a : sym.getAnnotationMirrors()) { + for (Attribute.Compound a : sym.getRawAttributes()) { res[i++] = new AnnotationDescImpl(env, a); } return res; diff --git a/src/share/classes/com/sun/tools/javadoc/ParameterImpl.java b/src/share/classes/com/sun/tools/javadoc/ParameterImpl.java index 524a5ead..14de4a2f 100644 --- a/src/share/classes/com/sun/tools/javadoc/ParameterImpl.java +++ b/src/share/classes/com/sun/tools/javadoc/ParameterImpl.java @@ -99,9 +99,9 @@ class ParameterImpl implements Parameter { * Return an empty array if there are none. */ public AnnotationDesc[] annotations() { - AnnotationDesc res[] = new AnnotationDesc[sym.getAnnotationMirrors().length()]; + AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()]; int i = 0; - for (Attribute.Compound a : sym.getAnnotationMirrors()) { + for (Attribute.Compound a : sym.getRawAttributes()) { res[i++] = new AnnotationDescImpl(env, a); } return res; diff --git a/src/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java b/src/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java index f4f923ea..d647b491 100644 --- a/src/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java +++ b/src/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java @@ -164,9 +164,9 @@ public abstract class ProgramElementDocImpl * Return an empty array if there are none. */ public AnnotationDesc[] annotations() { - AnnotationDesc res[] = new AnnotationDesc[sym.getAnnotationMirrors().length()]; + AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()]; int i = 0; - for (Attribute.Compound a : sym.getAnnotationMirrors()) { + for (Attribute.Compound a : sym.getRawAttributes()) { res[i++] = new AnnotationDescImpl(env, a); } return res; -- GitLab