< prev index next >

langtools/test/tools/javac/api/TestTrees.java

Print this page




  62 
  63     public static void main(String[] args) throws IOException {
  64         new TestTrees().run();
  65     }
  66 
  67     void run() throws IOException {
  68 
  69         JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
  70 
  71         DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() {
  72                 public void report(Diagnostic d) {
  73                     error(d.toString());
  74                 }
  75             };
  76 
  77         try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
  78             Iterable<? extends JavaFileObject> files =
  79                 fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
  80 
  81             Iterable<String> opts = Arrays.asList(
  82                 "-XaddExports:"
  83                 + "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
  84                 "-d", ".",
  85                 "-XDcompilePolicy=simple");
  86 
  87             System.err.println("simple compilation, no processing");
  88             JavacTask task = (JavacTask) tool.getTask(out, fm, dl, opts, null, files);
  89             task.setTaskListener(new MyTaskListener(task));
  90             if (!task.call())
  91                 throw new AssertionError("compilation failed");
  92 
  93             opts =  Arrays.asList(
  94                 "-XaddExports:"
  95                 + "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
  96                 "-XDaccessInternalAPI",
  97                 "-d", ".",
  98                 "-processorpath", testClassDir,
  99                 "-processor", self,
 100                 "-XDcompilePolicy=simple");
 101 
 102             System.err.println();
 103             System.err.println("compilation with processing");
 104             task = (JavacTask) tool.getTask(out, fm, dl,opts, null, files);
 105             if (!task.call())
 106                 throw new AssertionError("compilation failed");
 107 
 108             if (errors > 0)
 109                 throw new AssertionError(errors + " errors occurred");
 110         }
 111     }
 112 
 113     void testElement(Trees trees, Element e) {
 114         trees.getClass();
 115         e.getClass();




  62 
  63     public static void main(String[] args) throws IOException {
  64         new TestTrees().run();
  65     }
  66 
  67     void run() throws IOException {
  68 
  69         JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
  70 
  71         DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() {
  72                 public void report(Diagnostic d) {
  73                     error(d.toString());
  74                 }
  75             };
  76 
  77         try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
  78             Iterable<? extends JavaFileObject> files =
  79                 fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
  80 
  81             Iterable<String> opts = Arrays.asList(
  82                 "--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",

  83                 "-d", ".",
  84                 "-XDcompilePolicy=simple");
  85 
  86             System.err.println("simple compilation, no processing");
  87             JavacTask task = (JavacTask) tool.getTask(out, fm, dl, opts, null, files);
  88             task.setTaskListener(new MyTaskListener(task));
  89             if (!task.call())
  90                 throw new AssertionError("compilation failed");
  91 
  92             opts =  Arrays.asList(
  93                 "--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",

  94                 "-XDaccessInternalAPI",
  95                 "-d", ".",
  96                 "-processorpath", testClassDir,
  97                 "-processor", self,
  98                 "-XDcompilePolicy=simple");
  99 
 100             System.err.println();
 101             System.err.println("compilation with processing");
 102             task = (JavacTask) tool.getTask(out, fm, dl,opts, null, files);
 103             if (!task.call())
 104                 throw new AssertionError("compilation failed");
 105 
 106             if (errors > 0)
 107                 throw new AssertionError(errors + " errors occurred");
 108         }
 109     }
 110 
 111     void testElement(Trees trees, Element e) {
 112         trees.getClass();
 113         e.getClass();


< prev index next >