8005098: Provide isSynthesized() information on Attribute.Compound
authorjfranck
Sun, 16 Dec 2012 11:09:36 +0100
changeset 14961 e731935052af
parent 14960 ea7606a9683e
child 14962 19ffdfafbcd2
8005098: Provide isSynthesized() information on Attribute.Compound Reviewed-by: jjg
langtools/make/build.properties
langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java
langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java
langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java
langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
langtools/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java
langtools/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/ParameterImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java
--- a/langtools/make/build.properties	Wed Dec 19 11:29:56 2012 +0000
+++ b/langtools/make/build.properties	Sun Dec 16 11:09:36 2012 +0100
@@ -68,7 +68,7 @@
 # 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 <javadoc> task for javac
 #javadoc.jls3.url=http://java.sun.com/docs/books/jls/
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java	Wed Dec 19 11:29:56 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Attribute.java	Sun Dec 16 11:09:36 2012 +0100
@@ -60,6 +60,9 @@
         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 @@
          *  access this attribute.
          */
         public final List<Pair<MethodSymbol,Attribute>> values;
+
+        private boolean synthesized = false;
+
+        @Override
+        public boolean isSynthesized() {
+            return synthesized;
+        }
+
+        public void setSynthesized(boolean synthesized) {
+            this.synthesized = synthesized;
+        }
+
         public Compound(Type type,
                         List<Pair<MethodSymbol,Attribute>> values) {
             super(type);
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java	Wed Dec 19 11:29:56 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java	Sun Dec 16 11:09:36 2012 +0100
@@ -83,13 +83,13 @@
      *  Attributes of class symbols should be accessed through the accessor
      *  method to make sure that the class symbol is loaded.
      */
-    public List<Attribute.Compound> getAnnotationMirrors() {
-        return Assert.checkNonNull(annotations.getAttributes());
+    public List<Attribute.Compound> 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;
@@ -447,6 +447,14 @@
     }
 
     /**
+     * This is the implementation for {@code
+     * javax.lang.model.element.Element.getAnnotationMirrors()}.
+     */
+    public final List<Attribute.Compound> getAnnotationMirrors() {
+        return getRawAttributes();
+    }
+
+    /**
      * @deprecated this method should never be used by javac internally.
      */
     @Deprecated
@@ -662,15 +670,21 @@
             return flags_field;
         }
 
-        public List<Attribute.Compound> getAnnotationMirrors() {
+        @Override
+        public List<Attribute.Compound> 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 @@
             return members_field;
         }
 
-        public List<Attribute.Compound> getAnnotationMirrors() {
+        @Override
+        public List<Attribute.Compound> getRawAttributes() {
             if (completer != null) complete();
-            return Assert.checkNonNull(annotations.getAttributes());
+            return super.getRawAttributes();
         }
 
         public Type erasure(Types types) {
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java	Wed Dec 19 11:29:56 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java	Sun Dec 16 11:09:36 2012 +0100
@@ -400,6 +400,7 @@
             Attribute.Compound c = enterAnnotation(annoTree,
                                                    targetContainerType,
                                                    ctx.env);
+            c.setSynthesized(true);
             return c;
         } else {
             return null; // errors should have been reported elsewhere
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Wed Dec 19 11:29:56 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Sun Dec 16 11:09:36 2012 +0100
@@ -721,7 +721,7 @@
             endAttr(alenIdx);
             acount++;
         }
-        acount += writeJavaAnnotations(sym.getAnnotationMirrors());
+        acount += writeJavaAnnotations(sym.getRawAttributes());
         return acount;
     }
 
@@ -732,7 +732,7 @@
         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 @@
             databuf.appendByte(m.params.length());
             for (VarSymbol s : m.params) {
                 ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
-                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 @@
             databuf.appendByte(m.params.length());
             for (VarSymbol s : m.params) {
                 ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
-                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 @@
         }
 
         acount += writeFlagAttrs(c.flags());
-        acount += writeJavaAnnotations(c.getAnnotationMirrors());
+        acount += writeJavaAnnotations(c.getRawAttributes());
         acount += writeEnclosingMethodAttribute(c);
         acount += writeExtraClassAttributes(c);
 
--- a/langtools/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Wed Dec 19 11:29:56 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Sun Dec 16 11:09:36 2012 +0100
@@ -684,7 +684,7 @@
     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 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()),
--- a/langtools/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java	Wed Dec 19 11:29:56 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java	Sun Dec 16 11:09:36 2012 +0100
@@ -288,9 +288,9 @@
      * 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;
--- a/langtools/src/share/classes/com/sun/tools/javadoc/ParameterImpl.java	Wed Dec 19 11:29:56 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/ParameterImpl.java	Sun Dec 16 11:09:36 2012 +0100
@@ -99,9 +99,9 @@
      * 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;
--- a/langtools/src/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java	Wed Dec 19 11:29:56 2012 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java	Sun Dec 16 11:09:36 2012 +0100
@@ -164,9 +164,9 @@
      * 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;