當前位置: 首頁>>代碼示例>>Java>>正文


Java JavacTask.instance方法代碼示例

本文整理匯總了Java中com.sun.source.util.JavacTask.instance方法的典型用法代碼示例。如果您正苦於以下問題:Java JavacTask.instance方法的具體用法?Java JavacTask.instance怎麽用?Java JavacTask.instance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.source.util.JavacTask的用法示例。


在下文中一共展示了JavacTask.instance方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
 
開發者ID:prestongarno,項目名稱:trywithres-compat,代碼行數:22,代碼來源:FakeProcessor.java

示例2: add

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
public static void add(ProcessingEnvironment env, Runnable r) {
    // ensure this class in this class loader can access javac internals
    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();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:TestClose.java

示例3: 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;
        }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:TestSimpleAddRemove.java


注:本文中的com.sun.source.util.JavacTask.instance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。