Search in sources :

Example 76 with AbstractJClass

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

the class ViewNotifierHelper method replacePreviousNotifier.

public JVar replacePreviousNotifier(JBlock block) {
    AbstractJClass notifierClass = holder.getEnvironment().getJClass(OnViewChangedNotifier.class);
    if (notifier == null) {
        notifier = holder.getGeneratedClass().field(PRIVATE | FINAL, notifierClass, "onViewChangedNotifier" + generationSuffix(), _new(notifierClass));
        holder.getGeneratedClass()._implements(HasViews.class);
    }
    return block.decl(notifierClass, "previousNotifier", notifierClass.staticInvoke("replaceNotifier").arg(notifier));
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 77 with AbstractJClass

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

the class InstanceStateHandler method process.

@Override
public void process(Element element, HasInstanceState holder) {
    AbstractJClass elementClass = codeModelHelper.typeMirrorToJClass(element.asType());
    String fieldName = element.getSimpleName().toString();
    JBlock saveStateBody = holder.getSaveStateMethodBody();
    JVar saveStateBundleParam = holder.getSaveStateBundleParam();
    JMethod restoreStateMethod = holder.getRestoreStateMethod();
    JBlock restoreStateBody = holder.getRestoreStateMethodBody();
    JVar restoreStateBundleParam = holder.getRestoreStateBundleParam();
    TypeMirror type = codeModelHelper.getActualType(element, holder);
    BundleHelper bundleHelper = new BundleHelper(getEnvironment(), type);
    JFieldRef ref = ref(fieldName);
    saveStateBody.add(bundleHelper.getExpressionToSaveFromField(saveStateBundleParam, JExpr.lit(fieldName), ref));
    IJExpression restoreMethodCall = bundleHelper.getExpressionToRestoreFromBundle(elementClass, restoreStateBundleParam, JExpr.lit(fieldName), restoreStateMethod);
    restoreStateBody.assign(ref, restoreMethodCall);
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) TypeMirror(javax.lang.model.type.TypeMirror) JBlock(com.helger.jcodemodel.JBlock) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar) BundleHelper(org.androidannotations.helper.BundleHelper)

Example 78 with AbstractJClass

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

the class ItemClickHandler method processParameters.

