JVar superString = body.decl(jclass.owner().ref(String.class), "superString", JExpr._super().invoke("toString")); JBlock superToStringBlock = body._if(superString.ne(JExpr._null()))._then();
public void writeAs(Class cls) { JBlock block = currentBlock._if(objectVar.ne(JExpr._null()))._then(); if (cls.equals(String.class)) { writeAs(block, objectVar); } else if (cls.equals(int.class) || cls.equals(Integer.class)) { JClass jc = (JClass) model._ref(Integer.class); writeAs(block, jc.staticInvoke("toString").arg(objectVar)); } else if (cls.equals(boolean.class) || cls.equals(Boolean.class)) { JClass jc = (JClass) model._ref(Boolean.class); writeAs(block, jc.staticInvoke("toString").arg(objectVar)); } else if (cls.equals(short.class) || cls.equals(Short.class)) { JClass jc = (JClass) model._ref(Short.class); writeAs(block, jc.staticInvoke("toString").arg(objectVar)); } else if (cls.equals(double.class) || cls.equals(Double.class)) { JClass jc = (JClass) model._ref(Double.class); writeAs(block, jc.staticInvoke("toString").arg(objectVar)); } else if (cls.equals(long.class) || cls.equals(Long.class)) { JClass jc = (JClass) model._ref(Long.class); writeAs(block, jc.staticInvoke("toString").arg(objectVar)); } else if (cls.equals(float.class) || cls.equals(Float.class)) { JClass jc = (JClass) model._ref(Float.class); writeAs(block, jc.staticInvoke("toString").arg(objectVar)); } else if (cls.equals(byte.class) || cls.equals(Byte.class)) { JClass jc = (JClass) model._ref(Byte.class); writeAs(block, jc.staticInvoke("toString").arg(objectVar)); } else { throw new UnsupportedOperationException(); } }
private void createFieldReferenceSetterBody(JFieldVar field, JVar param, JBlock body) { JVar cont = body.decl(CLASS_MAP.get(PrismReferenceValue.class), REFERENCE_VALUE_FIELD_NAME, JOp.cond(param.ne(JExpr._null()), JExpr.invoke(param, METHOD_AS_REFERENCE_VALUE), JExpr._null())); JInvocation invocation = body.staticInvoke(CLASS_MAP.get(PrismForJAXBUtil.class), METHOD_PRISM_UTIL_SET_REFERENCE_VALUE_AS_REF); invocation.arg(JExpr.invoke(METHOD_AS_PRISM_CONTAINER_VALUE)); invocation.arg(JExpr.ref(fieldFPrefixUnderscoredUpperCase(field.name()))); invocation.arg(cont); }
private void writeXsiChecks(JBlock b) { if(xsiTypes.isEmpty() && unexpectedXsiType == null) { return; // no @xsi:type to look for. } b.add(new JBlankLine()); b.add(new JLineComment("Check xsi:type")); JVar xsiType = b.decl(model._ref(QName.class), "xsiType", xsrVar.invoke("getXsiType")); JConditional cond = b._if(xsiType.ne(JExpr._null())); writeXsiChecks(cond._then(), xsiType); }
private void createFieldReferenceUseSetterBody(JFieldVar field, ClassOutline classOutline, JVar param, JBlock body) { JVar cont = body.decl(CLASS_MAP.get(PrismObject.class), OBJECT_LOCAL_FIELD_NAME, JOp.cond(param.ne(JExpr._null()), JExpr.invoke(param, METHOD_AS_PRISM_CONTAINER), JExpr._null())); JInvocation invocation = body.staticInvoke(CLASS_MAP.get(PrismForJAXBUtil.class), METHOD_PRISM_UTIL_SET_REFERENCE_VALUE_AS_OBJECT); invocation.arg(JExpr.invoke(METHOD_AS_PRISM_CONTAINER_VALUE)); JFieldVar referencedField = getReferencedField(field, classOutline); invocation.arg(JExpr.ref(fieldFPrefixUnderscoredUpperCase(referencedField.name()))); invocation.arg(cont); }
static private void createConstructor(JDefinedClass clazz, ExecutableElement executableElement, boolean hasExpression){ JCodeModel codeModel = clazz.owner(); JMethod constructor = clazz.constructor(JMod.PUBLIC); List<? extends VariableElement> parameterElements = executableElement.getParameters(); for(VariableElement parameterElement : parameterElements){ constructor.param(toType(codeModel, parameterElement.asType()), String.valueOf(parameterElement.getSimpleName())); } JBlock body = constructor.body(); body.add(createSuperInvocation(clazz, constructor)); if((clazz.name()).endsWith("Value")){ JClass reportClazz = codeModel.ref("org.jpmml.evaluator.Report"); JVar reportParameter = constructor.param(reportClazz, "report"); body.add(JExpr.invoke("setReport").arg(reportParameter)); } // End if if(hasExpression){ JVar expressionParameter = constructor.param(String.class, "expression"); body._if(expressionParameter.ne(JExpr._null()))._then().add(JExpr.invoke("report").arg(expressionParameter)); } }
private void createContainerFieldSetterBody(JFieldVar field, ClassOutline classOutline, JMethod method) { JVar param = method.listParams()[0]; JBlock body = method.body(); JVar cont; if (isPrismContainer(param.type(), classOutline.parent())) { cont = body.decl(CLASS_MAP.get(PrismContainerValue.class), FIELD_CONTAINER_VALUE_LOCAL_VAR_NAME, JOp.cond(param.ne(JExpr._null()), JExpr.invoke(param, METHOD_AS_PRISM_CONTAINER_VALUE), JExpr._null())); } else { cont = body.decl(CLASS_MAP.get(PrismContainerValue.class), FIELD_CONTAINER_VALUE_LOCAL_VAR_NAME, JOp.cond(param.ne(JExpr._null()), JExpr.invoke(param, METHOD_AS_PRISM_CONTAINER_VALUE), JExpr._null())); } JInvocation invocation = body.staticInvoke(CLASS_MAP.get(PrismForJAXBUtil.class), METHOD_PRISM_UTIL_SET_FIELD_CONTAINER_VALUE); invocation.arg(JExpr.invoke(METHOD_AS_PRISM_CONTAINER_VALUE)); invocation.arg(JExpr.ref(fieldFPrefixUnderscoredUpperCase(field.name()))); invocation.arg(cont); }
private JExpression getIncludeCondition(final JVar fieldPathVar) { return JOp.cond( PartialCopyGenerator.this.propertyTreeUseParam.eq(PartialCopyGenerator.this.pluginContext.includeConst), fieldPathVar.ne(JExpr._null()), fieldPathVar.eq(JExpr._null()).cor(fieldPathVar.invoke("isLeaf").not()) ); } }
public void writeAs(Class cls, boolean nillable) { if (!cls.isPrimitive()) { JBlock block = currentBlock; JConditional cond = block._if(getObject().ne(JExpr._null())); JBlock newBlock = cond._then(); setCurrentBlock(newBlock); writeAs(cls); if (nillable) { newBlock = cond._else(); newBlock.add(xswVar.invoke("writeXsiNil")); setCurrentBlock(newBlock); } setCurrentBlock(block); } else { writeAs(cls); } }
@Override public void process(Element element, JCodeModel codeModel, EBeanHolder holder) { Classes classes = holder.classes(); String methodName = element.getSimpleName().toString(); ExecutableElement executableElement = (ExecutableElement) element; List<? extends VariableElement> parameters = executableElement.getParameters(); boolean hasViewParameter = parameters.size() == 1; List<JFieldRef> idsRefs = helper.extractAnnotationFieldRefs(holder, element, getTarget(), rClass.get(Res.ID), true); JDefinedClass onClickListenerClass = codeModel.anonymousClass(classes.VIEW_ON_CLICK_LISTENER); JMethod onClickMethod = onClickListenerClass.method(JMod.PUBLIC, codeModel.VOID, "onClick"); onClickMethod.annotate(Override.class); JVar onClickViewParam = onClickMethod.param(classes.VIEW, "view"); JExpression activityRef = holder.generatedClass.staticRef("this"); JInvocation clickCall = onClickMethod.body().invoke(activityRef, methodName); if (hasViewParameter) { clickCall.arg(onClickViewParam); } for (JFieldRef idRef : idsRefs) { JBlock block = holder.afterSetContentView.body().block(); JInvocation findViewById = invoke("findViewById"); JVar view = block.decl(classes.VIEW, "view", findViewById.arg(idRef)); block._if(view.ne(_null()))._then().invoke(view, "setOnClickListener").arg(_new(onClickListenerClass)); } }
/** * Adds call to injectFragmentArguments_() in onCreate and setIntent() * methods. */ private void injectFragmentArguments(EBeanHolder holder, JCodeModel codeModel) { Classes classes = holder.classes(); holder.fragmentArgumentsInjectMethod = holder.generatedClass.method(PRIVATE, codeModel.VOID, "injectFragmentArguments_"); injectArgumentsOnInit(holder, classes.INTENT, holder.fragmentArgumentsInjectMethod); JBlock injectArgumentsBody = holder.fragmentArgumentsInjectMethod.body(); holder.fragmentArguments = injectArgumentsBody.decl(classes.BUNDLE, "args_"); holder.fragmentArguments.init(invoke("getArguments")); holder.fragmentArgumentsNotNullBlock = injectArgumentsBody._if(holder.fragmentArguments.ne(_null()))._then(); }
block._if(view.ne(JExpr._null()))._then().invoke(view, "setOnLongClickListener").arg(JExpr._new(listenerAnonymousClass));
block._if(view.ne(_null()))._then().invoke(view, "setOnTouchListener").arg(_new(listenerClass));
JBlock body = fluentMethod.body(); JConditional cond = body._if( jvarParam.ne( JExpr._null())); JForEach forEach = cond._then()
/** * Adds call to injectExtras_() in onCreate and setIntent() methods. */ private void injectExtras(EBeanHolder holder, JCodeModel codeModel) { Classes classes = holder.classes(); JMethod injectExtrasMethod = holder.generatedClass.method(PRIVATE, codeModel.VOID, "injectExtras_"); overrideSetIntent(holder, codeModel, injectExtrasMethod); injectExtrasOnInit(holder, classes.INTENT, injectExtrasMethod); JBlock injectExtrasBody = injectExtrasMethod.body(); JVar intent = injectExtrasBody.decl(classes.INTENT, "intent_", invoke("getIntent")); holder.extras = injectExtrasBody.decl(classes.BUNDLE, "extras_"); holder.extras.init(intent.invoke("getExtras")); holder.extrasNotNullBlock = injectExtrasBody._if(holder.extras.ne(_null()))._then(); }
"clazz", _createClass(type)); JBlock block = method.body()._if(clazz.ne(JExpr._null()))._then(); block._return(_createBean(clazz)); method.body().assign(clazz, _createClass(lowerCase(type))); block = method.body()._if(clazz.ne(JExpr._null()))._then(); block._return(_createBean(clazz)); final JVar className = method.body().decl( format("{0}{1}", type, JExpr.lit(bean.name()))); method.body().assign(clazz, _createClass(className)); block = method.body()._if(clazz.ne(JExpr._null()))._then(); block._return(_createBean(clazz)); method.body().assign(className, format("{0}{1}", lowerCase(type), JExpr.lit(bean.name()))); //$NON-NLS-1$ method.body().assign(clazz, _createClass(className)); block = method.body()._if(clazz.ne(JExpr._null()))._then(); block._return(_createBean(clazz)); method.body()._return(JExpr._new(bean));
@Override public void renderMiddle(ClassGenerator<?> classGenerator, HoldingContainer[] inputVariables, JVar[] workspaceJVars) { classGenerator.getEvalBlock().directStatement(String.format("//---- start of eval portion of %s function. ----//", getRegisteredNames()[0])); JBlock sub = new JBlock(true, true); JBlock topSub = sub; JClass aggBatchClass = null; if (classGenerator.getCodeGenerator().getDefinition() == StreamingAggTemplate.TEMPLATE_DEFINITION) { aggBatchClass = classGenerator.getModel().ref(StreamingAggBatch.class); } assert aggBatchClass != null : "ComplexWriterAggFuncHolder should only be used with an Aggregate Operator"; JExpression aggBatch = JExpr.cast(aggBatchClass, classGenerator.getMappingSet().getOutgoing()); classGenerator.getSetupBlock().add(aggBatch.invoke("addComplexWriter").arg(complexWriter)); // Only set the writer if there is a position change. Calling setPosition may cause underlying writers to allocate // new vectors, thereby, losing the previously stored values JBlock condAssignCW = classGenerator.getEvalBlock()._if(lastWriterIdx.ne(writerIdx))._then(); condAssignCW.add(complexWriter.invoke("setPosition").arg(writerIdx)); condAssignCW.assign(lastWriterIdx, writerIdx); sub.decl(classGenerator.getModel()._ref(ComplexWriter.class), getReturnValue().getName(), complexWriter); // add the subblock after the out declaration. classGenerator.getEvalBlock().add(topSub); addProtectedBlock(classGenerator, sub, add(), inputVariables, workspaceJVars, false); classGenerator.getEvalBlock().directStatement(String.format("//---- end of eval portion of %s function. ----//", getRegisteredNames()[0])); }
private void generateAccessors(final FieldOutline fieldOutline, final String propertyName, final JType returnType, final JDefinedClass declaringClass, final F1<JExpression, JVar> getMaker, final F3<JExpression, JBlock, JVar, JVar> setMaker) { final String constantName = getConstantName(fieldOutline); final JMethod getMethod = declaringClass.method(JMod.PUBLIC, returnType, "get"); getMethod.annotate(Override.class); final JVar instanceParam = getMethod.param(JMod.FINAL, fieldOutline.parent().implClass, "_instance_"); getMethod.body()._return(JOp.cond(instanceParam.eq(JExpr._null()), JExpr._null(), getMaker.f(instanceParam))); final JMethod setMethod = declaringClass.method(JMod.PUBLIC, void.class, "set"); setMethod.annotate(Override.class); final JVar setInstanceParam = setMethod.param(JMod.FINAL, fieldOutline.parent().implClass, "_instance_"); final JVar valueParam = setMethod.param(JMod.FINAL, returnType, "_value_"); if (constantName == null) { final JConditional ifNotNull = setMethod.body()._if(setInstanceParam.ne(JExpr._null())); setMaker.f(ifNotNull._then(), setInstanceParam, valueParam); } }
final void generateCopyConstructor(final boolean partial) { final JMethod constructor = this.builderClass.raw.constructor(this.builderClass.raw.isAbstract() ? JMod.PROTECTED : JMod.PUBLIC); final JVar parentBuilderParam = constructor.param(JMod.FINAL, this.builderClass.typeParam, BuilderGenerator.PARENT_BUILDER_PARAM_NAME); final JVar otherParam = constructor.param(JMod.FINAL, this.typeOutline.getImplClass(), BuilderGenerator.OTHER_PARAM_NAME); final JVar copyParam = constructor.param(JMod.FINAL, this.pluginContext.codeModel.BOOLEAN, BuilderGenerator.COPY_FLAG_PARAM_NAME); final CopyGenerator cloneGenerator = this.pluginContext.createCopyGenerator(constructor, partial); if (this.typeOutline.getSuperClass() != null) { constructor.body().add(cloneGenerator.generatePartialArgs(this.pluginContext._super().arg(parentBuilderParam).arg(otherParam).arg(copyParam))); } else { constructor.body().assign(JExpr._this().ref(this.parentBuilderField), parentBuilderParam); } final JConditional ifNullStmt = constructor.body()._if(otherParam.ne(JExpr._null())); final JBlock body; if (!this.settings.isCopyAlways() && this.typeOutline.getSuperClass() == null) { final JConditional ifCopyStmt = ifNullStmt._then()._if(copyParam); ifCopyStmt._else().assign(this.storedValueField, otherParam); ifNullStmt._else().assign(this.storedValueField, JExpr._null()); body = ifCopyStmt._then(); body.assign(this.storedValueField, JExpr._null()); } else { body = ifNullStmt._then(); } generateFieldCopyExpressions(cloneGenerator, body, JExpr._this(), otherParam); }