use of com.helger.jcodemodel.JMethod 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.JMethod in project androidannotations by androidannotations.
the class UiThreadHandler method process.
@Override
public void process(Element element, EComponentHolder holder) throws Exception {
ExecutableElement executableElement = (ExecutableElement) element;
JMethod delegatingMethod = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
JBlock previousBody = codeModelHelper.removeBody(delegatingMethod);
JDefinedClass anonymousRunnableClass = codeModelHelper.createDelegatingAnonymousRunnableClass(previousBody);
UiThread annotation = element.getAnnotation(UiThread.class);
long delay = annotation.delay();
UiThread.Propagation propagation = annotation.propagation();
if (delay == 0 && propagation == UiThread.Propagation.REUSE) {
// Put in the check for the UI thread.
addUIThreadCheck(delegatingMethod, previousBody, holder);
}
delegatingMethod.body().add(//
getJClass(UiThreadExecutor.class).staticInvoke(METHOD_RUN_TASK).arg(//
annotation.id()).arg(//
_new(anonymousRunnableClass)).arg(lit(delay)));
}
use of com.helger.jcodemodel.JMethod in project androidannotations by androidannotations.
the class SupposeUiThreadHandler method process.
@Override
public void process(Element element, EComponentHolder holder) throws Exception {
ExecutableElement executableElement = (ExecutableElement) element;
JMethod delegatingMethod = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
JBlock body = delegatingMethod.body();
AbstractJClass bgExecutor = getJClass(BackgroundExecutor.class);
body.pos(0);
body.staticInvoke(bgExecutor, METHOD_CHECK_UI_THREAD);
body.pos(body.getContents().size());
}
use of com.helger.jcodemodel.JMethod in project RoboBinding by RoboBinding.
the class ViewBindingObjectClassGen method defineSimpleOneWayPropertyClasses.
/**
*
private static class ImageAlphaAttribute implements OneWayPropertyViewAttribute<ImageView, Integer> {
@Override
public void updateView(ImageView view, Integer newValue) {
view.setImageAlpha(newValue);
}
}
*
*/
public void defineSimpleOneWayPropertyClasses() {
for (SimpleOneWayPropertyInfo propInfo : simpleOneWayPropertyInfoList) {
JDefinedClass definedBindingAttributeClass = propInfo.defineBindingClass(new ClassDefinitionCallback() {
@Override
public JDefinedClass define(String typeName) {
try {
return definedClass._class(JMod.PUBLIC | JMod.STATIC, typeName);
} catch (JClassAlreadyExistsException e) {
throw new RuntimeException("Class '" + typeName + "' already exists", e);
}
}
});
AbstractJClass propertyClass = codeModel.ref(propInfo.propertyType());
AbstractJClass oneWayPropertyInterface = codeModel.ref(OneWayPropertyViewAttribute.class).narrow(viewClass, propertyClass);
definedBindingAttributeClass._implements(oneWayPropertyInterface);
JMethod method = definedBindingAttributeClass.method(JMod.PUBLIC, codeModel.VOID, "updateView");
method.annotate(Override.class);
JVar viewParam = method.param(viewClass, "view");
JVar newValueParam = method.param(propertyClass, "newValue");
JBlock body = method.body();
body.invoke(viewParam, propInfo.propertySetter()).arg(newValueParam);
}
}
use of com.helger.jcodemodel.JMethod in project RoboBinding by RoboBinding.
the class AbstractPresentationModelObjectClassGen method definePropertyNames.
/*
@Override
public Set<String> propertyNames() {
return Sets.newHasSet("prop1", "prop2", ...);
}
*/
public void definePropertyNames() {
JMethod method = declarePublicMethodOverride("propertyNames", setClassWithString);
method.body()._return(newHashSetInvocation(presentationModelInfo.propertyNames()));
}
Aggregations