Accessing the current JavaCompiler.CompilationTask within a Processor?

So,

I'd like to access the current CompilationTask to cast it to a com.sun.source.util.JavacTask in order to register a TaskListener.

This would all be done within the context of a javax.annotation.processing.Processor.

Is such a thing possible? (Basically, my Processor would like to compile a piece of code, but only after the CompilationTask has compiled a certain piece of code.--otherwise my Processor's compilation gets overwritten)

On another note, is there any way to get a list of all queued or running CompilationTasks? Or access to the outer JavaCompiler instance? ToolProvider.getSystemJavaCompiler() seems to give a new instance or one that is not configured with the same classpath...

Thanks.

[745 byte] By [pfnguyena] at [2007-11-27 1:52:36]
# 1
Have you tried casting your ProcessingEnvironment to CompilationTask?
brucechapmana at 2007-7-12 1:21:43 > top of Java-index,Core,Core APIs...
# 2

Bruce,

I haven't tried that, but I've been looking at javac sources, and unless that's new for java 7, it won't work. ProcessingEnvironment is actually an instance of JavacProcessingEnvironment (which doesn't implement o r extend any other classes [that I'm interested in]).

Doing some hacks, I'm able to do what I want... but since it involves using many of the javac internal classes, I'm afraid it won't work going forward :(

[

// Going with

com.sun.tools.javac.util.Context ctx = ((JavacProcessingEnvironment)processingEnv).getContext();

ctx.put(TaskListener.class, myTaskListener);

]

pfnguyena at 2007-7-12 1:21:43 > top of Java-index,Core,Core APIs...
# 3
Am I right that your task listener is a 'post-bytecode-generation' hook and that it enables you to instrument the bytecode once compilation/bytecode generation is done? that would be so cool (even though no-api)cheers, joh
riejoa at 2007-7-12 1:21:43 > top of Java-index,Core,Core APIs...
# 4

> Am I right that your task listener is a

> 'post-bytecode-generation' hook and that it enables

> you to instrument the bytecode once

> compilation/bytecode generation is done? that would

> be so cool (even though no-api)

Yes, it was my intent to do compile-time instrumentation, but that approach did not work--instead, see my @Property annotation thread to see how it's done.

pfnguyena at 2007-7-12 1:21:44 > top of Java-index,Core,Core APIs...