private void addSetPropertyCase(JDefinedClass jclass, JSwitch setterSwitch, String propertyName, JType propertyType, JVar valueVar, JsonNode node) { JBlock setterBody = setterSwitch._case(lit(propertyName)).body(); addSetProperty(jclass, setterBody, propertyName, propertyType, valueVar, node); setterBody._return(TRUE); }
private JMethod addInternalGetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) { JMethod method = jclass.method(PROTECTED, jclass.owner()._ref(Object.class), DEFINED_GETTER_NAME); JVar nameParam = method.param(String.class, "name"); JVar notFoundParam = method.param(jclass.owner()._ref(Object.class), "notFoundValue"); JBlock body = method.body(); JSwitch propertySwitch = body._switch(nameParam); if (propertiesNode != null) { for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) { Map.Entry<String, JsonNode> property = properties.next(); String propertyName = property.getKey(); JsonNode node = property.getValue(); String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node); JType propertyType = jclass.fields().get(fieldName).type(); addGetPropertyCase(jclass, propertySwitch, propertyName, propertyType, node); } } JClass extendsType = jclass._extends(); if (extendsType != null && extendsType instanceof JDefinedClass) { JDefinedClass parentClass = (JDefinedClass) extendsType; JMethod parentMethod = parentClass.getMethod(DEFINED_GETTER_NAME, new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) }); propertySwitch._default().body() ._return(_super().invoke(parentMethod).arg(nameParam).arg(notFoundParam)); } else { propertySwitch._default().body() ._return(notFoundParam); } return method; }
/** * Create a switch/case statement and add it to this block */ public JSwitch _switch(JExpression test) { return insert(new JSwitch(test)); }
staticReadSwitchBlock._case(generator.registry().cls().staticRef("NULL_FORMAT_CODE")).body()._return(cast(getJavaType(), generator.registry().cls() .staticInvoke("instance") .invoke("encoder") writeBodySwitchBlock._case(generator.registry().cls().staticRef("NULL_FORMAT_CODE")).body()._break(); readSwitchBlock._case(ref(staticCodeFieldName)).body() .assign(_this().ref("value"), generator.registry().cls() ._break(); staticReadSwitchBlock._case(ref(staticCodeFieldName)).body() ._return(generator.registry().cls() .staticInvoke("instance") .arg(ref("in"))); writeBodySwitchBlock._case(ref(staticCodeFieldName)).body() .add(generator.registry().cls().staticInvoke("instance") .invoke("encoder") readSwitchBlock._default().body()._throw(_new(cm.ref(Exception.class)).arg(lit("Unknown format code for " + type.getName() + " : 0x").plus(cm.ref("java.lang.String").staticInvoke("format").arg("%x").arg(ref("formatCode"))))); staticReadSwitchBlock._default().body()._throw(_new(cm.ref(Exception.class)).arg(lit("Unknown format code for " + type.getName() + " : 0x").plus(cm.ref("java.lang.String").staticInvoke("format").arg("%x").arg(ref("formatCode"))))); writeBodySwitchBlock._default().body()._throw(_new(cm.ref(Exception.class)).arg(lit("Unknown format code for " + type.getName() + " : 0x").plus(cm.ref("java.lang.String").staticInvoke("format").arg("%x").arg(ref("formatCode")))));
/** * Create a switch/case statement and add it to this block */ public JSwitch _switch(JExpression test) { return insert(new JSwitch(test)); }
private void addGetPropertyCase(JDefinedClass jclass, JSwitch propertySwitch, String propertyName, JType propertyType, JsonNode node) { JMethod propertyGetter = jclass.getMethod(getGetterName(propertyName, propertyType, node), new JType[] {}); propertySwitch._case(lit(propertyName)).body() ._return(invoke(propertyGetter)); }
JSwitch switchExpr = loop.body()._switch(fieldNameVar); JCase idCase = switchExpr._case(JExpr.lit("id")); JInvocation idValue = JExpr._new(uriImplType).arg(jsonParser.invoke("getValueAsString")); idCase.body().add(jsonParser.invoke("nextToken")); JCase typeCase = switchExpr._case(JExpr.lit("type")); typeCase.body().add(jsonParser.invoke("nextToken")); typeCase.body().assign(pojoVar, JExpr.invoke("parseType").arg(jsonParser)); switchExpr._default().body().add(JExpr.invoke("skipField").arg(jsonParser)); loop.body().add(jsonParser.invoke("nextToken")); if (anySubclass) {
/** * Create a switch/case statement and add it to this block */ public JSwitch _switch(JExpression test) { return insert(new JSwitch(test)); }
private JMethod addInternalSetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) { JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME); JVar nameParam = method.param(String.class, "name"); JVar valueParam = method.param(Object.class, "value"); JBlock body = method.body(); JSwitch propertySwitch = body._switch(nameParam); if (propertiesNode != null) { for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) { Map.Entry<String, JsonNode> property = properties.next(); String propertyName = property.getKey(); JsonNode node = property.getValue(); String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node); JType propertyType = jclass.fields().get(fieldName).type(); addSetPropertyCase(jclass, propertySwitch, propertyName, propertyType, valueParam, node); } } JBlock defaultBlock = propertySwitch._default().body(); JClass extendsType = jclass._extends(); if (extendsType != null && extendsType instanceof JDefinedClass) { JDefinedClass parentClass = (JDefinedClass) extendsType; JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME, new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) }); defaultBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam)); } else { defaultBlock._return(FALSE); } return method; }
private void addSetPropertyCase(JDefinedClass jclass, JSwitch setterSwitch, String propertyName, JType propertyType, JVar valueVar, JsonNode node) { JBlock setterBody = setterSwitch._case(lit(propertyName)).body(); addSetProperty(jclass, setterBody, propertyName, propertyType, valueVar, node); setterBody._return(TRUE); }
/** * Create a switch/case statement and add it to this block */ public JSwitch _switch(JExpression test) { return insert(new JSwitch(test)); }
private JMethod addInternalGetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) { JMethod method = jclass.method(PROTECTED, jclass.owner()._ref(Object.class), DEFINED_GETTER_NAME); JVar nameParam = method.param(String.class, "name"); JVar notFoundParam = method.param(jclass.owner()._ref(Object.class), "notFoundValue"); JBlock body = method.body(); JSwitch propertySwitch = body._switch(nameParam); if (propertiesNode != null) { for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) { Map.Entry<String, JsonNode> property = properties.next(); String propertyName = property.getKey(); JsonNode node = property.getValue(); String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node); JType propertyType = jclass.fields().get(fieldName).type(); addGetPropertyCase(jclass, propertySwitch, propertyName, propertyType, node); } } JClass extendsType = jclass._extends(); if (extendsType != null && extendsType instanceof JDefinedClass) { JDefinedClass parentClass = (JDefinedClass) extendsType; JMethod parentMethod = parentClass.getMethod(DEFINED_GETTER_NAME, new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) }); propertySwitch._default().body() ._return(_super().invoke(parentMethod).arg(nameParam).arg(notFoundParam)); } else { propertySwitch._default().body() ._return(notFoundParam); } return method; }
private void addGetPropertyCase(JDefinedClass jclass, JSwitch propertySwitch, String propertyName, JType propertyType, JsonNode node) { JMethod propertyGetter = jclass.getMethod(getGetterName(propertyName, propertyType, node), new JType[] {}); propertySwitch._case(lit(propertyName)).body() ._return(invoke(propertyGetter)); }
/** * Create a switch/case statement and add it to this block */ public JSwitch _switch(JExpression test) { return insert(new JSwitch(test)); }
private JMethod addInternalSetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) { JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME); JVar nameParam = method.param(String.class, "name"); JVar valueParam = method.param(Object.class, "value"); JBlock body = method.body(); JSwitch propertySwitch = body._switch(nameParam); if (propertiesNode != null) { for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) { Map.Entry<String, JsonNode> property = properties.next(); String propertyName = property.getKey(); JsonNode node = property.getValue(); String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node); JType propertyType = jclass.fields().get(fieldName).type(); addSetPropertyCase(jclass, propertySwitch, propertyName, propertyType, valueParam, node); } } JBlock defaultBlock = propertySwitch._default().body(); JClass extendsType = jclass._extends(); if (extendsType != null && extendsType instanceof JDefinedClass) { JDefinedClass parentClass = (JDefinedClass) extendsType; JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME, new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) }); defaultBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam)); } else { defaultBlock._return(FALSE); } return method; }
JCase onActivityResultCase = onActivityResultSwitch._case(JExpr.lit(requestCode));
literalSwitch._case(JExpr.lit(classId.stringValue())); Namespace ns = nsManager.findByName(classId.getNamespace()); if (ns != null) { builder.append(':'); builder.append(classId.getLocalName()); literalSwitch._case(JExpr.lit(builder.toString())); JCase caseBlock = literalSwitch._case(JExpr.lit(classId.getLocalName())); JVar subclassCode = dc.fields().get(codeName); JCase codeCase = codeSwitch._case(subclassCode); JDefinedClass reader = produceJsonReader(subclass, model);