use of com.helger.jcodemodel.JVar in project RoboBinding by RoboBinding.
the class PresentationModelObjectClassGen method defineConstructor.
/**
* public PresentationModelType_PM(PresentationModelType presentationModel) {
* super(presentationModel);
* this.presentationModel = presentationModel;
* }
*/
@Override
public void defineConstructor() {
/*
public class PresentationModelType_PM extends AbstractPresentationModelObject {
*/
definedClass._extends(AbstractPresentationModelObject.class);
JMethod constructor = definedClass.constructor(JMod.PUBLIC);
JVar presentationModelParam = constructor.param(presentationModelClass, "presentationModel");
JBlock block = constructor.body();
JInvocation superInvocation = JExpr.invoke("super").arg(presentationModelParam);
block.add(superInvocation);
block.assign(presentationModelField, presentationModelParam);
}
use of com.helger.jcodemodel.JVar 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.JVar 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;
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class InjectHelper method processParam.
private void processParam(Element element, T holder) {
ExecutableElement method = (ExecutableElement) element.getEnclosingElement();
List<? extends VariableElement> parameters = method.getParameters();
List<ParamHelper> parameterList = methodParameterMap.get(method);
JBlock targetBlock = methodBlockMap.get(method);
int paramCount = parameters.size();
if (parameterList == null) {
parameterList = new ArrayList<>();
methodParameterMap.put(method, parameterList);
}
if (targetBlock == null) {
targetBlock = createBlock(holder, true);
methodBlockMap.put(method, targetBlock);
}
for (int paramIndex = 0; paramIndex < paramCount; paramIndex++) {
VariableElement param = parameters.get(paramIndex);
if (param.equals(element)) {
AbstractJClass type = codeModelHelper.typeMirrorToJClass(param.asType());
JVar fieldRef = targetBlock.decl(type, param.getSimpleName().toString(), getDefault(param.asType()));
handler.assignValue(targetBlock, fieldRef, holder, param, param);
parameterList.add(new ParamHelper(fieldRef, paramIndex, param));
}
}
if (parameterList.size() == paramCount) {
String methodName = method.getSimpleName().toString();
Collections.sort(parameterList);
JInvocation invocation = JExpr.invoke(methodName);
for (ParamHelper parameter : parameterList) {
invocation.arg(parameter.beanInstance);
}
targetBlock.add(invocation);
if (handler instanceof MethodInjectionHandler.AfterAllParametersInjectedHandler<?>) {
((MethodInjectionHandler.AfterAllParametersInjectedHandler<T>) handler).afterAllParametersInjected(holder, method, parameterList);
}
methodParameterMap.remove(method);
}
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class APTCodeModelHelper method addParamToMethod.
private void addParamToMethod(JMethod method, VariableElement parameter, int mod, Map<String, TypeMirror> actualTypes, boolean varParam) {
String parameterName = parameter.getSimpleName().toString();
AbstractJClass parameterClass = typeMirrorToJClass(parameter.asType(), actualTypes);
JVar param = varParam ? method.varParam(mod, parameterClass.elementType(), parameterName) : method.param(mod, parameterClass, parameterName);
copyNonAAAnnotations(param, parameter.getAnnotationMirrors());
}
Aggregations