Search in sources :

Example 16 with JavacTaskImpl

use of com.sun.tools.javac.api.JavacTaskImpl in project ceylon by eclipse.

the class TestJavacTask method getTask.

static JavacTaskImpl getTask(JavaCompiler compiler, File... file) {
    StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(file));
    return (JavacTaskImpl) compiler.getTask(null, fm, null, null, null, files);
}
Also used : JavacTaskImpl(com.sun.tools.javac.api.JavacTaskImpl) StandardJavaFileManager(javax.tools.StandardJavaFileManager)

Example 17 with JavacTaskImpl

use of com.sun.tools.javac.api.JavacTaskImpl in project ceylon by eclipse.

the class TestJavacTask method main.

public static void main(String... args) throws IOException {
    JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    String srcdir = System.getProperty("test.src");
    File file = new File(srcdir, args[0]);
    JavacTaskImpl task = getTask(tool, file);
    for (TypeElement clazz : task.enter(task.parse())) System.out.println(clazz.getSimpleName());
}
Also used : JavacTaskImpl(com.sun.tools.javac.api.JavacTaskImpl) TypeElement(javax.lang.model.element.TypeElement) JavaCompiler(javax.tools.JavaCompiler) File(java.io.File)

Example 18 with JavacTaskImpl

use of com.sun.tools.javac.api.JavacTaskImpl in project ceylon by eclipse.

the class T6993301 method testExceptionParameterCorrectKind.

public void testExceptionParameterCorrectKind() throws IOException {
    final String bootPath = System.getProperty("sun.boot.class.path");
    final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    assert tool != null;
    String code = "package test; public class Test { { try { } catch (NullPointerException ex) {} } }";
    final JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath), null, Arrays.asList(new MyFileObject(code)));
    CompilationUnitTree cut = ct.parse().iterator().next();
    ct.analyze();
    new TreePathScanner<Void, Void>() {

        @Override
        public Void visitVariable(VariableTree node, Void p) {
            Element el = Trees.instance(ct).getElement(getCurrentPath());
            assertNotNull(el);
            assertEquals(ElementKind.EXCEPTION_PARAMETER, el.getKind());
            return super.visitVariable(node, p);
        }
    }.scan(cut, null);
}
Also used : JavacTaskImpl(com.sun.tools.javac.api.JavacTaskImpl) CompilationUnitTree(com.sun.source.tree.CompilationUnitTree) Element(javax.lang.model.element.Element) VariableTree(com.sun.source.tree.VariableTree) JavaCompiler(javax.tools.JavaCompiler)

Example 19 with JavacTaskImpl

use of com.sun.tools.javac.api.JavacTaskImpl in project ceylon by eclipse.

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);
    }
}
Also used : JavacTaskImpl(com.sun.tools.javac.api.JavacTaskImpl) TypeElement(javax.lang.model.element.TypeElement) Elements(javax.lang.model.util.Elements)

Example 20 with JavacTaskImpl

use of com.sun.tools.javac.api.JavacTaskImpl in project ceylon by eclipse.

the class T6400303 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("Test$1").complete();
    } catch (CompletionFailure ex) {
        System.err.println("Got expected completion failure: " + ex.getLocalizedMessage());
        return;
    }
    throw new AssertionError("No error reported");
}
Also used : JavacTaskImpl(com.sun.tools.javac.api.JavacTaskImpl) CompletionFailure(com.sun.tools.javac.code.Symbol.CompletionFailure) JavaCompiler(com.sun.tools.javac.main.JavaCompiler)

Aggregations

JavacTaskImpl (com.sun.tools.javac.api.JavacTaskImpl)29 JavaCompiler (javax.tools.JavaCompiler)10 JavaCompiler (com.sun.tools.javac.main.JavaCompiler)8 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)7 IOException (java.io.IOException)5 JavaFileObject (javax.tools.JavaFileObject)5 StandardJavaFileManager (javax.tools.StandardJavaFileManager)5 VariableTree (com.sun.source.tree.VariableTree)4 BadClassFile (com.sun.tools.javac.jvm.ClassReader.BadClassFile)4 Context (com.sun.tools.javac.util.Context)4 Element (javax.lang.model.element.Element)4 TypeElement (javax.lang.model.element.TypeElement)4 DiagnosticCollector (javax.tools.DiagnosticCollector)4 DescriptionBasedDiff (com.google.errorprone.apply.DescriptionBasedDiff)3 SourceFile (com.google.errorprone.apply.SourceFile)3 JCTree (com.sun.tools.javac.tree.JCTree)3 File (java.io.File)3 BinaryTree (com.sun.source.tree.BinaryTree)2 ClassTree (com.sun.source.tree.ClassTree)2 MethodTree (com.sun.source.tree.MethodTree)2