0

Is there any technique in Java to check if annotation processing or usual runtime (or some other kind of processing) is taking place?

For example something like this:

if(Processing.isAnnotationProcessing()) {
    ...
}

Or something like ...

if(Processing.getProcessingContext() == ProcessingContext.ANNOTATION_PROCESSING) {
    ...
}

So I am looking for a possibility to check this anywhere in the code. Any ideas?

narranoid
  • 155
  • 2
  • 12
  • 1
    What are you trying to do with this? How frequently do you need to check? Can you get a stack trace and look for some class in the call chain? – Andy Turner Dec 11 '15 at 15:01
  • I want to change the behavior of some utility method. I will update the question for the purpose. I need it just once for now but it would be fine to do it in a static code block. I also thought about checking the stack trace but that might be a quite expensive lookup in some cases. – narranoid Dec 11 '15 at 15:10
  • it might be expensive, but you can cache it. – Andy Turner Dec 11 '15 at 15:11
  • That's true and it seems to be the only way. I just found out that I could just catch javax.lang.model.type.MirroredTypeException to achieve what I need. So my problem got solved differently. I'll wait some time and maybe there is coming an answer, because I think it would be interesting to know if the thing asked in the question is possible. But I will delete it shortly if an answer is left out. – narranoid Dec 11 '15 at 15:23

0 Answers0