Tabnine Logo
com.sun.codemodel
Code IndexAdd Tabnine to your IDE (free)

How to use com.sun.codemodel

Best Java code snippets using com.sun.codemodel (Showing top 20 results out of 1,071)

origin: joelittlejohn/jsonschema2pojo

private JFieldVar addQuickLookupMap(JDefinedClass _enum, JType backingType) {
  JClass lookupType = _enum.owner().ref(Map.class).narrow(backingType.boxify(), _enum);
  JFieldVar lookupMap = _enum.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, lookupType, "CONSTANTS");
  JClass lookupImplType = _enum.owner().ref(HashMap.class).narrow(backingType.boxify(), _enum);
  lookupMap.init(JExpr._new(lookupImplType));
  JForEach forEach = _enum.init().forEach(_enum, "c", JExpr.invoke("values"));
  JInvocation put = forEach.body().invoke(lookupMap, "put");
  put.arg(forEach.var().ref("value"));
  put.arg(forEach.var());
  return lookupMap;
}
origin: joelittlejohn/jsonschema2pojo

private JInvocation illegalArgumentInvocation(JDefinedClass jclass, String propertyName, JType propertyType, JVar valueVar) {
  return _new(jclass.owner()._ref(IllegalArgumentException.class))
      .arg(lit("property \"" + propertyName + "\" is of type \"" + propertyType.fullName() + "\", but got ")
          .plus(valueVar.invoke("getClass").invoke("toString")));
}
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 addOverrideBuilder(JDefinedClass thisJDefinedClass, JMethod parentBuilder, JVar parentParam) {

    if (thisJDefinedClass.getMethod(parentBuilder.name(), new JType[] {parentParam.type()}) == null) {

      JMethod builder = thisJDefinedClass.method(parentBuilder.mods().getValue(), thisJDefinedClass, parentBuilder.name());
      builder.annotate(Override.class);

      JVar param = builder.param(parentParam.type(), parentParam.name());
      JBlock body = builder.body();
      body.invoke(JExpr._super(), parentBuilder).arg(param);
      body._return(JExpr._this());

    }
  }
}
origin: joelittlejohn/jsonschema2pojo

private JMethod addBuilder(JDefinedClass c, JFieldVar field, String jsonPropertyName, JsonNode node) {
  JMethod builder = c.method(JMod.PUBLIC, c, getBuilderName(jsonPropertyName, node));
  JVar param = builder.param(field.type(), field.name());
  JBlock body = builder.body();
  body.assign(JExpr._this().ref(field), param);
  body._return(JExpr._this());
  return builder;
}
origin: joelittlejohn/jsonschema2pojo

private void addCreateFromParcel(JDefinedClass jclass, JDefinedClass creatorClass) {
  JMethod createFromParcel = creatorClass.method(JMod.PUBLIC, jclass, "createFromParcel");
  JVar in = createFromParcel.param(jclass.owner().directClass("android.os.Parcel"), "in");
  suppressWarnings(createFromParcel, "unchecked");
  createFromParcel.body()._return(JExpr._new(jclass).arg(in));
}
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 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

private JFieldVar addValueField(JDefinedClass _enum, JType type) {
  JFieldVar valueField = _enum.field(JMod.PRIVATE | JMod.FINAL, type, VALUE_FIELD_NAME);
  JMethod constructor = _enum.constructor(JMod.PRIVATE);
  JVar valueParam = constructor.param(type, VALUE_FIELD_NAME);
  JBlock body = constructor.body();
  body.assign(JExpr._this().ref(valueField), valueParam);
  return valueField;
}
origin: joelittlejohn/jsonschema2pojo

private void addNewArray(JDefinedClass jclass, JDefinedClass creatorClass) {
  JMethod newArray = creatorClass.method(JMod.PUBLIC, jclass.array(), "newArray");
  newArray.param(int.class, "size");
  newArray.body()._return(JExpr.direct("new " + jclass.name() + "[size]"));
}
origin: joelittlejohn/jsonschema2pojo

public void addDescribeContents(JDefinedClass jclass) {
  JMethod method = jclass.method(JMod.PUBLIC, int.class, "describeContents");
  method.body()._return(JExpr.lit(0));
}

