3131import org .androidannotations .process .ProcessHolder ;
3232
3333import com .sun .codemodel .JBlock ;
34+ import com .sun .codemodel .JClass ;
3435import com .sun .codemodel .JFieldVar ;
3536import com .sun .codemodel .JMethod ;
3637import com .sun .codemodel .JVar ;
@@ -83,7 +84,11 @@ public void invokeInitInConstructor() {
8384
8485 public void createFactoryMethod (boolean hasSingletonScope ) {
8586
86- JMethod factoryMethod = generatedClass .method (PUBLIC | STATIC , generatedClass , GET_INSTANCE_METHOD_NAME );
87+ JClass narrowedGeneratedClass = codeModelHelper .narrowGeneratedClass (generatedClass , annotatedElement .asType (), this );
88+
89+ JMethod factoryMethod = generatedClass .method (PUBLIC | STATIC , narrowedGeneratedClass , GET_INSTANCE_METHOD_NAME );
90+
91+ codeModelHelper .generifyStaticHelper (this , factoryMethod , annotatedElement );
8792
8893 JVar factoryMethodContextParam = factoryMethod .param (classes ().CONTEXT , "context" );
8994
@@ -100,13 +105,13 @@ public void createFactoryMethod(boolean hasSingletonScope) {
100105 ._if (instanceField .eq (_null ())) //
101106 ._then ();
102107 JVar previousNotifier = viewNotifierHelper .replacePreviousNotifierWithNull (creationBlock );
103- creationBlock .assign (instanceField , _new (generatedClass ).arg (factoryMethodContextParam .invoke ("getApplicationContext" )));
108+ creationBlock .assign (instanceField , _new (narrowedGeneratedClass ).arg (factoryMethodContextParam .invoke ("getApplicationContext" )));
104109 creationBlock .invoke (instanceField , getInit ());
105110 viewNotifierHelper .resetPreviousNotifier (creationBlock , previousNotifier );
106111
107112 factoryMethodBody ._return (instanceField );
108113 } else {
109- factoryMethodBody ._return (_new (generatedClass ).arg (factoryMethodContextParam ));
114+ factoryMethodBody ._return (_new (narrowedGeneratedClass ).arg (factoryMethodContextParam ));
110115 }
111116 }
112117
0 commit comments