use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class RoboGuiceHandler method fireEvent.
private void fireEvent(JFieldVar eventManager, JBlock body, AbstractJClass eventClass, IJExpression... eventArguments) {
AbstractJClass actualEventClass = eventClass;
if (eventClass.fullName().startsWith("roboguice.context.event")) {
actualEventClass = eventClass.narrow(getClasses().ACTIVITY);
}
JInvocation newEvent = _new(actualEventClass);
newEvent.arg(_this());
for (IJExpression eventArgument : eventArguments) {
newEvent.arg(eventArgument);
}
body.invoke(eventManager, "fire").arg(newEvent);
}
use of com.helger.jcodemodel.JInvocation 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.JInvocation in project adt4j by sviperll.
the class ValueClassConfiguration method wrapValue.
public IJExpression wrapValue(AbstractJType usedWrappedClassType, IJExpression valueExpression) {
AbstractJClass wrapperClass = customization.wrapperClass();
if (wrapperClass == null)
return valueExpression;
else {
JInvocation invocation1 = JExpr._new(usedWrappedClassType);
invocation1.arg(valueExpression);
return invocation1;
}
}
use of com.helger.jcodemodel.JInvocation in project adt4j by sviperll.
the class EqualsMethod method appendNonnullObject.
private void appendNonnullObject(IJExpression value1, IJExpression value2, boolean isLast) {
JInvocation invocation = value1.invoke("equals");
invocation.arg(value2);
if (isLast) {
body._return(invocation);
} else {
JConditional _if = body._if(invocation.not());
_if._then()._return(JExpr.FALSE);
}
}
use of com.helger.jcodemodel.JInvocation in project RoboBinding by RoboBinding.
the class AbstractPresentationModelObjectClassGen method defineTryToCreateProperty.
/*
@Override
public SimpleProperty tryToCreateProperty(String name) {
if(name.equals(PROP1)) {
PropertyDescriptor descriptor = createPropertyDescriptor(String.class, name, true, true);
AbstractGetSet<?> getSet = new AbstractGetSet<String>(descriptor) {
@Override
public String getValue() {
return presentationModel.getProp1();
}
@Override
public void setValue(String newValue) {
presentationModel.setProp1(newValue);
}
};
return new SimpleProperty(this, descriptor, getSet);
}
if(name.equals(PROP2)) {
PropertyDescriptor descriptor = createPropertyDescriptor(Integer.class, name, true, true);
AbstractGetSet<?> getSet = new AbstractGetSet<Integer>(descriptor) {
@Override
public Integer getValue() {
return presentationModel.getProp2();
}
@Override
public void setValue(Integer newValue) {
presentationModel.setProp2(newValue);
}
};
return new SimpleProperty(this, descriptor, getSet);
}
return null;
}
*/
public void defineTryToCreateProperty() {
try {
JMethod method = declarePublicMethodOverride("tryToCreateProperty", SimpleProperty.class);
JVar nameParam = method.param(String.class, "name");
JBlock body = method.body();
for (PropertyInfo propertyInfo : presentationModelInfo.properties()) {
JConditional conditional = body._if(nameParam.invoke("equals").arg(propertyInfo.name()));
JBlock conditionalBody = conditional._then();
//create PropertyDescriptor.
AbstractJClass propertyClass = codeModel.ref(propertyInfo.typeName());
JInvocation createPropertyDescriptor = JExpr.invoke("createPropertyDescriptor").arg(propertyClass.dotclass()).arg(nameParam).arg(JExpr.lit(propertyInfo.isReadable())).arg(JExpr.lit(propertyInfo.isWritable()));
JVar descriptorVar = conditionalBody.decl(propertyDescriptorClass, "descriptor", createPropertyDescriptor);
//create AbstractGetSet.
//JClass narrowedGetSet = getSetClass.narrow(codeModel.ref(propertyInfo.typeName()));
AbstractJClass narrowedGetSet = getSetClass.narrow(propertyClass);
JDefinedClass anonymousGetSet = codeModel.anonymousClass(narrowedGetSet);
if (propertyInfo.isReadable()) {
JMethod getter = declarePublicMethodOverride(anonymousGetSet, "getValue", propertyClass);
getter.body()._return(presentationModelFieldWithoutThis.invoke(propertyInfo.getter()));
}
if (propertyInfo.isWritable()) {
JMethod setter = declarePublicMethodOverride(anonymousGetSet, "setValue", Void.TYPE);
JVar newValueParam = setter.param(propertyClass, "newValue");
setter.body().add(presentationModelFieldWithoutThis.invoke(propertyInfo.setter()).arg(newValueParam));
}
JVar getSetVar = conditionalBody.decl(wildcardGetSetClass, "getSet", JExpr._new(anonymousGetSet).arg(descriptorVar));
//return SimpleProperty.
conditionalBody._return(JExpr._new(simplePropertyClass).arg(JExpr._this()).arg(descriptorVar).arg(getSetVar));
}
body._return(JExpr._null());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations