< prev index next >

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

Print this page




  42  *          jdk.compiler/com.sun.tools.javac.util
  43  * @build AbstractTreeScannerTest SourceTreeScannerTest
  44  * @run main SourceTreeScannerTest -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.source.tree.CaseTree.CaseKind;
  54 import com.sun.source.tree.Tree;
  55 import com.sun.source.util.TreeScanner;
  56 import com.sun.tools.javac.tree.JCTree;
  57 import com.sun.tools.javac.tree.JCTree.JCCase;
  58 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
  59 import com.sun.tools.javac.tree.JCTree.JCModuleDecl;
  60 import com.sun.tools.javac.tree.JCTree.TypeBoundKind;
  61 import com.sun.tools.javac.util.List;

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


 152                         if (tree instanceof JCModuleDecl && f.getName().equals("mods")) {
 153                             // The modifiers will not found by TreeScanner,
 154                             // but the embedded annotations will be.
 155                             reflectiveScan(((JCModuleDecl) tree).mods.annotations);
 156                         } else if (tree instanceof JCCase &&
 157                                    ((JCCase) tree).getCaseKind() == CaseKind.RULE &&
 158                                    f.getName().equals("stats")) {
 159                             //value case, visit value:
 160                             reflectiveScan(((JCCase) tree).getBody());
 161                         } else {
 162                             reflectiveScan(f.get(tree));
 163                         }
 164                     } catch (IllegalAccessException e) {
 165                         error(e.toString());
 166                     }
 167                 }
 168             } else if (o instanceof List) {
 169                 List<?> list = (List<?>) o;
 170                 for (Object item: list)
 171                     reflectiveScan(item);


 172             } else
 173                 error("unexpected item: " + o);
 174         }
 175 
 176         JavaFileObject sourcefile;
 177         Set<Tree> found;
 178         Set<Tree> expect;
 179     }
 180 }


  42  *          jdk.compiler/com.sun.tools.javac.util
  43  * @build AbstractTreeScannerTest SourceTreeScannerTest
  44  * @run main SourceTreeScannerTest -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.source.tree.CaseTree.CaseKind;
  54 import com.sun.source.tree.Tree;
  55 import com.sun.source.util.TreeScanner;
  56 import com.sun.tools.javac.tree.JCTree;
  57 import com.sun.tools.javac.tree.JCTree.JCCase;
  58 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
  59 import com.sun.tools.javac.tree.JCTree.JCModuleDecl;
  60 import com.sun.tools.javac.tree.JCTree.TypeBoundKind;
  61 import com.sun.tools.javac.util.List;
  62 import com.sun.tools.javac.util.Pair;
  63 
  64 public class SourceTreeScannerTest extends AbstractTreeScannerTest {
  65     /**
  66      * Main entry point.
  67      * If test.src is set, program runs in jtreg mode, and will throw an Error
  68      * if any errors arise, otherwise System.exit will be used. In jtreg mode,
  69      * the default base directory for file args is the value of ${test.src}.
  70      * In jtreg mode, the -r option can be given to change the default base
  71      * directory to the root test directory.
  72      */
  73     public static void main(String... args) {
  74         String testSrc = System.getProperty("test.src");
  75         File baseDir = (testSrc == null) ? null : new File(testSrc);
  76         boolean ok = new SourceTreeScannerTest().run(baseDir, args);
  77         if (!ok) {
  78             if (testSrc != null)  // jtreg mode
  79                 throw new Error("failed");
  80             else
  81                 System.exit(1);
  82         }


 153                         if (tree instanceof JCModuleDecl && f.getName().equals("mods")) {
 154                             // The modifiers will not found by TreeScanner,
 155                             // but the embedded annotations will be.
 156                             reflectiveScan(((JCModuleDecl) tree).mods.annotations);
 157                         } else if (tree instanceof JCCase &&
 158                                    ((JCCase) tree).getCaseKind() == CaseKind.RULE &&
 159                                    f.getName().equals("stats")) {
 160                             //value case, visit value:
 161                             reflectiveScan(((JCCase) tree).getBody());
 162                         } else {
 163                             reflectiveScan(f.get(tree));
 164                         }
 165                     } catch (IllegalAccessException e) {
 166                         error(e.toString());
 167                     }
 168                 }
 169             } else if (o instanceof List) {
 170                 List<?> list = (List<?>) o;
 171                 for (Object item: list)
 172                     reflectiveScan(item);
 173             } else if (o instanceof Pair) {
 174                 return;
 175             } else
 176                 error("unexpected item: " + o);
 177         }
 178 
 179         JavaFileObject sourcefile;
 180         Set<Tree> found;
 181         Set<Tree> expect;
 182     }
 183 }
< prev index next >