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

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

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

Refine searchRefine arrow

  • JBlock._return
  • JMethod.body
  • JMethod.param
  • JInvocation.arg
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 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: stackoverflow.com

 JCodeModel cm = new JCodeModel();
JDefinedClass dc = cm._class("foo.Bar");
JMethod m = dc.method(0, int.class, "foo");
m.body()._return(JExpr.lit(5));

File file = new File("./target/classes");
file.mkdirs();
cm.build(file);
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;
}
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: 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 addValueMethod(JDefinedClass _enum, JFieldVar valueField) {
  JMethod fromValue = _enum.method(JMod.PUBLIC, valueField.type(), "value");
  JBlock body = fromValue.body();
  body._return(JExpr._this().ref(valueField));
  ruleFactory.getAnnotator().enumValueMethod(_enum, fromValue);
}
origin: stackoverflow.com

 final JDefinedClass exampleClass = codeModel._class( "com.example.ExampleClass" );
final JMethod method = exampleClass.method( JMod.PUBLIC, Object.class, "getValue" );
final JTypeVar t = method.generify( "T" );
method.type( t );
method.param( codeModel.ref( Class.class ).narrow( t ), "type" );
method.body()._return(JExpr._null());
origin: e-biz/androidkickstartr

public JCodeModel generate(JCodeModel jCodeModel, RefHelper ref) throws IOException {
  logger = LoggerFactory.getLogger(getClass());
  try {
    jClass = jCodeModel._class(appDetails.getApplicationPackage());
    jClass._extends(ref.application());
    jClass.annotate(ref.reportsCrashes()).param("formKey", "YOUR_FORM_KEY");
    JMethod onCreateMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "onCreate");
    onCreateMethod.annotate(ref.override());
    JBlock onCreateMethodBody = onCreateMethod.body();
    onCreateMethodBody.staticInvoke(ref.acra(), "init").arg(JExpr._this());
    onCreateMethodBody.invoke(JExpr._super(), "onCreate");
  } catch (JClassAlreadyExistsException e1) {
    logger.error("Classname already exists", e1);
  }
  return jCodeModel;
}
origin: e-biz/androidkickstartr

private void createConfigureActionBar() {
  if (appDetails.isActionBarSherlock() && (appDetails.isListNavigation() || appDetails.isTabNavigation())) {
    JMethod configureActionBar = jClass.method(JMod.PRIVATE, jCodeModel.VOID, "configureActionBar");
    JBlock configureActionBarBody = configureActionBar.body();
    // LIST NAVIGATION
    if (appDetails.isListNavigation()) {
      addListNavigationConfiguration(configureActionBarBody);
    }
    // TAB NAVIGATION
    if (appDetails.isTabNavigation()) {
      addTabNavigationConfiguration(configureActionBarBody);
    }
    afterViewsBody.invoke(configureActionBar);
  }
}
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

private JMethod addGetter(JDefinedClass jclass, JFieldVar field) {
  JMethod getter = jclass.method(JMod.PUBLIC, field.type(), "getAdditionalProperties");
  ruleFactory.getAnnotator().anyGetter(getter, jclass);
  getter.body()._return(JExpr._this().ref(field));
  return getter;
}
origin: javaee/glassfish

injectMethod = injector.method(JMod.PUBLIC, void.class, "inject");
injectMethod.param(Dom.class, "dom");
injectMethod.param(targetType, "target");
injectMethod.body();
injectAttributeMethod = injector.method(JMod.PUBLIC,void.class,"injectAttribute");
addReinjectionParam(injectAttributeMethod);
injectElementMethod = injector.method(JMod.PUBLIC,void.class,"injectElement");
addReinjectionParam(injectElementMethod);
origin: joelittlejohn/jsonschema2pojo

private void addSetter(JDefinedClass jclass, JType propertyType, JFieldVar field) {
  JMethod setter = jclass.method(JMod.PUBLIC, void.class, "setAdditionalProperty");
  ruleFactory.getAnnotator().anySetter(setter, jclass);
  JVar nameParam = setter.param(String.class, "name");
  JVar valueParam = setter.param(propertyType, "value");
  JInvocation mapInvocation = setter.body().invoke(JExpr._this().ref(field), "put");
  mapInvocation.arg(nameParam);
  mapInvocation.arg(valueParam);
}
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 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

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

    }
  }
}
com.sun.codemodelJDefinedClassmethod

Javadoc

Add a method to the list of method members of this JDefinedClass instance.

Popular methods of JDefinedClass

  • _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
  • owner
  • 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 Vim 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