Search in sources :

Example 1 with IJAssignmentTarget

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

the class ViewByIdHandler method assignValue.

@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentWithViewSupportHolder holder, Element element, Element param) {
    TypeMirror uiFieldTypeMirror = param.asType();
    JFieldRef idRef = annotationHelper.extractOneAnnotationFieldRef(element, IRClass.Res.ID, true);
    AbstractJClass viewClass = codeModelHelper.typeMirrorToJClass(uiFieldTypeMirror);
    IJAssignmentTarget viewHolderTarget = null;
    if (element.getKind() == ElementKind.FIELD) {
        viewHolderTarget = fieldRef;
    }
    FoundViewHolder viewHolder = holder.getFoundViewHolder(idRef, viewClass, viewHolderTarget);
    if (!viewHolder.getRef().equals(viewHolderTarget)) {
        targetBlock.add(fieldRef.assign(viewHolder.getOrCastRef(viewClass)));
    }
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) TypeMirror(javax.lang.model.type.TypeMirror) IJAssignmentTarget(com.helger.jcodemodel.IJAssignmentTarget) FoundViewHolder(org.androidannotations.holder.FoundViewHolder) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 2 with IJAssignmentTarget

use of com.helger.jcodemodel.IJAssignmentTarget 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 3 with IJAssignmentTarget

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

the class EComponentWithViewSupportHolder method createFoundViewAndIfNotNullBlock.

protected FoundViewHolder createFoundViewAndIfNotNullBlock(JFieldRef idRef, AbstractJClass viewClass, IJAssignmentTarget fieldRef) {
    IJExpression findViewExpression = findViewById(idRef);
    JBlock block = getOnViewChangedBodyBeforeInjectionBlock();
    if (viewClass == null) {
        viewClass = getClasses().VIEW;
    }
    IJAssignmentTarget foundView = fieldRef;
    if (foundView == null) {
        JVar view = block.decl(viewClass, "view_" + idRef.name(), findViewExpression);
        if (viewClass.isParameterized()) {
            codeModelHelper.addSuppressWarnings(view, "unchecked");
        }
        foundView = view;
    } else {
        block.add(foundView.assign(findViewExpression));
    }
    return new FoundViewHolder(this, viewClass, foundView, getOnViewChangedBodyViewHolderBlock());
}
Also used : IJExpression(com.helger.jcodemodel.IJExpression) JBlock(com.helger.jcodemodel.JBlock) IJAssignmentTarget(com.helger.jcodemodel.IJAssignmentTarget) JVar(com.helger.jcodemodel.JVar)

Example 4 with IJAssignmentTarget

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

the class PreferencesDelegate method createFoundPreferenceAndIfNotNullBlock.

private FoundPreferenceHolder createFoundPreferenceAndIfNotNullBlock(JFieldRef idRef, AbstractJClass preferenceClass, IJAssignmentTarget fieldRef) {
    IJExpression findPreferenceExpression = findPreferenceByKey(idRef);
    JBlock block = getAddPreferencesFromResourceInjectionBlock();
    if (preferenceClass == null) {
        preferenceClass = basePreferenceClass;
    } else if (!preferenceClass.equals(basePreferenceClass)) {
        findPreferenceExpression = cast(preferenceClass, findPreferenceExpression);
    }
    IJAssignmentTarget foundPref = fieldRef;
    if (foundPref == null) {
        foundPref = block.decl(preferenceClass, "preference_" + idRef.name(), findPreferenceExpression);
    } else {
        block.add(foundPref.assign(findPreferenceExpression));
    }
    return new FoundPreferenceHolder(this, preferenceClass, foundPref, block);
}
Also used : IJExpression(com.helger.jcodemodel.IJExpression) JBlock(com.helger.jcodemodel.JBlock) IJAssignmentTarget(com.helger.jcodemodel.IJAssignmentTarget)

Aggregations

IJAssignmentTarget (com.helger.jcodemodel.IJAssignmentTarget)4 AbstractJClass (com.helger.jcodemodel.AbstractJClass)2 IJExpression (com.helger.jcodemodel.IJExpression)2 JBlock (com.helger.jcodemodel.JBlock)2 JFieldRef (com.helger.jcodemodel.JFieldRef)2 TypeMirror (javax.lang.model.type.TypeMirror)2 JVar (com.helger.jcodemodel.JVar)1 FoundPreferenceHolder (org.androidannotations.holder.FoundPreferenceHolder)1 FoundViewHolder (org.androidannotations.holder.FoundViewHolder)1