Search in sources :

Example 21 with JVar

use of com.helger.jcodemodel.JVar 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 22 with JVar

use of com.helger.jcodemodel.JVar 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 23 with JVar

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

the class InjectHelper method processMethod.

private void processMethod(Element element, T holder) {
    ExecutableElement executableElement = (ExecutableElement) element;
    VariableElement param = executableElement.getParameters().get(0);
    String methodName = executableElement.getSimpleName().toString();
    JBlock block = createBlock(holder, true);
    AbstractJClass type = codeModelHelper.typeMirrorToJClass(param.asType());
    JVar fieldRef = block.decl(type, param.getSimpleName().toString(), getDefault(param.asType()));
    handler.assignValue(block, fieldRef, holder, element, param);
    block.add(JExpr.invoke(methodName).arg(fieldRef));
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) VariableElement(javax.lang.model.element.VariableElement) JVar(com.helger.jcodemodel.JVar)

Example 24 with JVar

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

the class PreferencesDelegate method setAddPreferencesFromResourceBlock.

private void setAddPreferencesFromResourceBlock() {
    JMethod method = getGeneratedClass().method(PUBLIC, codeModel().VOID, "addPreferencesFromResource");
    method.annotate(Override.class);
    JVar preferencesResIdParam = method.param(int.class, "preferencesResId");
    method.body().invoke(JExpr._super(), "addPreferencesFromResource").arg(preferencesResIdParam);
    addPreferencesFromResourceInjectionBlock = method.body().blockVirtual();
    addPreferencesFromResourceAfterInjectionBlock = method.body().blockVirtual();
}
Also used : JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 25 with JVar

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

the class KeyEventCallbackMethodsDelegate method createOnKeyMultipleMethod.

private void createOnKeyMultipleMethod() {
    JMethod method = getGeneratedClass().method(PUBLIC, codeModel().BOOLEAN, "onKeyMultiple");
    method.annotate(Override.class);
    JVar keyCode = method.param(codeModel().INT, "keyCode");
    onKeyMultipleCountParam = method.param(codeModel().INT, "count");
    onKeyMultipleKeyEventParam = method.param(getClasses().KEY_EVENT, "keyEvent");
    JBlock methodBody = method.body();
    onKeyMultipleSwitchBody = methodBody._switch(keyCode);
    methodBody._return(_super().invoke(method).arg(keyCode).arg(onKeyMultipleCountParam).arg(onKeyDownKeyEventParam));
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Aggregations

JVar (com.helger.jcodemodel.JVar)119 JBlock (com.helger.jcodemodel.JBlock)81 JMethod (com.helger.jcodemodel.JMethod)56 AbstractJClass (com.helger.jcodemodel.AbstractJClass)48 JInvocation (com.helger.jcodemodel.JInvocation)38 IJExpression (com.helger.jcodemodel.IJExpression)32 VariableElement (javax.lang.model.element.VariableElement)25 ExecutableElement (javax.lang.model.element.ExecutableElement)18 TypeMirror (javax.lang.model.type.TypeMirror)16 JDefinedClass (com.helger.jcodemodel.JDefinedClass)15 JFieldRef (com.helger.jcodemodel.JFieldRef)15 JFieldVar (com.helger.jcodemodel.JFieldVar)12 JConditional (com.helger.jcodemodel.JConditional)9 JTryBlock (com.helger.jcodemodel.JTryBlock)7 JCatchBlock (com.helger.jcodemodel.JCatchBlock)5 AbstractJType (com.helger.jcodemodel.AbstractJType)4 ArrayList (java.util.ArrayList)4 BundleHelper (org.androidannotations.helper.BundleHelper)4 JTypeVar (com.helger.jcodemodel.JTypeVar)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3