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

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

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

JBlock._if介绍

[英]Create an If statement and add it to this block
[中]创建If语句并将其添加到此块

代码示例

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

private void addSetProperty(JDefinedClass jclass, JBlock callSite, String propertyName, JType propertyType, JVar valueVar, JsonNode node) {
  JMethod propertySetter = jclass.getMethod(getSetterName(propertyName, node), new JType[] { propertyType });
  JConditional isInstance = callSite._if(valueVar._instanceof(propertyType.boxify().erasure()));
  isInstance._then()
  .invoke(propertySetter).arg(cast(propertyType.boxify(), valueVar));
  isInstance._else()
  ._throw(illegalArgumentInvocation(jclass, propertyName, propertyType, valueVar));
}

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

JType propertyType = jclass.fields().get(fieldName).type();
JExpression condition = lit(propertyName).invoke("equals").arg(nameParam);
propertyConditional = propertyConditional == null ? propertyConditional = body._if(condition)
    : propertyConditional._elseif(condition);
JBlock callSite = propertyConditional._then();
addSetProperty(jclass, callSite, propertyName, propertyType, valueParam, node);
callSite._return(TRUE);

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

propertyConditional = body._if(condition);
} else {
  propertyConditional = propertyConditional._elseif(condition);
propertyConditional._then()._return(invoke(propertyGetter));

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

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

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

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

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

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(_enum, fromValue);
}

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

body._if(otherObject.eq(JExpr._this()))._then()._return(JExpr.TRUE);
body._if(otherObject._instanceof(jclass).eq(JExpr.FALSE))._then()._return(JExpr.FALSE);

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

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

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

sub.assign(workspaceJVars[3].component(JExpr.lit(i)), workspaceJVars[2].component(JExpr.lit(i)));
JBlock conditionalBlock = new JBlock(false, false);
JConditional jc = conditionalBlock._if(inputVariables[i].getIsSet().ne(JExpr.lit(0)));
jc._then().assign(JExpr.ref(workspaceJVars[3].component(JExpr.lit(i)), "valueHolder"), inputVariables[i].getHolder());
jc._else().assign(JExpr.ref(workspaceJVars[3].component(JExpr.lit(i)), "valueHolder"), JExpr._null());
sub.add(conditionalBlock);

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

