use of com.sun.tools.javac.api.JavacTaskImpl in project ceylon-compiler by ceylon.
the class T6358786 method main.
public static void main(String... args) throws IOException {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
String srcdir = System.getProperty("test.src");
File file = new File(srcdir, args[0]);
JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, fm, null, null, null, fm.getJavaFileObjectsFromFiles(Arrays.asList(file)));
Elements elements = task.getElements();
for (TypeElement clazz : task.enter(task.parse())) {
String doc = elements.getDocComment(clazz);
if (doc == null)
throw new AssertionError(clazz.getSimpleName() + ": no doc comment");
System.out.format("%s: %s%n", clazz.getSimpleName(), doc);
}
}
use of com.sun.tools.javac.api.JavacTaskImpl in project ceylon-compiler by ceylon.
the class T6435291 method main.
public static void main(String... args) {
javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, null, null, null, null, null);
JavaCompiler compiler = JavaCompiler.instance(task.getContext());
try {
compiler.resolveIdent("T").complete();
} catch (BadClassFile e) {
System.err.println("Passed: expected completion failure " + e.getClass().getName());
return;
} catch (Exception e) {
throw new RuntimeException("Failed: unexpected exception");
}
throw new RuntimeException("Failed: no error reported");
}
use of com.sun.tools.javac.api.JavacTaskImpl in project error-prone by google.
the class CompilerBasedTest method compile.
protected void compile(TreeScanner scanner, JavaFileObject fileObject) {
JavaCompiler compiler = JavacTool.create();
DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticsCollector, Locale.ENGLISH, UTF_8);
JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(CharStreams.nullWriter(), fileManager, diagnosticsCollector, ImmutableList.<String>of(), null, ImmutableList.of(fileObject));
try {
this.sourceFile = SourceFile.create(fileObject);
Iterable<? extends CompilationUnitTree> trees = task.parse();
task.analyze();
for (CompilationUnitTree tree : trees) {
scanner.scan((JCCompilationUnit) tree);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
this.context = task.getContext();
}
use of com.sun.tools.javac.api.JavacTaskImpl in project error-prone by google.
the class BugCheckerRefactoringTestHelper method doCompile.
private JCCompilationUnit doCompile(final JavaFileObject input, Iterable<JavaFileObject> files, Context context) throws IOException {
JavacTool tool = JavacTool.create();
DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<>();
context.put(ErrorProneOptions.class, ErrorProneOptions.empty());
JavacTaskImpl task = (JavacTaskImpl) tool.getTask(CharStreams.nullWriter(), fileManager, diagnosticsCollector, options, /*classes=*/
null, files, context);
Iterable<? extends CompilationUnitTree> trees = task.parse();
task.analyze();
JCCompilationUnit tree = Iterables.getOnlyElement(Iterables.filter(Iterables.filter(trees, JCCompilationUnit.class), compilationUnit -> compilationUnit.getSourceFile() == input));
Iterable<Diagnostic<? extends JavaFileObject>> errorDiagnostics = Iterables.filter(diagnosticsCollector.getDiagnostics(), d -> d.getKind() == Diagnostic.Kind.ERROR);
if (!Iterables.isEmpty(errorDiagnostics)) {
fail("compilation failed unexpectedly: " + errorDiagnostics);
}
return tree;
}
use of com.sun.tools.javac.api.JavacTaskImpl in project ceylon by eclipse.
the class T6457284 method main.
public static void main(String[] args) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, null, null, null, null, List.of(new MyFileObject()));
MyMessages.preRegister(task.getContext());
task.parse();
for (Element e : task.analyze()) {
if (!e.getEnclosingElement().toString().equals("compiler.misc.unnamed.package"))
throw new AssertionError(e.getEnclosingElement());
System.out.println("OK: " + e.getEnclosingElement());
return;
}
throw new AssertionError("No top-level classes!");
}
Aggregations