Method from com.sun.tools.javac.model.AnnotationProxyMaker$ValueVisitor Detail: |
Object getValue(Attribute attr) {
Method method; // runtime method of annotation element
try {
method = annoType.getMethod(meth.name.toString());
} catch (NoSuchMethodException e) {
return null;
}
returnClass = method.getReturnType();
attr.accept(this);
if (!(value instanceof ExceptionProxy) &&
!AnnotationType.invocationHandlerReturnType(returnClass)
.isInstance(value)) {
typeMismatch(method, attr);
}
return value;
}
|
public void visitArray(Array a) {
Name elemName = ((ArrayType) a.type).elemtype.tsym.getQualifiedName();
if (elemName.equals(elemName.table.names.java_lang_Class)) { // Class[]
// Construct a proxy for a MirroredTypesException
ListBuffer< TypeMirror > elems = new ListBuffer< TypeMirror >();
for (Attribute value : a.values) {
Type elem = ((Attribute.Class) value).type;
elems.append(elem);
}
value = new MirroredTypesExceptionProxy(elems.toList());
} else {
int len = a.values.length;
Class< ? > returnClassSaved = returnClass;
returnClass = returnClass.getComponentType();
try {
Object res = Array.newInstance(returnClass, len);
for (int i = 0; i < len; i++) {
a.values[i].accept(this);
if (value == null || value instanceof ExceptionProxy) {
return;
}
try {
Array.set(res, i, value);
} catch (IllegalArgumentException e) {
value = null; // indicates a type mismatch
return;
}
}
value = res;
} finally {
returnClass = returnClassSaved;
}
}
}
|
public void visitClass(Class c) {
value = new MirroredTypeExceptionProxy(c.type);
}
|
public void visitCompound(Compound c) {
try {
Class< ? extends Annotation > nested =
returnClass.asSubclass(Annotation.class);
value = generateAnnotation(c, nested);
} catch (ClassCastException ex) {
value = null; // indicates a type mismatch
}
}
|
public void visitConstant(Constant c) {
value = c.getValue();
}
|
public void visitEnum(Enum e) {
if (returnClass.isEnum()) {
String constName = e.value.toString();
try {
value = Enum.valueOf((Class)returnClass, constName);
} catch (IllegalArgumentException ex) {
value = new EnumConstantNotPresentExceptionProxy(
(Class< Enum< ? > >) returnClass, constName);
}
} else {
value = null; // indicates a type mismatch
}
}
|
public void visitError(Error e) {
value = null; // indicates a type mismatch
}
|