Tabnine Logo
JExpression
Code IndexAdd Tabnine to your IDE (free)

How to use
JExpression
in
com.sun.codemodel

Best Java code snippets using com.sun.codemodel.JExpression (Showing top 20 results out of 531)

Refine searchRefine arrow

  • JBlock
  • JExpr
  • JInvocation
  • JMethod
  • JDefinedClass
  • JCodeModel
origin: joelittlejohn/jsonschema2pojo

private JMethod addInternalSetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) {
  JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME);
  JVar nameParam = method.param(String.class, "name");
  JVar valueParam = method.param(Object.class, "value");
  JBlock body = method.body();
  JSwitch propertySwitch = body._switch(nameParam);
  if (propertiesNode != null) {
    for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
      Map.Entry<String, JsonNode> property = properties.next();
      String propertyName = property.getKey();
      JsonNode node = property.getValue();
      String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
      JType propertyType = jclass.fields().get(fieldName).type();
      addSetPropertyCase(jclass, propertySwitch, propertyName, propertyType, valueParam, node);
    }
  }
  JBlock defaultBlock = propertySwitch._default().body();
  JClass extendsType = jclass._extends();
  if (extendsType != null && extendsType instanceof JDefinedClass) {
    JDefinedClass parentClass = (JDefinedClass) extendsType;
    JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME,
        new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
    defaultBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam));
  } else {
    defaultBlock._return(FALSE);
  }
  return method;
}
origin: joelittlejohn/jsonschema2pojo

private void addBuilder(JDefinedClass jclass, JType propertyType, JFieldVar field) {
  JMethod builder = jclass.method(JMod.PUBLIC, jclass, "withAdditionalProperty");
  JVar nameParam = builder.param(String.class, "name");
  JVar valueParam = builder.param(propertyType, "value");
  JBlock body = builder.body();
  JInvocation mapInvocation = body.invoke(JExpr._this().ref(field), "put");
  mapInvocation.arg(nameParam);
  mapInvocation.arg(valueParam);
  body._return(JExpr._this());
}
origin: joelittlejohn/jsonschema2pojo

