private Object createAnnotationInstance(TreeLogger logger,
Expression expression) {
Annotation annotation = (Annotation) expression;
// Determine the annotation class
TypeBinding resolvedType = annotation.resolvedType;
Class<?> classLiteral = getClassLiteral(logger, resolvedType);
if (classLiteral == null) {
return null;
}
Class<? extends java.lang.annotation.Annotation> clazz = classLiteral.asSubclass(java.lang.annotation.Annotation.class);
// Build the map of identifiers to values.
Map<String, Object> identifierToValue = new HashMap<String, Object>();
for (MemberValuePair mvp : annotation.memberValuePairs()) {
// Method name
String identifier = String.valueOf(mvp.name);
// Value
Expression expressionValue = mvp.value;
TypeBinding expectedElementValueType = mvp.binding.returnType;
Object elementValue = getAnnotationElementValue(logger,
expectedElementValueType, expressionValue);
if (elementValue == null) {
return null;
}
/*
* If the expected value is supposed to be an array then the element value
* had better be an array.
*/
assert (expectedElementValueType.isArrayType() == false || expectedElementValueType.isArrayType()
&& elementValue.getClass().isArray());
identifierToValue.put(identifier, elementValue);
}