use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class TransactionalHandler method process.
@Override
public void process(Element element, EComponentHolder holder) {
ExecutableElement executableElement = (ExecutableElement) element;
String returnTypeName = executableElement.getReturnType().toString();
AbstractJClass returnType = getJClass(returnTypeName);
JMethod method = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
codeModelHelper.removeBody(method);
JVar db = method.params().get(0);
JBlock body = method.body();
body.invoke(db, "beginTransaction");
JTryBlock tryBlock = body._try();
IJExpression activitySuper = holder.getGeneratedClass().staticRef("super");
JInvocation superCall = JExpr.invoke(activitySuper, method);
for (JVar param : method.params()) {
superCall.arg(param);
}
JBlock tryBody = tryBlock.body();
if (returnTypeName.equals("void")) {
tryBody.add(superCall);
tryBody.invoke(db, "setTransactionSuccessful");
tryBody._return();
} else {
JVar result = tryBody.decl(returnType, "result_", superCall);
tryBody.invoke(db, "setTransactionSuccessful");
tryBody._return(result);
}
JCatchBlock catchBlock = tryBlock._catch(getJClass(RuntimeException.class));
JVar exceptionParam = catchBlock.param("e");
JBlock catchBody = catchBlock.body();
JInvocation errorInvoke = catchBody.staticInvoke(getClasses().LOG, "e");
errorInvoke.arg(logTagForClassHolder(holder));
errorInvoke.arg("Error in transaction");
errorInvoke.arg(exceptionParam);
catchBody._throw(exceptionParam);
tryBlock._finally().invoke(db, "endTransaction");
}
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 callSuperMethod.
public void callSuperMethod(JMethod superMethod, GeneratedClassHolder holder, JBlock callBlock) {
JInvocation superCall = getSuperCall(holder, superMethod);
AbstractJType returnType = superMethod.type();
if (returnType.fullName().equals("void")) {
callBlock.add(superCall);
} else {
callBlock._return(superCall);
}
}
use of com.helger.jcodemodel.JInvocation 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.JInvocation in project androidannotations by androidannotations.
the class EComponentWithViewSupportHolder method findViewById.
public JInvocation findViewById(JFieldRef idRef) {
JInvocation findViewById = invoke(getOnViewChangedHasViewsParam(), "findViewById");
findViewById.arg(idRef);
return findViewById;
}
Aggregations