0

I'm currently writing an annotation processor in which I want it to scan the available methods in classes that their parameters are annotated as NonNull and generate some code inside that methods.

During my search, I didn't find any kind of specification regarding my problem. What steps do I follow at this stage?

@Override
 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(NonNull.class)) { 
}
        return true;
}
Chetan chadha
  • 558
  • 1
  • 4
  • 19
  • https://stackoverflow.com/questions/7976827/how-to-get-parameters-annotation-in-java – StanislavL Aug 08 '17 at 12:19
  • Thanks for your comment but this is using reflection. –  Aug 08 '17 at 12:20
  • Please do some research how annotation processors work first… You can not "generate code inside method block" using annotation processor. Lombock offers limites API to modify source code structure, but it is still far away from adding some arbitrary code to method. It is also possible to generate *bytecode* and insert it into compiled classes post-factum. There are libraries like [afterburner](https://github.com/stephanenicolas/afterburner), that can automate that somewhat. The later looks like something, that might be good place to start (since you probably just want some null checks) – user1643723 Aug 08 '17 at 14:56

0 Answers0