final FieldAccessExpr field = (FieldAccessExpr) expression;
final String fieldName = field.getField();
// Determine the type
final Expression scope = field.getScope();
NameExpr nameToFind = null;
if (scope instanceof FieldAccessExpr) {
final FieldAccessExpr fScope = (FieldAccessExpr) scope;
nameToFind = JavaParserUtils.getNameExpr(fScope.toString());
}
else if (scope instanceof NameExpr) {
nameToFind = (NameExpr) scope;
}
else {
throw new UnsupportedOperationException(
"A FieldAccessExpr for '"
+ field.getScope()
+ "' should return a NameExpr or FieldAccessExpr (was "
+ field.getScope().getClass().getName() + ")");
}
final JavaType fieldType = JavaParserUtils.getJavaType(
compilationUnitServices, nameToFind, null);
final EnumDetails enumDetails = new EnumDetails(fieldType,
new JavaSymbolName(fieldName));
return new EnumAttributeValue(annotationName, enumDetails);
}
if (expression instanceof NameExpr) {
final NameExpr field = (NameExpr) expression;
final String name = field.getName();
// As we have no way of finding out the real type
final JavaType fieldType = new JavaType("unknown.Object");
final EnumDetails enumDetails = new EnumDetails(fieldType,
new JavaSymbolName(name));
return new EnumAttributeValue(annotationName, enumDetails);