use of javax.lang.model.element.ExecutableElement 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 javax.lang.model.element.ExecutableElement 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 javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class SharedPrefHandler method generateFieldMethodAndEditorFieldMethod.
private void generateFieldMethodAndEditorFieldMethod(Element element, SharedPrefHolder sharedPrefHolder) {
for (ExecutableElement method : getValidMethods(element)) {
IJExpression keyExpression = generateFieldMethod(sharedPrefHolder, method);
sharedPrefHolder.createEditorFieldMethods(method, keyExpression);
}
}
use of javax.lang.model.element.ExecutableElement 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 javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class TouchHandler method validate.
@Override
public void validate(Element element, ElementValidation validation) {
super.validate(element, validation);
ExecutableElement executableElement = (ExecutableElement) element;
validatorHelper.returnTypeIsVoidOrBoolean(executableElement, validation);
//
validatorHelper.param.anyOrder().type(CanonicalNameConstants.MOTION_EVENT).optional().extendsType(CanonicalNameConstants.VIEW).optional().validate(executableElement, validation);
}
Aggregations