Method from com.sun.tools.javac.jvm.ClassReader$AnnotationDeproxy Detail: |
Attribute deproxy(Type t,
Attribute a) {
Type oldType = type;
try {
type = t;
a.accept(this);
return result;
} finally {
type = oldType;
}
}
|
Compound deproxyCompound(CompoundAnnotationProxy a) {
ListBuffer< Pair< Symbol.MethodSymbol,Attribute > > buf =
new ListBuffer< Pair< Symbol.MethodSymbol,Attribute > >();
for (List< Pair< Name,Attribute > > l = a.values;
l.nonEmpty();
l = l.tail) {
MethodSymbol meth = findAccessMethod(a.type, l.head.fst);
buf.append(new Pair< Symbol.MethodSymbol,Attribute >
(meth, deproxy(meth.type.getReturnType(), l.head.snd)));
}
return new Attribute.Compound(a.type, buf.toList());
}
|
List<Compound> deproxyCompoundList(List<CompoundAnnotationProxy> pl) {
// also must fill in types!!!!
ListBuffer< Attribute.Compound > buf =
new ListBuffer< Attribute.Compound >();
for (List< CompoundAnnotationProxy > l = pl; l.nonEmpty(); l=l.tail) {
buf.append(deproxyCompound(l.head));
}
return buf.toList();
}
|
MethodSymbol findAccessMethod(Type container,
Name name) {
CompletionFailure failure = null;
try {
for (Scope.Entry e = container.tsym.members().lookup(name);
e.scope != null;
e = e.next()) {
Symbol sym = e.sym;
if (sym.kind == MTH && sym.type.getParameterTypes().length() == 0)
return (MethodSymbol) sym;
}
} catch (CompletionFailure ex) {
failure = ex;
}
// The method wasn't found: emit a warning and recover
JavaFileObject prevSource = log.useSource(requestingOwner.classfile);
try {
if (failure == null) {
log.warning("annotation.method.not.found",
container,
name);
} else {
log.warning("annotation.method.not.found.reason",
container,
name,
failure.getDetailValue());//diagnostic, if present
}
} finally {
log.useSource(prevSource);
}
// Construct a new method type and symbol. Use bottom
// type (typeof null) as return type because this type is
// a subtype of all reference types and can be converted
// to primitive types by unboxing.
MethodType mt = new MethodType(List.< Type >nil(),
syms.botType,
List.< Type >nil(),
syms.methodClass);
return new MethodSymbol(PUBLIC | ABSTRACT, name, mt, container.tsym);
}
|
public void visitArray(Array array) {
throw new AssertionError(); // shouldn't happen
}
|
public void visitArrayAttributeProxy(ArrayAttributeProxy proxy) {
int length = proxy.values.length();
Attribute[] ats = new Attribute[length];
Type elemtype = types.elemtype(type);
int i = 0;
for (List< Attribute > p = proxy.values; p.nonEmpty(); p = p.tail) {
ats[i++] = deproxy(elemtype, p.head);
}
result = new Attribute.Array(type, ats);
}
|
public void visitClass(Class clazz) {
result = clazz;
}
|
public void visitCompound(Compound compound) {
throw new AssertionError(); // shouldn't happen
}
|
public void visitCompoundAnnotationProxy(CompoundAnnotationProxy proxy) {
result = deproxyCompound(proxy);
}
|
public void visitConstant(Constant value) {
// assert value.type == type;
result = value;
}
|
public void visitEnum(Enum e) {
throw new AssertionError(); // shouldn't happen
}
|
public void visitEnumAttributeProxy(EnumAttributeProxy proxy) {
// type.tsym.flatName() should == proxy.enumFlatName
TypeSymbol enumTypeSym = proxy.enumType.tsym;
VarSymbol enumerator = null;
CompletionFailure failure = null;
try {
for (Scope.Entry e = enumTypeSym.members().lookup(proxy.enumerator);
e.scope != null;
e = e.next()) {
if (e.sym.kind == VAR) {
enumerator = (VarSymbol)e.sym;
break;
}
}
}
catch (CompletionFailure ex) {
failure = ex;
}
if (enumerator == null) {
if (failure != null) {
log.warning("unknown.enum.constant.reason",
currentClassFile, enumTypeSym, proxy.enumerator,
failure.getDiagnostic());
} else {
log.warning("unknown.enum.constant",
currentClassFile, enumTypeSym, proxy.enumerator);
}
result = new Attribute.Enum(enumTypeSym.type,
new VarSymbol(0, proxy.enumerator, syms.botType, enumTypeSym));
} else {
result = new Attribute.Enum(enumTypeSym.type, enumerator);
}
}
|
public void visitError(Error e) {
throw new AssertionError(); // shouldn't happen
}
|