8005098: Provide isSynthesized() information on Attribute.Compound

Sun, 16 Dec 2012 11:09:36 +0100

author
jfranck
date
Sun, 16 Dec 2012 11:09:36 +0100
changeset 1464
f72c9c5aeaef
parent 1463
67b01d295cd2
child 1465
a22f23fb7abf

8005098: Provide isSynthesized() information on Attribute.Compound
Reviewed-by: jjg

make/build.properties file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Attribute.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Symbol.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Annotate.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/tree/TreeMaker.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/ParameterImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java file | annotate | diff | comparison | revisions
     1.1 --- a/make/build.properties	Wed Dec 19 11:29:56 2012 +0000
     1.2 +++ b/make/build.properties	Sun Dec 16 11:09:36 2012 +0100
     1.3 @@ -68,7 +68,7 @@
     1.4  # set the following to -version to verify the versions of javac being used
     1.5  javac.version.opt =
     1.6  # in time, there should be no exceptions to -Xlint:all
     1.7 -javac.lint.opts = -Xlint:all,-deprecation -Werror
     1.8 +javac.lint.opts = -Xlint:all -Werror
     1.9  
    1.10  # options for the <javadoc> task for javac
    1.11  #javadoc.jls3.url=http://java.sun.com/docs/books/jls/
     2.1 --- a/src/share/classes/com/sun/tools/javac/code/Attribute.java	Wed Dec 19 11:29:56 2012 +0000
     2.2 +++ b/src/share/classes/com/sun/tools/javac/code/Attribute.java	Sun Dec 16 11:09:36 2012 +0100
     2.3 @@ -60,6 +60,9 @@
     2.4          throw new UnsupportedOperationException();
     2.5      }
     2.6  
     2.7 +    public boolean isSynthesized() {
     2.8 +        return false;
     2.9 +    }
    2.10  
    2.11      /** The value for an annotation element of primitive type or String. */
    2.12      public static class Constant extends Attribute {
    2.13 @@ -136,6 +139,18 @@
    2.14           *  access this attribute.
    2.15           */
    2.16          public final List<Pair<MethodSymbol,Attribute>> values;
    2.17 +
    2.18 +        private boolean synthesized = false;
    2.19 +
    2.20 +        @Override
    2.21 +        public boolean isSynthesized() {
    2.22 +            return synthesized;
    2.23 +        }
    2.24 +
    2.25 +        public void setSynthesized(boolean synthesized) {
    2.26 +            this.synthesized = synthesized;
    2.27 +        }
    2.28 +
    2.29          public Compound(Type type,
    2.30                          List<Pair<MethodSymbol,Attribute>> values) {
    2.31              super(type);
     3.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Wed Dec 19 11:29:56 2012 +0000
     3.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Sun Dec 16 11:09:36 2012 +0100
     3.3 @@ -83,13 +83,13 @@
     3.4       *  Attributes of class symbols should be accessed through the accessor
     3.5       *  method to make sure that the class symbol is loaded.
     3.6       */
     3.7 -    public List<Attribute.Compound> getAnnotationMirrors() {
     3.8 -        return Assert.checkNonNull(annotations.getAttributes());
     3.9 +    public List<Attribute.Compound> getRawAttributes() {
    3.10 +        return annotations.getAttributes();
    3.11      }
    3.12  
    3.13      /** Fetch a particular annotation from a symbol. */
    3.14      public Attribute.Compound attribute(Symbol anno) {
    3.15 -        for (Attribute.Compound a : getAnnotationMirrors()) {
    3.16 +        for (Attribute.Compound a : getRawAttributes()) {
    3.17              if (a.type.tsym == anno) return a;
    3.18          }
    3.19          return null;
    3.20 @@ -447,6 +447,14 @@
    3.21      }
    3.22  
    3.23      /**
    3.24 +     * This is the implementation for {@code
    3.25 +     * javax.lang.model.element.Element.getAnnotationMirrors()}.
    3.26 +     */
    3.27 +    public final List<Attribute.Compound> getAnnotationMirrors() {
    3.28 +        return getRawAttributes();
    3.29 +    }
    3.30 +
    3.31 +    /**
    3.32       * @deprecated this method should never be used by javac internally.
    3.33       */
    3.34      @Deprecated
    3.35 @@ -662,15 +670,21 @@
    3.36              return flags_field;
    3.37          }
    3.38  
    3.39 -        public List<Attribute.Compound> getAnnotationMirrors() {
    3.40 +        @Override
    3.41 +        public List<Attribute.Compound> getRawAttributes() {
    3.42              if (completer != null) complete();
    3.43              if (package_info != null && package_info.completer != null) {
    3.44                  package_info.complete();
    3.45 -                if (annotations.isEmpty()) {
    3.46 -                    annotations.setAttributes(package_info.annotations);
    3.47 +                mergeAttributes();
    3.48              }
    3.49 +            return super.getRawAttributes();
    3.50 +        }
    3.51 +
    3.52 +        private void mergeAttributes() {
    3.53 +            if (annotations.isEmpty() &&
    3.54 +                !package_info.annotations.isEmpty()) {
    3.55 +                annotations.setAttributes(package_info.annotations);
    3.56              }
    3.57 -            return Assert.checkNonNull(annotations.getAttributes());
    3.58          }
    3.59  
    3.60          /** A package "exists" if a type or package that exists has
    3.61 @@ -770,9 +784,10 @@
    3.62              return members_field;
    3.63          }
    3.64  
    3.65 -        public List<Attribute.Compound> getAnnotationMirrors() {
    3.66 +        @Override
    3.67 +        public List<Attribute.Compound> getRawAttributes() {
    3.68              if (completer != null) complete();
    3.69 -            return Assert.checkNonNull(annotations.getAttributes());
    3.70 +            return super.getRawAttributes();
    3.71          }
    3.72  
    3.73          public Type erasure(Types types) {
     4.1 --- a/src/share/classes/com/sun/tools/javac/comp/Annotate.java	Wed Dec 19 11:29:56 2012 +0000
     4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Annotate.java	Sun Dec 16 11:09:36 2012 +0100
     4.3 @@ -400,6 +400,7 @@
     4.4              Attribute.Compound c = enterAnnotation(annoTree,
     4.5                                                     targetContainerType,
     4.6                                                     ctx.env);
     4.7 +            c.setSynthesized(true);
     4.8              return c;
     4.9          } else {
    4.10              return null; // errors should have been reported elsewhere
     5.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Wed Dec 19 11:29:56 2012 +0000
     5.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Sun Dec 16 11:09:36 2012 +0100
     5.3 @@ -721,7 +721,7 @@
     5.4              endAttr(alenIdx);
     5.5              acount++;
     5.6          }
     5.7 -        acount += writeJavaAnnotations(sym.getAnnotationMirrors());
     5.8 +        acount += writeJavaAnnotations(sym.getRawAttributes());
     5.9          return acount;
    5.10      }
    5.11  
    5.12 @@ -732,7 +732,7 @@
    5.13          boolean hasVisible = false;
    5.14          boolean hasInvisible = false;
    5.15          if (m.params != null) for (VarSymbol s : m.params) {
    5.16 -            for (Attribute.Compound a : s.getAnnotationMirrors()) {
    5.17 +            for (Attribute.Compound a : s.getRawAttributes()) {
    5.18                  switch (types.getRetention(a)) {
    5.19                  case SOURCE: break;
    5.20                  case CLASS: hasInvisible = true; break;
    5.21 @@ -748,7 +748,7 @@
    5.22              databuf.appendByte(m.params.length());
    5.23              for (VarSymbol s : m.params) {
    5.24                  ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
    5.25 -                for (Attribute.Compound a : s.getAnnotationMirrors())
    5.26 +                for (Attribute.Compound a : s.getRawAttributes())
    5.27                      if (types.getRetention(a) == RetentionPolicy.RUNTIME)
    5.28                          buf.append(a);
    5.29                  databuf.appendChar(buf.length());
    5.30 @@ -763,7 +763,7 @@
    5.31              databuf.appendByte(m.params.length());
    5.32              for (VarSymbol s : m.params) {
    5.33                  ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
    5.34 -                for (Attribute.Compound a : s.getAnnotationMirrors())
    5.35 +                for (Attribute.Compound a : s.getRawAttributes())
    5.36                      if (types.getRetention(a) == RetentionPolicy.CLASS)
    5.37                          buf.append(a);
    5.38                  databuf.appendChar(buf.length());
    5.39 @@ -1636,7 +1636,7 @@
    5.40          }
    5.41  
    5.42          acount += writeFlagAttrs(c.flags());
    5.43 -        acount += writeJavaAnnotations(c.getAnnotationMirrors());
    5.44 +        acount += writeJavaAnnotations(c.getRawAttributes());
    5.45          acount += writeEnclosingMethodAttribute(c);
    5.46          acount += writeExtraClassAttributes(c);
    5.47  
     6.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Wed Dec 19 11:29:56 2012 +0000
     6.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Sun Dec 16 11:09:36 2012 +0100
     6.3 @@ -684,7 +684,7 @@
     6.4      public JCVariableDecl VarDef(VarSymbol v, JCExpression init) {
     6.5          return (JCVariableDecl)
     6.6              new JCVariableDecl(
     6.7 -                Modifiers(v.flags(), Annotations(v.getAnnotationMirrors())),
     6.8 +                Modifiers(v.flags(), Annotations(v.getRawAttributes())),
     6.9                  v.name,
    6.10                  Type(v.type),
    6.11                  init,
    6.12 @@ -800,7 +800,7 @@
    6.13      public JCMethodDecl MethodDef(MethodSymbol m, Type mtype, JCBlock body) {
    6.14          return (JCMethodDecl)
    6.15              new JCMethodDecl(
    6.16 -                Modifiers(m.flags(), Annotations(m.getAnnotationMirrors())),
    6.17 +                Modifiers(m.flags(), Annotations(m.getRawAttributes())),
    6.18                  m.name,
    6.19                  Type(mtype.getReturnType()),
    6.20                  TypeParams(mtype.getTypeArguments()),
     7.1 --- a/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java	Wed Dec 19 11:29:56 2012 +0000
     7.2 +++ b/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java	Sun Dec 16 11:09:36 2012 +0100
     7.3 @@ -288,9 +288,9 @@
     7.4       * Return an empty array if there are none.
     7.5       */
     7.6      public AnnotationDesc[] annotations() {
     7.7 -        AnnotationDesc res[] = new AnnotationDesc[sym.getAnnotationMirrors().length()];
     7.8 +        AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()];
     7.9          int i = 0;
    7.10 -        for (Attribute.Compound a : sym.getAnnotationMirrors()) {
    7.11 +        for (Attribute.Compound a : sym.getRawAttributes()) {
    7.12              res[i++] = new AnnotationDescImpl(env, a);
    7.13          }
    7.14          return res;
     8.1 --- a/src/share/classes/com/sun/tools/javadoc/ParameterImpl.java	Wed Dec 19 11:29:56 2012 +0000
     8.2 +++ b/src/share/classes/com/sun/tools/javadoc/ParameterImpl.java	Sun Dec 16 11:09:36 2012 +0100
     8.3 @@ -99,9 +99,9 @@
     8.4       * Return an empty array if there are none.
     8.5       */
     8.6      public AnnotationDesc[] annotations() {
     8.7 -        AnnotationDesc res[] = new AnnotationDesc[sym.getAnnotationMirrors().length()];
     8.8 +        AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()];
     8.9          int i = 0;
    8.10 -        for (Attribute.Compound a : sym.getAnnotationMirrors()) {
    8.11 +        for (Attribute.Compound a : sym.getRawAttributes()) {
    8.12              res[i++] = new AnnotationDescImpl(env, a);
    8.13          }
    8.14          return res;
     9.1 --- a/src/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java	Wed Dec 19 11:29:56 2012 +0000
     9.2 +++ b/src/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java	Sun Dec 16 11:09:36 2012 +0100
     9.3 @@ -164,9 +164,9 @@
     9.4       * Return an empty array if there are none.
     9.5       */
     9.6      public AnnotationDesc[] annotations() {
     9.7 -        AnnotationDesc res[] = new AnnotationDesc[sym.getAnnotationMirrors().length()];
     9.8 +        AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()];
     9.9          int i = 0;
    9.10 -        for (Attribute.Compound a : sym.getAnnotationMirrors()) {
    9.11 +        for (Attribute.Compound a : sym.getRawAttributes()) {
    9.12              res[i++] = new AnnotationDescImpl(env, a);
    9.13          }
    9.14          return res;

mercurial