use of com.sun.codemodel.JMethod in project jsonschema2pojo by joelittlejohn.
the class EnumRule method addValueField.
private JFieldVar addValueField(JDefinedClass _enum, JType type) {
JFieldVar valueField = _enum.field(JMod.PRIVATE | JMod.FINAL, type, VALUE_FIELD_NAME);
JMethod constructor = _enum.constructor(JMod.PRIVATE);
JVar valueParam = constructor.param(type, VALUE_FIELD_NAME);
JBlock body = constructor.body();
body.assign(JExpr._this().ref(valueField), valueParam);
return valueField;
}
use of com.sun.codemodel.JMethod in project jsonschema2pojo by joelittlejohn.
the class EnumRule method addFactoryMethod.
private void addFactoryMethod(JDefinedClass _enum, JType backingType) {
JFieldVar quickLookupMap = addQuickLookupMap(_enum, backingType);
JMethod fromValue = _enum.method(JMod.PUBLIC | JMod.STATIC, _enum, "fromValue");
JVar valueParam = fromValue.param(backingType, "value");
JBlock body = fromValue.body();
JVar constant = body.decl(_enum, "constant");
constant.init(quickLookupMap.invoke("get").arg(valueParam));
JConditional _if = body._if(constant.eq(JExpr._null()));
JInvocation illegalArgumentException = JExpr._new(_enum.owner().ref(IllegalArgumentException.class));
JExpression expr = valueParam;
// if string no need to add ""
if (!isString(backingType)) {
expr = expr.plus(JExpr.lit(""));
}
illegalArgumentException.arg(expr);
_if._then()._throw(illegalArgumentException);
_if._else()._return(constant);
ruleFactory.getAnnotator().enumCreatorMethod(fromValue);
}
use of com.sun.codemodel.JMethod in project jsonschema2pojo by joelittlejohn.
the class AdditionalPropertiesRule method addSetter.
private void addSetter(JDefinedClass jclass, JType propertyType, JFieldVar field) {
JMethod setter = jclass.method(JMod.PUBLIC, void.class, "setAdditionalProperty");
ruleFactory.getAnnotator().anySetter(setter);
JVar nameParam = setter.param(String.class, "name");
JVar valueParam = setter.param(propertyType, "value");
JInvocation mapInvocation = setter.body().invoke(JExpr._this().ref(field), "put");
mapInvocation.arg(nameParam);
mapInvocation.arg(valueParam);
}
use of com.sun.codemodel.JMethod in project jsonschema2pojo by joelittlejohn.
the class AdditionalPropertiesRule method addGetter.
private JMethod addGetter(JDefinedClass jclass, JFieldVar field) {
JMethod getter = jclass.method(JMod.PUBLIC, field.type(), "getAdditionalProperties");
ruleFactory.getAnnotator().anyGetter(getter);
getter.body()._return(JExpr._this().ref(field));
return getter;
}
use of com.sun.codemodel.JMethod in project rest.li by linkedin.
the class JavaDataTemplateGenerator method generateConstructorWithObjectArg.
private static void generateConstructorWithObjectArg(JDefinedClass cls, JVar schemaField) {
final JMethod argConstructor = cls.constructor(JMod.PUBLIC);
final JVar param = argConstructor.param(Object.class, "data");
argConstructor.body().invoke(SUPER).arg(param).arg(schemaField);
}
Aggregations