[source] ButterKnife code

Do yourself a visitor mode for AnnotationProcessing . Take a look at how the big cow (really a huge cow) does it.

Main features of the project:

  • processing:compiler,做annotation processing
  • plugin: plugin, used for copying R2, mainly for the annotation of weak chickens
  • lib: annotation and suffix-free butterknife library, the actual library used by the App, the Compiler needs to depend on annotation, so the annotation should be independent, not dependent on the Android library

Generate logic:

  • External view:
    each class Foo will generate a corresponding Foo_ViewBinding class. The constructor of this class will bind everything, and unbind will release the corresponding resources.

  • Internal view: The
    mapping relationship is the code in the class hierarchy Foo->Foo_ViewBinding, Annotation->function. Therefore, there is a God map in the process, which does the mapping between classes and BindingSet. BindingSet consists of some column type beans, which are aggregates of all the data that needs to be fetched in the environment.
    From this moment on, the Processor has no knowledge of the compilation environment at all. The generation uses JavaFiler, and different types of code generation are concentrated in the BindingSet, which is equivalent to the Processor is the data store, the data is stored in the data part of the BindingSet, and the brewJava method of the BindingSet is data processing. A string is output.

It seems to be a fairly simple architecture. I can only say that this kind of library for the benefit of mankind may only take a few days to come up with no architecture, but it is really easy to use.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325837188&siteId=291194637