switch(poi.getPrimitiveCategory()) {
 case BOOLEAN:{
  JConditional jc = block._if(returnValue.eq(JExpr._null()));
  jc._then().assign(returnValueHolder.ref("isSet"), JExpr.lit(0));
  jc._else().assign(returnValueHolder.ref("isSet"), JExpr.lit(1));
  JVar castedOI = jc._else().decl(
  JConditional booleanJC = jc._else()._if(castedOI.invoke("get").arg(returnValue));
  booleanJC._then().assign(returnValueHolder.ref("value"), JExpr.lit(1));
  booleanJC._else().assign(returnValueHolder.ref("value"), JExpr.lit(0));
  JConditional jc = block._if(returnValue.eq(JExpr._null()));
  jc._then().assign(returnValueHolder.ref("isSet"), JExpr.lit(0));
  jc._else().assign(returnValueHolder.ref("isSet"), JExpr.lit(1));
  JVar castedOI = jc._else().decl(
  JConditional jc = block._if(returnValue.eq(JExpr._null()));
  JConditional jc = block._if(returnValue.eq(JExpr._null()));
  JConditional jc = block._if(returnValue.eq(JExpr._null()));
  JConditional jc = block._if(returnValue.eq(JExpr._null()));
  JConditional jc = block._if(returnValue.eq(JExpr._null()));
  JConditional jc = block._if(returnValue.eq(JExpr._null()));
  JConditional jnullif = jc._else()._if(data.eq(JExpr._null()));

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

JVar superString = body.decl(jclass.owner().ref(String.class), "superString", JExpr._super().invoke("toString"));
  JBlock superToStringBlock = body._if(superString.ne(JExpr._null()))._then();
      superString.invoke("lastIndexOf").arg(JExpr.lit(']')));
  JConditional superToStringInnerConditional = superToStringBlock._if(
      contentStart.gte(JExpr.lit(0)).cand(contentEnd.gt(contentStart)));
  superToStringInnerConditional._then().add(
      sb.invoke("append")
          .arg(superString)
  body._if(sb.invoke("length").gt(baseLength))
      ._then().add(sb.invoke("append").arg(JExpr.lit(',')));
JConditional trailerConditional = body._if(
    sb.invoke("charAt").arg(sb.invoke("length").minus(JExpr.lit(1)))
        .eq(JExpr.lit(',')));

代码示例来源:origin: javaee/glassfish

protected void generate() {
  conv = createConverter(itemType);
  conv.addMetadata(xmlTokenName(),itemType);
  if(!isVariableExpansion() && toJtype.visit(itemType,null)!=cm.ref(String.class))
    printError("variableExpansion=false is only allowed on String", p.decl());
  if(!generateNoopConfigInjector) {
    JVar value = var(
      packer!=null ? cm.ref(List.class).narrow(conv.sourceType()) : conv.sourceType(),getXmlValue());
    if(!isRequired())
      body._if(value.eq(JExpr._null()))._then()._return();
    if(packer!=null)
      handleMultiValue(value);
    else
      assign(conv.as(value,itemType));
  }
  if(p.isKey())
    addKey();
}

代码示例来源:origin: javaee/glassfish

MethodGenerator(String methodNamePrefix, JMethod reinjectionMethod, Property p, String xmlName) {
  this.xmlName = p.inferName(xmlName);
  this.p = p;
  if(generateNoopConfigInjector) {
    body = null;
    $dom = null;
    $target = null;
  } else {
    JMethod m = injector.method(JMod.PUBLIC,void.class, methodNamePrefix+p.seedName());
    $dom = m.param(Dom.class,"dom");
    $target = m.param(targetType,"target");
    body = m.body();
    injectMethod.body().invoke(m).arg($dom).arg($target);
    reinjectionMethod.body()._if(JExpr.lit(this.xmlName).invoke("equals").arg(JExpr.ref("name")))
      ._then().invoke(m).arg($dom).arg($target);
  }
  erasure = erasure(p.type());
  packer = createPacker(p.type(),erasure);
  itemType = packer==null ? erasure : erasure(packer.itemType());
}

代码示例来源:origin: org.metatype.sxc/sxc-core

public ElementWriterBuilder writeElement(QName name, JExpression condition, JType type, JExpression var) {
  JConditional conditional = currentBlock._if(condition);
  JBlock block = conditional._then();
  
  return writeElement(name, type, var, block);
}

代码示例来源:origin: sun-jaxb/jaxb-xjc

/**
 * Generates statement(s) so that the successive {@link Accessor#ref(boolean)} with
 * true will always return a non-null list.
 *
 * This is useful to avoid generating redundant internal getter.
 */
protected final void fixNullRef(JBlock block) {
  block._if(field.eq(JExpr._null()))._then()
    .assign(field,newCoreList());
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-xjc

/**
 * Generates statement(s) so that the successive {@link Accessor#ref(boolean)} with
 * true will always return a non-null list.
 *
 * This is useful to avoid generating redundant internal getter.
 */
protected final void fixNullRef(JBlock block) {
  block._if(field.eq(JExpr._null()))._then()
    .assign(field,newCoreList());
}

代码示例来源:origin: sun-jaxb/jaxb-xjc

public void toRawValue(JBlock block, JVar $var) {
  // [RESULT]
  // if([core.hasSetValue])
  //   $var = [core.toRawValue].getValue();
  // else
  //   $var = null;
  JConditional cond = block._if(acc.hasSetValue());
  JVar $v = cond._then().decl(core.getRawType(), "v" + hashCode());// TODO: unique value control
  acc.toRawValue(cond._then(),$v);
  cond._then().assign($var,$v.invoke("getValue"));
  cond._else().assign($var, JExpr._null());
}

代码示例来源:origin: org.metatype.sxc/sxc-core

public void writeNilIfNull() {
  JBlock ifBlock = currentBlock;
  JConditional cond2 = ifBlock._if(getObject().eq(JExpr._null()));
  JBlock nullBlock2 = cond2._then();
  nullBlock2.add(xswVar.invoke("writeXsiNil"));
  nullBlock2._return();
}

代码示例来源:origin: net.anwiba.commons.tools/anwiba-tools-generator-bean

@Override
 public void execute(final JVar param) throws RuntimeException {
  ensureThatArgument(param, notNull());
  method.body()._if(param.eq(JExpr._null()))._then()._return(JExpr._null());
 }
};

代码示例来源:origin: javaee/metro-jax-ws

private void writeGetWsdlLocation(JType retType, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
  JMethod m = cls.method(JMod.PRIVATE|JMod.STATIC , retType, "__getWsdlLocation");
  JConditional ifBlock = m.body()._if(exField.ne(JExpr._null()));
  ifBlock._then()._throw(exField);
  m.body()._return(urlField);
}

相关文章