@Override
public Void visitEnumDeclaration(EnumDeclaration node) {
//
// Finish building the enum.
//
ClassElementImpl enumElement = (ClassElementImpl) node.getName().getStaticElement();
InterfaceType enumType = enumElement.getType();
enumElement.setSupertype(typeProvider.getObjectType());
//
// Populate the fields.
//
ArrayList<FieldElement> fields = new ArrayList<FieldElement>();
ArrayList<PropertyAccessorElement> getters = new ArrayList<PropertyAccessorElement>();
InterfaceType intType = typeProvider.getIntType();
String indexFieldName = "index";
FieldElementImpl indexField = new FieldElementImpl(indexFieldName, -1);
indexField.setFinal(true);
indexField.setSynthetic(true);
indexField.setType(intType);
fields.add(indexField);
getters.add(createGetter(indexField));
FieldElementImpl valuesField = new FieldElementImpl("values", -1);
valuesField.setStatic(true);
valuesField.setConst(true);
valuesField.setSynthetic(true);
valuesField.setType(typeProvider.getListType().substitute(new Type[] {enumType}));
fields.add(valuesField);
getters.add(createGetter(valuesField));
//
// Build the enum constants.
//
NodeList<EnumConstantDeclaration> constants = node.getConstants();
int constantCount = constants.size();
for (int i = 0; i < constantCount; i++) {
SimpleIdentifier constantName = constants.get(i).getName();
FieldElementImpl constantField = new ConstFieldElementImpl(constantName);
constantField.setStatic(true);
constantField.setConst(true);
constantField.setType(enumType);
//
// Create a value for the constant.
//
HashMap<String, DartObjectImpl> fieldMap = new HashMap<String, DartObjectImpl>();
fieldMap.put(indexFieldName, new DartObjectImpl(intType, new IntState(BigInteger.valueOf(i))));
DartObjectImpl value = new DartObjectImpl(enumType, new GenericState(fieldMap));
constantField.setEvaluationResult(new ValidResult(value));
fields.add(constantField);
getters.add(createGetter(constantField));
constantName.setStaticElement(constantField);
}
//
// Finish building the enum.
//
enumElement.setFields(fields.toArray(new FieldElement[fields.size()]));
enumElement.setAccessors(getters.toArray(new PropertyAccessorElement[getters.size()]));
// Client code isn't allowed to invoke the constructor, so we do not model it.
return super.visitEnumDeclaration(node);
}