< prev index next >

test/langtools/tools/javac/tree/JavacTreeScannerTest.java

Print this page




  30  * jtreg: Note that by using the -r switch in the test description below, this test
  31  * will process all java files in the langtools/test directory, thus implicitly
  32  * covering any new language features that may be tested in this test suite.
  33  */
  34 
  35 /*
  36  * @test
  37  * @bug 6923080
  38  * @summary TreeScanner.visitNewClass should scan tree.typeargs
  39  * @modules jdk.compiler/com.sun.tools.javac.api
  40  *          jdk.compiler/com.sun.tools.javac.file
  41  *          jdk.compiler/com.sun.tools.javac.tree
  42  *          jdk.compiler/com.sun.tools.javac.util
  43  * @build AbstractTreeScannerTest JavacTreeScannerTest
  44  * @run main JavacTreeScannerTest -q -r .
  45  */
  46 
  47 import java.io.*;
  48 import java.lang.reflect.*;
  49 import java.util.*;

  50 import javax.tools.*;
  51 
  52 import com.sun.tools.javac.tree.JCTree;
  53 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
  54 import com.sun.tools.javac.tree.TreeScanner;
  55 import com.sun.tools.javac.util.List;

  56 
  57 public class JavacTreeScannerTest extends AbstractTreeScannerTest {
  58     /**
  59      * Main entry point.
  60      * If test.src is set, program runs in jtreg mode, and will throw an Error
  61      * if any errors arise, otherwise System.exit will be used. In jtreg mode,
  62      * the default base directory for file args is the value of ${test.src}.
  63      * In jtreg mode, the -r option can be given to change the default base
  64      * directory to the root test directory.
  65      */
  66     public static void main(String... args) {
  67         String testSrc = System.getProperty("test.src");
  68         File baseDir = (testSrc == null) ? null : new File(testSrc);
  69         boolean ok = new JavacTreeScannerTest().run(baseDir, args);
  70         if (!ok) {
  71             if (testSrc != null)  // jtreg mode
  72                 throw new Error("failed");
  73             else
  74                 System.exit(1);
  75         }


 131         /** record all tree nodes found by reflection. */
 132         public void reflectiveScan(Object o) {
 133             if (o == null)
 134                 return;
 135             if (o instanceof JCTree) {
 136                 JCTree tree = (JCTree) o;
 137                 //System.err.println("EXPECT: " + tree.getTag() + " " + trim(tree, 64));
 138                 expect.add(tree);
 139                 for (Field f: getFields(tree)) {
 140                     try {
 141                         //System.err.println("FIELD: " + f.getName());
 142                         reflectiveScan(f.get(tree));
 143                     } catch (IllegalAccessException e) {
 144                         error(e.toString());
 145                     }
 146                 }
 147             } else if (o instanceof List) {
 148                 List<?> list = (List<?>) o;
 149                 for (Object item: list)
 150                     reflectiveScan(item);


 151             } else
 152                 error("unexpected item: " + o);
 153         }
 154 
 155         JavaFileObject sourcefile;
 156         Set<JCTree> found;
 157         Set<JCTree> expect;
 158     }
 159 }


  30  * jtreg: Note that by using the -r switch in the test description below, this test
  31  * will process all java files in the langtools/test directory, thus implicitly
  32  * covering any new language features that may be tested in this test suite.
  33  */
  34 
  35 /*
  36  * @test
  37  * @bug 6923080
  38  * @summary TreeScanner.visitNewClass should scan tree.typeargs
  39  * @modules jdk.compiler/com.sun.tools.javac.api
  40  *          jdk.compiler/com.sun.tools.javac.file
  41  *          jdk.compiler/com.sun.tools.javac.tree
  42  *          jdk.compiler/com.sun.tools.javac.util
  43  * @build AbstractTreeScannerTest JavacTreeScannerTest
  44  * @run main JavacTreeScannerTest -q -r .
  45  */
  46 
  47 import java.io.*;
  48 import java.lang.reflect.*;
  49 import java.util.*;
  50 
  51 import javax.tools.*;
  52 
  53 import com.sun.tools.javac.tree.JCTree;
  54 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
  55 import com.sun.tools.javac.tree.TreeScanner;
  56 import com.sun.tools.javac.util.List;
  57 import com.sun.tools.javac.util.Pair;
  58 
  59 public class JavacTreeScannerTest extends AbstractTreeScannerTest {
  60     /**
  61      * Main entry point.
  62      * If test.src is set, program runs in jtreg mode, and will throw an Error
  63      * if any errors arise, otherwise System.exit will be used. In jtreg mode,
  64      * the default base directory for file args is the value of ${test.src}.
  65      * In jtreg mode, the -r option can be given to change the default base
  66      * directory to the root test directory.
  67      */
  68     public static void main(String... args) {
  69         String testSrc = System.getProperty("test.src");
  70         File baseDir = (testSrc == null) ? null : new File(testSrc);
  71         boolean ok = new JavacTreeScannerTest().run(baseDir, args);
  72         if (!ok) {
  73             if (testSrc != null)  // jtreg mode
  74                 throw new Error("failed");
  75             else
  76                 System.exit(1);
  77         }


 133         /** record all tree nodes found by reflection. */
 134         public void reflectiveScan(Object o) {
 135             if (o == null)
 136                 return;
 137             if (o instanceof JCTree) {
 138                 JCTree tree = (JCTree) o;
 139                 //System.err.println("EXPECT: " + tree.getTag() + " " + trim(tree, 64));
 140                 expect.add(tree);
 141                 for (Field f: getFields(tree)) {
 142                     try {
 143                         //System.err.println("FIELD: " + f.getName());
 144                         reflectiveScan(f.get(tree));
 145                     } catch (IllegalAccessException e) {
 146                         error(e.toString());
 147                     }
 148                 }
 149             } else if (o instanceof List) {
 150                 List<?> list = (List<?>) o;
 151                 for (Object item: list)
 152                     reflectiveScan(item);
 153             } else if (o instanceof Pair) {
 154                 return;
 155             } else
 156                 error("unexpected item: " + o);
 157         }
 158 
 159         JavaFileObject sourcefile;
 160         Set<JCTree> found;
 161         Set<JCTree> expect;
 162     }
 163 }
< prev index next >