use of javax.lang.model.SourceVersion in project bazel by bazelbuild.
the class BazelJavaCompiler method newInstance.
private static JavaCompiler newInstance(final JavaCompiler delegate) {
// We forward most operations to the JavaCompiler implementation in langtools.jar.
return new JavaCompiler() {
@Override
public CompilationTask getTask(Writer out, JavaFileManager fileManager, DiagnosticListener<? super JavaFileObject> diagnosticListener, Iterable<String> options, Iterable<String> classes, Iterable<? extends JavaFileObject> compilationUnits) {
// We prepend bazel's default javacopts to user javacopts,
// so that the user can override them. javac supports this
// "last option wins" style of option override.
ImmutableList.Builder<String> fullOptions = ImmutableList.builder();
fullOptions.addAll(getDefaultJavacopts());
if (options != null) {
fullOptions.addAll(options);
}
return delegate.getTask(out, fileManager, diagnosticListener, fullOptions.build(), classes, compilationUnits);
}
@Override
public StandardJavaFileManager getStandardFileManager(DiagnosticListener<? super JavaFileObject> diagnosticListener, Locale locale, Charset charset) {
StandardJavaFileManager fileManager = delegate.getStandardFileManager(diagnosticListener, locale, charset);
try {
fileManager.setLocation(// bootclasspath
StandardLocation.PLATFORM_CLASS_PATH, JavacBootclasspath.asFiles());
} catch (IOException e) {
// Should never happen, according to javadocs for setLocation
throw new RuntimeException(e);
}
return fileManager;
}
@Override
public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) {
// prepend bazel's default javacopts to user arguments
List<String> args = ImmutableList.<String>builder().addAll(getDefaultJavacopts()).add(arguments).build();
return delegate.run(in, out, err, args.toArray(new String[0]));
}
@Override
public Set<SourceVersion> getSourceVersions() {
return delegate.getSourceVersions();
}
@Override
public int isSupportedOption(String option) {
return delegate.isSupportedOption(option);
}
};
}
use of javax.lang.model.SourceVersion in project ceylon-compiler by ceylon.
the class AbstractProcessor method getSupportedSourceVersion.
/**
* If the processor class is annotated with {@link
* SupportedSourceVersion}, return the source version in the
* annotation. If the class is not so annotated, {@link
* SourceVersion#RELEASE_6} is returned.
*
* @return the latest source version supported by this processor
*/
public SourceVersion getSupportedSourceVersion() {
SupportedSourceVersion ssv = this.getClass().getAnnotation(SupportedSourceVersion.class);
SourceVersion sv = null;
if (ssv == null) {
sv = SourceVersion.RELEASE_6;
if (isInitialized())
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "No SupportedSourceVersion annotation " + "found on " + this.getClass().getName() + ", returning " + sv + ".");
} else
sv = ssv.value();
return sv;
}
use of javax.lang.model.SourceVersion in project ceylon-compiler by ceylon.
the class T6395981 method main.
public static void main(String... args) {
Tool compiler = ToolProvider.getSystemJavaCompiler();
Set<SourceVersion> expected = EnumSet.noneOf(SourceVersion.class);
for (String arg : args) expected.add(SourceVersion.valueOf(arg));
Set<SourceVersion> found = compiler.getSourceVersions();
Set<SourceVersion> notExpected = EnumSet.copyOf(found);
for (SourceVersion version : expected) {
if (!found.contains(version))
throw new AssertionError("Expected source version not found: " + version);
else
notExpected.remove(version);
}
if (!notExpected.isEmpty())
throw new AssertionError("Unexpected source versions: " + notExpected);
}
use of javax.lang.model.SourceVersion in project ceylon-compiler by ceylon.
the class TestSourceVersion method process.
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment) {
SourceVersion expectedVersion = SourceVersion.valueOf(processingEnv.getOptions().get("ExpectedVersion"));
SourceVersion actualVersion = processingEnv.getSourceVersion();
System.out.println("Expected SourceVersion " + expectedVersion + " actual SourceVersion " + actualVersion);
if (expectedVersion != actualVersion)
throw new RuntimeException();
return true;
}
Aggregations