use of javax.tools.StandardJavaFileManager in project ceylon-compiler by ceylon.
the class GenericConstructorAndDiamondTest method main.
public static void main(String... args) throws Exception {
//create default shared JavaCompiler - reused across multiple compilations
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
for (BoundKind boundKind : BoundKind.values()) {
for (ConstructorKind constructorKind : ConstructorKind.values()) {
for (TypeArgumentKind declArgKind : TypeArgumentKind.values()) {
for (TypeArgArity arity : TypeArgArity.values()) {
for (TypeArgumentKind useArgKind : TypeArgumentKind.values()) {
for (TypeArgumentKind diamondArgKind : TypeArgumentKind.values()) {
for (ArgumentKind argKind : ArgumentKind.values()) {
new GenericConstructorAndDiamondTest(boundKind, constructorKind, declArgKind, arity, useArgKind, diamondArgKind, argKind).run(comp, fm);
}
}
}
}
}
}
}
}
use of javax.tools.StandardJavaFileManager in project ceylon-compiler by ceylon.
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);
}
use of javax.tools.StandardJavaFileManager in project ceylon-compiler by ceylon.
the class T6993305 method run.
void run() throws Exception {
File testSrc = new File(System.getProperty("test.src"));
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File f = new File(testSrc, T6993305.class.getSimpleName() + ".java");
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f);
JavacTask task = tool.getTask(null, fm, null, null, null, fos);
Iterable<? extends CompilationUnitTree> cus = task.parse();
TestScanner s = new TestScanner();
s.scan(cus, task);
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
use of javax.tools.StandardJavaFileManager in project ceylon-compiler by ceylon.
the class TestSuperclass method main.
public static void main(String... args) throws Exception {
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
int errors = 0;
for (ClassKind ck : ClassKind.values()) {
for (GenericKind gk : GenericKind.values()) {
for (SuperKind sk : SuperKind.values()) {
errors += new TestSuperclass(ck, gk, sk).run(comp, fm);
}
}
}
if (errors > 0)
throw new Exception(errors + " errors found");
}
use of javax.tools.StandardJavaFileManager in project bazel by bazelbuild.
the class VanillaJavaBuilder method run.
public VanillaJavaBuilderResult run(List<String> args) throws IOException {
OptionsParser optionsParser;
try {
optionsParser = new OptionsParser(args);
} catch (InvalidCommandLineException e) {
return new VanillaJavaBuilderResult(false, e.getMessage());
}
DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>();
StringWriter output = new StringWriter();
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = javaCompiler.getStandardFileManager(diagnosticCollector, ENGLISH, UTF_8);
setLocations(optionsParser, fileManager);
ImmutableList<JavaFileObject> sources = getSources(optionsParser, fileManager);
boolean ok;
if (sources.isEmpty()) {
ok = true;
} else {
CompilationTask task = javaCompiler.getTask(new PrintWriter(output, true), fileManager, diagnosticCollector, JavacOptions.removeBazelSpecificFlags(optionsParser.getJavacOpts()), ImmutableList.<String>of(), /*classes*/
sources);
setProcessors(optionsParser, fileManager, task);
ok = task.call();
}
if (ok) {
writeOutput(optionsParser);
}
writeGeneratedSourceOutput(optionsParser);
// the file to be created
if (optionsParser.getOutputDepsProtoFile() != null) {
try (OutputStream os = Files.newOutputStream(Paths.get(optionsParser.getOutputDepsProtoFile()))) {
Deps.Dependencies.newBuilder().setRuleLabel(optionsParser.getTargetLabel()).setSuccess(ok).build().writeTo(os);
}
}
// TODO(cushon): support manifest protos & genjar
if (optionsParser.getManifestProtoPath() != null) {
try (OutputStream os = Files.newOutputStream(Paths.get(optionsParser.getManifestProtoPath()))) {
Manifest.getDefaultInstance().writeTo(os);
}
}
for (Diagnostic<? extends JavaFileObject> diagnostic : diagnosticCollector.getDiagnostics()) {
StringBuilder message = new StringBuilder();
if (diagnostic.getSource() != null) {
message.append(diagnostic.getSource().getName());
if (diagnostic.getLineNumber() != -1) {
message.append(':').append(diagnostic.getLineNumber());
}
message.append(": ");
}
message.append(diagnostic.getKind().toString().toLowerCase(ENGLISH));
message.append(": ").append(diagnostic.getMessage(ENGLISH)).append(System.lineSeparator());
output.write(message.toString());
}
return new VanillaJavaBuilderResult(ok, output.toString());
}
Aggregations