Search in sources :

Example 56 with JBlock

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

the class OrmLiteHolder method injectReleaseInOnDestroy.

private void injectReleaseInOnDestroy(JFieldVar databaseHelperRef) {
    if (holder() instanceof HasLifecycleMethods) {
        JBlock destroyBody = ((HasLifecycleMethods) holder()).getOnDestroyBeforeSuperBlock();
        destroyBody.staticInvoke(getJClass(OrmLiteClasses.OPEN_HELPER_MANAGER), "releaseHelper");
        destroyBody.assign(databaseHelperRef, _null());
    }
}
Also used : HasLifecycleMethods(org.androidannotations.holder.HasLifecycleMethods) JBlock(com.helger.jcodemodel.JBlock)

Example 57 with JBlock

use of com.helger.jcodemodel.JBlock 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 58 with JBlock

use of com.helger.jcodemodel.JBlock 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 59 with JBlock

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

the class RoboGuiceHolder method getCurrentConfig.

public JVar getCurrentConfig() {
    if (currentConfig == null) {
        AbstractJClass configurationClass = environment().getClasses().CONFIGURATION;
        JBlock onConfigurationChangedBeforeSuperBlock = holder().getOnConfigurationChangedBeforeSuperBlock();
        currentConfig = onConfigurationChangedBeforeSuperBlock.decl(configurationClass, "currentConfig", JExpr.invoke("getResources").invoke("getConfiguration"));
        onConfigurationChangedBeforeSuperBlock.bracesRequired(false).indentRequired(false);
    }
    return currentConfig;
}
Also used : JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 60 with JBlock

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

the class ReceiverActionHandler method addActionInOnReceive.

private void addActionInOnReceive(EReceiverHolder holder, ExecutableElement executableElement, String methodName, JFieldVar actionsField, JFieldVar dataSchemesField) {
    String actionsInvoke = getInvocationName(actionsField);
    IJExpression filterCondition = actionsField.invoke(actionsInvoke).arg(holder.getOnReceiveIntentAction());
    if (dataSchemesField != null) {
        String dataSchemesInvoke = getInvocationName(dataSchemesField);
        filterCondition = filterCondition.cand(dataSchemesField.invoke(dataSchemesInvoke).arg(holder.getOnReceiveIntentDataScheme()));
    }
    JBlock callActionBlock = holder.getOnReceiveBody()._if(filterCondition)._then();
    IJExpression receiverRef = holder.getGeneratedClass().staticRef("this");
    JInvocation callActionInvocation = receiverRef.invoke(methodName);
    JVar intent = holder.getOnReceiveIntent();
    JVar extras = null;
    List<? extends VariableElement> methodParameters = executableElement.getParameters();
    for (VariableElement param : methodParameters) {
        AbstractJClass extraParamClass = codeModelHelper.typeMirrorToJClass(param.asType());
        if (extraParamClass.equals(getClasses().CONTEXT)) {
            callActionInvocation.arg(holder.getOnReceiveContext());
        } else if (extraParamClass.equals(getClasses().INTENT) && param.getAnnotation(ReceiverAction.Extra.class) == null) {
            callActionInvocation.arg(intent);
        } else if (param.getAnnotation(ReceiverAction.Extra.class) != null) {
            if (extras == null) {
                extras = callActionBlock.decl(getClasses().BUNDLE, "extras_", JOp.cond(//
                intent.invoke("getExtras").ne(_null()), intent.invoke("getExtras"), _new(getClasses().BUNDLE)));
            }
            callActionInvocation.arg(extraHandler.getExtraValue(param, extras, callActionBlock, holder));
        }
    }
    callActionBlock.add(callActionInvocation);
    callActionBlock._return();
}
Also used : IJExpression(com.helger.jcodemodel.IJExpression) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) VariableElement(javax.lang.model.element.VariableElement) JVar(com.helger.jcodemodel.JVar)

Aggregations

JBlock (com.helger.jcodemodel.JBlock)148 JVar (com.helger.jcodemodel.JVar)81 JMethod (com.helger.jcodemodel.JMethod)73 JInvocation (com.helger.jcodemodel.JInvocation)37 AbstractJClass (com.helger.jcodemodel.AbstractJClass)35 IJExpression (com.helger.jcodemodel.IJExpression)31 ExecutableElement (javax.lang.model.element.ExecutableElement)25 JFieldRef (com.helger.jcodemodel.JFieldRef)19 JDefinedClass (com.helger.jcodemodel.JDefinedClass)15 VariableElement (javax.lang.model.element.VariableElement)15 TypeMirror (javax.lang.model.type.TypeMirror)13 JFieldVar (com.helger.jcodemodel.JFieldVar)11 JConditional (com.helger.jcodemodel.JConditional)10 JTryBlock (com.helger.jcodemodel.JTryBlock)9 JCatchBlock (com.helger.jcodemodel.JCatchBlock)4 TypeElement (javax.lang.model.element.TypeElement)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 TextWatcherHolder (org.androidannotations.holder.TextWatcherHolder)3 AbstractJType (com.helger.jcodemodel.AbstractJType)2 IJAssignmentTarget (com.helger.jcodemodel.IJAssignmentTarget)2