Search in sources :

Example 21 with Context

use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.

the class TestLog method test.

static void test(boolean genEndPos) throws IOException {
    Context context = new Context();
    Options options = Options.instance(context);
    options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m");
    Log log = Log.instance(context);
    log.multipleErrors = true;
    JavacFileManager.preRegister(context);
    ParserFactory pfac = ParserFactory.instance(context);
    final String text = "public class Foo {\n" + "  public static void main(String[] args) {\n" + "    if (args.length == 0)\n" + "      System.out.println(\"no args\");\n" + "    else\n" + "      System.out.println(args.length + \" args\");\n" + "  }\n" + "}\n";
    JavaFileObject fo = new StringJavaFileObject("Foo", text);
    log.useSource(fo);
    CharSequence cs = fo.getCharContent(true);
    Parser parser = pfac.newParser(cs, false, genEndPos, false);
    JCTree.JCCompilationUnit tree = parser.parseCompilationUnit();
    log.setEndPosTable(fo, tree.endPositions);
    TreeScanner ts = new LogTester(log, tree.endPositions);
    ts.scan(tree);
    check(log.nerrors, 4, "errors");
    check(log.nwarnings, 4, "warnings");
}
Also used : Context(com.sun.tools.javac.util.Context) Options(com.sun.tools.javac.util.Options) Log(com.sun.tools.javac.util.Log) JCTree(com.sun.tools.javac.tree.JCTree) ParserFactory(com.sun.tools.javac.parser.ParserFactory) Parser(com.sun.tools.javac.parser.Parser) SimpleJavaFileObject(javax.tools.SimpleJavaFileObject) JavaFileObject(javax.tools.JavaFileObject) TreeScanner(com.sun.tools.javac.tree.TreeScanner)

Example 22 with Context

use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.

the class T6589361 method main.

public static void main(String[] args) throws Exception {
    JavacFileManager fm = null;
    try {
        fm = new JavacFileManager(new Context(), false, null);
        Set<JavaFileObject.Kind> set = new HashSet<JavaFileObject.Kind>();
        set.add(JavaFileObject.Kind.CLASS);
        Iterable<JavaFileObject> files = fm.list(StandardLocation.PLATFORM_CLASS_PATH, "java.lang", set, false);
        for (JavaFileObject file : files) {
            // we normalize the filename as well.
            if (file.getName().replace(File.separatorChar, '/').contains("java/lang/Object.class")) {
                String str = fm.inferBinaryName(StandardLocation.CLASS_PATH, file);
                if (!str.equals("java.lang.Object")) {
                    throw new AssertionError("Error in JavacFileManager.inferBinaryName method!");
                } else {
                    return;
                }
            }
        }
    } finally {
        if (fm != null) {
            fm.close();
        }
    }
    throw new AssertionError("Could not find java/lang/Object.class while compiling");
}
Also used : JavacFileManager(com.sun.tools.javac.file.JavacFileManager) Context(com.sun.tools.javac.util.Context) JavaFileObject(javax.tools.JavaFileObject) Kind(javax.tools.JavaFileObject.Kind) HashSet(java.util.HashSet)

Example 23 with Context

use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.

the class A method getFileManager.

JavaFileManager getFileManager(String classpathProperty, boolean symFileKind, boolean zipFileIndexKind) throws IOException {
    Context ctx = new Context();
    Options options = Options.instance(ctx);
    options.put("useOptimizedZip", Boolean.toString(zipFileIndexKind == USE_ZIP_FILE_INDEX));
    if (symFileKind == IGNORE_SYMBOL_FILE)
        options.put("ignore.symbol.file", "true");
    JavacFileManager fm = new JavacFileManager(ctx, false, null);
    List<File> path = getPath(System.getProperty(classpathProperty));
    fm.setLocation(CLASS_PATH, path);
    return fm;
}
Also used : Context(com.sun.tools.javac.util.Context) JavacFileManager(com.sun.tools.javac.file.JavacFileManager) Options(com.sun.tools.javac.util.Options)

Example 24 with Context

use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.

the class T6838467 method createFileManager.

JavacFileManager createFileManager(boolean useOptimizedZip) {
    Context ctx = new Context();
    Options options = Options.instance(ctx);
    options.put("useOptimizedZip", Boolean.toString(useOptimizedZip));
    return new JavacFileManager(ctx, false, null);
}
Also used : Context(com.sun.tools.javac.util.Context) JavacFileManager(com.sun.tools.javac.file.JavacFileManager) Options(com.sun.tools.javac.util.Options)

Example 25 with Context

use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.

the class T6877206 method createFileManager.

JavacFileManager createFileManager(boolean useOptimizedZip, boolean useSymbolFile) {
    Context ctx = new Context();
    Options options = Options.instance(ctx);
    options.put("useOptimizedZip", Boolean.toString(useOptimizedZip));
    if (!useSymbolFile) {
        options.put("ignore.symbol.file", "true");
    }
    return new JavacFileManager(ctx, false, null);
}
Also used : Context(com.sun.tools.javac.util.Context) JavacFileManager(com.sun.tools.javac.file.JavacFileManager) Options(com.sun.tools.javac.util.Options)

Aggregations

Context (com.sun.tools.javac.util.Context)65 JavacFileManager (com.sun.tools.javac.file.JavacFileManager)19 Test (org.junit.Test)9 Options (com.sun.tools.javac.util.Options)8 IOException (java.io.IOException)8 PrintWriter (java.io.PrintWriter)8 JavaFileObject (javax.tools.JavaFileObject)7 ListBuffer (com.sun.tools.javac.util.ListBuffer)6 JavacTask (com.sun.source.util.JavacTask)5 JavacProcessingEnvironment (com.sun.tools.javac.processing.JavacProcessingEnvironment)5 JCCompilationUnit (com.sun.tools.javac.tree.JCTree.JCCompilationUnit)5 JavaFileManager (javax.tools.JavaFileManager)5 OutputStreamWriter (java.io.OutputStreamWriter)4 Path (java.nio.file.Path)4 DiagnosticListener (javax.tools.DiagnosticListener)4 ImmutableList (com.google.common.collect.ImmutableList)3 JavacTaskImpl (com.sun.tools.javac.api.JavacTaskImpl)3 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)3 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)3 StringWriter (java.io.StringWriter)3