@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation call, List<? extends VariableElement> parameters) {
    boolean hasItemParameter = parameters.size() == 1;
    AbstractJClass narrowAdapterViewClass = getClasses().ADAPTER_VIEW.narrow(getCodeModel().wildcard());
    JVar onItemClickParentParam = listenerMethod.param(narrowAdapterViewClass, "parent");
    listenerMethod.param(getClasses().VIEW, "view");
    JVar onItemClickPositionParam = listenerMethod.param(getCodeModel().INT, "position");
    listenerMethod.param(getCodeModel().LONG, "id");
    if (hasItemParameter) {
        VariableElement parameter = parameters.get(0);
        TypeMirror parameterType = parameter.asType();
        if (parameterType.getKind() == TypeKind.INT) {
            call.arg(onItemClickPositionParam);
        } else {
            AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(parameterType);
            call.arg(cast(parameterClass, invoke(onItemClickParentParam, "getAdapter").invoke("getItem").arg(onItemClickPositionParam)));
            if (parameterClass.isParameterized()) {
                codeModelHelper.addSuppressWarnings(listenerMethod, "unchecked");
            }
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) AbstractJClass(com.helger.jcodemodel.AbstractJClass) VariableElement(javax.lang.model.element.VariableElement) JVar(com.helger.jcodemodel.JVar)

Example 79 with AbstractJClass

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

the class ItemLongClickHandler method processParameters.

@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation call, List<? extends VariableElement> parameters) {
    boolean hasItemParameter = parameters.size() == 1;
    AbstractJClass narrowAdapterViewClass = getClasses().ADAPTER_VIEW.narrow(getCodeModel().wildcard());
    JVar onItemClickParentParam = listenerMethod.param(narrowAdapterViewClass, "parent");
    listenerMethod.param(getClasses().VIEW, "view");
    JVar onItemClickPositionParam = listenerMethod.param(getCodeModel().INT, "position");
    listenerMethod.param(getCodeModel().LONG, "id");
    if (hasItemParameter) {
        VariableElement parameter = parameters.get(0);
        TypeMirror parameterType = parameter.asType();
        if (parameterType.getKind() == TypeKind.INT) {
            call.arg(onItemClickPositionParam);
        } else {
            AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(parameterType);
            call.arg(cast(parameterClass, invoke(onItemClickParentParam, "getAdapter").invoke("getItem").arg(onItemClickPositionParam)));
            if (parameterClass.isParameterized()) {
                codeModelHelper.addSuppressWarnings(listenerMethod, "unchecked");
            }
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) AbstractJClass(com.helger.jcodemodel.AbstractJClass) VariableElement(javax.lang.model.element.VariableElement) JVar(com.helger.jcodemodel.JVar)

Example 80 with AbstractJClass

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

the class ActivityIntentBuilder method overrideStartForResultMethod.

private void overrideStartForResultMethod() {
    AbstractJClass postActivityStarterClass = environment.getJClass(PostActivityStarter.class);
    JMethod method = holder.getIntentBuilderClass().method(PUBLIC, postActivityStarterClass, "startForResult");
    method.annotate(Override.class);
    JVar requestCode = method.param(environment.getCodeModel().INT, "requestCode");
    JBlock body = method.body();
    JConditional condition = null;
    if (fragmentSupportField != null) {
        condition = body._if(fragmentSupportField.ne(JExpr._null()));
        //
        condition._then().invoke(fragmentSupportField, "startActivityForResult").arg(intentField).arg(requestCode);
    }
    if (fragmentField != null) {
        if (condition == null) {
            condition = body._if(fragmentField.ne(JExpr._null()));
        } else {
            condition = condition._elseif(fragmentField.ne(JExpr._null()));
        }
        JBlock fragmentStartForResultInvocationBlock;
        if (hasActivityOptionsInFragment() && shouldGuardActivityOptions()) {
            fragmentStartForResultInvocationBlock = createCallWithIfGuard(requestCode, condition._then(), fragmentField);
        } else {
            fragmentStartForResultInvocationBlock = condition._then();
        }
        JInvocation invocation = //
        fragmentStartForResultInvocationBlock.invoke(fragmentField, "startActivityForResult").arg(intentField).arg(requestCode);
        if (hasActivityOptionsInFragment()) {
            invocation.arg(optionsField);
        }
    }
    JBlock activityStartInvocationBlock = null;
    if (condition != null) {
        activityStartInvocationBlock = condition._else();
    } else {
        activityStartInvocationBlock = method.body();
    }
    JConditional activityCondition = activityStartInvocationBlock._if(contextField._instanceof(getClasses().ACTIVITY));
    JBlock thenBlock = activityCondition._then();
    JVar activityVar = thenBlock.decl(getClasses().ACTIVITY, "activity", JExpr.cast(getClasses().ACTIVITY, contextField));
    if (hasActivityCompatInClasspath() && hasActivityOptionsInActivityCompat()) {
        //
        thenBlock.staticInvoke(getClasses().ACTIVITY_COMPAT, "startActivityForResult").arg(activityVar).arg(intentField).arg(requestCode).arg(optionsField);
    } else if (hasActivityOptionsInFragment()) {
        JBlock startForResultInvocationBlock;
        if (shouldGuardActivityOptions()) {
            startForResultInvocationBlock = createCallWithIfGuard(requestCode, thenBlock, activityVar);
        } else {
            startForResultInvocationBlock = thenBlock;
        }
        //
        startForResultInvocationBlock.invoke(activityVar, "startActivityForResult").arg(intentField).arg(requestCode).arg(optionsField);
    } else {
        thenBlock.invoke(activityVar, "startActivityForResult").arg(intentField).arg(requestCode);
    }
    if (hasActivityOptionsInFragment()) {
        JBlock startInvocationBlock;
        if (shouldGuardActivityOptions()) {
            startInvocationBlock = createCallWithIfGuard(null, activityCondition._else(), contextField);
        } else {
            startInvocationBlock = activityCondition._else();
        }
        startInvocationBlock.invoke(contextField, "startActivity").arg(intentField).arg(optionsField);
    } else {
        activityCondition._else().invoke(contextField, "startActivity").arg(intentField);
    }
    body._return(_new(postActivityStarterClass).arg(contextField));
}
Also used : JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JConditional(com.helger.jcodemodel.JConditional) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Aggregations

AbstractJClass (com.helger.jcodemodel.AbstractJClass)125 JVar (com.helger.jcodemodel.JVar)48 JMethod (com.helger.jcodemodel.JMethod)36 JBlock (com.helger.jcodemodel.JBlock)35 JInvocation (com.helger.jcodemodel.JInvocation)31 TypeMirror (javax.lang.model.type.TypeMirror)24 IJExpression (com.helger.jcodemodel.IJExpression)23 JDefinedClass (com.helger.jcodemodel.JDefinedClass)19 VariableElement (javax.lang.model.element.VariableElement)14 JFieldVar (com.helger.jcodemodel.JFieldVar)13 GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)9 ExecutableElement (javax.lang.model.element.ExecutableElement)9 JAnnotationUse (com.helger.jcodemodel.JAnnotationUse)8 JConditional (com.helger.jcodemodel.JConditional)8 JTypeVar (com.helger.jcodemodel.JTypeVar)8 DeclaredType (javax.lang.model.type.DeclaredType)8 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)6 JFieldRef (com.helger.jcodemodel.JFieldRef)6 ArrayList (java.util.ArrayList)6 BundleHelper (org.androidannotations.helper.BundleHelper)6