Search in sources :

Example 26 with JFieldRef

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

the class TextChangeHandler 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 startParameterPosition = -1;
    int countParameterPosition = -1;
    int beforeParameterPosition = -1;
    int charSequenceParameterPosition = -1;
    int viewParameterPosition = -1;
    TypeMirror viewParameterType = null;
    for (int i = 0; i < parameters.size(); i++) {
        VariableElement parameter = parameters.get(i);
        String parameterName = parameter.toString();
        TypeMirror parameterType = parameter.asType();
        if (CanonicalNameConstants.CHAR_SEQUENCE.equals(parameterType.toString())) {
            charSequenceParameterPosition = i;
        } else if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
            if ("start".equals(parameterName)) {
                startParameterPosition = i;
            } else if ("count".equals(parameterName)) {
                countParameterPosition = i;
            } else if ("before".equals(parameterName)) {
                beforeParameterPosition = i;
            }
        } else {
            TypeMirror textViewType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.TEXT_VIEW).asType();
            if (annotationHelper.isSubtype(parameterType, textViewType)) {
                viewParameterPosition = i;
                viewParameterType = parameterType;
            }
        }
    }
    List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
    for (JFieldRef idRef : idsRefs) {
        TextWatcherHolder textWatcherHolder = holder.getTextWatcherHolder(idRef, viewParameterType);
        JBlock methodBody = textWatcherHolder.getOnTextChangedBody();
        IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
        JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
        for (int i = 0; i < parameters.size(); i++) {
            if (i == startParameterPosition) {
                JVar startParameter = textWatcherHolder.getOnTextChangedStartParam();
                textChangeCall.arg(startParameter);
            } else if (i == countParameterPosition) {
                JVar countParameter = textWatcherHolder.getOnTextChangedCountParam();
                textChangeCall.arg(countParameter);
            } else if (i == beforeParameterPosition) {
                JVar beforeParameter = textWatcherHolder.getOnTextChangedBeforeParam();
                textChangeCall.arg(beforeParameter);
            } else if (i == charSequenceParameterPosition) {
                JVar charSequenceParam = textWatcherHolder.getOnTextChangedCharSequenceParam();
                textChangeCall.arg(charSequenceParam);
            } else if (i == viewParameterPosition) {
                JVar viewParameter = textWatcherHolder.getTextViewVariable();
                textChangeCall.arg(viewParameter);
            }
        }
    }
}
Also used : 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) TextWatcherHolder(org.androidannotations.holder.TextWatcherHolder) TypeMirror(javax.lang.model.type.TypeMirror) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 27 with JFieldRef

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

the class PageScrollStateChangedHandler method process.

@Override
public void process(Element element, EComponentWithViewSupportHolder holder) {
    String methodName = element.getSimpleName().toString();
    ExecutableElement executableElement = (ExecutableElement) element;
    List<? extends VariableElement> parameters = executableElement.getParameters();
    int stateParameterPosition = -1;
    int viewPagerParameterPosition = -1;
    TypeMirror viewPagerParameterType = null;
    for (int i = 0; i < parameters.size(); i++) {
        VariableElement parameter = parameters.get(i);
        TypeMirror parameterType = parameter.asType();
        if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
            stateParameterPosition = i;
        } else {
            TypeMirror viewPagerType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.VIEW_PAGER).asType();
            if (annotationHelper.isSubtype(parameterType, viewPagerType)) {
                viewPagerParameterPosition = i;
                viewPagerParameterType = parameterType;
            }
        }
    }
    List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
    for (JFieldRef idRef : idsRefs) {
        PageChangeHolder pageChangeHolder = holder.getPageChangeHolder(idRef, viewPagerParameterType, hasAddOnPageChangeListenerMethod());
        JBlock methodBody = pageChangeHolder.getPageScrollStateChangedBody();
        IJExpression thisRef = holder.getGeneratedClass().staticRef("this");
        JInvocation methodCall = methodBody.invoke(thisRef, methodName);
        for (int i = 0; i < parameters.size(); i++) {
            if (i == stateParameterPosition) {
                JVar stateParam = pageChangeHolder.getPageScrollStateChangedStateParam();
                methodCall.arg(stateParam);
            } else if (i == viewPagerParameterPosition) {
                JVar viewParameter = pageChangeHolder.getViewPagerVariable();
                methodCall.arg(viewParameter);
            }
        }
    }
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) ExecutableElement(javax.lang.model.element.ExecutableElement) IJExpression(com.helger.jcodemodel.IJExpression) PageChangeHolder(org.androidannotations.holder.PageChangeHolder) 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)

Example 28 with JFieldRef

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

