Search in sources :

Example 11 with JFieldVar

use of com.helger.jcodemodel.JFieldVar 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 12 with JFieldVar

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

the class ExtraHandler method getOrCreateStaticExtraField.

private JFieldVar getOrCreateStaticExtraField(EActivityHolder holder, String extraKey, String fieldName) {
    String staticFieldName = CaseHelper.camelCaseToUpperSnakeCase(null, fieldName, "Extra");
    JFieldVar staticExtraField = holder.getGeneratedClass().fields().get(staticFieldName);
    if (staticExtraField == null) {
        staticExtraField = holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, getClasses().STRING, staticFieldName, lit(extraKey));
    }
    return staticExtraField;
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar)

Example 13 with JFieldVar

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

the class ExtraHandler method afterAllParametersInjected.

@Override
public void afterAllParametersInjected(EActivityHolder holder, ExecutableElement method, List<InjectHelper.ParamHelper> parameterList) {
    List<IntentBuilder.IntentExtra> params = new ArrayList<>();
    for (InjectHelper.ParamHelper paramHelper : parameterList) {
        Element param = paramHelper.getParameterElement();
        String fieldName = param.getSimpleName().toString();
        String extraKey = extractExtraKey(param, fieldName);
        JFieldVar extraKeyStaticField = getOrCreateStaticExtraField(holder, extraKey, fieldName);
        params.add(new IntentBuilder.IntentExtra(param.asType(), fieldName, extraKeyStaticField));
    }
    holder.getIntentBuilder().getPutExtraMethod(method, params);
}
Also used : InjectHelper(org.androidannotations.helper.InjectHelper) JFieldVar(com.helger.jcodemodel.JFieldVar) IntentBuilder(org.androidannotations.internal.core.helper.IntentBuilder) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) ArrayList(java.util.ArrayList)

Example 14 with JFieldVar

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

the class FragmentArgHandler method getOrCreateStaticArgField.

private JFieldVar getOrCreateStaticArgField(EFragmentHolder holder, String argKey, String fieldName) {
    String staticFieldName = CaseHelper.camelCaseToUpperSnakeCase(null, fieldName, "Arg");
    JFieldVar staticExtraField = holder.getGeneratedClass().fields().get(staticFieldName);
    if (staticExtraField == null) {
        staticExtraField = holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, getClasses().STRING, staticFieldName, lit(argKey));
    }
    return staticExtraField;
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar)

Example 15 with JFieldVar

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

Aggregations

JFieldVar (com.helger.jcodemodel.JFieldVar)34 AbstractJClass (com.helger.jcodemodel.AbstractJClass)13 JVar (com.helger.jcodemodel.JVar)12 JBlock (com.helger.jcodemodel.JBlock)11 JMethod (com.helger.jcodemodel.JMethod)10 IJExpression (com.helger.jcodemodel.IJExpression)7 JDefinedClass (com.helger.jcodemodel.JDefinedClass)5 JInvocation (com.helger.jcodemodel.JInvocation)5 TypeMirror (javax.lang.model.type.TypeMirror)5 BundleHelper (org.androidannotations.helper.BundleHelper)4 ExecutableElement (javax.lang.model.element.ExecutableElement)3 JFieldRef (com.helger.jcodemodel.JFieldRef)2 JTypeVar (com.helger.jcodemodel.JTypeVar)2 VariableElement (javax.lang.model.element.VariableElement)2 DeclaredType (javax.lang.model.type.DeclaredType)2 IntentBuilder (org.androidannotations.internal.core.helper.IntentBuilder)2 Caching (com.github.sviperll.adt4j.Caching)1 VariableDeclaration (com.github.sviperll.adt4j.model.config.VariableDeclaration)1 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)1 MethodUsage (com.github.sviperll.adt4j.model.config.VisitorDefinition.MethodUsage)1