// process EnumDeclaration
if (abstractTypeDeclaration instanceof EnumDeclaration) {
EnumDeclaration enumDeclaration = (EnumDeclaration)abstractTypeDeclaration;
// is a class top level type
EnumMetadata enumMetadata = TypeMetadata.enumType(JavaMetadataUtil.getName(enumDeclaration.getName()));
processModifiersOfTypeDeclaration(enumDeclaration, enumMetadata);
// Store the enum values
List<EnumConstantDeclaration> enumValues = enumDeclaration.enumConstants();
for (EnumConstantDeclaration enumValue : enumValues) {
enumMetadata.getValues().add(enumValue.getName().getIdentifier());
}
// Enums don't have superclasses
// detect the interfaces, if any
for (Type superInterfaceType : (List<Type>)enumDeclaration.superInterfaceTypes()) {
enumMetadata.getInterfaceNames().add(getTypeName(superInterfaceType));
}
/*
* It would be nice to be able to reuse the convenience methods from AbstractTypeDeclaration,
* but they don't exist in EnumDeclaration. So we improvise!
*/
List<BodyDeclaration> bodyDecls = enumDeclaration.bodyDeclarations();
for (BodyDeclaration bodyDecl : bodyDecls) {
if (bodyDecl instanceof FieldDeclaration) {
// fields of the class top level type
FieldMetadata fieldMetadata = getFieldMetadataFrom((FieldDeclaration)bodyDecl);
enumMetadata.getFields().add(fieldMetadata);
} else if (bodyDecl instanceof MethodDeclaration) {
// methods of the class top level type
MethodMetadata methodMetadata = getMethodMetadataFrom((MethodDeclaration)bodyDecl);
enumMetadata.getMethods().add(methodMetadata);
}
}
metadata.add(enumMetadata);
}