Search in sources :

Example 46 with JBlock

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

the class EActivityHolder method setFindSupportFragmentByTag.

@Override
protected void setFindSupportFragmentByTag() {
    JMethod method = generatedClass.method(PRIVATE, getClasses().SUPPORT_V4_FRAGMENT, "findSupportFragmentByTag");
    JVar tagParam = method.param(getClasses().STRING, "tag");
    JBlock body = method.body();
    body._return(invoke("getSupportFragmentManager").invoke("findFragmentByTag").arg(tagParam));
    findSupportFragmentByTag = method;
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 47 with JBlock

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

the class EActivityHolder method setOnRetainNonConfigurationInstance.

private void setOnRetainNonConfigurationInstance() throws JClassAlreadyExistsException {
    AnnotationHelper annotationHelper = new AnnotationHelper(getEnvironment());
    TypeElement fragmentActivityTypeElement = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.FRAGMENT_ACTIVITY);
    TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(generatedClass._extends().fullName());
    String onRetainNonConfigurationInstanceName = "onRetainNonConfigurationInstance";
    if (fragmentActivityTypeElement != null && annotationHelper.isSubtype(typeElement.asType(), fragmentActivityTypeElement.asType())) {
        onRetainNonConfigurationInstanceName = "onRetainCustomNonConfigurationInstance";
    }
    NonConfigurationHolder ncHolder = getNonConfigurationHolder();
    JDefinedClass ncHolderClass = ncHolder.getGeneratedClass();
    JMethod onRetainNonConfigurationInstanceMethod = generatedClass.method(PUBLIC, ncHolderClass, onRetainNonConfigurationInstanceName);
    onRetainNonConfigurationInstanceMethod.annotate(Override.class);
    JBlock methodBody = onRetainNonConfigurationInstanceMethod.body();
    onRetainNonConfigurationInstance = methodBody.decl(ncHolderClass, "nonConfigurationInstanceState_", _new(ncHolderClass));
    IJExpression superCall = _super().invoke(onRetainNonConfigurationInstanceMethod);
    methodBody.assign(onRetainNonConfigurationInstance.ref(ncHolder.getSuperNonConfigurationInstanceField()), superCall);
    onRetainNonConfigurationInstanceBindBlock = methodBody.blockSimple();
    methodBody._return(onRetainNonConfigurationInstance);
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) AnnotationHelper(org.androidannotations.helper.AnnotationHelper) TypeElement(javax.lang.model.element.TypeElement) JBlock(com.helger.jcodemodel.JBlock) IJExpression(com.helger.jcodemodel.IJExpression) JMethod(com.helger.jcodemodel.JMethod)

Example 48 with JBlock

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

the class RoboGuiceHandler method onNewIntentMethod.

private void onNewIntentMethod(EActivityHolder holder, JFieldVar eventManager) {
    JBlock onNewIntentAfterSuperBlock = holder.getOnNewIntentAfterSuperBlock();
    fireEvent(eventManager, onNewIntentAfterSuperBlock, getJClass(RoboGuiceClasses.ON_NEW_INTENT_EVENT));
}
Also used : JBlock(com.helger.jcodemodel.JBlock)

Example 49 with JBlock

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

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

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