提交 39458a8b 编写于 作者: J jfranck

8005098: Provide isSynthesized() information on Attribute.Compound

Reviewed-by: jjg
上级 2172d121
......@@ -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 <javadoc> task for javac
#javadoc.jls3.url=http://java.sun.com/docs/books/jls/
......
......@@ -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<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);
......
......@@ -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<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;
......@@ -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<Attribute.Compound> 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<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 @@ public abstract class Symbol implements Element {
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) {
......
......@@ -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
......
......@@ -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<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 @@ public class ClassWriter extends ClassFile {
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 @@ public class ClassWriter extends ClassFile {
}
acount += writeFlagAttrs(c.flags());
acount += writeJavaAnnotations(c.getAnnotationMirrors());
acount += writeJavaAnnotations(c.getRawAttributes());
acount += writeEnclosingMethodAttribute(c);
acount += writeExtraClassAttributes(c);
......
......@@ -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()),
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册