origin: joelittlejohn/jsonschema2pojo

private JInvocation illegalArgumentInvocation(JDefinedClass jclass, JVar propertyName) {
  return _new(jclass.owner()._ref(IllegalArgumentException.class))
      .arg(lit("property \"").plus(propertyName).plus(lit("\" is not defined")));
}
origin: joelittlejohn/jsonschema2pojo

public void addCreator(JDefinedClass jclass) {
  JClass creatorType = jclass.owner().directClass("android.os.Parcelable.Creator").narrow(jclass);
  JDefinedClass creatorClass = jclass.owner().anonymousClass(creatorType);
  
  addCreateFromParcel(jclass, creatorClass);
  addNewArray(jclass, creatorClass);
  
  JFieldVar creatorField = jclass.field(JMod.PUBLIC | JMod.STATIC | JMod.FINAL, creatorType, "CREATOR");
  creatorField.init(JExpr._new(creatorClass));
}
origin: joelittlejohn/jsonschema2pojo

private void addGetPropertyCase(JDefinedClass jclass, JSwitch propertySwitch, String propertyName, JType propertyType, JsonNode node) {
  JMethod propertyGetter = jclass.getMethod(getGetterName(propertyName, propertyType, node), new JType[] {});
  propertySwitch._case(lit(propertyName)).body()
  ._return(invoke(propertyGetter));
}
origin: joelittlejohn/jsonschema2pojo

JFieldRef getOrAddNotFoundVar(JDefinedClass jclass) {
  jclass.field(PROTECTED | STATIC | FINAL, Object.class, NOT_FOUND_VALUE_FIELD,
      _new(jclass.owner()._ref(Object.class)));
  return jclass.staticRef(NOT_FOUND_VALUE_FIELD);
}
origin: joelittlejohn/jsonschema2pojo

@Override
public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) {
  JClass moshiAnnotation = clazz.owner().directClass("com.squareup.moshi.Json");
  field.annotate(moshiAnnotation).param("name", propertyName);
}
origin: joelittlejohn/jsonschema2pojo

private static JDefinedClass definedClassOrNullFromType(JType type)
{
  if (type == null || type.isPrimitive())
  {
    return null;
  }
  JClass fieldClass = type.boxify();
  JPackage jPackage = fieldClass._package();
  return jPackage._getClass(fieldClass.name());
}
origin: joelittlejohn/jsonschema2pojo

@Override
public void enumConstant(JDefinedClass _enum, JEnumConstant constant, String value) {
  JClass moshiAnnotation = _enum.owner().directClass("com.squareup.moshi.Json");
  constant.annotate(moshiAnnotation).param("name", value);
}
origin: joelittlejohn/jsonschema2pojo

public static void suppressWarnings(JMethod method, String... values) {
  JAnnotationUse annotation = method.annotate(SuppressWarnings.class);
  JAnnotationArrayMember member = annotation.paramArray("value");
  for( String value : values ) {
    member.param(value);
  }
}
origin: joelittlejohn/jsonschema2pojo

private JMethod addSetter(JDefinedClass c, JFieldVar field, String jsonPropertyName, JsonNode node) {
  JMethod setter = c.method(JMod.PUBLIC, void.class, getSetterName(jsonPropertyName, node));
  JVar param = setter.param(field.type(), field.name());
  JBlock body = setter.body();
  body.assign(JExpr._this().ref(field), param);
  return setter;
}
com.sun.codemodel

Most used classes

  • JCodeModel
    Root of the code DOM. Here's your typical CodeModel application. JCodeModel cm = new JCodeModel();
  • JDefinedClass
    A generated Java class/interface/enum/.... This class models a declaration, and since a declaration
  • JClass
    Represents a Java reference type, such as a class, an interface, an enum, an array type, a parameter
  • JMethod
    Java method.
  • JBlock
    A block of Java code, which may contain statements and local declarations. JBlock contains a large
  • JInvocation,
  • JType,
  • JPackage,
  • JFieldVar,
  • JVar,
  • JExpression,
  • JConditional,
  • JAnnotationUse,
  • JDocComment,
  • JFieldRef,
  • JAnnotationArrayMember,
  • JClassAlreadyExistsException,
  • JOp,
  • JMods
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