private void addEquals(JDefinedClass jclass, JsonNode node) {
  Map<String, JFieldVar> fields = removeFieldsExcludedFromEqualsAndHashCode(jclass.fields(), node);
  JMethod equals = jclass.method(JMod.PUBLIC, boolean.class, "equals");
  JVar otherObject = equals.param(Object.class, "other");
  JBlock body = equals.body();
  body._if(otherObject.eq(JExpr._this()))._then()._return(JExpr.TRUE);
  body._if(otherObject._instanceof(jclass).eq(JExpr.FALSE))._then()._return(JExpr.FALSE);
  JVar rhsVar = body.decl(jclass, "rhs").init(JExpr.cast(jclass, otherObject));
  JExpression result = JExpr.lit(true);
  if (!jclass._extends().fullName().equals(Object.class.getName())) {
    result = result.cand(JExpr._super().invoke("equals").arg(rhsVar));
      fieldEquals = jclass.owner().ref(Arrays.class).staticInvoke("equals").arg(thisFieldRef).arg(otherFieldRef);
    } else {
      fieldEquals = thisFieldRef.eq(otherFieldRef).cor(
          thisFieldRef.ne(JExpr._null())
              .cand(thisFieldRef.invoke("equals").arg(otherFieldRef)));
    result = result.cand(fieldEquals);
  body._return(result);
  equals.annotate(Override.class);
origin: joelittlejohn/jsonschema2pojo

private void addToString(JDefinedClass _enum, JFieldVar valueField) {
  JMethod toString = _enum.method(JMod.PUBLIC, String.class, "toString");
  JBlock body = toString.body();
  JExpression toReturn = JExpr._this().ref(valueField);
  if(!isString(valueField.type())){
    toReturn = toReturn.plus(JExpr.lit(""));
  }
  body._return(toReturn);
  toString.annotate(Override.class);
}
origin: joelittlejohn/jsonschema2pojo

private void addHashCode(JDefinedClass jclass, JsonNode node) {
  Map<String, JFieldVar> fields = removeFieldsExcludedFromEqualsAndHashCode(jclass.fields(), node);
  JMethod hashCode = jclass.method(JMod.PUBLIC, int.class, "hashCode");
  JBlock body = hashCode.body();
  JVar result = body.decl(jclass.owner().INT, "result", JExpr.lit(1));
    JFieldRef fieldRef = JExpr.refthis(fieldVar.name());
        fieldHash = fieldRef;
      } else if ("double".equals(fieldVar.type().name())) {
        JClass doubleClass = jclass.owner().ref(Double.class);
        JExpression longField = doubleClass.staticInvoke("doubleToLongBits").arg(fieldRef);
        fieldHash = JExpr.cast(jclass.owner().INT,
            longField.xor(longField.shrz(JExpr.lit(32))));
      } else if ("float".equals(fieldVar.type().name())) {
        fieldHash = jclass.owner().ref(Float.class).staticInvoke("floatToIntBits").arg(fieldRef);
      } else {
        fieldHash = JExpr.cast(jclass.owner().INT, fieldRef);
    body.assign(result, result.mul(JExpr.lit(31)).plus(fieldHash));
  if (!jclass._extends().fullName().equals(Object.class.getName())) {
    body.assign(result, result.mul(JExpr.lit(31)).plus(JExpr._super().invoke("hashCode")));
  body._return(result);
  hashCode.annotate(Override.class);
origin: org.glassfish.metro/webservices-tools

public void generateAccessors() {
  body = $getAll.body();
  body._if( acc.ref(true).eq(JExpr._null()) )._then()
    ._return(JExpr.newArray(exposedType,0));
  JVar var = body.decl(exposedType.array(), "retVal", JExpr.newArray(implType,acc.ref(true).ref("length")));
  body.add(codeModel.ref(System.class).staticInvoke("arraycopy")
          .arg(acc.ref(true)).arg(JExpr.lit(0))
          .arg(var)
          .arg(JExpr.lit(0)).arg(acc.ref(true).ref("length")));
  body._return(JExpr.direct("retVal"));
  $get.body()._if(acc.ref(true).eq(JExpr._null()))._then()
    ._throw(JExpr._new(codeModel.ref(IndexOutOfBoundsException.class)));
  $get.body()._return(acc.ref(true).component($idx));
  $getLength.body()._if(acc.ref(true).eq(JExpr._null()))._then()
      ._return(JExpr.lit(0));
  $getLength.body()._return(acc.ref(true).ref("length"));
  _for.test( JOp.lt($i,$len) );
  _for.update( $i.incr() );
  _for.body().assign(acc.ref(true).component($i), castToImplType(acc.box($value.component($i))));
  body = $set.body();
  body._return( JExpr.assign(acc.ref(true).component($idx),
                castToImplType(acc.box($value))));
origin: joelittlejohn/jsonschema2pojo

JBlock body = toString.body();
JClass stringBuilderClass = jclass.owner().ref(StringBuilder.class);
JVar sb = body.decl(stringBuilderClass, "sb", JExpr._new(stringBuilderClass));
body.add(sb
    .invoke("append").arg(jclass.dotclass().invoke("getName"))
    .invoke("append").arg(JExpr.lit('@'))
    .invoke("append").arg(
        jclass.owner().ref(Integer.class).staticInvoke("toHexString").arg(
            jclass.owner().ref(System.class).staticInvoke("identityHashCode").arg(JExpr._this())))
    .invoke("append").arg(JExpr.lit('[')));
if (!jclass._extends().fullName().equals(Object.class.getName())) {
  JVar baseLength = body.decl(jclass.owner().INT, "baseLength", sb.invoke("length"));
  JVar superString = body.decl(jclass.owner().ref(String.class), "superString", JExpr._super().invoke("toString"));
  JBlock superToStringBlock = body._if(superString.ne(JExpr._null()))._then();
  JConditional superToStringInnerConditional = superToStringBlock._if(
      contentStart.gte(JExpr.lit(0)).cand(contentEnd.gt(contentStart)));
  superToStringInnerConditional._then().add(
body._return(sb.invoke("toString"));
toString.annotate(Override.class);
origin: bonitasoft/bonita-engine

public JMethod addListSetter(final JDefinedClass definedClass, final JFieldVar field) {
  final JMethod method = definedClass.method(JMod.PUBLIC, Void.TYPE, getSetterName(field));
  method.param(field.type(), field.name());
  final JFieldRef thisField = JExpr._this().ref(field.name());
  final JConditional ifListIsNull = method.body()._if(thisField.eq(JExpr._null()));
  ifListIsNull._then().assign(JExpr._this().ref(field.name()), JExpr.ref(field.name()));
  final JBlock elseBlock = ifListIsNull._else();
  final JVar copyVar = elseBlock.decl(field.type(), "copy", JExpr._new(getModel().ref(ArrayList.class)).arg(field));
  elseBlock.invoke(JExpr._this().ref(field.name()), "clear");
  elseBlock.invoke(JExpr._this().ref(field.name()), "addAll").arg(copyVar);
  return method;
}
origin: org.jvnet.jaxb2_commons/basic

protected JMethod generateObject$Equals(final ClassOutline classOutline,
    final JDefinedClass theClass) {
  final JMethod objectEquals = theClass.method(JMod.PUBLIC, theClass
      .owner().BOOLEAN, "equals");
  {
    final JVar object = objectEquals.param(Object.class, "object");
    final JBlock body = objectEquals.body();
    body._if(JOp.not(object._instanceof(theClass)))._then()._return(
        JExpr.FALSE);
    body._if(JExpr._this().eq(object))._then()._return(JExpr.TRUE);
    final JVar equalsBuilder = body.decl(JMod.FINAL, theClass.owner()
        .ref(EqualsBuilder.class), "equalsBuilder", JExpr
        ._new(theClass.owner().ref(getEqualsBuilderClass())));
    body.invoke("equals").arg(object).arg(equalsBuilder);
    body._return(equalsBuilder.invoke("isEquals"));
  }
  return objectEquals;
}
origin: com.sun.xml.ws/jaxws-tools

private void writeResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
  JBlock staticBlock = cls.init();
  staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(wsdlLocation));
  JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
  JConditional ifBlock = staticBlock._if(urlField.eq(JExpr._null()));
  ifBlock._then().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(
      "Cannot find "+JExpr.quotify('\'', wsdlLocation)+" wsdl. Place the resource correctly in the classpath."));
  staticBlock.assign(exField, exVar);
}
origin: com.github.vsspt/jaxb-ri-xjc

private void createEqualsMethod(final JDefinedClass implClass, final List<JFieldVar> fields, final boolean isSuperClass) {
 final JMethod method = implClass.method(JMod.PUBLIC, implClass.owner().BOOLEAN, OPERATION_EQUALS);
 method.annotate(Override.class);
 final JVar vObj = method.param(Object.class, OBJ);
 final JConditional condMe = method.body()._if(JExpr._this().eq(vObj));
 condMe._then()._return(JExpr.TRUE);
 final JConditional condNull = method.body()._if(vObj.eq(JExpr._null()));
 condNull._then()._return(JExpr.FALSE);
 if (isSuperClass) {
  final JConditional condSuper = method.body()._if(JExpr._super().invoke(OPERATION_EQUALS).arg(vObj).eq(JExpr.FALSE));
  condSuper._then()._return(JExpr.FALSE);
 }
 final JVar vOther = method.body().decl(JMod.FINAL, implClass, OTHER, JExpr.cast(implClass, vObj));
 final JClass objectsClass = implClass.owner().ref(Objects.class);
 final List<JFieldVar> clonedList = new ArrayList<JFieldVar>(fields.size());
 clonedList.addAll(fields);
 final JFieldVar first = clonedList.remove(IDX_TO_REMOVE);
 final JBlock block = new JBlock();
 JExpression invocation = block.staticInvoke(objectsClass, OPERATION_EQUALS).arg(JExpr.ref(first.name())).arg(vOther.ref(first.name()));
 for (final JFieldVar jFieldVar : clonedList) {
  invocation = JOp.cand(invocation, block.staticInvoke(objectsClass, OPERATION_EQUALS).arg(JExpr.ref(jFieldVar.name())).arg(vOther.ref(jFieldVar.name())));
 }
 method.body()._return(invocation);
}
origin: e-biz/androidkickstartr

public JCodeModel generate(JCodeModel jCodeModel, RefHelper ref) throws IOException {
  try {
    jClass = jCodeModel._class(appDetails.getViewPagerAdapterPackage());
    jClass._extends(ref.fragmentPagerAdapter());
    if (hasLocationsField) {
      locationsField = jClass.field(JMod.PRIVATE, ref.string().array(), "locations");
    JBlock constructorBody = constructor.body();
    constructorBody.directStatement("super(fm);");
      constructorBody.assign(JExpr._this().ref("locations"), locationsField);
    if (hasLocationsField) {
      getCountMethodBody._return(locationsField.ref("length"));
    } else {
    JVar fragmentVar = getItemMethodBody.decl(ref.fragment(), "fragment", JExpr._new(ref.ref(sampleFragmentPackage)));
    JVar bundleVar = getItemMethodBody.decl(ref.bundle(), "bundle", JExpr._new(ref.bundle()));
    getItemMethodBody.invoke(fragmentVar, "setArguments").arg(bundleVar);
origin: fusesource/fuse-extra

private void generateEquals() {
  equalsGeneric = cls().method(JMod.PUBLIC, cm.BOOLEAN, "equals");
  equalsGeneric.param(cm.ref("java.lang.Object"), "other");
  equalsGeneric.body().block()._if(_this().eq(ref("other")))
      ._then()
      ._return(TRUE);
  equalsGeneric.body().block()._if(
      ref("other").eq(_null())
          .cor((ref("other")._instanceof(cls()).not())))
      ._then()
      ._return(FALSE);
  equalsGeneric.body().block()._return(_this().invoke("equals").arg(cast(cls(), ref("other"))));
  equalsTypeSpecific = cls().method(JMod.PUBLIC, cm.BOOLEAN, "equals");
  equalsTypeSpecific.param(cls(), "other");
  equalsTypeSpecific.body().block()._if(ref("other").eq(_null()))._then()._return(FALSE);
  JConditional test = equalsTypeSpecific.body().block()._if(_this().ref("value").eq(_null()).cand(ref("other").invoke("getValue").ne(_null())));
  test._then().block()._return(FALSE);
  JConditional test2 = test._elseif(_this().ref("value").ne(_null()).cand(ref("other").invoke("getValue").eq(_null())));
  test2._then().block()._return(FALSE);
  JConditional test3 = test2._elseif(_this().ref("value").eq(_null()).cand(ref("other").invoke("getValue").eq(_null())));
  test3._then().block()._return(TRUE);
  test3._else().block()._return(_this().ref("value").invoke("equals").arg(ref("other").invoke("getValue")));
}
origin: dremio/dremio-oss

JExpression indexVariable = generator.getMappingSet().getValueReadIndex();
JExpression componentVariable = indexVariable.shrz(JExpr.lit(16));
if (e.isSuperReader()) {
 vv1 = (vv1.component(componentVariable));
 indexVariable = indexVariable.band(JExpr.lit((int) Character.MAX_VALUE));
 JExpression vector = e.isSuperReader() ? vv1.component(componentVariable) : vv1;
 JExpression expr = vector.invoke("getReader");
 PathSegment seg = e.getReadPath();
 eval.add(expr.invoke("reset"));
 eval.add(expr.invoke("setPosition").arg(indexVariable));
 int listNum = 0;
   JVar list = generator.declareClassField("list", generator.getModel()._ref(FieldReader.class));
       .cand(list.invoke("next"))).body().assign(currentIndex, currentIndex.plus(JExpr.lit(1)));
   expr = expr.invoke("reader").arg(fieldName);
  JVar complexReader = generator.declareClassField("reader", generator.getModel()._ref(FieldReader.class));
 } else {
  if (seg != null) {
   eval.add(expr.invoke("read").arg(JExpr.lit(seg.getArraySegment().getIndex())).arg(out.getHolder()));
  } else {
   eval.add(expr.invoke("read").arg(out.getHolder()));
origin: org.jvnet.hyperjaxb3/hyperjaxb3-tools

protected JMethod generateEquals$Equals(ClassOutline classOutline, final JDefinedClass theClass) {
 ClassUtils._implements(theClass, theClass.owner().ref(Equals.class));
 final JMethod equals = theClass.method(JMod.PUBLIC, theClass.owner().VOID, "equals");
  final JBlock body = equals.body();
  final JVar object = equals.param(Object.class, "object");
  final JVar equalsBuilder = equals.param(EqualsBuilder.class, "equalsBuilder");
  final JConditional ifNotInstanceof = body._if(JOp.not(object._instanceof(theClass)));
  ifNotInstanceof._then().invoke(equalsBuilder, "appendSuper").arg(JExpr.FALSE);
  ifNotInstanceof._then()._return();
  body._if(JExpr._this().eq(object))._then()._return();
   body.invoke(JExpr._super(), "equals").arg(object).arg(equalsBuilder);
  final JVar rhs = body.decl(JMod.FINAL, theClass, "rhs", JExpr.cast(theClass, object));
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: fusesource/fuse-extra

private void generateToString() {
  toString = cls().method(JMod.PUBLIC, cm.ref("java.lang.String"), "toString");
  toString.body()._return(ref("this").invoke("toString").arg(lit("")));
  JMethod toString2 = cls().method(JMod.PUBLIC, cm.ref("java.lang.String"), "toString");
  toString2.param(String.class, "indent");
  toString2.body()._if(_this().ref("value").eq(_null()))._then().block()._return(lit("null"));
  if ( type.getName().equals("array") ) {
    toString2.body()._return(cm.ref("java.util.Arrays").staticInvoke("toString").arg(_this().ref("value")));
  } else {
    toString2.body()._return(_this().ref("value").invoke("toString"));
  }
}
origin: com.linkedin.pegasus/restli-tools

private static void generateQueryParamSetMethod(JDefinedClass derivedBuilderClass, ParameterSchema param, JClass paramClass, JClass paramItemsClass)
{
 final String paramName = param.getName();
 final boolean isOptional = RestLiToolsUtils.isParameterOptional(param);
 final String methodName = RestLiToolsUtils.nameCamelCase(paramName + "Param");
 final JMethod setMethod = derivedBuilderClass.method(JMod.PUBLIC, derivedBuilderClass, methodName);
 final JVar setMethodParam = setMethod.param(paramClass, "value");
 setMethod.body().add(JExpr._super().invoke(isOptional ? "setParam" : "setReqParam").arg(paramName).arg(setMethodParam).arg(paramItemsClass.dotclass()));
 setMethod.body()._return(JExpr._this());
 generateParamJavadoc(setMethod, setMethodParam, param);
}
origin: jpmml/jpmml-evaluator

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()));
}
origin: net.anwiba.commons.tools/anwiba-tools-generator-bean

 public void createEquals(final JDefinedClass bean, final Iterable<JFieldVar> fields) {
  final JMethod method = bean.method(JMod.PUBLIC, this.codeModel.BOOLEAN, "equals");
  method.annotate(java.lang.Override.class);
  final JVar object = method.param(_type(java.lang.Object.class.getName()), "object");
  final JBlock block = method.body();
  block._if(JExpr._this().eq(object))._then()._return(JExpr.TRUE);
  block._if(object._instanceof(bean).not())._then()._return(JExpr.FALSE);
  JExpression result = JExpr.TRUE;
  final JExpression other = block.decl(bean, "other", JExpr.cast(bean, object));
  final JClass objectUtilities = _classByNames(net.anwiba.commons.lang.object.ObjectUtilities.class.getName());
  for (final JFieldVar field : fields) {
   result =
     result.cand(objectUtilities.staticInvoke("equals").arg(JExpr.refthis(field.name())).arg(other.ref(field)));
  }
  block._return(result);
 }
}
com.sun.codemodelJExpression

Javadoc

A Java expression.

Unlike most of CodeModel, JExpressions are built bottom-up ( meaning you start from leaves and then gradually build compliated expressions by combining them.)

JExpression defines a series of composer methods, which returns a complicated expression (by often taking other JExpressions as parameters. For example, you can build "5+2" by JExpr.lit(5).add(JExpr.lit(2))

Most used methods

  • invoke
    Returns "[this].[method]". Arguments shall be added to the returned JInvocation object.
  • ref
  • eq
  • cand
    Logical AND '&&'.
  • component
  • ne
  • cor
    Logical OR '||'.
  • not
    Returns "![this]" from "[this]".
  • plus
    Returns "[this]+[right]"
  • _instanceof
    Returns "[this] instanceof [right]"
  • shrz
    Returns " [this]>>>[right]"
  • band
    Bit-wise AND '&'.
  • shrz,
  • band,
  • mul,
  • generate,
  • xor

Popular in Java

  • Finding current android device location
  • getSupportFragmentManager (FragmentActivity)
  • setContentView (Activity)
  • runOnUiThread (Activity)
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now