com.sun.source.util.TaskEvent.Kind Java Examples
The following examples show how to use
com.sun.source.util.TaskEvent.Kind.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventsBalancedTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
void test(Iterable<String> options, Iterable<JavaFileObject> files) throws IOException { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); TestListener listener = new TestListener(); JavacTask task = tool.getTask(pw, fm, null, options, null, files); task.setTaskListener(listener); task.call(); for (Entry<Kind, Integer> e : listener.kind2Count.entrySet()) { if (e.getValue() != null && e.getValue() != 0) { throw new IllegalStateException("Not balanced event: " + e.getKey()); } } }
Example #2
Source File: EventsBalancedTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
void test(Iterable<String> options, Iterable<JavaFileObject> files) throws IOException { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); TestListener listener = new TestListener(); JavacTask task = tool.getTask(pw, fm, null, options, null, files); task.setTaskListener(listener); task.call(); for (Entry<Kind, Integer> e : listener.kind2Count.entrySet()) { if (e.getValue() != null && e.getValue() != 0) { throw new IllegalStateException("Not balanced event: " + e.getKey()); } } }
Example #3
Source File: DeptectivePlugin.java From deptective with Apache License 2.0 | 6 votes |
private TaskEventKind getTaskEventKind(TaskEvent.Kind kind, int totalSourceFiles, int analyzedSourceFiles) { if (kind == Kind.PARSE) { return TaskEventKind.PARSE; } else if (kind == Kind.ANALYZE) { if (!HAS_KIND_COMPILATION && analyzedSourceFiles >= totalSourceFiles - 1) { return TaskEventKind.LAST_ANALYZE; } else { return TaskEventKind.ANALYZE; } } else if (kind.name().equals("COMPILATION")) { return TaskEventKind.COMPILATION; } else { return TaskEventKind.OTHER; } }
Example #4
Source File: EventsBalancedTest.java From hottub with GNU General Public License v2.0 | 6 votes |
void test(Iterable<String> options, Iterable<JavaFileObject> files) throws IOException { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); TestListener listener = new TestListener(); JavacTask task = tool.getTask(pw, fm, null, options, null, files); task.setTaskListener(listener); task.call(); for (Entry<Kind, Integer> e : listener.kind2Count.entrySet()) { if (e.getValue() != null && e.getValue() != 0) { throw new IllegalStateException("Not balanced event: " + e.getKey()); } } }
Example #5
Source File: EventsBalancedTest.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
void test(Iterable<String> options, Iterable<JavaFileObject> files) throws IOException { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); TestListener listener = new TestListener(); JavacTask task = tool.getTask(pw, fm, null, options, null, files); task.setTaskListener(listener); task.call(); for (Entry<Kind, Integer> e : listener.kind2Count.entrySet()) { if (e.getValue() != null && e.getValue() != 0) { throw new IllegalStateException("Not balanced event: " + e.getKey()); } } }
Example #6
Source File: DeptectivePlugin.java From deptective with Apache License 2.0 | 6 votes |
private TaskEventKind getTaskEventKind(TaskEvent.Kind kind, int totalSourceFiles, int analyzedSourceFiles) { if (kind == Kind.PARSE) { return TaskEventKind.PARSE; } else if (kind == Kind.ANALYZE) { if (!HAS_KIND_COMPILATION && analyzedSourceFiles >= totalSourceFiles - 1) { return TaskEventKind.LAST_ANALYZE; } else { return TaskEventKind.ANALYZE; } } else if (kind.name().equals("COMPILATION")) { return TaskEventKind.COMPILATION; } else { return TaskEventKind.OTHER; } }
Example #7
Source File: JavacTurbineTest.java From bazel with Apache License 2.0 | 6 votes |
@Override public void finished(TaskEvent e) { if (e.getKind() == Kind.ANALYZE) { e.getCompilationUnit().accept(new Scanner(), null); } else if (e.getKind() == Kind.GENERATE) { try { FileObject file = processingEnv .getFiler() .createResource( StandardLocation.CLASS_OUTPUT, "", "output.txt", e.getTypeElement()); try (OutputStream os = file.openOutputStream()) { os.write(values.toString().getBytes(UTF_8)); } } catch (IOException exception) { throw new IOError(exception); } } }
Example #8
Source File: EventsBalancedTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
void test(Iterable<String> options, Iterable<JavaFileObject> files) throws IOException { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); TestListener listener = new TestListener(); JavacTask task = tool.getTask(pw, fm, null, options, null, files); task.setTaskListener(listener); task.call(); for (Entry<Kind, Integer> e : listener.kind2Count.entrySet()) { if (e.getValue() != null && e.getValue() != 0) { throw new IllegalStateException("Not balanced event: " + e.getKey()); } } }
Example #9
Source File: JavacTurbineTest.java From bazel with Apache License 2.0 | 5 votes |
private Map<String, Deps.Dependency.Kind> getEntries(Deps.Dependencies deps) { Map<String, Deps.Dependency.Kind> result = new LinkedHashMap<>(); for (Dependency dep : deps.getDependencyList()) { result.put(dep.getPath(), dep.getKind()); } return result; }
Example #10
Source File: ErrorPronePlugin.java From bazel with Apache License 2.0 | 5 votes |
/** Run Error Prone analysis after performing dataflow checks. */ @Override public void postFlow(Env<AttrContext> env) { elapsed.start(); try { errorProneAnalyzer.finished(new TaskEvent(Kind.ANALYZE, env.toplevel, env.enclClass.sym)); } catch (ErrorProneError e) { e.logFatalError(log); // let the exception propagate to javac's main, where it will cause the compilation to // terminate with Result.ABNORMAL throw e; } finally { elapsed.stop(); } }
Example #11
Source File: EventsBalancedTest.java From hottub with GNU General Public License v2.0 | 5 votes |
int get(Kind k) { Integer count = kind2Count.get(k); if (count == null) kind2Count.put(k, count = 0); return count; }
Example #12
Source File: EventsBalancedTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
int get(Kind k) { Integer count = kind2Count.get(k); if (count == null) kind2Count.put(k, count = 0); return count; }
Example #13
Source File: ReusableContext.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public Void visitClass(ClassTree node, Symtab syms) { Symbol sym = ((JCClassDecl)node).sym; if (sym != null) { syms.removeClass(sym.packge().modle, sym.flatName()); Type sup = supertype(sym); if (isCoreClass(sym) || (sup != null && isCoreClass(sup.tsym) && sup.tsym.kind != Kinds.Kind.TYP)) { polluted = true; } } return super.visitClass(node, syms); }
Example #14
Source File: EventsBalancedTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
int get(Kind k) { Integer count = kind2Count.get(k); if (count == null) kind2Count.put(k, count = 0); return count; }
Example #15
Source File: EventsBalancedTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void test(List<String> options, List<JavaFileObject> files) throws IOException { System.err.println("testing: " + options + ", " + files); TestListener listener = new TestListener(); JavacTask task = tool.getTask(null, fm, null, options, null, files); task.setTaskListener(listener); task.call(); for (Entry<Kind, Integer> e : listener.kind2Count.entrySet()) { if (e.getValue() != null && e.getValue() != 0) { throw new IllegalStateException("Not balanced event: " + e.getKey()); } } }
Example #16
Source File: LocalInAnonymous.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public Void visitBlock(BlockTree node, Void p) { if (getCurrentPath().getParentPath().getLeaf().getKind() != Tree.Kind.CLASS) { return super.visitBlock(node, p); } Element prevOwner = currentOwner; try { currentOwner = null; return super.visitBlock(node, p); } finally { currentOwner = prevOwner; } }
Example #17
Source File: AssertCheckAnalyzer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
boolean isSimpleStringArg(JCExpression e) { switch (e.getTag()) { case LAMBDA: JCLambda lambda = (JCLambda)e; return (lambda.getBodyKind() == BodyKind.EXPRESSION) && isSimpleStringArg((JCExpression)lambda.body); default: Symbol argSym = TreeInfo.symbolFor(e); return (e.type.constValue() != null || (argSym != null && argSym.kind == Kinds.Kind.VAR)); } }
Example #18
Source File: JavacFlowListener.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void finished(TaskEvent e) { if (e.getKind() == Kind.ANALYZE) { JCCompilationUnit toplevel = (JCCompilationUnit) e.getCompilationUnit(); if (toplevel != null && toplevel.sourcefile != null) { flowCompleted.add(toplevel.sourcefile.toUri()); } } }
Example #19
Source File: DeptectivePlugin.java From deptective with Apache License 2.0 | 5 votes |
private static boolean hasKindCompilation() { for (TaskEvent.Kind kind : TaskEvent.Kind.values()) { if (kind.name().equals("COMPILATION")) { return true; } } return false; }
Example #20
Source File: DeptectivePlugin.java From deptective with Apache License 2.0 | 5 votes |
private static boolean hasKindCompilation() { for (TaskEvent.Kind kind : TaskEvent.Kind.values()) { if (kind.name().equals("COMPILATION")) { return true; } } return false; }
Example #21
Source File: JavacTaskPool.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override @DefinedBy(Api.COMPILER_TREE) public Void visitClass(ClassTree node, Symtab syms) { Symbol sym = ((JCClassDecl)node).sym; if (sym != null) { syms.removeClass(sym.packge().modle, sym.flatName()); Type sup = supertype(sym); if (isCoreClass(sym) || (sup != null && isCoreClass(sup.tsym) && sup.tsym.kind != Kinds.Kind.TYP)) { polluted = true; } } return super.visitClass(node, syms); }
Example #22
Source File: EventsBalancedTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
int get(Kind k) { Integer count = kind2Count.get(k); if (count == null) kind2Count.put(k, count = 0); return count; }
Example #23
Source File: EventsBalancedTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
int get(Kind k) { Integer count = kind2Count.get(k); if (count == null) kind2Count.put(k, count = 0); return count; }
Example #24
Source File: EventsBalancedTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
int get(Kind k) { Integer count = kind2Count.get(k); if (count == null) kind2Count.put(k, count = 0); return count; }
Example #25
Source File: T6395974.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public void started(TaskEvent e) { if (e.getKind() != Kind.COMPILATION) { throw new AssertionError("Unexpected TaskListener event: " + e); } }
Example #26
Source File: JavacTurbineTest.java From bazel with Apache License 2.0 | 4 votes |
@Test public void bazelReducedSuccess() throws Exception { Path libD = temp.newFile("libd.jar").toPath(); compileLib( libD, ImmutableList.<Path>of(), ImmutableList.of(new StringJavaFileObject("D.java", "public class D {}"))); Path libC = temp.newFile("libc.jar").toPath(); compileLib( libC, Collections.singleton(libD), ImmutableList.of(new StringJavaFileObject("C.java", "class C { static D d; }"))); Path libB = temp.newFile("libb.jar").toPath(); compileLib( libB, ImmutableList.of(libC, libD), ImmutableList.of(new StringJavaFileObject("B.java", "class B { static C c; }"))); Path libA = temp.newFile("liba.jar").toPath(); compileLib( libA, ImmutableList.of(libB, libC, libD), ImmutableList.of(new StringJavaFileObject("A.java", "class A { static B b; }"))); optionsBuilder.addClassPathEntries(ImmutableList.of(libA.toString(), libB.toString())); optionsBuilder.setReducedClasspathMode(ReducedClasspathMode.BAZEL_REDUCED); optionsBuilder.setTargetLabel("//my:target"); addSourceLines( "Hello.java", "class Hello {", " public static A a = new A();", " public static void main(String[] args) {", " A a = null;", " B b = null;", " C c = null;", " D d = null;", " }", "}"); optionsBuilder.addSources(ImmutableList.copyOf(Iterables.transform(sources, TO_STRING))); try (JavacTurbine turbine = new JavacTurbine( new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)), true), optionsBuilder.build())) { assertThat(turbine.compile()).isEqualTo(Result.OK_WITH_REDUCED_CLASSPATH); Context context = turbine.context; JavacFileManager fm = (JavacFileManager) context.get(JavaFileManager.class); assertThat(fm.getLocationAsPaths(StandardLocation.CLASS_PATH)).containsExactly(libA, libB); Deps.Dependencies depsProto = getDeps(); assertThat(depsProto.getSuccess()).isTrue(); assertThat(depsProto.getRequiresReducedClasspathFallback()).isFalse(); assertThat(depsProto.getRuleLabel()).isEqualTo("//my:target"); assertThat(getEntries(depsProto)) .containsExactly( libA.toString(), Deps.Dependency.Kind.EXPLICIT, libB.toString(), Deps.Dependency.Kind.INCOMPLETE); } }
Example #27
Source File: EventsBalancedTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public TestSource(String fileName, String content) { super(URI.create("myfo:/" + fileName + ".java"), JavaFileObject.Kind.SOURCE); this.content = content; }
Example #28
Source File: JavacTurbineTest.java From bazel with Apache License 2.0 | 4 votes |
@Test public void reducedClasspathFallback() throws Exception { Path libD = temp.newFile("libd.jar").toPath(); compileLib( libD, ImmutableList.<Path>of(), ImmutableList.of( new StringJavaFileObject("D.java", "public class D { static final int CONST = 42; }"))); Path libC = temp.newFile("libc.jar").toPath(); compileLib( libC, Collections.singleton(libD), ImmutableList.of(new StringJavaFileObject("C.java", "class C extends D {}"))); Path libB = temp.newFile("libb.jar").toPath(); compileLib( libB, ImmutableList.of(libC, libD), ImmutableList.of(new StringJavaFileObject("B.java", "class B extends C {}"))); Path libA = temp.newFile("liba.jar").toPath(); compileLib( libA, ImmutableList.of(libB, libC, libD), ImmutableList.of(new StringJavaFileObject("A.java", "class A extends B {}"))); Path depsA = writedeps( "liba.jdeps", Deps.Dependencies.newBuilder() .setSuccess(true) .setRuleLabel("//lib:a") .addDependency( Deps.Dependency.newBuilder() .setPath(libB.toString()) .setKind(Deps.Dependency.Kind.EXPLICIT)) .build()); optionsBuilder.addClassPathEntries( ImmutableList.of(libA.toString(), libB.toString(), libC.toString(), libD.toString())); optionsBuilder.addAllDepsArtifacts(ImmutableList.of(depsA.toString())); optionsBuilder.addDirectJars(ImmutableList.of(libA.toString())); optionsBuilder.setTargetLabel("//my:target"); addSourceLines( "Hello.java", "class Hello {", " public static final int CONST = A.CONST;", " public static void main(String[] args) {}", "}"); optionsBuilder.addSources(ImmutableList.copyOf(Iterables.transform(sources, TO_STRING))); try (JavacTurbine turbine = new JavacTurbine( new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8))), optionsBuilder.build())) { assertThat(turbine.compile()).isEqualTo(Result.OK_WITH_FULL_CLASSPATH); Context context = turbine.context; JavacFileManager fm = (JavacFileManager) context.get(JavaFileManager.class); assertThat(fm.getLocationAsPaths(StandardLocation.CLASS_PATH)) .containsExactly(libA, libB, libC, libD); Deps.Dependencies depsProto = getDeps(); assertThat(depsProto.getSuccess()).isTrue(); assertThat(depsProto.getRequiresReducedClasspathFallback()).isFalse(); assertThat(depsProto.getRuleLabel()).isEqualTo("//my:target"); assertThat(getEntries(depsProto)) .containsExactly( libA.toString(), Deps.Dependency.Kind.EXPLICIT, libB.toString(), Deps.Dependency.Kind.IMPLICIT, libC.toString(), Deps.Dependency.Kind.IMPLICIT, libD.toString(), Deps.Dependency.Kind.IMPLICIT); } }
Example #29
Source File: JavacTurbineTest.java From bazel with Apache License 2.0 | 4 votes |
@Test public void reducedClasspath() throws Exception { Path libD = temp.newFile("libd.jar").toPath(); compileLib( libD, ImmutableList.<Path>of(), ImmutableList.of(new StringJavaFileObject("D.java", "public class D {}"))); Path libC = temp.newFile("libc.jar").toPath(); compileLib( libC, Collections.singleton(libD), ImmutableList.of(new StringJavaFileObject("C.java", "class C { static D d; }"))); Path libB = temp.newFile("libb.jar").toPath(); compileLib( libB, ImmutableList.of(libC, libD), ImmutableList.of(new StringJavaFileObject("B.java", "class B { static C c; }"))); Path libA = temp.newFile("liba.jar").toPath(); compileLib( libA, ImmutableList.of(libB, libC, libD), ImmutableList.of(new StringJavaFileObject("A.java", "class A { static B b; }"))); Path depsA = writedeps( "liba.jdeps", Deps.Dependencies.newBuilder() .setSuccess(true) .setRuleLabel("//lib:a") .addDependency( Deps.Dependency.newBuilder() .setPath(libB.toString()) .setKind(Deps.Dependency.Kind.EXPLICIT)) .build()); optionsBuilder.addClassPathEntries( ImmutableList.of(libA.toString(), libB.toString(), libC.toString(), libD.toString())); optionsBuilder.addAllDepsArtifacts(ImmutableList.of(depsA.toString())); optionsBuilder.addDirectJars(ImmutableList.of(libA.toString())); optionsBuilder.setTargetLabel("//my:target"); addSourceLines( "Hello.java", "class Hello {", " public static A a = new A();", " public static void main(String[] args) {", " A a = null;", " B b = null;", " C c = null;", " D d = null;", " }", "}"); optionsBuilder.addSources(ImmutableList.copyOf(Iterables.transform(sources, TO_STRING))); try (JavacTurbine turbine = new JavacTurbine( new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8))), optionsBuilder.build())) { assertThat(turbine.compile()) .isAnyOf(Result.OK_WITH_FULL_CLASSPATH, Result.OK_WITH_REDUCED_CLASSPATH); Context context = turbine.context; JavacFileManager fm = (JavacFileManager) context.get(JavaFileManager.class); assertThat(fm.getLocationAsPaths(StandardLocation.CLASS_PATH)).containsAtLeast(libA, libB); Deps.Dependencies depsProto = getDeps(); assertThat(depsProto.getSuccess()).isTrue(); assertThat(depsProto.getRequiresReducedClasspathFallback()).isFalse(); assertThat(depsProto.getRuleLabel()).isEqualTo("//my:target"); assertThat(getEntries(depsProto)) .containsAtLeast( libA.toString(), Deps.Dependency.Kind.EXPLICIT, libB.toString(), Deps.Dependency.Kind.INCOMPLETE); } }
Example #30
Source File: JavacTurbineTest.java From bazel with Apache License 2.0 | 4 votes |
StringJavaFileObject(String name, String... lines) { super(URI.create(name), JavaFileObject.Kind.SOURCE); this.content = Joiner.on('\n').join(lines); }