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

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2010-04-28T08:03:58Z Indexed on 2010/04/28 8:23 UTC
Read the original article Hit count: 258

I have created an annotation, applied it to a DTO and written a Java 1.6 style annotationProcessor. I can see how to have the annotationProcessor write a new source file, which isn't what I want to do, I cannot see or find out how to have it modify the existing class (ideally just modify the byte code). The modification is actually fairly trivial, all I want the processor to do is to insert a new getter and setter where the name comes from the value of the annotation being processed.

My annotation processor looks like 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 some stuff
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about annotation