Search in sources :

Example 6 with JavaCompiler

use of com.sun.tools.javac.main.JavaCompiler in project ceylon-compiler by ceylon.

the class T6358168 method testAnnotationProcessing.

static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);
    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new ListBuffer<File>();
    compilerMain.processArgs(new String[] { "-XprintRounds", "-processorpath", testClasses, "-processor", self, "-d", "." });
    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.initProcessAnnotations(null);
    JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f))));
    try {
        compiler2.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
Also used : JavaCompiler(com.sun.tools.javac.main.JavaCompiler)

Example 7 with JavaCompiler

use of com.sun.tools.javac.main.JavaCompiler in project ceylon-compiler by ceylon.

the class T6358168 method testNoAnnotationProcessing.

static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);
    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new ListBuffer<File>();
    compilerMain.processArgs(new String[] { "-d", "." });
    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
Also used : JavaCompiler(com.sun.tools.javac.main.JavaCompiler)

Example 8 with JavaCompiler

use of com.sun.tools.javac.main.JavaCompiler 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");
}
Also used : JavacTaskImpl(com.sun.tools.javac.api.JavacTaskImpl) BadClassFile(com.sun.tools.javac.jvm.ClassReader.BadClassFile) JavaCompiler(com.sun.tools.javac.main.JavaCompiler)

Example 9 with JavaCompiler

use of com.sun.tools.javac.main.JavaCompiler in project ceylon-compiler by ceylon.

the class T6330997 method main.

public static void main(String... args) {
    increaseMajor("T1.class", 1);
    increaseMajor("T2.class", 2);
    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("T1").complete();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Failed: unexpected exception while reading class T1");
    }
    try {
        compiler.resolveIdent("T2").complete();
    } catch (BadClassFile e) {
        System.err.println("Passed: expected completion failure " + e.getClass().getName());
        return;
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Failed: unexpected exception while reading class T2");
    }
    throw new RuntimeException("Failed: no error reported");
}
Also used : JavacTaskImpl(com.sun.tools.javac.api.JavacTaskImpl) BadClassFile(com.sun.tools.javac.jvm.ClassReader.BadClassFile) JavaCompiler(com.sun.tools.javac.main.JavaCompiler)

Example 10 with JavaCompiler

use of com.sun.tools.javac.main.JavaCompiler in project ceylon-compiler by ceylon.

the class TestResolveIdent method main.

public static void main(String[] args) throws IOException {
    javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, null, null, null, null, null);
    JavaCompiler compiler = JavaCompiler.instance(task.getContext());
    System.out.println(compiler.resolveIdent(getDeprecatedClass().getCanonicalName()));
}
Also used : JavacTaskImpl(com.sun.tools.javac.api.JavacTaskImpl) JavaCompiler(com.sun.tools.javac.main.JavaCompiler)

Aggregations

JavaCompiler (com.sun.tools.javac.main.JavaCompiler)18 JavacTaskImpl (com.sun.tools.javac.api.JavacTaskImpl)4 JavaFileObject (javax.tools.JavaFileObject)4 Field (java.lang.reflect.Field)3 CompletionFailure (com.sun.tools.javac.code.Symbol.CompletionFailure)2 JavacFileManager (com.sun.tools.javac.file.JavacFileManager)2 BadClassFile (com.sun.tools.javac.jvm.ClassReader.BadClassFile)2 Context (com.sun.tools.javac.util.Context)2 File (java.io.File)2 JavaFileManager (javax.tools.JavaFileManager)2 EnvironmentException (com.redhat.ceylon.compiler.EnvironmentException)1 RepositoryException (com.redhat.ceylon.model.cmr.RepositoryException)1 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)1 MethodTree (com.sun.source.tree.MethodTree)1 TaskEvent (com.sun.source.util.TaskEvent)1 TaskListener (com.sun.source.util.TaskListener)1 TreePathScanner (com.sun.source.util.TreePathScanner)1 Symbol (com.sun.tools.javac.code.Symbol)1 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)1 Type (com.sun.tools.javac.code.Type)1