CLASSINDEX - SZYBKA ALTERNATYWA DLA SKANOWANIA KLAS
W Javie częstym problemem jest potrzeba znalezienia klas oznaczonych daną adnotacją. Choć oficjalnie Java nie wspiera takiej funkcjonalności, de facto standardowym rozwiązaniem tego problemu jest skanowanie klas. W tej prezentacji chciałbym przedstawić dużo szybszą alternatywę - autorski projekt oparty na mechanizmach procesowania adnotacji.
7. 8
List of classesList of classes
@Plugin@Plugin
class AuthPlugin {class AuthPlugin {
}}
How to get a list of plugins?How to get a list of plugins?
8. 9
List of classesList of classes
@Plugin@Plugin
class AuthPlugin {class AuthPlugin {
}}
How to get a list of plugins?How to get a list of plugins?
There is no API in Java for that!There is no API in Java for that!
10. 11
Ugly hackUgly hack
((UrlClassLoader) classloader).getURLs();((UrlClassLoader) classloader).getURLs();
Returns the list of URLs to scanReturns the list of URLs to scan
==> Classpath Scanning==> Classpath Scanning
11. 12
Ugly hackUgly hack
((UrlClassLoader) classloader).getURLs();((UrlClassLoader) classloader).getURLs();
Returns the list of URLs to scanReturns the list of URLs to scan
==> Classpath Scanning==> Classpath Scanning
Scannotation, Reflections, Corn CPS,Scannotation, Reflections, Corn CPS,
Spring, JavaEESpring, JavaEE
15. 16
Annotation ProcessorAnnotation Processor
Compiler plugin which can:Compiler plugin which can:
analyse syntax tree of the source filesanalyse syntax tree of the source files
analyse resource filesanalyse resource files
generate new source code filesgenerate new source code files
generate new resource filesgenerate new resource files
generate error messagesgenerate error messages
generate completionsgenerate completions
25. 26
What's moreWhat's more
Android compatibilityAndroid compatibility
• Maven transformer for shader jarsMaven transformer for shader jars
●
Project Jigsaw will have @IndexedProject Jigsaw will have @Indexed
Efficient annotation detection — It must be possible to identify all of the class filesEfficient annotation detection — It must be possible to identify all of the class files
in a module… [in a module… [linklink]]
●
Incremental compilationIncremental compilation
●
MoonshineMoonshine