You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
We should refactor the current implementation so that :
Validators and processors are bound together, and know the annotation they are bound too.
From that we can extract the annotation list, which therefore doesn't need to be maintained at the top of the annotation processor
It would also be nice if each processor / validator had access to only its own bean holder scope, because in most case they don't need anything else. But a broader scope should be available for cases where you need to share stuff.
I also think it would be a good idea to refactor a part of the code of androidannotations and to change a bit its architecture, because:
Some parts (EBeanHolder for example) become very messy (which is a pity for a project whose aim is to make code clearer).
And above all, the current model leads to some issues because some annotations can interfere with others :
Ex: try to use the annotation @OnActivityResult in an Activity annotated with RoboGuice and you'll have two methods onActivityResult in the generated class.
I have started to work on this issue in my fork (branch 368_refactor) and propose the following model:
A class extending EComponentHolder for each enhanced component: EActivityHolder for @EActivity, EServiceHolder for @EService, etc... These classes replace the current class EBeanHolder which is very messy. These classes are responsible for creating methods, fields and blocks used by the AnnotationHandlers. These blocks are got using getters which enables to create methods only if they are used thanks to lazy instantation.
A class extending AnnotationHandler for each annotation which is responsible for the validation and the processing and which contains the annotation it handles. From the list of all AnnotationHandlers, we can have the list of all annotations. AnnotationHandlers doesn't create any methods in EComponentHolders and only use blocks provided by the EComponentHolder. If an AnnotationHandler works on different kind of EComponentHolder (like @ViewById), an interface is created and implemented by targeted EComponentHolders.
GeneratingAnnotationHandler extending AnnotationHandler for each annotation @EXxxxx which is also responsible for instantiating a new EComponentHolder depending on the annotation. GeneratingAnnotationHandlers generate only the code implied by the annotation and don't create the whole generated class like now. Ex: the GeneratingAnnotationHandler for @EActivity only set the layout and doesn't create the IntentBuilder. (The EActivityHolder is responsible for that).
This model has some advantages:
Only one list to maintain instead of three : (Validators, Processors, Annotations -> AnnotationHandlers).
Code is clearer, easier to understand, to maintain and to extend.
Only used methods are generated thanks to lazy instantiation.
Annotations doesn't interfere because it's the EComponentHolder which creates the methods and fields.
Refactoring the whole project is quite a big task, and I'm at the beginning so I would like to have some feedback, and to know if it could be integrated into the project to know if and how I continue my work.
Activity
yDelouis commentedon May 29, 2013
Hi,
I also think it would be a good idea to refactor a part of the code of androidannotations and to change a bit its architecture, because:
EBeanHolderfor example) become very messy (which is a pity for a project whose aim is to make code clearer).Ex: try to use the annotation
@OnActivityResultin anActivityannotated withRoboGuiceand you'll have two methodsonActivityResultin the generated class.I have started to work on this issue in my fork (branch 368_refactor) and propose the following model:
EComponentHolderfor each enhanced component:EActivityHolderfor@EActivity,EServiceHolderfor@EService, etc... These classes replace the current classEBeanHolderwhich is very messy. These classes are responsible for creating methods, fields and blocks used by theAnnotationHandlers. These blocks are got using getters which enables to create methods only if they are used thanks to lazy instantation.AnnotationHandlerfor each annotation which is responsible for the validation and the processing and which contains the annotation it handles. From the list of allAnnotationHandlers, we can have the list of all annotations.AnnotationHandlers doesn't create any methods inEComponentHolders and only use blocks provided by theEComponentHolder. If anAnnotationHandlerworks on different kind ofEComponentHolder(like@ViewById), an interface is created and implemented by targetedEComponentHolders.GeneratingAnnotationHandlerextendingAnnotationHandlerfor each annotation@EXxxxxwhich is also responsible for instantiating a newEComponentHolderdepending on the annotation.GeneratingAnnotationHandlers generate only the code implied by the annotation and don't create the whole generated class like now. Ex: theGeneratingAnnotationHandlerfor@EActivityonly set the layout and doesn't create theIntentBuilder. (TheEActivityHolderis responsible for that).This model has some advantages:
Validators,Processors,Annotations ->AnnotationHandlers).EComponentHolderwhich creates the methods and fields.Refactoring the whole project is quite a big task, and I'm at the beginning so I would like to have some feedback, and to know if it could be integrated into the project to know if and how I continue my work.
yDelouis commentedon Jun 11, 2013
Same issue than #282
DayS commentedon Dec 16, 2013
Finally merged :) Thanks