com.sun.codemodel.JBlock.directStatement()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(97)

本文整理了Java中com.sun.codemodel.JBlock.directStatement()方法的一些代码示例,展示了JBlock.directStatement()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JBlock.directStatement()方法的具体详情如下:
包路径:com.sun.codemodel.JBlock
类名称:JBlock
方法名:directStatement

JBlock.directStatement介绍

[英]Creates a "literal" statement directly.

Specified string is printed as-is. This is useful as a short-cut.

For example, you can invoke this method as: directStatement("a=b+c;").
[中]直接创建“literal”语句。
指定的字符串按原样打印。这是一条有用的捷径。
例如,您可以将此方法调用为:directStatement("a=b+c;")

代码示例

代码示例来源:origin: joelittlejohn/jsonschema2pojo

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);
    }
  }
}

代码示例来源:origin: apache/drill

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+")" : "")));

代码示例来源:origin: joelittlejohn/jsonschema2pojo

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()"))
          )
      );
    }
  }
}

代码示例来源:origin: apache/drill

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+")" : "")));

代码示例来源:origin: org.jvnet.jaxbvalidation/jaxbvalidation-core

private void onSingleOptionalField(
  final FieldItem fieldItem,
  final JExpression fieldLocator,
  final JBlock ifSet,
  final JBlock ifNotSet) {
 ifNotSet.directStatement("// Optional field - nothing to report");
}

代码示例来源:origin: org.jvnet.jaxbvalidation/jaxbvalidation-core

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;
 }
}

代码示例来源:origin: e-biz/androidkickstartr

constructorBody.directStatement("super(fm);");
} else {
  getCountMethodBody.directStatement("return 3;");
  getItemMethodBody.directStatement("bundle.putString(\"label\", locations[position]);");
} else {
  getItemMethodBody.directStatement("bundle.putString(\"label\", \"LABEL \" + position);");

代码示例来源:origin: org.jvnet.jaxbvalidation/jaxbvalidation-core

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;
}

代码示例来源:origin: org.jvnet.jaxbvalidation/jaxbvalidation-core

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;
 }
}

代码示例来源:origin: org.kuali.rice/rice-development-tools

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();");
}

代码示例来源:origin: org.jvnet.jaxbvalidation/jaxbvalidation-core

public Object onNullSet() {
 final JBlock block = JBlock.dummyInstance.block();
 block.directStatement("// NullSetExpression - nothing to check");
 return block;
}

代码示例来源:origin: org.jvnet.jaxbvalidation/jaxbvalidation-core

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;
}

代码示例来源:origin: e-biz/androidkickstartr

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);
}

代码示例来源:origin: dremio/dremio-oss

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;
}

代码示例来源:origin: net.sourceforge.ccxjc/cc-xjc-plugin

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 );
}

代码示例来源:origin: org.jvnet.jaxbvalidation/jaxbvalidation-core

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;
 }
}

代码示例来源:origin: org.jvnet.jaxbvalidation/jaxbvalidation-core

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;
 }
}

代码示例来源:origin: net.sourceforge.ccxjc/cc-xjc-plugin

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 ) );
}

代码示例来源:origin: org.jvnet.jaxbvalidation/jaxbvalidation-core

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;
}

代码示例来源:origin: org.jvnet.jaxbvalidation/jaxbvalidation-core

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;
}

相关文章