Search in sources :

Example 26 with AbstractJClass

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

the class RoboGuiceHolder method getCurrentConfig.

public JVar getCurrentConfig() {
    if (currentConfig == null) {
        AbstractJClass configurationClass = environment().getClasses().CONFIGURATION;
        JBlock onConfigurationChangedBeforeSuperBlock = holder().getOnConfigurationChangedBeforeSuperBlock();
        currentConfig = onConfigurationChangedBeforeSuperBlock.decl(configurationClass, "currentConfig", JExpr.invoke("getResources").invoke("getConfiguration"));
        onConfigurationChangedBeforeSuperBlock.bracesRequired(false).indentRequired(false);
    }
    return currentConfig;
}
Also used : JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 27 with AbstractJClass

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

the class NonConfigurationInstanceHandler method process.

@Override
public void process(Element element, EActivityHolder holder) throws JClassAlreadyExistsException {
    String fieldName = element.getSimpleName().toString();
    AbstractJClass fieldType = codeModelHelper.typeMirrorToJClass(element.asType());
    NonConfigurationHolder ncHolder = holder.getNonConfigurationHolder();
    JFieldVar ncHolderField = ncHolder.createField(fieldName, fieldType);
    injectInInit(element, holder, fieldName, ncHolderField);
    retainInOnRetain(holder, fieldName, ncHolderField);
}
Also used : NonConfigurationHolder(org.androidannotations.holder.NonConfigurationHolder) JFieldVar(com.helger.jcodemodel.JFieldVar) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 28 with AbstractJClass

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

the class NonConfigurationInstanceHandler method rebindContextIfBean.

private void rebindContextIfBean(Element element, JBlock initIfNonConfigurationNotNullBlock, JFieldVar field) {
    boolean hasBeanAnnotation = element.getAnnotation(Bean.class) != null;
    if (hasBeanAnnotation) {
        TypeMirror elementType = annotationHelper.extractAnnotationClassParameter(element, Bean.class.getName());
        if (elementType == null) {
            elementType = element.asType();
        }
        String typeQualifiedName = elementType.toString();
        AbstractJClass fieldGeneratedBeanClass = getJClass(typeQualifiedName + classSuffix());
        // do not generate rebind call for singleton beans
        Element eBeanTypeElement = annotationHelper.getTypeUtils().asElement(elementType);
        EBean eBean = eBeanTypeElement.getAnnotation(EBean.class);
        if (eBean != null && eBean.scope() != EBean.Scope.Singleton) {
            initIfNonConfigurationNotNullBlock.invoke(cast(fieldGeneratedBeanClass, field), "rebind").arg(_this());
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Element(javax.lang.model.element.Element) AbstractJClass(com.helger.jcodemodel.AbstractJClass) EBean(org.androidannotations.annotations.EBean) EBean(org.androidannotations.annotations.EBean) Bean(org.androidannotations.annotations.Bean)

Example 29 with AbstractJClass

use of com.helger.jcodemodel.AbstractJClass 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 30 with AbstractJClass

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

AbstractJClass (com.helger.jcodemodel.AbstractJClass)125 JVar (com.helger.jcodemodel.JVar)48 JMethod (com.helger.jcodemodel.JMethod)36 JBlock (com.helger.jcodemodel.JBlock)35 JInvocation (com.helger.jcodemodel.JInvocation)31 TypeMirror (javax.lang.model.type.TypeMirror)24 IJExpression (com.helger.jcodemodel.IJExpression)23 JDefinedClass (com.helger.jcodemodel.JDefinedClass)19 VariableElement (javax.lang.model.element.VariableElement)14 JFieldVar (com.helger.jcodemodel.JFieldVar)13 GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)9 ExecutableElement (javax.lang.model.element.ExecutableElement)9 JAnnotationUse (com.helger.jcodemodel.JAnnotationUse)8 JConditional (com.helger.jcodemodel.JConditional)8 JTypeVar (com.helger.jcodemodel.JTypeVar)8 DeclaredType (javax.lang.model.type.DeclaredType)8 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)6 JFieldRef (com.helger.jcodemodel.JFieldRef)6 ArrayList (java.util.ArrayList)6 BundleHelper (org.androidannotations.helper.BundleHelper)6