public void addWriteToParcel(JDefinedClass jclass) { JMethod method = jclass.method(JMod.PUBLIC, void.class, "writeToParcel"); JVar dest = method.param(jclass.owner().directClass("android.os.Parcel"), "dest"); method.param(int.class, "flags"); // Call super.writeToParcel if (extendsParcelable(jclass)) { method.body().directStatement("super.writeToParcel(dest, flags);"); } for (JFieldVar f : jclass.fields().values()) { if( (f.mods().getValue() & JMod.STATIC) == JMod.STATIC ) { continue; } if (f.type().erasure().name().equals("List")) { method.body().invoke(dest, "writeList").arg(f); } else { method.body().invoke(dest, "writeValue").arg(f); } } }
setup.directStatement(String.format("/** start %s for function %s **/ ", ClassGenerator.BlockType.SETUP.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : ""))); setup.directStatement(String.format("/** end %s for function %s **/ ", ClassGenerator.BlockType.SETUP.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : "")));
public void addConstructorFromParcel(JDefinedClass jclass) { JMethod ctorFromParcel = jclass.constructor(JMod.PROTECTED); JVar in = ctorFromParcel.param(jclass.owner().directClass("android.os.Parcel"), "in"); if (extendsParcelable(jclass)) { ctorFromParcel.body().directStatement("super(in);"); } for (JFieldVar f : jclass.fields().values()) { if( (f.mods().getValue() & JMod.STATIC) == JMod.STATIC ) { continue; } if (f.type().erasure().name().equals("List")) { ctorFromParcel.body() .invoke(in, "readList") .arg(JExpr._this().ref(f)) .arg(JExpr.direct(getListType(f.type()) + ".class.getClassLoader()")); } else { ctorFromParcel.body().assign( JExpr._this().ref(f), JExpr.cast( f.type(), in.invoke("readValue").arg(JExpr.direct(f.type().erasure().name() + ".class.getClassLoader()")) ) ); } } }
setup.directStatement(String.format("/** start %s for function %s **/ ", ClassGenerator.BlockType.EVAL.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : ""))); setup.add(sub); setup.directStatement(String.format("/** end %s for function %s **/ ", ClassGenerator.BlockType.EVAL.name(), genericUdfClazz.getName() + (!isGenericUDF ? "("+udfName+")" : "")));
private void onSingleOptionalField( final FieldItem fieldItem, final JExpression fieldLocator, final JBlock ifSet, final JBlock ifNotSet) { ifNotSet.directStatement("// Optional field - nothing to report"); }
public JStatement diagnoseByFacet(final DataTypeWithFacet datatype, final JCodeModel codeModel, final JDefinedClass theClass, final JExpression value, final JAssignmentTarget problem) { final JBlock block = newBlock(); block.directStatement("// todo: check the semantics"); block.directStatement("// WhiteSpace facet is always valid"); return block; } }
constructorBody.directStatement("super(fm);"); } else { getCountMethodBody.directStatement("return 3;"); getItemMethodBody.directStatement("bundle.putString(\"label\", locations[position]);"); } else { getItemMethodBody.directStatement("bundle.putString(\"label\", \"LABEL \" + position);");
public JStatement validate(final DatabindableDatatype datatype, final JCodeModel codeModel, final JDefinedClass theClass, final JExpression value, final JAssignmentTarget problem) { final JBlock block = newBlock(); block.directStatement("// todo: validate entity type. How?"); return block; }
public JStatement diagnoseByFacet(final DataTypeWithFacet datatype, final JCodeModel codeModel, final JDefinedClass theClass, final JExpression value, final JAssignmentTarget problem) { final JBlock block = newBlock(); block.directStatement("// todo: Check lexical constraints. How???"); return block; } }
private void renderBuilderDefaultCreate(JDefinedClass builderClass, JClass literalBuilderClass) { JMethod createMethod = builderClass.method(JMod.PUBLIC | JMod.STATIC, literalBuilderClass, "create"); JBlock createMethodBody = createMethod.body(); createMethodBody.directStatement("// TODO modify as needed to pass any required values and add them to the signature of the 'create' method"); createMethodBody.directStatement("return new Builder();"); }
public Object onNullSet() { final JBlock block = JBlock.dummyInstance.block(); block.directStatement("// NullSetExpression - nothing to check"); return block; }
public JStatement validate(final DatabindableDatatype datatype, final JCodeModel codeModel, final JDefinedClass theClass, final JExpression value, final JAssignmentTarget problem) { final JBlock block = newBlock(); block.directStatement("// Fallback type: no validation rules"); return block; }
private void addRestClient(JFieldVar textViewField) { // add annotated restClient field JFieldVar restClient = jClass.field(JMod.NONE, ref.ref(appDetails.getRestClientPackage()), "restClient"); restClient.annotate(ref.restService()); // add doSomethingElseOnUiThread method JMethod doSomethingElseOnUiThread = jClass.method(JMod.NONE, jCodeModel.VOID, "doSomethingElseOnUiThread"); doSomethingElseOnUiThread.annotate(ref.uithread()); JBlock body = doSomethingElseOnUiThread.body(); if (textViewField != null) { body.invoke(textViewField, "setText").arg("Hi!"); } else { body.directStatement("// do something on UIThread"); } // add doSomethingInBackground method JMethod doSomethingInBackground = jClass.method(JMod.NONE, jCodeModel.VOID, "doSomethingInBackground"); doSomethingInBackground.annotate(ref.background()); JBlock doSomethingInBackgroundBody = doSomethingInBackground.body(); doSomethingInBackgroundBody.invoke(restClient, "main"); doSomethingInBackgroundBody.invoke(doSomethingElseOnUiThread); }
private JBlock generateInitWorkspaceBlockHA(ClassGenerator<?> g, BlockType bt, String body, JVar[] workspaceJVars, JExpression wsIndexVariable){ JBlock initBlock = new JBlock(true, true); if(!Strings.isNullOrEmpty(body) && !body.trim().isEmpty()){ JBlock sub = new JBlock(true, true); addProtectedBlockHA(g, sub, body, null, workspaceJVars, wsIndexVariable); initBlock.directStatement(String.format("/** start %s for function %s **/ ", bt.name(), registeredNames[0])); initBlock.add(sub); initBlock.directStatement(String.format("/** end %s for function %s **/ ", bt.name(), registeredNames[0])); } return initBlock; }
private JExpression getElementCopyExpression( final FieldOutline fieldOutline, final CElementInfo type, final JBlock block, final JExpression sourceExpr ) { block.directStatement( "// CElementInfo: " + type.toType( fieldOutline.parent().parent(), Aspect.IMPLEMENTATION ).binaryName() ); return this.getCopyOfElementInfoInvocation( fieldOutline, type ).arg( sourceExpr ); }
public JStatement validate(final DatabindableDatatype datatype, final JCodeModel codeModel, final JDefinedClass theClass, final JExpression value, final JAssignmentTarget problem) { final JBlock block = newBlock(); final JConditional ifValueIsNmtoken = block._if(codeModel.ref(XmlNames.class).staticInvoke("isNmtoken").arg(value)); ifValueIsNmtoken._then().directStatement("// Value is a valid Nmtoken"); ifValueIsNmtoken._else(). assign(problem, JExpr._new(codeModel.ref(NmtokenProblem.class)).arg(value)); return block; } }
public JStatement validate(final DatabindableDatatype datatype, final JCodeModel codeModel, final JDefinedClass theClass, final JExpression value, final JAssignmentTarget problem) { final JBlock block = newBlock(); final JConditional ifValueIsName = block._if(codeModel.ref(XmlNames.class).staticInvoke("isName").arg(value)); ifValueIsName._then().directStatement("// Value is a valid Name"); ifValueIsName._else(). assign(problem, JExpr._new(codeModel.ref(NameProblem.class)).arg(value)); return block; } }
private JExpression getAdapterInfoCopyExpression( final FieldOutline fieldOutline, final CAdapterInfo type, final JBlock block, final JExpression source ) { block.directStatement( "// CAdapterInfo: " + type.toType( fieldOutline.parent().parent(), Aspect.IMPLEMENTATION ).binaryName() ); final JType jType = type.toType( fieldOutline.parent().parent(), Aspect.IMPLEMENTATION ); return JExpr.cast( jType, this.getCopyOfObjectInvocation( fieldOutline.parent() ).arg( source ) ); }
public JStatement validate(final DatabindableDatatype datatype, final JCodeModel codeModel, final JDefinedClass theClass, final JExpression value, final JAssignmentTarget problem) { final JBlock block = newBlock(); final JConditional ifIsAnyURI = block._if(codeModel.ref(org.jvnet.jaxbvalidation.util.ValidationUtils.class).staticInvoke("isAnyURI").arg(value)); ifIsAnyURI._then().directStatement("// This value is a valid URI"); ifIsAnyURI._else(). assign(problem, JExpr._new(codeModel.ref(AnyURIProblem.class)).arg(value)); return block; }
public JStatement diagnoseByFacet(final DataTypeWithFacet datatype, final JCodeModel codeModel, final JDefinedClass theClass, final JExpression value, final JAssignmentTarget problem) { final JBlock block = newBlock(); final Beholder vc = BeholderFactory.getBeholder(datatype.getConcreteType()); final JExpression length = ((DiscreteVC) vc).countLength(codeModel, value); final JExpression expectedLength = JExpr.lit(expectedLength(datatype)); final JConditional ifValueLengthIsCorrect = block._if(lengthValid(codeModel, length, expectedLength)); ifValueLengthIsCorrect._then().directStatement("// Value length is correct"); ifValueLengthIsCorrect._else(). assign(problem, JExpr._new(problemClass(codeModel)).arg(value).arg(length).arg(expectedLength)); return block; }