use of com.helger.jcodemodel.JInvocation in project RoboBinding by RoboBinding.
the class AbstractPresentationModelObjectClassGen method defineTryToCreateFunction.
/*
@Override
public Function tryToCreateFunction(MethodDescriptor methodDescriptor) {
if(methodDescriptor.equals(createMethodDescriptor(ON_CLICK))) {
return new Function() {
@Override
public Object call(Object... args) {
presentationModel.onClick();
return null;
}
};
}
if(methodDescriptor.equals(createMethodDescriptor(ON_CLICK_WITH_EVENT, AbstractViewEvent.class))){
return new Function() {
@Override
public Object call(Object... args) {
boolean result = presentationModel.onLongClickWithEvent((AbstractViewEvent)args[0]);
return (Boolean)result;
}
};
}
return null;
}
*/
public void defineTryToCreateFunction() {
JMethod method = declarePublicMethodOverride("tryToCreateFunction", Function.class);
JVar methodDescriptorParam = method.param(MethodDescriptor.class, "methodDescriptor");
JBlock body = method.body();
for (EventMethodInfo eventMethodInfo : presentationModelInfo.eventMethods()) {
JInvocation getMethod = JExpr.invoke("createMethodDescriptor").arg(eventMethodInfo.name());
if (eventMethodInfo.hasEventArg()) {
getMethod.arg(codeModel.ref(eventMethodInfo.eventArgType()).dotclass());
}
JConditional conditional = body._if(methodDescriptorParam.invoke("equals").arg(getMethod));
JBlock conditionalBody = conditional._then();
//create Function.
JDefinedClass anonymousFunction = codeModel.anonymousClass(Function.class);
JMethod call = declarePublicMethodOverride(anonymousFunction, "call", Object.class);
JVar argsVar = call.varParam(Object.class, "args");
JBlock callBody = call.body();
//call event method.
JInvocation onEvent = presentationModelFieldWithoutThis.invoke(eventMethodInfo.name());
if (eventMethodInfo.hasEventArg()) {
AbstractJClass eventArgClass = codeModel.ref(eventMethodInfo.eventArgType());
onEvent.arg(JExpr.cast(eventArgClass, argsVar.component(JExpr.lit(0))));
}
//call return.
if (eventMethodInfo.hasReturn()) {
JVar returnVar = callBody.decl(codeModel.ref(eventMethodInfo.nonPrimitiveReturnType()), "result", onEvent);
callBody._return(returnVar);
} else {
callBody.add(onEvent);
callBody._return(JExpr._null());
}
//return Function.
conditionalBody._return(JExpr._new(anonymousFunction));
}
body._return(JExpr._null());
}
use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class APTCodeModelHelper method getSuperCall.
public JInvocation getSuperCall(GeneratedClassHolder holder, JMethod superMethod) {
IJExpression activitySuper = holder.getGeneratedClass().staticRef("super");
JInvocation superCall = JExpr.invoke(activitySuper, superMethod);
for (JVar param : superMethod.params()) {
superCall.arg(param);
}
if (superMethod.hasVarArgs()) {
superCall.arg(superMethod.varParam());
}
return superCall;
}
use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class EActivityHolder method setContentViewMethod.
private JMethod setContentViewMethod(AbstractJType[] paramTypes, String[] paramNames) {
JMethod method = generatedClass.method(JMod.PUBLIC, getCodeModel().VOID, "setContentView");
method.annotate(Override.class);
List<JVar> params = new ArrayList<>();
for (int i = 0; i < paramTypes.length; i++) {
JVar param = method.param(paramTypes[i], paramNames[i]);
params.add(param);
}
JBlock body = method.body();
JInvocation superCall = body.invoke(JExpr._super(), method);
for (JVar arg : params) {
superCall.arg(arg);
}
viewNotifierHelper.invokeViewChanged(body);
return method;
}
use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class RestHolder method implementGetCookie.
private void implementGetCookie(List<ExecutableElement> methods) {
JMethod getCookieMethod = codeModelHelper.implementMethod(this, methods, "getCookie", STRING, STRING);
if (getCookieMethod != null) {
JInvocation cookieValue = JExpr.invoke(getAvailableCookiesField(), "get").arg(getCookieMethod.params().get(0));
getCookieMethod.body()._return(cookieValue);
}
}
use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class RestHandler method setConverters.
private void setConverters(Element element, RestHolder holder) {
List<DeclaredType> converters = annotationHelper.extractAnnotationClassArrayParameter(element, getTarget(), "converters");
JFieldVar restTemplateField = holder.getRestTemplateField();
JBlock init = holder.getInit().body();
init.add(invoke(restTemplateField, "getMessageConverters").invoke("clear"));
for (DeclaredType converterType : converters) {
JInvocation newConverter = codeModelHelper.newBeanOrEBean(converterType, holder.getInitContextParam());
init.add(invoke(restTemplateField, "getMessageConverters").invoke("add").arg(newConverter));
}
}
Aggregations