本文整理汇总了Java中com.sun.source.util.JavacTask.addTaskListener方法的典型用法代码示例。如果您正苦于以下问题:Java JavacTask.addTaskListener方法的具体用法?Java JavacTask.addTaskListener怎么用?Java JavacTask.addTaskListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.util.JavacTask
的用法示例。
在下文中一共展示了JavacTask.addTaskListener方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
/*****************************************
* Add task to the javac compilation process
* @param pe the processing environment
****************************************/
@Override
public synchronized void init(ProcessingEnvironment pe) {
JavacTask task = JavacTask.instance(pe);
if (!(task instanceof BasicJavacTask)) {
pe.getMessager()
.printMessage(Diagnostic.Kind.WARNING,
"Unfortunately you are using an incompatible " +
"version of the javac. Please report this at " +
"https://github.com/prestongarno/trywithres-compat/issues. Thank you.");
return;
}
super.init(pe);
task.addTaskListener(new Loader.TaskListenerImpl(task));
String v = Options.instance(((BasicJavacTask) task).getContext()).get("-g:source");
INJECT_STDOUT_STATEMENT = v != null;
}
示例2: process
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
// System.err.println("TestProcessor.process " + roundEnv);
JavacTask task = JavacTask.instance(processingEnv);
if (++round == 1) {
switch (ak) {
case ADD_IN_PROCESSOR:
task.addTaskListener(listener);
break;
case ADD_IN_LISTENER:
addInListener(task, TaskEvent.Kind.ANALYZE, listener);
break;
}
} else if (roundEnv.processingOver()) {
switch (rk) {
case REMOVE_IN_PROCESSOR:
task.removeTaskListener(listener);
break;
case REMOVE_IN_LISTENER:
removeInListener(task, TaskEvent.Kind.GENERATE, listener);
break;
}
}
return true;
}
示例3: getTask
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
/**
* Fork a new compilation task; if possible the compilation context from previous executions is
* retained (see comments in ReusableContext as to when it's safe to do so); otherwise a brand
* new context is created.
*/
public JavacTask getTask() {
if (task == null) {
ReusableContext context = env.context();
String opts = options == null ? "" :
StreamSupport.stream(options.spliterator(), false).collect(Collectors.joining());
context.clear();
if (!context.polluted && (context.opts == null || context.opts.equals(opts))) {
//we can reuse former context
env.info().ctxReusedCount++;
} else {
env.info().ctxDroppedCount++;
//it's not safe to reuse context - create a new one
context = env.setContext(new ReusableContext());
}
context.opts = opts;
JavacTask javacTask = ((JavacTool)env.javaCompiler()).getTask(out, env.fileManager(),
diagsCollector, options, null, sources, context);
javacTask.setTaskListener(context);
for (TaskListener l : listeners) {
javacTask.addTaskListener(l);
}
task = javacTask;
}
return task;
}
示例4: CompiledTypeProcessor
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
CompiledTypeProcessor( JavacTask javacTask )
{
_javacTask = javacTask;
javacTask.addTaskListener( this );
Context context = ((BasicJavacTask)javacTask).getContext();
JavaCompiler compiler = JavaCompiler.instance( context );
compiler.shouldStopPolicyIfNoError = CompileState.max( compiler.shouldStopPolicyIfNoError, CompileState.FLOW );
_issueReporter = new IssueReporter<>( Log.instance( context ) );
_types = Types.instance( context );
// DiagnosticListener dl = context.get( DiagnosticListener.class );
// context.put( DiagnosticListener.class, (DiagnosticListener)null );
// context.put( DiagnosticListener.class, new WrappedDiagnosticListener( dl ) );
_typesToProcess = new HashMap<>();
_innerClassForGeneration = new HashMap<>();
}
示例5: init
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
@Override
public void init( JavacTask task, String... args )
{
_javacTask = (BasicJavacTask)task;
if( isCompilingCore() )
{
// Do not apply the plugin on Manifold core itself
// Note this can only happen during incremental compile when JavacPlugin.class was previously compiled and in
// the classpath but other parts of core manifold were changed and need compilation (the placeholder plugin is'nt
// used in this case).
JavacProcessingEnvironment.instance( getContext() ).getMessager().printMessage( Diagnostic.Kind.NOTE, "Bypassing JavacPlugin during incremental compilation of Manifold core" );
return;
}
hijackJavacFileManager();
task.addTaskListener( this );
}
示例6: init
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
@DefinedBy(Api.COMPILER_TREE)
public void init(JavacTask task, String... args) {
BasicJavacTask impl = (BasicJavacTask)task;
Context context = impl.getContext();
log = Log.instance(context);
trees = Trees.instance(task);
task.addTaskListener(new PostAnalyzeTaskListener(
new MutableFieldsAnalyzer(task),
new AssertCheckAnalyzer(task),
new DefinedByAnalyzer(task),
new LegacyLogMethodAnalyzer(task)
));
}
示例7: testTaskListener
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
void testTaskListener(JavacTool javac, StandardJavaFileManager fm,
Iterable<? extends JavaFileObject> files, PrintWriter out,
int expectedDocComments) {
out.println("Test task listener");
JavacTask task = javac.getTask(out, fm, null, null, null, files);
TaskListnr tl = new TaskListnr(DocTrees.instance(task));
task.addTaskListener(tl);
task.call();
tl.checker.checkDocComments(expectedDocComments);
}
示例8: init
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
@Override
public void init(JavacTask task, String... args) {
task.addTaskListener(new EffectivelyFinalTaskListener(task));
}
示例9: init
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
public void init(JavacTask task, String... args) {
Pattern pattern = null;
if (args.length == 1)
pattern = Pattern.compile(args[0]);
task.addTaskListener(new PostAnalyzeTaskListener(task, pattern));
}
示例10: test
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
void test(CompileKind ck, AddKind ak, RemoveKind rk) throws IOException {
System.err.println("Test: " + ck + " " + ak + " " + rk);
File tmpDir = new File(ck + "-" + ak + "-" + rk);
tmpDir.mkdirs();
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tmpDir));
List<String> options = new ArrayList<String>();
Iterable<? extends JavaFileObject> files = Arrays.asList(new TestSource());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
JavacTask task = tool.getTask(pw, fm, null, options, null, files);
EventKindCounter ec = new EventKindCounter();
TaskListener listener = new TestListener(ec);
boolean needProcessor = false;
switch (ak) {
case SET_IN_TASK:
task.setTaskListener(listener);
break;
case ADD_IN_TASK:
task.addTaskListener(listener);
break;
case ADD_IN_PROCESSOR:
case ADD_IN_LISTENER:
needProcessor = true;
}
switch (rk) {
case REMOVE_IN_TASK:
task.removeTaskListener(listener);
break;
case REMOVE_IN_PROCESSOR:
case REMOVE_IN_LISTENER:
needProcessor = true;
}
if (needProcessor)
task.setProcessors(Arrays.asList(new TestProcessor(ak, rk, listener)));
ck.run(task);
System.err.println(ec);
check(ck, ak, rk, ec);
System.err.println();
}
示例11: init
import com.sun.source.util.JavacTask; //导入方法依赖的package包/类
@Override
public void init( JavacTask task, String... args )
{
_ctx = ((BasicJavacTask)task).getContext();
task.addTaskListener( this );
}