Search in sources :

Example 51 with JVar

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

the class EditorActionHandler method processParameters.

@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation call, List<? extends VariableElement> userParameters) {
    JVar textView = listenerMethod.param(getClasses().TEXT_VIEW, "textView");
    JVar actionId = listenerMethod.param(getCodeModel().INT, "actionId");
    JVar event = listenerMethod.param(getClasses().KEY_EVENT, "event");
    for (VariableElement param : userParameters) {
        String paramClassQualifiedName = param.asType().toString();
        if (isTypeOrSubclass(CanonicalNameConstants.TEXT_VIEW, param)) {
            call.arg(castArgumentIfNecessary(holder, CanonicalNameConstants.TEXT_VIEW, textView, param));
        } else if (paramClassQualifiedName.equals(CanonicalNameConstants.INTEGER) || paramClassQualifiedName.equals(getCodeModel().INT.fullName())) {
            call.arg(actionId);
        } else if (paramClassQualifiedName.equals(CanonicalNameConstants.KEY_EVENT)) {
            call.arg(event);
        }
    }
}
Also used : VariableElement(javax.lang.model.element.VariableElement) JVar(com.helger.jcodemodel.JVar)

Example 52 with JVar

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

the class FragmentArgHandler method createBuilderInjectMethod.

public void createBuilderInjectMethod(EFragmentHolder holder, Element element, List<ArgHelper> argHelpers) {
    JDefinedClass builderClass = holder.getBuilderClass();
    JFieldRef builderArgsField = holder.getBuilderArgsField();
    JMethod builderMethod = builderClass.method(PUBLIC, holder.narrow(builderClass), element.getSimpleName().toString());
    String docComment = getProcessingEnvironment().getElementUtils().getDocComment(element);
    codeModelHelper.addTrimmedDocComment(builderMethod, docComment);
    for (ArgHelper argHelper : argHelpers) {
        String fieldName = argHelper.param.getSimpleName().toString();
        TypeMirror actualType = codeModelHelper.getActualTypeOfEnclosingElementOfInjectedElement(holder, argHelper.param);
        BundleHelper bundleHelper = new BundleHelper(getEnvironment(), actualType);
        JFieldVar argKeyStaticField = getOrCreateStaticArgField(holder, argHelper.argKey, fieldName);
        AbstractJClass paramClass = codeModelHelper.typeMirrorToJClass(actualType);
        JVar arg = builderMethod.param(paramClass, fieldName);
        builderMethod.body().add(bundleHelper.getExpressionToSaveFromField(builderArgsField, argKeyStaticField, arg));
        builderMethod.javadoc().addParam(fieldName).append("value for this Fragment argument");
    }
    builderMethod.javadoc().addReturn().append("the FragmentBuilder to chain calls");
    builderMethod.body()._return(_this());
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) JDefinedClass(com.helger.jcodemodel.JDefinedClass) TypeMirror(javax.lang.model.type.TypeMirror) JFieldVar(com.helger.jcodemodel.JFieldVar) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod) BundleHelper(org.androidannotations.helper.BundleHelper) JVar(com.helger.jcodemodel.JVar)

Example 53 with JVar

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

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

the class CheckedChangeHandler method processParameters.

@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation call, List<? extends VariableElement> parameters) {
    JVar btnParam = listenerMethod.param(getClasses().COMPOUND_BUTTON, "buttonView");
    JVar isCheckedParam = listenerMethod.param(getCodeModel().BOOLEAN, "isChecked");
    for (VariableElement parameter : parameters) {
        String parameterType = parameter.asType().toString();
        if (isTypeOrSubclass(CanonicalNameConstants.COMPOUND_BUTTON, parameter)) {
            call.arg(castArgumentIfNecessary(holder, CanonicalNameConstants.COMPOUND_BUTTON, btnParam, parameter));
        } else if (parameterType.equals(CanonicalNameConstants.BOOLEAN) || parameter.asType().getKind() == TypeKind.BOOLEAN) {
            call.arg(isCheckedParam);
        }
    }
}
Also used : VariableElement(javax.lang.model.element.VariableElement) JVar(com.helger.jcodemodel.JVar)

Example 55 with JVar

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

JVar (com.helger.jcodemodel.JVar)126 JBlock (com.helger.jcodemodel.JBlock)86 JMethod (com.helger.jcodemodel.JMethod)61 AbstractJClass (com.helger.jcodemodel.AbstractJClass)53 JInvocation (com.helger.jcodemodel.JInvocation)39 IJExpression (com.helger.jcodemodel.IJExpression)33 VariableElement (javax.lang.model.element.VariableElement)25 ExecutableElement (javax.lang.model.element.ExecutableElement)19 JFieldRef (com.helger.jcodemodel.JFieldRef)16 TypeMirror (javax.lang.model.type.TypeMirror)16 JDefinedClass (com.helger.jcodemodel.JDefinedClass)15 JFieldVar (com.helger.jcodemodel.JFieldVar)15 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 VariableDeclaration (com.github.sviperll.adt4j.model.config.VariableDeclaration)2