the class PageSelectedHandler 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 positionParameterPosition = -1;
    int viewPagerParameterPosition = -1;
    TypeMirror viewPagerParameterType = null;
    for (int i = 0; i < parameters.size(); i++) {
        VariableElement parameter = parameters.get(i);
        TypeMirror parameterType = parameter.asType();
        if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
            positionParameterPosition = i;
        } else {
            TypeMirror viewPagerType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.VIEW_PAGER).asType();
            if (annotationHelper.isSubtype(parameterType, viewPagerType)) {
                viewPagerParameterPosition = i;
                viewPagerParameterType = parameterType;
            }
        }
    }
    List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
    for (JFieldRef idRef : idsRefs) {
        PageChangeHolder pageChangeHolder = holder.getPageChangeHolder(idRef, viewPagerParameterType, hasAddOnPageChangeListenerMethod());
        JBlock methodBody = pageChangeHolder.getPageSelectedBody();
        IJExpression thisRef = holder.getGeneratedClass().staticRef("this");
        JInvocation methodCall = methodBody.invoke(thisRef, methodName);
        for (int i = 0; i < parameters.size(); i++) {
            if (i == positionParameterPosition) {
                JVar stateParam = pageChangeHolder.getPageSelectedPositionParam();
                methodCall.arg(stateParam);
            } else if (i == viewPagerParameterPosition) {
                JVar viewParameter = pageChangeHolder.getViewPagerVariable();
                methodCall.arg(viewParameter);
            }
        }
    }
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) ExecutableElement(javax.lang.model.element.ExecutableElement) IJExpression(com.helger.jcodemodel.IJExpression) PageChangeHolder(org.androidannotations.holder.PageChangeHolder) 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)

Example 29 with JFieldRef

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

the class PreferenceByKeyHandler method assignValue.

@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, HasPreferences holder, Element element, Element param) {
    TypeMirror prefFieldTypeMirror = param.asType();
    String typeQualifiedName = prefFieldTypeMirror.toString();
    JFieldRef idRef = annotationHelper.extractOneAnnotationFieldRef(element, IRClass.Res.STRING, true);
    AbstractJClass preferenceClass = getJClass(typeQualifiedName);
    IJAssignmentTarget preferenceHolderTarget = null;
    if (element.getKind() == ElementKind.FIELD) {
        preferenceHolderTarget = fieldRef;
    }
    FoundPreferenceHolder preferenceHolder = holder.getFoundPreferenceHolder(idRef, preferenceClass, preferenceHolderTarget);
    if (!preferenceHolder.getRef().equals(preferenceHolderTarget)) {
        targetBlock.add(fieldRef.assign(preferenceHolder.getOrCastRef(preferenceClass)));
    }
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) TypeMirror(javax.lang.model.type.TypeMirror) FoundPreferenceHolder(org.androidannotations.holder.FoundPreferenceHolder) IJAssignmentTarget(com.helger.jcodemodel.IJAssignmentTarget) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 30 with JFieldRef

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

the class PreferenceHeadersHandler method process.

@Override
public void process(Element element, HasPreferenceHeaders holder) throws Exception {
    JFieldRef headerId = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.XML, false).get(0);
    JBlock block = holder.getOnBuildHeadersBlock();
    JVar targetParam = holder.getOnBuildHeadersTargetParam();
    block.invoke("loadHeadersFromResource").arg(headerId).arg(targetParam);
    block.invoke(JExpr._super(), "onBuildHeaders").arg(targetParam);
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Aggregations

JFieldRef (com.helger.jcodemodel.JFieldRef)33 JBlock (com.helger.jcodemodel.JBlock)19 IJExpression (com.helger.jcodemodel.IJExpression)15 JVar (com.helger.jcodemodel.JVar)15 TypeMirror (javax.lang.model.type.TypeMirror)15 JInvocation (com.helger.jcodemodel.JInvocation)14 ExecutableElement (javax.lang.model.element.ExecutableElement)10 VariableElement (javax.lang.model.element.VariableElement)7 AbstractJClass (com.helger.jcodemodel.AbstractJClass)6 JMethod (com.helger.jcodemodel.JMethod)5 JDefinedClass (com.helger.jcodemodel.JDefinedClass)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 TextWatcherHolder (org.androidannotations.holder.TextWatcherHolder)3 IJAssignmentTarget (com.helger.jcodemodel.IJAssignmentTarget)2 JFieldVar (com.helger.jcodemodel.JFieldVar)2 DefaultRes (org.androidannotations.annotations.sharedpreferences.DefaultRes)2 DefaultString (org.androidannotations.annotations.sharedpreferences.DefaultString)2 BundleHelper (org.androidannotations.helper.BundleHelper)2 FoundPreferenceHolder (org.androidannotations.holder.FoundPreferenceHolder)2 FoundViewHolder (org.androidannotations.holder.FoundViewHolder)2