< prev index next >

test/langtools/tools/javac/options/release/ReleaseOptionThroughAPI.java

Print this page




  33 import java.util.Arrays;
  34 import java.util.List;
  35 import javax.tools.JavaCompiler;
  36 import javax.tools.JavaFileObject;
  37 import javax.tools.StandardJavaFileManager;
  38 import javax.tools.ToolProvider;
  39 
  40 public class ReleaseOptionThroughAPI {
  41     public static void main(String... args) throws IOException {
  42         new ReleaseOptionThroughAPI().run();
  43     }
  44 
  45     void run() throws IOException {
  46         String lineSep = System.getProperty("line.separator");
  47         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  48         try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
  49              StringWriter out = new StringWriter();
  50              PrintWriter outWriter = new PrintWriter(out)) {
  51             Iterable<? extends JavaFileObject> input =
  52                     fm.getJavaFileObjects(System.getProperty("test.src") + "/ReleaseOption.java");
  53             List<String> options = Arrays.asList("--release", "7", "-XDrawDiagnostics");
  54 
  55             compiler.getTask(outWriter, fm, null, options, null, input).call();
  56             String expected =
  57                     "ReleaseOption.java:9:49: compiler.err.doesnt.exist: java.util.stream" + lineSep +
  58                     "1 error" + lineSep;
  59             if (!expected.equals(out.toString())) {
  60                 throw new AssertionError("Unexpected output: " + out.toString());
  61             }
  62         }
  63     }
  64 }


  33 import java.util.Arrays;
  34 import java.util.List;
  35 import javax.tools.JavaCompiler;
  36 import javax.tools.JavaFileObject;
  37 import javax.tools.StandardJavaFileManager;
  38 import javax.tools.ToolProvider;
  39 
  40 public class ReleaseOptionThroughAPI {
  41     public static void main(String... args) throws IOException {
  42         new ReleaseOptionThroughAPI().run();
  43     }
  44 
  45     void run() throws IOException {
  46         String lineSep = System.getProperty("line.separator");
  47         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  48         try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
  49              StringWriter out = new StringWriter();
  50              PrintWriter outWriter = new PrintWriter(out)) {
  51             Iterable<? extends JavaFileObject> input =
  52                     fm.getJavaFileObjects(System.getProperty("test.src") + "/ReleaseOption.java");
  53             List<String> options = Arrays.asList("--release", "7", "-XDrawDiagnostics", "-Xlint:-options");
  54 
  55             compiler.getTask(outWriter, fm, null, options, null, input).call();
  56             String expected =
  57                     "ReleaseOption.java:9:49: compiler.err.doesnt.exist: java.util.stream" + lineSep +
  58                     "1 error" + lineSep;
  59             if (!expected.equals(out.toString())) {
  60                 throw new AssertionError("Unexpected output: " + out.toString());
  61             }
  62         }
  63     }
  64 }
< prev index next >