Search in sources :

Example 56 with ExecutableElement

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");
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod) JTryBlock(com.helger.jcodemodel.JTryBlock) JCatchBlock(com.helger.jcodemodel.JCatchBlock) JVar(com.helger.jcodemodel.JVar)

Example 57 with ExecutableElement

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)));
}
Also used : UiThreadExecutor(org.androidannotations.api.UiThreadExecutor) JDefinedClass(com.helger.jcodemodel.JDefinedClass) UiThread(org.androidannotations.annotations.UiThread) ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod)

Example 58 with ExecutableElement

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);
    }
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) IJExpression(com.helger.jcodemodel.IJExpression)

Example 59 with ExecutableElement

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());
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod)

Example 60 with ExecutableElement

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);
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement)

Aggregations

ExecutableElement (javax.lang.model.element.ExecutableElement)345 TypeElement (javax.lang.model.element.TypeElement)158 TypeMirror (javax.lang.model.type.TypeMirror)97 VariableElement (javax.lang.model.element.VariableElement)85 Element (javax.lang.model.element.Element)72 Test (org.junit.Test)41 GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)32 DeclaredType (javax.lang.model.type.DeclaredType)31 ArrayList (java.util.ArrayList)26 JBlock (com.helger.jcodemodel.JBlock)25 JInvocation (com.helger.jcodemodel.JInvocation)20 MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)18 JVar (com.helger.jcodemodel.JVar)18 Map (java.util.Map)18 HashSet (java.util.HashSet)17 IJExpression (com.helger.jcodemodel.IJExpression)16 ElementValidation (org.androidannotations.ElementValidation)15 Block (com.google.devtools.j2objc.ast.Block)13 JMethod (com.helger.jcodemodel.JMethod)13 Elements (javax.lang.model.util.Elements)13