Search in sources :

Example 56 with JVar

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

the class ExtraHandler method assignValue.

@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EActivityHolder holder, Element element, Element param) {
    String fieldName = element.getSimpleName().toString();
    String extraKey = extractExtraKey(element, fieldName);
    TypeMirror actualType = codeModelHelper.getActualTypeOfEnclosingElementOfInjectedElement(holder, param);
    BundleHelper bundleHelper = new BundleHelper(getEnvironment(), actualType);
    JFieldVar extraKeyStaticField = getOrCreateStaticExtraField(holder, extraKey, fieldName);
    if (element.getKind() != ElementKind.PARAMETER) {
        holder.getIntentBuilder().getPutExtraMethod(element, new IntentBuilder.IntentExtra(param.asType(), fieldName, extraKeyStaticField));
    }
    AbstractJClass elementClass = codeModelHelper.typeMirrorToJClass(param.asType());
    JMethod injectExtrasMethod = holder.getInjectExtrasMethod();
    JVar extras = holder.getInjectExtras();
    IJExpression restoreMethodCall = bundleHelper.getExpressionToRestoreFromBundle(elementClass, extras, extraKeyStaticField, injectExtrasMethod);
    JBlock ifContainsKey = targetBlock._if(JExpr.invoke(extras, "containsKey").arg(extraKeyStaticField))._then();
    ifContainsKey.assign(fieldRef, restoreMethodCall);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) JFieldVar(com.helger.jcodemodel.JFieldVar) IntentBuilder(org.androidannotations.internal.core.helper.IntentBuilder) IJExpression(com.helger.jcodemodel.IJExpression) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod) BundleHelper(org.androidannotations.helper.BundleHelper) JVar(com.helger.jcodemodel.JVar)

Example 57 with JVar

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

the class AfterTextChangeHandler 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 editableParameterPosition = -1;
    int viewParameterPosition = -1;
    TypeMirror viewParameterType = null;
    for (int i = 0; i < parameters.size(); i++) {
        VariableElement parameter = parameters.get(i);
        TypeMirror parameterType = parameter.asType();
        if (CanonicalNameConstants.EDITABLE.equals(parameterType.toString())) {
            editableParameterPosition = 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.getAfterTextChangedBody();
        IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
        JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
        for (int i = 0; i < parameters.size(); i++) {
            if (i == editableParameterPosition) {
                JVar afterTextChangeEditableParam = textWatcherHolder.getAfterTextChangedEditableParam();
                textChangeCall.arg(afterTextChangeEditableParam);
            } 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 58 with JVar

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

the class PreferencesDelegate method setAddPreferencesFromResourceBlock.

private void setAddPreferencesFromResourceBlock() {
    JMethod method = getGeneratedClass().method(PUBLIC, codeModel().VOID, "addPreferencesFromResource");
    method.annotate(Override.class);
    JVar preferencesResIdParam = method.param(int.class, "preferencesResId");
    method.body().invoke(JExpr._super(), "addPreferencesFromResource").arg(preferencesResIdParam);
    addPreferencesFromResourceInjectionBlock = method.body().blockVirtual();
    addPreferencesFromResourceAfterInjectionBlock = method.body().blockVirtual();
}
Also used : JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 59 with JVar

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

the class SharedPrefHolder method createEditorConstructor.

private void createEditorConstructor() {
    editorConstructor = editorClass.constructor(JMod.NONE);
    AbstractJClass sharedPreferencesClass = getJClass("android.content.SharedPreferences");
    JVar sharedPreferencesParam = editorConstructor.param(sharedPreferencesClass, "sharedPreferences");
    editorConstructor.body().invoke("super").arg(sharedPreferencesParam);
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) JVar(com.helger.jcodemodel.JVar)

Example 60 with JVar

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

the class ViewInstanceStateDelegate method setSaveStateMethod.

private void setSaveStateMethod() {
    JMethod method = getGeneratedClass().method(PUBLIC, getClasses().PARCELABLE, "onSaveInstanceState");
    method.annotate(Override.class);
    JMethod saveStateMethod = getGeneratedClass().method(PRIVATE, codeModel().VOID, "saveInstanceState");
    saveStateBundleParam = saveStateMethod.param(getClasses().BUNDLE, "bundle");
    saveStateMethodBody = saveStateMethod.body();
    JBlock methodBody = method.body();
    JVar onSaveSuperInstanceState = methodBody.decl(getClasses().PARCELABLE, "instanceState", _super().invoke("onSaveInstanceState"));
    JVar bundleParam = methodBody.decl(getClasses().BUNDLE, "bundle" + generationSuffix(), _new(getClasses().BUNDLE));
    methodBody.invoke(bundleParam, "putParcelable").arg(getInstanceStateKey()).arg(onSaveSuperInstanceState);
    methodBody.invoke(saveStateMethod).arg(bundleParam);
    methodBody._return(bundleParam);
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod) 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