Search in sources :

Example 11 with IJExpression

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

the class ActivityIntentBuilder method addFragmentConstructor.

private JFieldVar addFragmentConstructor(AbstractJClass fragmentClass, String fieldName) {
    JFieldVar fragmentField = holder.getIntentBuilderClass().field(PRIVATE, fragmentClass, fieldName);
    IJExpression generatedClass = holder.getGeneratedClass().dotclass();
    JMethod constructor = holder.getIntentBuilderClass().constructor(JMod.PUBLIC);
    JVar constructorFragmentParam = constructor.param(fragmentClass, "fragment");
    JBlock constructorBody = constructor.body();
    constructorBody.invoke("super").arg(constructorFragmentParam.invoke("getActivity")).arg(generatedClass);
    constructorBody.assign(fragmentField, constructorFragmentParam);
    return fragmentField;
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) IJExpression(com.helger.jcodemodel.IJExpression) JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 12 with IJExpression

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

the class OptionsItemHandler method process.

@Override
public void process(Element element, HasOptionsMenu holder) {
    String methodName = element.getSimpleName().toString();
    ExecutableElement executableElement = (ExecutableElement) element;
    List<? extends VariableElement> parameters = executableElement.getParameters();
    TypeMirror returnType = executableElement.getReturnType();
    boolean returnMethodResult = returnType.getKind() != TypeKind.VOID;
    boolean hasItemParameter = parameters.size() == 1;
    List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
    JBlock block = holder.getOnOptionsItemSelectedMiddleBlock();
    IJExpression ifExpr = holder.getOnOptionsItemSelectedItemId().eq(idsRefs.get(0));
    for (int i = 1; i < idsRefs.size(); i++) {
        ifExpr = ifExpr.cor(holder.getOnOptionsItemSelectedItemId().eq(idsRefs.get(i)));
    }
    JBlock itemIfBody = block._if(ifExpr)._then();
    JInvocation methodCall = invoke(methodName);
    if (returnMethodResult) {
        itemIfBody._return(methodCall);
    } else {
        itemIfBody.add(methodCall);
        itemIfBody._return(TRUE);
    }
    if (hasItemParameter) {
        methodCall.arg(holder.getOnOptionsItemSelectedItem());
    }
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) IJExpression(com.helger.jcodemodel.IJExpression) JInvocation(com.helger.jcodemodel.JInvocation)

Example 13 with IJExpression

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

the class PageScrolledHandler method process.

@Override
public void process(Element element, EComponentWithViewSupportHolder holder) throws Exception {
    String methodName = element.getSimpleName().toString();
    ExecutableElement executableElement = (ExecutableElement) element;
    List<? extends VariableElement> parameters = executableElement.getParameters();
    int positionParameterPosition = -1;
    int positionOffsetParameterPosition = -1;
    int positionOffsetPixelsParameterPosition = -1;
    int viewPagerParameterPosition = -1;
    int numberOfIntParameters = 0;
    TypeMirror viewPagerParameterType = null;
    for (int i = 0; i < parameters.size(); i++) {
        VariableElement parameter = parameters.get(i);
        TypeMirror parameterType = parameter.asType();
        if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
            if (numberOfIntParameters == 0 && positionOffsetParameterPosition == -1) {
                positionParameterPosition = i;
            } else {
                positionOffsetPixelsParameterPosition = i;
            }
            numberOfIntParameters++;
        } else if (parameterType.getKind() == TypeKind.FLOAT || CanonicalNameConstants.FLOAT.equals(parameterType.toString())) {
            positionOffsetParameterPosition = i;
        } else {
            if (isViewPagerParameter(parameterType)) {
                viewPagerParameterPosition = i;
                viewPagerParameterType = parameterType;
            }
        }
    }
    List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
    for (JFieldRef idRef : idsRefs) {
        PageChangeHolder pageChangeHolder = holder.getPageChangeHolder(idRef, viewPagerParameterType, hasAddOnPageChangeListenerMethod());
        JBlock methodBody = pageChangeHolder.getPageScrolledBody();
        IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
        JInvocation pageScrollCall = methodBody.invoke(activityRef, methodName);
        for (int i = 0; i < parameters.size(); i++) {
            if (i == positionParameterPosition) {
                JVar positionParam = pageChangeHolder.getPageScrolledPositionParam();
                pageScrollCall.arg(positionParam);
            } else if (i == positionOffsetParameterPosition) {
                JVar pageScrolledPositionOffsetParam = pageChangeHolder.getPageScrolledPositionOffsetParam();
                pageScrollCall.arg(pageScrolledPositionOffsetParam);
            } else if (i == positionOffsetPixelsParameterPosition) {
                JVar pageScrolledPositionOffsetPixelsParam = pageChangeHolder.getPageScrolledPositionOffsetPixelsParam();
                pageScrollCall.arg(pageScrolledPositionOffsetPixelsParam);
            } else if (i == viewPagerParameterPosition) {
                JVar viewParameter = pageChangeHolder.getViewPagerVariable();
                pageScrollCall.arg(viewParameter);
            }
        }
    }
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) ExecutableElement(javax.lang.model.element.ExecutableElement) IJExpression(com.helger.jcodemodel.IJExpression) PageChangeHolder(org.androidannotations.holder.PageChangeHolder) JInvocation(com.helger.jcodemodel.JInvocation) VariableElement(javax.lang.model.element.VariableElement) TypeMirror(javax.lang.model.type.TypeMirror) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 14 with IJExpression

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

Example 15 with IJExpression

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

IJExpression (com.helger.jcodemodel.IJExpression)56 JVar (com.helger.jcodemodel.JVar)33 JBlock (com.helger.jcodemodel.JBlock)31 JInvocation (com.helger.jcodemodel.JInvocation)28 AbstractJClass (com.helger.jcodemodel.AbstractJClass)24 TypeMirror (javax.lang.model.type.TypeMirror)21 JMethod (com.helger.jcodemodel.JMethod)16 ExecutableElement (javax.lang.model.element.ExecutableElement)16 JFieldRef (com.helger.jcodemodel.JFieldRef)15 VariableElement (javax.lang.model.element.VariableElement)12 JConditional (com.helger.jcodemodel.JConditional)7 JFieldVar (com.helger.jcodemodel.JFieldVar)7 JDefinedClass (com.helger.jcodemodel.JDefinedClass)5 BundleHelper (org.androidannotations.helper.BundleHelper)5 JTryBlock (com.helger.jcodemodel.JTryBlock)4 JCatchBlock (com.helger.jcodemodel.JCatchBlock)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 TextWatcherHolder (org.androidannotations.holder.TextWatcherHolder)3 IJAssignmentTarget (com.helger.jcodemodel.IJAssignmentTarget)2 OnSeekBarChangeListenerHolder (org.androidannotations.holder.OnSeekBarChangeListenerHolder)2