Search in sources :

Example 21 with IJExpression

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

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

the class ViewNotifierHelper method implementHasViewsInHolder.

private void implementHasViewsInHolder() {
    holder.getGeneratedClass()._implements(HasViews.class);
    JCodeModel codeModel = environment.getCodeModel();
    JDirectClass genericType = codeModel.directClass("T");
    JMethod findViewById = holder.getGeneratedClass().method(PUBLIC, genericType, "internalFindViewById");
    findViewById.generify("T", environment.getClasses().VIEW);
    findViewById.annotate(Override.class);
    JVar idParam = findViewById.param(codeModel.INT, "id");
    IJExpression findViewByIdExpression = holder.getFindViewByIdExpression(idParam);
    findViewById.body()._return(JExpr.cast(genericType, findViewByIdExpression));
}
Also used : JDirectClass(com.helger.jcodemodel.JDirectClass) IJExpression(com.helger.jcodemodel.IJExpression) JMethod(com.helger.jcodemodel.JMethod) JCodeModel(com.helger.jcodemodel.JCodeModel) JVar(com.helger.jcodemodel.JVar)

Example 23 with IJExpression

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

the class FragmentArgHandler method assignValue.

@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EFragmentHolder holder, Element element, Element param) {
    String fieldName = element.getSimpleName().toString();
    String argKey = extractArgKey(element, fieldName);
    if (element.getKind() != ElementKind.PARAMETER) {
        createBuilderInjectionMethod(holder, element, new ArgHelper(param, argKey));
    }
    TypeMirror actualType = codeModelHelper.getActualTypeOfEnclosingElementOfInjectedElement(holder, param);
    AbstractJClass elementClass = codeModelHelper.typeMirrorToJClass(actualType);
    BundleHelper bundleHelper = new BundleHelper(getEnvironment(), actualType);
    JVar bundle = holder.getInjectBundleArgs();
    JMethod injectExtrasMethod = holder.getInjectArgsMethod();
    JFieldVar extraKeyStaticField = getOrCreateStaticArgField(holder, argKey, fieldName);
    IJExpression restoreMethodCall = bundleHelper.getExpressionToRestoreFromBundle(elementClass, bundle, extraKeyStaticField, injectExtrasMethod);
    JConditional conditional = targetBlock._if(JExpr.invoke(bundle, "containsKey").arg(extraKeyStaticField));
    conditional._then().add(fieldRef.assign(restoreMethodCall));
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) JFieldVar(com.helger.jcodemodel.JFieldVar) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JConditional(com.helger.jcodemodel.JConditional) JMethod(com.helger.jcodemodel.JMethod) BundleHelper(org.androidannotations.helper.BundleHelper) JVar(com.helger.jcodemodel.JVar)

Example 24 with IJExpression

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

the class AbstractListenerHandler method process.

@Override
public void process(Element element, T holder) {
    methodName = element.getSimpleName().toString();
    ExecutableElement executableElement = (ExecutableElement) element;
    List<? extends VariableElement> parameters = executableElement.getParameters();
    TypeMirror returnType = executableElement.getReturnType();
    List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, getResourceType(), true);
    JDefinedClass listenerAnonymousClass = getCodeModel().anonymousClass(getListenerClass(holder));
    JMethod listenerMethod = createListenerMethod(listenerAnonymousClass);
    listenerMethod.annotate(Override.class);
    JBlock listenerMethodBody = listenerMethod.body();
    IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
    JInvocation call = invoke(activityRef, methodName);
    makeCall(listenerMethodBody, call, returnType);
    processParameters(holder, listenerMethod, call, parameters);
    assignListeners(holder, idsRefs, listenerAnonymousClass);
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) TypeMirror(javax.lang.model.type.TypeMirror) JDefinedClass(com.helger.jcodemodel.JDefinedClass) ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) IJExpression(com.helger.jcodemodel.IJExpression) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod)

Example 25 with IJExpression

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

the class AbstractSeekBarTouchHandler method process.

@Override
public void process(Element element, EComponentWithViewSupportHolder holder) throws Exception {
    String methodName = element.getSimpleName().toString();
    List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
    for (JFieldRef idRef : idsRefs) {
        OnSeekBarChangeListenerHolder onSeekBarChangeListenerHolder = holder.getOnSeekBarChangeListenerHolder(idRef);
        JBlock methodBody = getMethodBodyToCall(onSeekBarChangeListenerHolder);
        IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
        JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
        ExecutableElement executableElement = (ExecutableElement) element;
        List<? extends VariableElement> parameters = executableElement.getParameters();
        if (parameters.size() == 1) {
            JVar progressParameter = getMethodParamToPass(onSeekBarChangeListenerHolder);
            textChangeCall.arg(progressParameter);
        }
    }
}
Also used : OnSeekBarChangeListenerHolder(org.androidannotations.holder.OnSeekBarChangeListenerHolder) JFieldRef(com.helger.jcodemodel.JFieldRef) ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) IJExpression(com.helger.jcodemodel.IJExpression) JInvocation(com.helger.jcodemodel.JInvocation) 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