How do you use Java 1.6 Annotation Processing to perform compile time weaving? -


i have created annotation, applied dto , written java 1.6 style annotationprocessor. can see how have annotationprocessor write new source file, isn't want do, cannot see or find out how have modify existing class (ideally modify byte code). modification trivial, want processor insert new getter , setter name comes value of annotation being processed.

my annotation processor looks this;

@supportedsourceversion(sourceversion.release_6) @supportedannotationtypes({ "com.kn.salog.annotation.aggregatefield" }) public class salogdtoannotationprocessor extends abstractprocessor {      @override     public boolean process(final set<? extends typeelement> annotations, final roundenvironment roundenv) {         //do stuff     } } 

you looking "instrumentation", frameworks aspectj do. in case have specify jar in command line "-agent" option, , have possibility filter loaded classes. during filter step can check annotations, , modify bytecode before gets loaded in virtual machine. libraries doing actual bytecode modification include "asm", , maybe highlevel wrappers "cglib" , "javassist". precompile classes generate list of classes have instrumented you, make filtering in beginning bit faster.

see java.lang.instrumentation more info.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -