use of com.helger.jcodemodel.AbstractJType in project androidannotations by androidannotations.
the class RestAnnotationHelper method declareHttpEntity.
public IJExpression declareHttpEntity(JBlock body, JVar entitySentToServer, JVar httpHeaders) {
AbstractJType entityType = getEnvironment().getJClass(Object.class);
if (entitySentToServer != null) {
entityType = entitySentToServer.type();
if (entityType.isPrimitive()) {
// Don't narrow primitive types...
entityType = entityType.boxify();
}
}
AbstractJClass httpEntity = getEnvironment().getJClass(HTTP_ENTITY);
AbstractJClass narrowedHttpEntity = httpEntity.narrow(entityType);
JInvocation newHttpEntityVarCall = JExpr._new(narrowedHttpEntity);
if (entitySentToServer != null) {
newHttpEntityVarCall.arg(entitySentToServer);
}
if (httpHeaders != null) {
newHttpEntityVarCall.arg(httpHeaders);
} else if (entitySentToServer == null) {
return JExpr._null();
}
return body.decl(narrowedHttpEntity, "requestEntity", newHttpEntityVarCall);
}
use of com.helger.jcodemodel.AbstractJType in project RoboBinding by RoboBinding.
the class ItemPresentationModelObjectClassGen method defineConstructor.
/**
* public StringItemPresentationModel_IPM(StringItemPresentationModel itemPresentationModel) {
* super(itemPresentationModel);
* this.itemPresentationModel = itemPresentationModel;
* }
*
*/
@Override
public void defineConstructor() {
/*
public class StringItemPresentationModel_IPM extends AbstractItemPresentationModelObject {
*/
definedClass._extends(AbstractItemPresentationModelObject.class);
JMethod constructor = definedClass.constructor(JMod.PUBLIC);
AbstractJType itemPresentationModelClass = codeModel.ref(presentationModelInfo.getPresentationModelTypeName());
JVar itemPresentationModelParam = constructor.param(itemPresentationModelClass, "itemPresentationModel");
JBlock block = constructor.body();
JInvocation superInvocation = JExpr.invoke("super").arg(itemPresentationModelParam);
block.add(superInvocation);
block.assign(presentationModelField, itemPresentationModelParam);
}
use of com.helger.jcodemodel.AbstractJType in project adt4j by sviperll.
the class FinalValueClassModel method buildCaseClass.
private JDefinedClass buildCaseClass(String interfaceMethodName, Serialization serialization) throws JClassAlreadyExistsException {
JDefinedClass caseClass = environment.buildValueClassInnerClass(JMod.PRIVATE | JMod.STATIC, Source.capitalize(interfaceMethodName) + "Case" + environment.acceptingInterfaceName(), EClassType.CLASS);
for (JTypeVar visitorTypeParameter : environment.getValueTypeParameters()) {
JTypeVar typeParameter = caseClass.generify(visitorTypeParameter.name());
typeParameter.boundLike(visitorTypeParameter);
}
AbstractJClass usedAcceptingInterfaceType = environment.acceptingInterfaceType(caseClass.typeParams());
AbstractJClass usedValueClassType = environment.wrappedValueClassType(caseClass.typeParams());
VisitorDefinition.VisitorUsage usedVisitor = environment.visitor(usedValueClassType, usedValueClassType, types._RuntimeException);
MethodUsage interfaceMethod = usedVisitor.findMethod(interfaceMethodName);
if (interfaceMethod == null)
throw new IllegalStateException("Method with given name not found: " + interfaceMethodName);
JTypeVar[] methodArguments = new JTypeVar[interfaceMethod.typeParams().length];
for (int i = 0; i < methodArguments.length; i++) {
JTypeVar visitorMethodTypeParameter = interfaceMethod.typeParams()[i];
JTypeVar typeParameter = caseClass.generify(visitorMethodTypeParameter.name());
typeParameter.boundLike(visitorMethodTypeParameter);
methodArguments[i] = typeParameter;
}
MethodUsage usedInterfaceMethod = interfaceMethod.narrow(methodArguments);
caseClass._implements(usedAcceptingInterfaceType);
if (serialization.isSerializable()) {
caseClass._implements(types._Serializable);
caseClass.field(JMod.PRIVATE | JMod.FINAL | JMod.STATIC, types._long, "serialVersionUID", JExpr.lit(serialization.serialVersionUIDForGeneratedCode()));
}
JMethod constructor = caseClass.constructor(JMod.NONE);
for (VariableDeclaration param : usedInterfaceMethod.params()) {
AbstractJType paramType = param.type().declarable();
JFieldVar field = caseClass.field(JMod.PRIVATE | JMod.FINAL, paramType, param.name());
JVar argument = constructor.param(paramType, param.name());
constructor.body().assign(JExpr._this().ref(field), argument);
}
VariableDeclaration param = usedInterfaceMethod.varParam();
if (param != null) {
AbstractJType paramType = param.type().elementType().declarable();
JFieldVar field = caseClass.field(JMod.PRIVATE | JMod.FINAL, paramType.array(), param.name());
JVar argument = constructor.varParam(paramType, param.name());
constructor.body().assign(JExpr._this().ref(field), argument);
}
JMethod acceptMethod = declareAcceptMethod(caseClass, usedValueClassType);
JInvocation invocation = JExpr.invoke(acceptMethod.params().get(0), usedInterfaceMethod.name());
for (AbstractJClass argument : methodArguments) {
invocation.narrow(argument);
}
for (VariableDeclaration param1 : usedInterfaceMethod.params()) {
invocation.arg(JExpr._this().ref(param1.name()));
}
VariableDeclaration param1 = usedInterfaceMethod.varParam();
if (param1 != null) {
invocation.arg(JExpr._this().ref(param1.name()));
}
acceptMethod.body()._return(invocation);
return caseClass;
}
Aggregations