Search in sources :

Example 11 with JInvocation

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

the class ItemSelectHandler method processParameters.

@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation itemSelectedCall, List<? extends VariableElement> parameters) {
    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");
    itemSelectedCall.arg(JExpr.TRUE);
    boolean hasItemParameter = parameters.size() == 2;
    boolean secondParameterIsInt = false;
    String secondParameterQualifiedName = null;
    if (hasItemParameter) {
        VariableElement secondParameter = parameters.get(1);
        TypeMirror secondParameterType = secondParameter.asType();
        secondParameterQualifiedName = secondParameterType.toString();
        secondParameterIsInt = secondParameterType.getKind() == TypeKind.INT;
    }
    if (hasItemParameter) {
        if (secondParameterIsInt) {
            itemSelectedCall.arg(onItemClickPositionParam);
        } else {
            itemSelectedCall.arg(JExpr.cast(getJClass(secondParameterQualifiedName), invoke(onItemClickParentParam, "getAdapter").invoke("getItem").arg(onItemClickPositionParam)));
        }
    }
    onNothingSelectedMethod.param(narrowAdapterViewClass, "parent");
    IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
    JInvocation nothingSelectedCall = invoke(activityRef, getMethodName());
    onNothingSelectedMethod.body().add(nothingSelectedCall);
    nothingSelectedCall.arg(JExpr.FALSE);
    if (hasItemParameter) {
        if (secondParameterIsInt) {
            nothingSelectedCall.arg(lit(-1));
        } else {
            nothingSelectedCall.arg(_null());
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) VariableElement(javax.lang.model.element.VariableElement) JVar(com.helger.jcodemodel.JVar)

Example 12 with JInvocation

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

the class APTCodeModelHelper method getSuperCall.

public JInvocation getSuperCall(GeneratedClassHolder holder, JMethod superMethod) {
    IJExpression activitySuper = holder.getGeneratedClass().staticRef("super");
    JInvocation superCall = JExpr.invoke(activitySuper, superMethod);
    for (JVar param : superMethod.params()) {
        superCall.arg(param);
    }
    if (superMethod.hasVarArgs()) {
        superCall.arg(superMethod.varParam());
    }
    return superCall;
}
Also used : IJExpression(com.helger.jcodemodel.IJExpression) JInvocation(com.helger.jcodemodel.JInvocation) JVar(com.helger.jcodemodel.JVar)

Example 13 with JInvocation

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

the class EActivityHolder method setContentViewMethod.

private JMethod setContentViewMethod(AbstractJType[] paramTypes, String[] paramNames) {
    JMethod method = generatedClass.method(JMod.PUBLIC, getCodeModel().VOID, "setContentView");
    method.annotate(Override.class);
    List<JVar> params = new ArrayList<>();
    for (int i = 0; i < paramTypes.length; i++) {
        JVar param = method.param(paramTypes[i], paramNames[i]);
        params.add(param);
    }
    JBlock body = method.body();
    JInvocation superCall = body.invoke(JExpr._super(), method);
    for (JVar arg : params) {
        superCall.arg(arg);
    }
    viewNotifierHelper.invokeViewChanged(body);
    return method;
}
Also used : ArrayList(java.util.ArrayList) JBlock(com.helger.jcodemodel.JBlock) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 14 with JInvocation

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

the class RestHolder method implementGetCookie.

private void implementGetCookie(List<ExecutableElement> methods) {
    JMethod getCookieMethod = codeModelHelper.implementMethod(this, methods, "getCookie", STRING, STRING);
    if (getCookieMethod != null) {
        JInvocation cookieValue = JExpr.invoke(getAvailableCookiesField(), "get").arg(getCookieMethod.params().get(0));
        getCookieMethod.body()._return(cookieValue);
    }
}
Also used : JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod)

Example 15 with JInvocation

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

the class RestHandler method setConverters.

private void setConverters(Element element, RestHolder holder) {
    List<DeclaredType> converters = annotationHelper.extractAnnotationClassArrayParameter(element, getTarget(), "converters");
    JFieldVar restTemplateField = holder.getRestTemplateField();
    JBlock init = holder.getInit().body();
    init.add(invoke(restTemplateField, "getMessageConverters").invoke("clear"));
    for (DeclaredType converterType : converters) {
        JInvocation newConverter = codeModelHelper.newBeanOrEBean(converterType, holder.getInitContextParam());
        init.add(invoke(restTemplateField, "getMessageConverters").invoke("add").arg(newConverter));
    }
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) JBlock(com.helger.jcodemodel.JBlock) JInvocation(com.helger.jcodemodel.JInvocation) DeclaredType(javax.lang.model.type.DeclaredType)

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