Added Sidecars, which are companion classes for controllers and components that implement the behavior of various annotations as regular but generated code.
Sidecars are a performance and understandability improvement over the reflection code that is currently used. Instead of several reflective calls to methods annotated with OnInit, OnRender, Param, etc., these methods are collected at compile time and their calls including proper parameter injection are generated into the Sidecar class. At runtime, the ControllerManager can check for existing Sidecar classes (for a component FooComponent, the sidecar class will always be called FooComponent_Fx), and statically invoke the predefined methods for init, render, destroy, resources, title, etc.. If no sidecar exists, the manager can fall back to reflection.
Benefits:
No runtime reflection necessary, apart from finding the Sidecar class once per component class.
Easily readable Stack Traces and debugging.
Better performance from static calls instead of reflection.
Drawbacks:
Potential for differences in some implementation details (e.g. order of method calls, edge cases).
Re-implementation effort (most of it is already done).
All annotated methods and fields must be at least package-private.
If we want to enforce the use of the annotation processor, we can even remove all reflective implementations entirely.
@LeStegii Please add a check/warning for private fields and methods with our annotations. Feel free to add to this PR or merge first and create a new one.
New Features
Sidecars are a performance and understandability improvement over the reflection code that is currently used. Instead of several reflective calls to methods annotated with OnInit, OnRender, Param, etc., these methods are collected at compile time and their calls including proper parameter injection are generated into the Sidecar class. At runtime, the ControllerManager can check for existing Sidecar classes (for a component
FooComponent
, the sidecar class will always be calledFooComponent_Fx
), and statically invoke the predefined methods for init, render, destroy, resources, title, etc.. If no sidecar exists, the manager can fall back to reflection.Benefits:
Drawbacks:
If we want to enforce the use of the annotation processor, we can even remove all reflective implementations entirely.