Search in sources :

Example 51 with JMethod

use of com.helger.jcodemodel.JMethod in project androidannotations by androidannotations.

the class AbstractOttoHandler method process.

@Override
public void process(Element element, EComponentHolder holder) throws Exception {
    if (!annotationHelper.enclosingElementHasEnhancedComponentAnnotation(element)) {
        // do nothing when otto annotations are used in non-enhanced classes
        return;
    }
    ExecutableElement executableElement = (ExecutableElement) element;
    JMethod method = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
    addOttoAnnotation(executableElement, method);
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) JMethod(com.helger.jcodemodel.JMethod)

Example 52 with JMethod

use of com.helger.jcodemodel.JMethod in project androidannotations by androidannotations.

the class RoboGuiceHandler method onDestroyMethod.

private void onDestroyMethod(EActivityHolder holder, JFieldVar eventManager) {
    JBlock onDestroyBlock = new JBlock().bracesRequired(false).indentRequired(false);
    JTryBlock tryBlock = onDestroyBlock._try();
    fireEvent(eventManager, tryBlock.body(), getJClass(RoboGuiceClasses.ON_DESTROY_EVENT));
    JBlock finallyBody = tryBlock._finally();
    JTryBlock tryInFinally = finallyBody._try();
    tryInFinally.body().add(getJClass(RoboGuiceClasses.ROBO_GUICE).staticInvoke("destroyInjector").arg(_this()));
    tryInFinally._finally().invoke(_super(), "onDestroy");
    JMethod onDestroy = holder.getOnDestroy();
    codeModelHelper.replaceSuperCall(onDestroy, onDestroyBlock);
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JTryBlock(com.helger.jcodemodel.JTryBlock) JMethod(com.helger.jcodemodel.JMethod)

Example 53 with JMethod

use of com.helger.jcodemodel.JMethod in project androidannotations by androidannotations.

the class RoboGuiceHandler method onStopMethod.

private void onStopMethod(EActivityHolder holder, JFieldVar eventManager) {
    JBlock onStopBlock = new JBlock().bracesRequired(false).indentRequired(false);
    JTryBlock tryBlock = onStopBlock._try();
    fireEvent(eventManager, tryBlock.body(), getJClass(RoboGuiceClasses.ON_STOP_EVENT));
    JBlock finallyBody = tryBlock._finally();
    finallyBody.invoke(_super(), "onStop");
    JMethod onStop = holder.getOnStop();
    codeModelHelper.replaceSuperCall(onStop, onStopBlock);
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JTryBlock(com.helger.jcodemodel.JTryBlock) JMethod(com.helger.jcodemodel.JMethod)

Example 54 with JMethod

use of com.helger.jcodemodel.JMethod in project androidannotations by androidannotations.

the class IntentBuilder method addPutExtraMethod.

private JMethod addPutExtraMethod(Element element, List<IntentExtra> intentExtras) {
    String docComment = elementUtils.getDocComment(element);
    JMethod method = holder.getIntentBuilderClass().method(PUBLIC, holder.getIntentBuilderClass(), element.getSimpleName().toString());
    method.javadoc().addReturn().append("the IntentBuilder to chain calls");
    codeModelHelper.addTrimmedDocComment(method, docComment);
    int paramCount = intentExtras.size();
    for (int i = 0; i < paramCount; i++) {
        IntentExtra intentExtra = intentExtras.get(i);
        method.javadoc().addParam(intentExtra.parameterName).append("the value for this extra");
        AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(intentExtra.type);
        JVar extraParameterVar = method.param(parameterClass, intentExtra.parameterName);
        JInvocation superCall = getSuperPutExtraInvocation(intentExtra.type, extraParameterVar, intentExtra.keyField);
        if (i + 1 == paramCount) {
            method.body()._return(superCall);
        } else {
            method.body().add(superCall);
        }
    }
    return method;
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 55 with JMethod

use of com.helger.jcodemodel.JMethod in project androidannotations by androidannotations.

the class IntentBuilder method createContextConstructor.

private void createContextConstructor() {
    IJExpression generatedClass = holder.getGeneratedClass().dotclass();
    JMethod constructor = holder.getIntentBuilderClass().constructor(JMod.PUBLIC);
    JVar constructorContextParam = constructor.param(getClasses().CONTEXT, "context");
    constructor.body().invoke("super").arg(constructorContextParam).arg(generatedClass);
}
Also used : IJExpression(com.helger.jcodemodel.IJExpression) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Aggregations

JMethod (com.helger.jcodemodel.JMethod)122 JBlock (com.helger.jcodemodel.JBlock)73 JVar (com.helger.jcodemodel.JVar)56 AbstractJClass (com.helger.jcodemodel.AbstractJClass)36 JInvocation (com.helger.jcodemodel.JInvocation)26 JDefinedClass (com.helger.jcodemodel.JDefinedClass)20 IJExpression (com.helger.jcodemodel.IJExpression)15 ExecutableElement (javax.lang.model.element.ExecutableElement)13 JFieldVar (com.helger.jcodemodel.JFieldVar)10 JConditional (com.helger.jcodemodel.JConditional)8 JTryBlock (com.helger.jcodemodel.JTryBlock)7 JTypeVar (com.helger.jcodemodel.JTypeVar)7 TypeMirror (javax.lang.model.type.TypeMirror)7 VariableElement (javax.lang.model.element.VariableElement)6 JFieldRef (com.helger.jcodemodel.JFieldRef)5 JPrimitiveType (com.helger.jcodemodel.JPrimitiveType)5 ArrayList (java.util.ArrayList)5 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)4 GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)4 AbstractJType (com.helger.jcodemodel.AbstractJType)4