Search in sources :

Example 1 with JForEach

use of com.sun.codemodel.JForEach in project jsonschema2pojo by joelittlejohn.

the class EnumRule method addQuickLookupMap.

private JFieldVar addQuickLookupMap(JDefinedClass _enum, JType backingType) {
    JClass lookupType = _enum.owner().ref(Map.class).narrow(backingType.boxify(), _enum);
    JFieldVar lookupMap = _enum.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, lookupType, "CONSTANTS");
    JClass lookupImplType = _enum.owner().ref(HashMap.class).narrow(backingType.boxify(), _enum);
    lookupMap.init(JExpr._new(lookupImplType));
    JForEach forEach = _enum.init().forEach(_enum, "c", JExpr.invoke("values"));
    JInvocation put = forEach.body().invoke(lookupMap, "put");
    put.arg(forEach.var().ref("value"));
    put.arg(forEach.var());
    return lookupMap;
}
Also used : JFieldVar(com.sun.codemodel.JFieldVar) HashMap(java.util.HashMap) JClass(com.sun.codemodel.JClass) JInvocation(com.sun.codemodel.JInvocation) JForEach(com.sun.codemodel.JForEach) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

JClass (com.sun.codemodel.JClass)1 JFieldVar (com.sun.codemodel.JFieldVar)1 JForEach (com.sun.codemodel.JForEach)1 JInvocation (com.sun.codemodel.JInvocation)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1