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;
}
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()));
}
}
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);
}
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();
}
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));
}
}
Aggregations