langtools/test/tools/javac/tree/JavacTreeScannerTest.java
changeset 6601 90c4a1a64217
parent 6597 9367c22c445f
child 30730 d3ce7619db2c
equal deleted inserted replaced
6600:b3bb16faccc2 6601:90c4a1a64217
    87             sourcefile = tree.sourcefile;
    87             sourcefile = tree.sourcefile;
    88             found = new HashSet<JCTree>();
    88             found = new HashSet<JCTree>();
    89             scan(tree);
    89             scan(tree);
    90             expect = new HashSet<JCTree>();
    90             expect = new HashSet<JCTree>();
    91             reflectiveScan(tree);
    91             reflectiveScan(tree);
       
    92 
    92             if (found.equals(expect)) {
    93             if (found.equals(expect)) {
    93                 System.err.println(found.size() + " trees compared OK");
    94                 //System.err.println(sourcefile.getName() + ": trees compared OK");
    94                 return found.size();
    95                 return found.size();
    95             }
    96             }
    96 
    97 
    97             error("Differences found for " + tree.sourcefile.getName());
    98             error(sourcefile, "differences found");
    98 
    99 
    99             if (found.size() != expect.size())
   100             if (found.size() != expect.size())
   100                 error("Size mismatch; found: " + found.size() + ", expected: " + expect.size());
   101                 error("Size mismatch; found: " + found.size() + ", expected: " + expect.size());
   101 
   102 
   102             Set<JCTree> missing = new HashSet<JCTree>();
   103             Set<JCTree> missing = new HashSet<JCTree>();
   103             missing.addAll(expect);
   104             missing.addAll(expect);
   104             missing.removeAll(found);
   105             missing.removeAll(found);
   105             for (JCTree t: missing)
   106             for (JCTree t: missing)
   106                 error(tree.sourcefile, t, "missing");
   107                 error(sourcefile, t, "missing");
   107 
   108 
   108             Set<JCTree> excess = new HashSet<JCTree>();
   109             Set<JCTree> excess = new HashSet<JCTree>();
   109             excess.addAll(found);
   110             excess.addAll(found);
   110             excess.removeAll(expect);
   111             excess.removeAll(expect);
   111             for (JCTree t: excess)
   112             for (JCTree t: excess)
   112                 error(tree.sourcefile, t, "unexpected");
   113                 error(sourcefile, t, "unexpected");
   113 
   114 
   114             return 0;
   115             return 0;
   115         }
   116         }
   116 
   117 
   117         /** Record all tree nodes found by scanner. */
   118         /** Record all tree nodes found by scanner. */
   118         @Override
   119         @Override
   119         public void scan(JCTree tree) {
   120         public void scan(JCTree tree) {
   120             if (tree == null)
   121             if (tree == null)
   121                 return;
   122                 return;
   122             System.err.println("FOUND: " + tree.getTag() + " " + trim(tree, 64));
   123             //System.err.println("FOUND: " + tree.getTag() + " " + trim(tree, 64));
   123             found.add(tree);
   124             found.add(tree);
   124             super.scan(tree);
   125             super.scan(tree);
   125         }
   126         }
   126 
   127 
   127         /** record all tree nodes found by reflection. */
   128         /** record all tree nodes found by reflection. */
   128         public void reflectiveScan(Object o) {
   129         public void reflectiveScan(Object o) {
   129             if (o == null)
   130             if (o == null)
   130                 return;
   131                 return;
   131             if (o instanceof JCTree) {
   132             if (o instanceof JCTree) {
   132                 JCTree tree = (JCTree) o;
   133                 JCTree tree = (JCTree) o;
   133                 System.err.println("EXPECT: " + tree.getTag() + " " + trim(tree, 64));
   134                 //System.err.println("EXPECT: " + tree.getTag() + " " + trim(tree, 64));
   134                 expect.add(tree);
   135                 expect.add(tree);
   135                 for (Field f: getFields(tree)) {
   136                 for (Field f: getFields(tree)) {
   136                     try {
   137                     try {
   137                         //System.err.println("FIELD: " + f.getName());
   138                         //System.err.println("FIELD: " + f.getName());
   138                         reflectiveScan(f.get(tree));
   139                         reflectiveScan(f.get(tree));