Java Code Examples for com.sun.codemodel.JBlock.invoke()

The following are Jave code examples for showing how to use invoke() of the com.sun.codemodel.JBlock class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GitHub   File: AdditionalPropertiesRule.java   Source Code and License Vote up 5 votes
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());
}
 
Example 2
Project: dremio-oss   File: ClassGenerator.java   Source Code and License Vote up 5 votes
@SuppressWarnings("unchecked")
ClassGenerator(CodeGenerator<T> codeGenerator, MappingSet mappingSet, SignatureHolder signature, EvaluationVisitor eval, JDefinedClass clazz, JCodeModel model) throws JClassAlreadyExistsException {
  this.codeGenerator = codeGenerator;
  this.clazz = clazz;
  this.mappings = mappingSet;
  this.sig = signature;
  this.evaluationVisitor = eval;
  this.model = Preconditions.checkNotNull(model, "Code model object cannot be null.");
  blocks = new LinkedList[sig.size()];

  for (int i =0; i < sig.size(); i++) {
    blocks[i] = Lists.newLinkedList();
  }
  rotateBlock();

  for (SignatureHolder child : signature.getChildHolders()) {
    final String innerClassName = child.getSignatureClass().getSimpleName();
    final JDefinedClass innerClazz;
    // we need to extend the template class and avoid using static inner classes.
    innerClazz = clazz._class(JMod.FINAL, innerClassName)._extends(child.getSignatureClass());

    // we also need to delegate any inner class constructors.
    for(Constructor<?> c : child.getSignatureClass().getDeclaredConstructors()){
      final Class<?>[] params = c.getParameterTypes();
      JMethod constructor = innerClazz.constructor(JMod.PUBLIC);
      JBlock block = constructor.body();
      JInvocation invoke = block.invoke("super");
      block.invoke(SignatureHolder.INIT_METHOD);

      // start at 1 since first parameter is the parent class
      for (int i = 1; i < params.length; i++) {
        constructor.param(params[i], "arg" + i);
        invoke.arg(JExpr.direct("arg" + i));
      }
    }

    innerClasses.put(innerClassName, new ClassGenerator<>(codeGenerator, mappingSet, child, eval, innerClazz, model));
  }
}
 
Example 3
Project: springmvc-raml-plugin   File: PojoBuilder.java   Source Code and License Vote up 5 votes
private void withDefaultConstructor(String className) {
	// Create default constructor
	JMethod constructor = this.pojo.constructor(JMod.PUBLIC);
	constructor.javadoc().add("Creates a new " + className + ".");
	JBlock defaultConstructorBody = constructor.body();
	defaultConstructorBody.invoke("super");
}
 
Example 4
Project: springmvc-raml-plugin   File: PojoBuilder.java   Source Code and License Vote up 5 votes
private void addSuperConstructorInvocation(JMethod constructor, Map<String, JVar> superParametersToAdd) {
	JBlock constructorBody = constructor.body();
	JInvocation invocation = constructorBody.invoke("super");
	for (JVar arg : superParametersToAdd.values()) {
		JVar param = constructor.param(arg.type(), arg.name());
		invocation.arg(param);
	}

}
 
Example 5
Project: jaxb2-basics   File: PropertyFieldAccessorFactory.java   Source Code and License Vote up 5 votes
public void unsetValues(JBlock body) {
	if (constantField != null) {

	} else if (unSetter != null) {
		body.invoke(targetObject, unSetter);
	} else {

		fieldAccessor.unsetValues(body);
	}
}
 
Example 6
Project: jaxb2-rich-contract-plugin   File: BoundPropertiesPlugin.java   Source Code and License Vote up 5 votes
private JInvocation invokeListener(final JBlock block, final JFieldVar field, final JVar oldValueVar, final JVar setterArg, final String aspectName) {
	final String aspectNameCap = aspectName.substring(0, 1).toUpperCase() + aspectName.substring(1);
	final JInvocation fvcInvoke = block.invoke(JExpr._this().ref(aspectName + BoundPropertiesPlugin.SUPPORT_FIELD_SUFFIX), "fire" + aspectNameCap);
	fvcInvoke.arg(JExpr.lit(field.name()));
	fvcInvoke.arg(oldValueVar);
	fvcInvoke.arg(setterArg);
	return fvcInvoke;
}