Search in sources :

Example 1 with SourceVersion

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);
        }
    };
}
Also used : Locale(java.util.Locale) JavaFileManager(javax.tools.JavaFileManager) StandardJavaFileManager(javax.tools.StandardJavaFileManager) ImmutableList(com.google.common.collect.ImmutableList) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) JavaCompiler(javax.tools.JavaCompiler) Charset(java.nio.charset.Charset) DiagnosticListener(javax.tools.DiagnosticListener) SourceVersion(javax.lang.model.SourceVersion) IOException(java.io.IOException) JavaFileObject(javax.tools.JavaFileObject) StandardJavaFileManager(javax.tools.StandardJavaFileManager) Writer(java.io.Writer)

Example 2 with SourceVersion

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;
}
Also used : SourceVersion(javax.lang.model.SourceVersion)

Example 3 with SourceVersion

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);
}
Also used : SourceVersion(javax.lang.model.SourceVersion) Tool(javax.tools.Tool)

Example 4 with SourceVersion

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;
}
Also used : SourceVersion(javax.lang.model.SourceVersion)

Aggregations

SourceVersion (javax.lang.model.SourceVersion)4 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Writer (java.io.Writer)1 Charset (java.nio.charset.Charset)1 Locale (java.util.Locale)1 DiagnosticListener (javax.tools.DiagnosticListener)1 JavaCompiler (javax.tools.JavaCompiler)1 JavaFileManager (javax.tools.JavaFileManager)1 JavaFileObject (javax.tools.JavaFileObject)1 StandardJavaFileManager (javax.tools.StandardJavaFileManager)1 Tool (javax.tools.Tool)1