Search in sources :

Example 41 with JVar

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

the class EApplicationHolder method createSingleton.

private void createSingleton() {
    AbstractJClass annotatedComponent = generatedClass._extends();
    staticInstanceField = generatedClass.field(PRIVATE | STATIC, annotatedComponent, "INSTANCE" + generationSuffix());
    // Static singleton getter and setter
    JMethod getInstance = generatedClass.method(PUBLIC | STATIC, annotatedComponent, GET_APPLICATION_INSTANCE);
    getInstance.body()._return(staticInstanceField);
    JMethod setInstance = generatedClass.method(PUBLIC | STATIC, getCodeModel().VOID, "setForTesting");
    setInstance.javadoc().append("Visible for testing purposes");
    JVar applicationParam = setInstance.param(annotatedComponent, "application");
    setInstance.body().assign(staticInstanceField, applicationParam);
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 42 with JVar

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

the class RoboGuiceHandler method onConfigurationChangedMethod.

private void onConfigurationChangedMethod(EActivityHolder holder, RoboGuiceHolder roboGuiceHolder, JFieldVar eventManager) {
    JVar currentConfig = roboGuiceHolder.getCurrentConfig();
    IJExpression newConfig = holder.getOnConfigurationChangedNewConfigParam();
    JBlock onConfigurationChangedAfterSuperBlock = holder.getOnConfigurationChangedAfterSuperBlock();
    fireEvent(eventManager, onConfigurationChangedAfterSuperBlock, getJClass(RoboGuiceClasses.ON_CONFIGURATION_CHANGED_EVENT), currentConfig, newConfig);
}
Also used : IJExpression(com.helger.jcodemodel.IJExpression) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 43 with JVar

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

the class RoboGuiceHandler method beforeCreateMethod.

private void beforeCreateMethod(EActivityHolder holder, JFieldVar scope, JFieldVar scopedObjects, JFieldVar eventManager) {
    JBlock body = holder.getInitBody();
    AbstractJClass keyWildCard = getJClass(RoboGuiceClasses.KEY).narrow(getCodeModel().wildcard());
    AbstractJClass scopedHashMap = getClasses().HASH_MAP.narrow(keyWildCard, getClasses().OBJECT);
    body.assign(scopedObjects, JExpr._new(scopedHashMap));
    JVar injector = body.decl(getJClass(RoboGuiceClasses.ROBO_INJECTOR), "injector_", getJClass(RoboGuiceClasses.ROBO_GUICE).staticInvoke("getInjector").arg(_this()));
    body.assign(scope, invoke(injector, "getInstance").arg(getJClass(RoboGuiceClasses.CONTEXT_SCOPE).dotclass()));
    body.assign(eventManager, invoke(injector, "getInstance").arg(getJClass(RoboGuiceClasses.EVENT_MANAGER).dotclass()));
    body.add(injector.invoke("injectMembersWithoutViews").arg(_this()));
    fireEvent(eventManager, body, getJClass(RoboGuiceClasses.ON_CREATE_EVENT), holder.getInitSavedInstanceParam());
}
Also used : JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JVar(com.helger.jcodemodel.JVar)

Example 44 with JVar

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

the class RoboGuiceHandler method onActivityResultMethod.

private void onActivityResultMethod(EActivityHolder holder, JFieldVar eventManager) {
    JBlock onActivityResultAfterSuperBlock = holder.getOnActivityResultAfterSuperBlock();
    JVar requestCode = holder.getOnActivityResultRequestCodeParam();
    JVar resultCode = holder.getOnActivityResultResultCodeParam();
    JVar data = holder.getOnActivityResultDataParam();
    fireEvent(eventManager, onActivityResultAfterSuperBlock, getJClass(RoboGuiceClasses.ON_ACTIVITY_RESULT_EVENT), requestCode, resultCode, data);
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 45 with JVar

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

the class RestMethodHandler method surroundWithRestTryCatch.

/**
	 * Adds the try/catch around the rest execution code.
	 *
	 * If an exception is caught, it will first check if the handler is set. If
	 * the handler is set, it will call the handler and return null (or nothing
	 * if void). If the handler isn't set, it will re-throw the exception so
	 * that it behaves as it did previous to this feature.
	 */
private JBlock surroundWithRestTryCatch(RestHolder holder, JBlock block, boolean methodReturnVoid) {
    if (holder.getRestErrorHandlerField() != null) {
        JBlock newBlock = new JBlock().bracesRequired(false).indentRequired(false);
        JTryBlock tryBlock = newBlock._try();
        codeModelHelper.copy(block, tryBlock.body());
        JCatchBlock jCatch = tryBlock._catch(getJClass(NESTED_RUNTIME_EXCEPTION));
        JBlock catchBlock = jCatch.body();
        JConditional conditional = catchBlock._if(JOp.ne(holder.getRestErrorHandlerField(), JExpr._null()));
        JVar exceptionParam = jCatch.param("e");
        JBlock thenBlock = conditional._then();
        // call the handler method if it was set.
        thenBlock.add(holder.getRestErrorHandlerField().invoke("onRestClientExceptionThrown").arg(exceptionParam));
        // return null if exception was caught and handled.
        if (!methodReturnVoid) {
            thenBlock._return(JExpr._null());
        }
        // re-throw the exception if handler wasn't set.
        conditional._else()._throw(exceptionParam);
        return newBlock;
    }
    return block;
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JConditional(com.helger.jcodemodel.JConditional) JTryBlock(com.helger.jcodemodel.JTryBlock) JCatchBlock(com.helger.jcodemodel.JCatchBlock) JVar(com.helger.jcodemodel.JVar)

Aggregations

JVar (com.helger.jcodemodel.JVar)119 JBlock (com.helger.jcodemodel.JBlock)81 JMethod (com.helger.jcodemodel.JMethod)56 AbstractJClass (com.helger.jcodemodel.AbstractJClass)48 JInvocation (com.helger.jcodemodel.JInvocation)38 IJExpression (com.helger.jcodemodel.IJExpression)32 VariableElement (javax.lang.model.element.VariableElement)25 ExecutableElement (javax.lang.model.element.ExecutableElement)18 TypeMirror (javax.lang.model.type.TypeMirror)16 JDefinedClass (com.helger.jcodemodel.JDefinedClass)15 JFieldRef (com.helger.jcodemodel.JFieldRef)15 JFieldVar (com.helger.jcodemodel.JFieldVar)12 JConditional (com.helger.jcodemodel.JConditional)9 JTryBlock (com.helger.jcodemodel.JTryBlock)7 JCatchBlock (com.helger.jcodemodel.JCatchBlock)5 AbstractJType (com.helger.jcodemodel.AbstractJType)4 ArrayList (java.util.ArrayList)4 BundleHelper (org.androidannotations.helper.BundleHelper)4 JTypeVar (com.helger.jcodemodel.JTypeVar)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3