本文整理匯總了Java中com.sun.source.util.JavacTask.setProcessors方法的典型用法代碼示例。如果您正苦於以下問題:Java JavacTask.setProcessors方法的具體用法?Java JavacTask.setProcessors怎麽用?Java JavacTask.setProcessors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.source.util.JavacTask
的用法示例。
在下文中一共展示了JavacTask.setProcessors方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: check
import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
protected void check() throws Exception {
JavacTask ct = (JavacTask) comp.getTask(null, fm, null, Arrays.asList("-g"),
null, Arrays.asList(jfo));
System.err.println("compiling code " + jfo);
ct.setProcessors(Collections.singleton(new AliveRangeFinder()));
if (!ct.call()) {
throw new AssertionError("Error during compilation");
}
File javaFile = new File(jfo.getName());
File classFile = new File(javaFile.getName().replace(".java", ".class"));
checkClassFile(classFile);
//check all candidates have been used up
for (Map.Entry<ElementKey, AliveRanges> entry : aliveRangeMap.entrySet()) {
if (!seenAliveRanges.contains(entry.getKey())) {
error("Redundant @AliveRanges annotation on method " +
entry.getKey().elem + " with key " + entry.getKey());
}
}
}
示例2: run
import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
public void run() throws IOException {
File srcDir = new File(System.getProperty("test.src"));
File thisFile = new File(srcDir, getClass().getName() + ".java");
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
List<String> opts = Arrays.asList("-proc:only", "-doe");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files);
t.setProcessors(Collections.singleton(this));
boolean ok = t.call();
if (!ok)
throw new Error("compilation failed");
}
}
示例3: check
import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
protected void check() throws Exception {
String[] options = {
"--should-stop:at=ATTR",
"--debug:verboseResolution=success,failure,applicable,inapplicable,deferred-inference,predef"
};
AbstractProcessor[] processors = { new ResolveCandidateFinder(), null };
@SuppressWarnings("unchecked")
DiagnosticListener<? super JavaFileObject>[] diagListeners =
new DiagnosticListener[] { new DiagnosticHandler(false), new DiagnosticHandler(true) };
for (int i = 0 ; i < options.length ; i ++) {
JavacTask ct = (JavacTask)comp.getTask(null, fm, diagListeners[i],
Arrays.asList(options[i]), null, Arrays.asList(jfo));
if (processors[i] != null) {
ct.setProcessors(Collections.singleton(processors[i]));
}
ct.analyze();
}
//check diags
for (Diagnostic<? extends JavaFileObject> diag : diags) {
for (DiagnosticProcessor proc : diagProcessors) {
if (proc.matches(diag)) {
proc.process(diag);
break;
}
}
}
//check all candidates have been used up
for (Map.Entry<ElementKey, Candidate> entry : candidatesMap.entrySet()) {
if (!seenCandidates.contains(entry.getKey())) {
error("Redundant @Candidate annotation on method " + entry.getKey().elem + " sig = " + entry.getKey().elem.asType());
}
}
}
示例4: compileAndCheck
import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
static void compileAndCheck(ParameterType ptA, ClassType ctA, ParameterType ptB, ClassType ctB) throws Exception {
JavaSource source = new JavaSource(ptA.instantiate(ctA), ptB.instantiate(ctB));
JavacTask ct = (JavacTask)tool.getTask(null, fm, null,
null, null, Arrays.asList(source));
ct.setProcessors(Arrays.asList(new ContainTypesTester(ParameterType.contains(ptA, ctA, ptB, ctB), source)));
System.err.println("A = " + ptA +" / " + ptA.instantiate(ctA));
System.err.println("B = " + ptB +" / " + ptB.instantiate(ctB));
System.err.println("Source = " + source.source);
ct.analyze();
}
示例5: testAnnoProcessor
import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void testAnnoProcessor(JavacTool javac, StandardJavaFileManager fm,
Iterable<? extends JavaFileObject> files, PrintWriter out,
int expectedDocComments) {
out.println("Test annotation processor");
JavacTask task = javac.getTask(out, fm, null, null, null, files);
AnnoProc ap = new AnnoProc(DocTrees.instance(task));
task.setProcessors(Arrays.asList(ap));
task.call();
ap.checker.checkDocComments(expectedDocComments);
}
示例6: test
import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void test(String src, WarningKind wk, int gen) throws Exception {
count++;
System.err.println("Test " + count + ": wk:" + wk + " gen:" + gen + " src:" +src);
File testDir = new File("test" + count);
File srcDir = createDir(testDir, "src");
File gensrcDir = createDir(testDir, "gensrc");
File classesDir = createDir(testDir, "classes");
File x = writeFile(new File(srcDir, "X.java"), src);
DiagListener dl = new DiagListener();
JavacTool tool = JavacTool.create();
try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
fm.setLocation(StandardLocation.CLASS_PATH,
Arrays.asList(classesDir, new File(System.getProperty("test.classes"))));
fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir));
fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir));
List<String> args = new ArrayList<String>();
// args.add("-XprintProcessorInfo");
args.add("-XprintRounds");
args.add("-Agen=" + gen);
if (wk == WarningKind.YES)
args.add("-Xlint:serial");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
JavacTask task = tool.getTask(pw, fm, dl, args, null, files);
task.setProcessors(Arrays.asList(new AnnoProc()));
boolean ok = task.call();
pw.close();
System.err.println("ok:" + ok + " diags:" + dl.counts);
if (sw.toString().length() > 0) {
System.err.println("output:\n" + sw.toString());
}
for (Diagnostic.Kind dk: Diagnostic.Kind.values()) {
Integer v = dl.counts.get(dk);
int found = (v == null) ? 0 : v;
int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0;
if (found != expect) {
error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found);
}
}
System.err.println();
}
}
示例7: 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();
}