Search in sources :

Example 31 with JFieldRef

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

the class InstanceStateHandler method process.

@Override
public void process(Element element, HasInstanceState holder) {
    AbstractJClass elementClass = codeModelHelper.typeMirrorToJClass(element.asType());
    String fieldName = element.getSimpleName().toString();
    JBlock saveStateBody = holder.getSaveStateMethodBody();
    JVar saveStateBundleParam = holder.getSaveStateBundleParam();
    JMethod restoreStateMethod = holder.getRestoreStateMethod();
    JBlock restoreStateBody = holder.getRestoreStateMethodBody();
    JVar restoreStateBundleParam = holder.getRestoreStateBundleParam();
    TypeMirror type = codeModelHelper.getActualType(element, holder);
    BundleHelper bundleHelper = new BundleHelper(getEnvironment(), type);
    JFieldRef ref = ref(fieldName);
    saveStateBody.add(bundleHelper.getExpressionToSaveFromField(saveStateBundleParam, JExpr.lit(fieldName), ref));
    IJExpression restoreMethodCall = bundleHelper.getExpressionToRestoreFromBundle(elementClass, restoreStateBundleParam, JExpr.lit(fieldName), restoreStateMethod);
    restoreStateBody.assign(ref, restoreMethodCall);
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) TypeMirror(javax.lang.model.type.TypeMirror) JBlock(com.helger.jcodemodel.JBlock) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar) BundleHelper(org.androidannotations.helper.BundleHelper)

Example 32 with JFieldRef

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

the class ViewsByIdHandler method assignValue.

@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentWithViewSupportHolder holder, Element element, Element param) {
    TypeMirror viewType = extractViewClass(param);
    AbstractJClass viewClass = codeModelHelper.typeMirrorToJClass(viewType);
    String listName = getListName(element, param);
    IJExpression arrayList = instantiateArrayList(viewType, holder, "list_" + listName);
    List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
    for (JFieldRef idRef : idsRefs) {
        addViewToListIfNotNull(arrayList, viewClass, idRef, holder);
    }
    targetBlock.add(fieldRef.assign(arrayList));
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) TypeMirror(javax.lang.model.type.TypeMirror) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 33 with JFieldRef

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

the class OptionsMenuHandler method process.

@Override
public void process(Element element, HasOptionsMenu holder) {
    JBlock body = holder.getOnCreateOptionsMenuMethodInflateBody();
    JVar menuInflater = holder.getOnCreateOptionsMenuMenuInflaterVar();
    JVar menuParam = holder.getOnCreateOptionsMenuMenuParam();
    List<JFieldRef> fieldRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.MENU, false);
    for (JFieldRef optionsMenuRefId : fieldRefs) {
        body.invoke(menuInflater, "inflate").arg(optionsMenuRefId).arg(menuParam);
    }
}
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