Search in sources :

Example 6 with AbstractJClass

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

the class APTCodeModelHelper method typeMirrorToJClass.

private AbstractJClass typeMirrorToJClass(DeclaredType declaredType, Map<String, TypeMirror> substitute) {
    String declaredTypeName = declaredType.asElement().toString();
    AbstractJClass declaredClass = environment.getJClass(declaredTypeName);
    List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
    List<AbstractJClass> typeArgumentJClasses = new ArrayList<>();
    for (TypeMirror typeArgument : typeArguments) {
        typeArgumentJClasses.add(typeMirrorToJClass(typeArgument, substitute));
    }
    if (typeArgumentJClasses.size() > 0) {
        declaredClass = declaredClass.narrow(typeArgumentJClasses);
    }
    return declaredClass;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ArrayList(java.util.ArrayList) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 7 with AbstractJClass

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

the class APTCodeModelHelper method newBeanOrEBean.

public JInvocation newBeanOrEBean(DeclaredType beanType, JVar contextVar) {
    if (beanType.asElement().getAnnotation(EBean.class) != null) {
        String typeQualifiedName = beanType.toString();
        AbstractJClass injectedClass = environment.getJClass(typeQualifiedName + classSuffix());
        return injectedClass.staticInvoke(EBeanHolder.GET_INSTANCE_METHOD_NAME).arg(contextVar);
    } else {
        return _new(environment.getJClass(beanType.toString()));
    }
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) EBean(org.androidannotations.annotations.EBean)

Example 8 with AbstractJClass

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

the class BaseGeneratedClassHolder method setExtends.

protected void setExtends() {
    AbstractJClass annotatedComponent = getCodeModel().directClass(annotatedElement.asType().toString());
    generatedClass._extends(annotatedComponent);
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 9 with AbstractJClass

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

the class EActivityHolder method setOnConfigurationChanged.

private void setOnConfigurationChanged() {
    JMethod method = generatedClass.method(JMod.PUBLIC, getCodeModel().VOID, "onConfigurationChanged");
    method.annotate(Override.class);
    AbstractJClass configurationClass = getClasses().CONFIGURATION;
    onConfigurationChangedNewConfigParam = method.param(configurationClass, "newConfig");
    JBlock body = method.body();
    onConfigurationChangedBeforeSuperBlock = body.blockSimple();
    body.invoke(_super(), method).arg(onConfigurationChangedNewConfigParam);
    onConfigurationChangedAfterSuperBlock = body.blockSimple();
}
Also used : JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod)

Example 10 with AbstractJClass

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

the class EBeanHolder method createFactoryMethod.

public void createFactoryMethod(boolean hasSingletonScope) {
    AbstractJClass narrowedGeneratedClass = codeModelHelper.narrowGeneratedClass(generatedClass, annotatedElement.asType());
    JMethod factoryMethod = generatedClass.method(PUBLIC | STATIC, narrowedGeneratedClass, GET_INSTANCE_METHOD_NAME);
    codeModelHelper.generify(factoryMethod, annotatedElement);
    JVar factoryMethodContextParam = factoryMethod.param(getClasses().CONTEXT, "context");
    JBlock factoryMethodBody = factoryMethod.body();
    /*
		 * Singletons are bound to the application context
		 */
    if (hasSingletonScope) {
        JFieldVar instanceField = generatedClass.field(PRIVATE | STATIC, generatedClass, "instance" + generationSuffix());
        JBlock creationBlock = //
        factoryMethodBody._if(//
        instanceField.eq(_null()))._then();
        JVar previousNotifier = viewNotifierHelper.replacePreviousNotifierWithNull(creationBlock);
        creationBlock.assign(instanceField, _new(narrowedGeneratedClass).arg(factoryMethodContextParam.invoke("getApplicationContext")));
        creationBlock.invoke(instanceField, getInit());
        viewNotifierHelper.resetPreviousNotifier(creationBlock, previousNotifier);
        factoryMethodBody._return(instanceField);
    } else {
        factoryMethodBody._return(_new(narrowedGeneratedClass).arg(factoryMethodContextParam));
    }
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod) 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