List fields = enumClass.getFields();
List arrayInit = new ArrayList();
int value = -1;
Token assign = Token.newSymbol(Types.ASSIGN, -1, -1);
List block = new ArrayList();
FieldNode tempMin = null;
FieldNode tempMax = null;
for (Iterator iterator = fields.iterator(); iterator.hasNext();) {
FieldNode field = (FieldNode) iterator.next();
if ((field.getModifiers()&Opcodes.ACC_ENUM) == 0) continue;
value++;
if (tempMin == null) tempMin = field;
tempMax = field;
ClassNode enumBase = enumClass;
ArgumentListExpression args = new ArgumentListExpression();
args.addExpression(new ConstantExpression(field.getName()));
args.addExpression(new ConstantExpression(Integer.valueOf(value)));
if (field.getInitialExpression()!=null) {
ListExpression oldArgs = (ListExpression) field.getInitialExpression();
for (Iterator oldArgsIterator = oldArgs.getExpressions().iterator(); oldArgsIterator.hasNext();) {
Expression exp = (Expression) oldArgsIterator.next();
if (exp instanceof MapEntryExpression) {
String msg = "The usage of a map entry expression to initialize an Enum is currently not supported, please use an explicit map instead.";
sourceUnit.getErrorCollector().addErrorAndContinue(
new SyntaxErrorMessage(
new SyntaxException(msg + '\n', exp.getLineNumber(), exp.getColumnNumber()), sourceUnit)
);
continue;
}
InnerClassNode inner = null;
if (exp instanceof ClassExpression) {
ClassExpression clazzExp = (ClassExpression) exp;
ClassNode ref = clazzExp.getType();
if (ref instanceof EnumConstantClassNode) {
inner = (InnerClassNode) ref;
}
}
if (inner!=null) {
if (inner.getVariableScope()==null) {
enumBase = inner;
/*
* GROOVY-3985: Remove the final modifier from $INIT method in this case
* so that subclasses of enum generated for enum constants (aic) can provide
* their own $INIT method
*/
initMethod.setModifiers(initMethod.getModifiers() & ~Opcodes.ACC_FINAL);
continue;
}
}
args.addExpression(exp);
}
}
field.setInitialValueExpression(null);
block.add(
new ExpressionStatement(
new BinaryExpression(
new FieldExpression(field),
assign,