@Override
 public final void init(ProcessingEnvironment env) {
   super.init(env);
   JavacTask.instance(env).addTaskListener(listener);
   Context ctx = ((JavacProcessingEnvironment) processingEnv).getContext();
   JavaCompiler compiler = JavaCompiler.instance(ctx);
   compiler.shouldStopPolicyIfNoError =
       CompileState.max(compiler.shouldStopPolicyIfNoError, CompileState.FLOW);
 }
Esempio n. 2
0
 public static void add(ProcessingEnvironment env, Runnable r) {
   try {
     JavacTask task = JavacTask.instance(env);
     TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next();
     // The TaskListener is an instanceof TestClose, but when using the
     // default class loaders. the taskListener uses a different
     // instance of Class<TestClose> than the anno processor.
     // If you try to evaluate
     //      TestClose tc = (TestClose) (l).
     // you get the following somewhat confusing error:
     //   java.lang.ClassCastException: TestClose cannot be cast to TestClose
     // The workaround is to access the fields of TestClose with reflection.
     Field f = l.getClass().getField("runnables");
     @SuppressWarnings("unchecked")
     List<Runnable> runnables = (List<Runnable>) f.get(l);
     runnables.add(r);
   } catch (Throwable t) {
     t.printStackTrace();
   }
 }