congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
JDefinedClass.owner
Code IndexAdd Tabnine to your IDE (free)

How to use
owner
method
in
com.sun.codemodel.JDefinedClass

Best Java code snippets using com.sun.codemodel.JDefinedClass.owner (Showing top 20 results out of 315)

origin: joelittlejohn/jsonschema2pojo

private JMethod getInternalSetMethod(JDefinedClass jclass) {
  return jclass.getMethod(DEFINED_SETTER_NAME,
      new JType[] { jclass.owner().ref(String.class), jclass.owner().ref(Object.class) });
}
origin: joelittlejohn/jsonschema2pojo

private JMethod getInternalGetMethod(JDefinedClass jclass) {
  return jclass.getMethod(DEFINED_GETTER_NAME,
      new JType[] { jclass.owner().ref(String.class), jclass.owner().ref(Object.class) });
}
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

@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

private JFieldVar addAdditionalPropertiesField(JDefinedClass jclass, JType propertyType) {
  JClass propertiesMapType = jclass.owner().ref(Map.class);
  propertiesMapType = propertiesMapType.narrow(jclass.owner().ref(String.class), propertyType.boxify());
  JClass propertiesMapImplType = jclass.owner().ref(HashMap.class);
  propertiesMapImplType = propertiesMapImplType.narrow(jclass.owner().ref(String.class), propertyType.boxify());
  JFieldVar field = jclass.field(JMod.PRIVATE, propertiesMapType, "additionalProperties");
  ruleFactory.getAnnotator().additionalPropertiesField(field, jclass, "additionalProperties");
  field.init(JExpr._new(propertiesMapImplType));
  return field;
}
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

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 JMethod addInternalGetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) {
  JMethod method = jclass.method(PROTECTED, jclass.owner()._ref(Object.class), DEFINED_GETTER_NAME);
  JVar nameParam = method.param(String.class, "name");
  JVar notFoundParam = method.param(jclass.owner()._ref(Object.class), "notFoundValue");
  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();
      addGetPropertyCase(jclass, propertySwitch, propertyName, propertyType, node);
    }
  }
  JClass extendsType = jclass._extends();
  if (extendsType != null && extendsType instanceof JDefinedClass) {
    JDefinedClass parentClass = (JDefinedClass) extendsType;
    JMethod parentMethod = parentClass.getMethod(DEFINED_GETTER_NAME,
        new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
    propertySwitch._default().body()
    ._return(_super().invoke(parentMethod).arg(nameParam).arg(notFoundParam));
  } else {
    propertySwitch._default().body()
    ._return(notFoundParam);
  }
  return method;
}
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

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 JType getReturnType(final JDefinedClass c, final JFieldVar field, final boolean required, final boolean usesOptional) {
  JType returnType = field.type();
  if (ruleFactory.getGenerationConfig().isUseOptionalForGetters() || usesOptional) {
    if (!required && field.type().isReference()) {
      returnType = c.owner().ref("java.util.Optional").narrow(field.type());
    }
  }
  return returnType;
}
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 addParcelSupport(JDefinedClass jclass) {
  jclass._implements(jclass.owner().directClass("android.os.Parcelable"));
  parcelableHelper.addWriteToParcel(jclass);
  parcelableHelper.addDescribeContents(jclass);
  parcelableHelper.addCreator(jclass);
  parcelableHelper.addConstructorFromParcel(jclass);
  // #742 : includeConstructors will include the default constructor
  if (!ruleFactory.getGenerationConfig().isIncludeConstructors()) {
    // Add empty constructor
    jclass.constructor(JMod.PUBLIC);
  }
}
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

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: joelittlejohn/jsonschema2pojo

private JMethod addGetter(JDefinedClass c, JFieldVar field, String jsonPropertyName, JsonNode node, boolean isRequired, boolean usesOptional) {
  JType type = getReturnType(c, field, isRequired, usesOptional);
  JMethod getter = c.method(JMod.PUBLIC, type, getGetterName(jsonPropertyName, field.type(), node));
  JBlock body = getter.body();
  if ((ruleFactory.getGenerationConfig().isUseOptionalForGetters() || usesOptional) && !isRequired
      && field.type().isReference()) {
    body._return(c.owner().ref("java.util.Optional").staticInvoke("ofNullable").arg(field));
  } else {
    body._return(field);
  }
  return getter;
}
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: 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

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: 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);
}
com.sun.codemodelJDefinedClassowner

Popular methods of JDefinedClass

  • method
  • _extends
  • field
  • _implements
  • name
    JClass name accessor. For example, for java.util.List, this method returns "List""
  • constructor
    Adds a constructor to this class.
  • fields
    Returns all the fields declred in this class. The returned Map is a read-only live view.
  • annotate
    Adding ability to annotate a class
  • fullName
    Gets the fully qualified name of this class.
  • methods
  • javadoc
    Creates, if necessary, and returns the class javadoc for this JDefinedClass
  • _class
    Add a new public nested class to this class.
  • javadoc,
  • _class,
  • getMethod,
  • _package,
  • dotclass,
  • enumConstant,
  • staticInvoke,
  • staticRef,
  • init

Popular in Java

  • Making http post requests using okhttp
  • onRequestPermissionsResult (Fragment)
  • putExtra (Intent)
  • scheduleAtFixedRate (Timer)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • Top PhpStorm plugins
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