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;
}
}
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" });
}
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);
}
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());
}
}
Aggregations