Search in sources :

Example 1 with Main

use of com.sun.tools.javac.main.Main in project error-prone by google.

the class RefasterRuleCompiler method run.

private Result run(String[] argv, Context context) {
    try {
        argv = prepareCompilation(argv, context);
    } catch (InvalidCommandLineOptionException e) {
        System.err.println(e.getMessage());
        System.err.flush();
        return Result.CMDERR;
    }
    try {
        Result compileResult = new Main("RefasterRuleCompiler", new PrintWriter(new OutputStreamWriter(System.err, StandardCharsets.UTF_8))).compile(argv, context);
        System.err.flush();
        return compileResult;
    } catch (InvalidCommandLineOptionException e) {
        System.err.println(e.getMessage());
        System.err.flush();
        return Result.CMDERR;
    }
}
Also used : InvalidCommandLineOptionException(com.google.errorprone.InvalidCommandLineOptionException) OutputStreamWriter(java.io.OutputStreamWriter) Main(com.sun.tools.javac.main.Main) Result(com.sun.tools.javac.main.Main.Result) PrintWriter(java.io.PrintWriter)

Example 2 with Main

use of com.sun.tools.javac.main.Main in project mastering-java by Kingminghuang.

the class JavaCompiler method main.

public static void main(String[] args) {
    Main compiler = new Main("javac");
    compiler.compile(new String[] { "/home/hqm2zxy/Downloads/mastering-java/src/main/java/jvm/bytecode/TestClass.java" });
}
Also used : Main(com.sun.tools.javac.main.Main)

Example 3 with Main

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

the class T7021650 method compile.

void compile(Context context, String... args) throws Exception {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    Main m = new Main("javac", pw);
    int rc = m.compile(args, context);
    pw.close();
    String out = sw.toString();
    if (!out.isEmpty())
        System.err.println(out);
    if (rc != 0)
        throw new Exception("compilation failed unexpectedly: rc=" + rc);
}
Also used : Main(com.sun.tools.javac.main.Main)

Example 4 with Main

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

the class JavacTool method getTask.

public JavacTask getTask(Writer out, JavaFileManager fileManager, DiagnosticListener<? super JavaFileObject> diagnosticListener, Iterable<String> options, Iterable<String> classes, Iterable<? extends JavaFileObject> compilationUnits) {
    try {
        Context context = new Context();
        ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);
        final String kindMsg = "All compilation units must be of SOURCE kind";
        if (options != null)
            for (String option : options) // null check
            option.getClass();
        if (classes != null) {
            for (String cls : classes) if (// implicit null check
            !SourceVersion.isName(cls))
                throw new IllegalArgumentException("Not a valid class name: " + cls);
        }
        if (compilationUnits != null) {
            // implicit null check
            compilationUnits = ccw.wrapJavaFileObjects(compilationUnits);
            for (JavaFileObject cu : compilationUnits) {
                if (cu.getKind() != JavaFileObject.Kind.SOURCE)
                    throw new IllegalArgumentException(kindMsg);
            }
        }
        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));
        if (out == null)
            context.put(Log.outKey, new PrintWriter(System.err, true));
        else
            context.put(Log.outKey, new PrintWriter(out, true));
        if (fileManager == null)
            fileManager = getStandardFileManager(diagnosticListener, null, null);
        fileManager = ccw.wrap(fileManager);
        context.put(JavaFileManager.class, fileManager);
        processOptions(context, fileManager, options);
        Main compiler = new Main("javacTask", context.get(Log.outKey));
        return new JavacTaskImpl(compiler, options, context, classes, compilationUnits);
    } catch (ClientCodeException ex) {
        throw new RuntimeException(ex.getCause());
    }
}
Also used : Context(com.sun.tools.javac.util.Context) ClientCodeException(com.sun.tools.javac.util.ClientCodeException) Main(com.sun.tools.javac.main.Main) PrintWriter(java.io.PrintWriter)

Aggregations

Main (com.sun.tools.javac.main.Main)4 PrintWriter (java.io.PrintWriter)2 InvalidCommandLineOptionException (com.google.errorprone.InvalidCommandLineOptionException)1 Result (com.sun.tools.javac.main.Main.Result)1 ClientCodeException (com.sun.tools.javac.util.ClientCodeException)1 Context (com.sun.tools.javac.util.Context)1 OutputStreamWriter (java.io.OutputStreamWriter)1