modifiers.setFinal(true);
modifiers.makePrivate();
jField.setModifiers(modifiers);
jEnum.addField(jField);
JMethod valueMethod = new JMethod("value", new JClass("java.lang.String"),
"the value of this constant");
valueMethod.setSourceCode("return this.value;");
jEnum.addMethod(valueMethod, false);
JMethod fromValueMethod = new JMethod("fromValue", jEnum, "the constant for this value");
fromValueMethod.addParameter(new JParameter(new JClass("java.lang.String"), "value"));
JSourceCode sourceCode = new JSourceCode();
sourceCode.add("for (" + jEnum.getLocalName() + " c: "
+ jEnum.getLocalName() + ".values()) {");
sourceCode.indent();
sourceCode.add("if (c.value.equals(value)) {");
sourceCode.indent();
sourceCode.add("return c;");
sourceCode.unindent();
sourceCode.add("}");
sourceCode.unindent();
sourceCode.add("}");
sourceCode.add("throw new IllegalArgumentException(value);");
fromValueMethod.setSourceCode(sourceCode);
modifiers = new JModifiers();
modifiers.setStatic(true);
fromValueMethod.setModifiers(modifiers);
jEnum.addMethod(fromValueMethod, false);
JMethod setValueMethod = new JMethod("setValue");
setValueMethod.addParameter(new JParameter(new JClass("java.lang.String"), "value"));
jEnum.addMethod(setValueMethod, false);
JMethod toStringMethod = new JMethod("toString",
new JClass("java.lang.String"), "the value of this constant");
toStringMethod.setSourceCode("return this.value;");
jEnum.addMethod(toStringMethod, false);
JConstructor constructor = jEnum.createConstructor();
constructor.addParameter(new JParameter(new JClass("java.lang.String"), "value"));
constructor.setSourceCode("this.value = value;");