Search in sources :

Example 16 with JInvocation

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

the class RestHandler method setResponseErrorHandler.

private void setResponseErrorHandler(Element element, RestHolder holder) {
    DeclaredType responseErrorHandler = annotationHelper.extractAnnotationClassParameter(element, getTarget(), "responseErrorHandler");
    if (responseErrorHandler != null) {
        JInvocation errorHandler = codeModelHelper.newBeanOrEBean(responseErrorHandler, holder.getInitContextParam());
        holder.getInit().body().add(invoke(holder.getRestTemplateField(), "setErrorHandler").arg(errorHandler));
    }
}
Also used : JInvocation(com.helger.jcodemodel.JInvocation) DeclaredType(javax.lang.model.type.DeclaredType)

Example 17 with JInvocation

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

the class IntentBuilder method addPutExtraMethod.

private JMethod addPutExtraMethod(Element element, List<IntentExtra> intentExtras) {
    String docComment = elementUtils.getDocComment(element);
    JMethod method = holder.getIntentBuilderClass().method(PUBLIC, holder.getIntentBuilderClass(), element.getSimpleName().toString());
    method.javadoc().addReturn().append("the IntentBuilder to chain calls");
    codeModelHelper.addTrimmedDocComment(method, docComment);
    int paramCount = intentExtras.size();
    for (int i = 0; i < paramCount; i++) {
        IntentExtra intentExtra = intentExtras.get(i);
        method.javadoc().addParam(intentExtra.parameterName).append("the value for this extra");
        AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(intentExtra.type);
        JVar extraParameterVar = method.param(parameterClass, intentExtra.parameterName);
        JInvocation superCall = getSuperPutExtraInvocation(intentExtra.type, extraParameterVar, intentExtra.keyField);
        if (i + 1 == paramCount) {
            method.body()._return(superCall);
        } else {
            method.body().add(superCall);
        }
    }
    return method;
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 18 with JInvocation

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

Example 19 with JInvocation

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

the class ReceiverActionHandler method createStaticField.

private JFieldVar createStaticField(EReceiverHolder holder, String prefix, String methodName, String[] values) {
    String staticFieldName = CaseHelper.camelCaseToUpperSnakeCase(prefix, methodName, null);
    if (values == null || values.length == 0) {
        return null;
    } else if (values.length == 1) {
        return holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, getClasses().STRING, staticFieldName, lit(values[0]));
    }
    JInvocation asListInvoke = getClasses().ARRAYS.staticInvoke("asList");
    for (String scheme : values) {
        asListInvoke.arg(scheme);
    }
    AbstractJClass listOfStrings = getClasses().LIST.narrow(getClasses().STRING);
    return holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, listOfStrings, staticFieldName, asListInvoke);
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation)

Example 20 with JInvocation

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

the class SeekBarProgressChangeHandler 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 seekBarViewParameterPosition = -1;
    int progressParameterPosition = -1;
    int fromUserParameterPosition = -1;
    for (int i = 0; i < parameters.size(); i++) {
        VariableElement parameter = parameters.get(i);
        TypeMirror parameterType = parameter.asType();
        if (CanonicalNameConstants.SEEKBAR.equals(parameterType.toString())) {
            seekBarViewParameterPosition = i;
        } else if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
            progressParameterPosition = i;
        } else if (parameterType.getKind() == TypeKind.BOOLEAN || CanonicalNameConstants.BOOLEAN.equals(parameterType.toString())) {
            fromUserParameterPosition = i;
        }
    }
    List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
    for (JFieldRef idRef : idsRefs) {
        OnSeekBarChangeListenerHolder onSeekBarChangeListenerHolder = holder.getOnSeekBarChangeListenerHolder(idRef);
        JBlock methodBody = onSeekBarChangeListenerHolder.getOnProgressChangedBody();
        IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
        JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
        for (int i = 0; i < parameters.size(); i++) {
            if (i == seekBarViewParameterPosition) {
                JVar seekBarViewParameter = onSeekBarChangeListenerHolder.getOnProgressChangedSeekBarParam();
                textChangeCall.arg(seekBarViewParameter);
            } else if (i == progressParameterPosition) {
                JVar progressParameter = onSeekBarChangeListenerHolder.getOnProgressChangedProgressParam();
                textChangeCall.arg(progressParameter);
            } else if (i == fromUserParameterPosition) {
                JVar fromUserParameter = onSeekBarChangeListenerHolder.getOnProgressChangedFromUserParam();
                textChangeCall.arg(fromUserParameter);
            }
        }
    }
}
Also used : OnSeekBarChangeListenerHolder(org.androidannotations.holder.OnSeekBarChangeListenerHolder) JFieldRef(com.helger.jcodemodel.JFieldRef) ExecutableElement(javax.lang.model.element.ExecutableElement) IJExpression(com.helger.jcodemodel.IJExpression) 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)

Aggregations

JInvocation (com.helger.jcodemodel.JInvocation)71 JVar (com.helger.jcodemodel.JVar)38 JBlock (com.helger.jcodemodel.JBlock)37 AbstractJClass (com.helger.jcodemodel.AbstractJClass)31 IJExpression (com.helger.jcodemodel.IJExpression)27 JMethod (com.helger.jcodemodel.JMethod)26 ExecutableElement (javax.lang.model.element.ExecutableElement)20 VariableElement (javax.lang.model.element.VariableElement)16 JFieldRef (com.helger.jcodemodel.JFieldRef)14 TypeMirror (javax.lang.model.type.TypeMirror)14 JConditional (com.helger.jcodemodel.JConditional)11 JDefinedClass (com.helger.jcodemodel.JDefinedClass)9 AbstractJType (com.helger.jcodemodel.AbstractJType)5 JFieldVar (com.helger.jcodemodel.JFieldVar)5 JTryBlock (com.helger.jcodemodel.JTryBlock)5 ArrayList (java.util.ArrayList)4 DeclaredType (javax.lang.model.type.DeclaredType)4 JCatchBlock (com.helger.jcodemodel.JCatchBlock)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 TextWatcherHolder (org.androidannotations.holder.TextWatcherHolder)3