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)); }
private JMethod addPublicSetMethod(JDefinedClass jclass, JMethod internalSetMethod) { JMethod method = jclass.method(PUBLIC, jclass.owner().VOID, SETTER_NAME); JVar nameParam = method.param(String.class, "name"); JVar valueParam = method.param(Object.class, "value"); JBlock body = method.body(); JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then(); // if we have additional properties, then put value. JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {}); if (getAdditionalProperties != null) { JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1); notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam) .arg(cast(additionalPropertiesType, valueParam))); } // else throw exception. else { notFound._throw(illegalArgumentInvocation(jclass, nameParam)); } return method; }
private JMethod addPublicWithMethod(JDefinedClass jclass, JMethod internalSetMethod) { JMethod method = jclass.method(PUBLIC, jclass, BUILDER_NAME); JVar nameParam = method.param(String.class, "name"); JVar valueParam = method.param(Object.class, "value"); JBlock body = method.body(); JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then(); // if we have additional properties, then put value. JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {}); if (getAdditionalProperties != null) { JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1); notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam) .arg(cast(additionalPropertiesType, valueParam))); } // else throw exception. else { notFound._throw(illegalArgumentInvocation(jclass, nameParam)); } body._return(_this()); return method; }
propertyConditional._then()._return(invoke(propertyGetter));
private JMethod addPublicGetMethod(JDefinedClass jclass, JMethod internalGetMethod, JFieldRef notFoundValue) { JMethod method = jclass.method(PUBLIC, jclass.owner()._ref(Object.class), GETTER_NAME); JTypeVar returnType = method.generify("T"); method.type(returnType); Models.suppressWarnings(method, "unchecked"); JVar nameParam = method.param(String.class, "name"); JBlock body = method.body(); JVar valueVar = body.decl(jclass.owner()._ref(Object.class), "value", invoke(internalGetMethod).arg(nameParam).arg(notFoundValue)); JConditional found = method.body()._if(notFoundValue.ne(valueVar)); found._then()._return(cast(returnType, valueVar)); JBlock notFound = found._else(); JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {}); if (getAdditionalProperties != null) { notFound._return(cast(returnType, invoke(getAdditionalProperties).invoke("get").arg(nameParam))); } else { notFound._throw(illegalArgumentInvocation(jclass, nameParam)); } return method; }
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; }
@Override public JExpression visitPrimitive(PrimitiveType type, JExpression param) { String kind = type.getKind().toString(); return JExpr.invoke("as" + kind.charAt(0) + kind.substring(1).toLowerCase(Locale.ENGLISH)).arg(param); }
private JInvocation inflateView(JVar inflaterParam, JVar containerParam) { // inflater.inflate(R.layout.fragment_sample, container, false); return JExpr.invoke(inflaterParam, "inflate").arg(ref.r().staticRef("layout").ref("fragment_sample")).// arg(containerParam). // arg(JExpr.FALSE); }
JExpression as(JExpression rhs, TypeMirror targetType) { return JExpr.invoke("reference").arg($dom).arg(rhs).arg(toJtype.visit(targetType, null).boxify().dotclass()); } JClass sourceType() {
public void doFindViewById(JBlock afterViewsBody, String id, JFieldVar field, JVar contentViewVar) { JFieldRef rId = ref.r().staticRef("id").ref(id); JInvocation findViewById = JExpr.invoke(contentViewVar, "findViewById").arg(rId); JExpression findViewByIdCasted = JExpr.cast(field.type(), findViewById); afterViewsBody.assign(field, findViewByIdCasted); }
private void extractArguments(JFieldVar labelTextField, JBlock methodBody) { // Bundle bundle = getArguments(); JVar bundleVar = methodBody.decl(ref.bundle(), "bundle", JExpr.invoke("getArguments")); // String label = bundle.getString("label"); JVar labelVar = methodBody.decl(ref.string(), "label", bundleVar.invoke("getString").arg("label")); // labelText.setText(label); methodBody.invoke(labelTextField, "setText").arg(labelVar); }
private void createAndInitLocationsField() { // private String[] locations; locationsField = jClass.field(JMod.PRIVATE, ref.string().array(), "locations"); // locations = getResources().getStringArray(R.array.locations); JFieldRef rArrayLocations = ref.r().staticRef("array").ref("locations"); JInvocation getResources = JExpr.invoke("getResources"); JInvocation getStringArray = getResources.invoke("getStringArray").arg(rArrayLocations); afterViewsBody.assign(locationsField, getStringArray); }
JInvocation getFragmentManagerInvoke = JExpr.invoke("getSupportFragmentManager"); JInvocation newViewPagerAdapter = JExpr._new(viewPagerAdapterClass).arg(getFragmentManagerInvoke); if (appDetails.isListNavigation() || appDetails.isTabNavigation()) { JInvocation getTabAtMethod = JExpr.invoke("getSupportActionBar").invoke("getTabAt").arg(positionVar); JVar tabVar = onPageSelectedBody.decl(ref.sTab(), "tab", getTabAtMethod); JInvocation getSupportActionBarInvoke = JExpr.invoke("getSupportActionBar"); onPageSelectedBody.invoke(getSupportActionBarInvoke, "selectTab").arg(tabVar); JInvocation getSupportActionBarInvoke = JExpr.invoke("getSupportActionBar"); onPageSelectedBody.invoke(getSupportActionBarInvoke, "setSelectedNavigationItem").arg(positionVar);
"public void onTabReselected(Tab tab, FragmentTransaction ft) {}"); JInvocation getSupportActionBar = JExpr.invoke("getSupportActionBar");
JInvocation getSupportActionbar = JExpr.invoke("getSupportActionBar"); JInvocation getContext = getSupportActionbar.invoke("getThemedContext"); JVar contextVar = configureActionBarBody.decl(ref.context(), "context", getContext);
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)); }
static private void createAggregationMethod(JDefinedClass clazz, JClass valueClazz, String name, JExpression valueExpression, String operation, JPrimitiveType type){ JMethod method = clazz.method(JMod.PUBLIC, valueClazz, name); method.annotate(Override.class); JBlock body = method.body(); body._return(JExpr._new(valueClazz).arg(valueExpression).arg(JExpr.invoke("newReport")).arg(createReportInvocation(clazz, operation, Collections.emptyList(), type))); }
public JInvocation invokeInnerMethod(JMethod method, BlockType blockType) { JInvocation invocation = JExpr.invoke(method); String methodName = getCurrentMapping().getMethodName(blockType); CodeGeneratorMethod cgm = sig.get(sig.get(methodName)); for (CodeGeneratorArgument arg : cgm) { invocation.arg(JExpr.ref(arg.getName())); } return invocation; }
static private void createGetMethod(JDefinedClass clazz, JClass valueClazz, JExpression valueExpression){ JCodeModel codeModel = clazz.owner(); JMethod method = clazz.method(JMod.PUBLIC, valueClazz, "get"); method.annotate(Override.class); method.param(codeModel.INT, "index"); JBlock body = method.body(); body._return(JExpr._new(valueClazz).arg(valueExpression).arg(JExpr.invoke("newReport"))); }
static private void createCopyMethod(JDefinedClass clazz){ JCodeModel codeModel = clazz.owner(); JClass reportClazz = codeModel.ref("org.jpmml.evaluator.Report"); JMethod method = clazz.method(JMod.PUBLIC, clazz, "copy"); method.annotate(Override.class); JBlock body = method.body(); JVar reportVariable = body.decl(reportClazz, "report", JExpr.invoke("getReport")); body._return(JExpr._new(clazz).arg(JExpr._super().ref("value")).arg(reportVariable.invoke("copy")).arg(JExpr._null())); }