< prev index next >

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

Print this page
rev 51258 : imported patch switch
   1 /*
   2  * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  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 SourceTreeScannerTest
  44  * @run main SourceTreeScannerTest -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.source.tree.Tree;
  53 import com.sun.source.util.TreeScanner;
  54 import com.sun.tools.javac.tree.JCTree;

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


 133 
 134         /** record all tree nodes found by reflection. */
 135         public void reflectiveScan(Object o) {
 136             if (o == null)
 137                 return;
 138             if (o instanceof JCTree) {
 139                 JCTree tree = (JCTree) o;
 140                 //System.err.println("EXPECT: " + tree.getKind() + " " + trim(tree, 64));
 141                 expect.add(tree);
 142                 for (Field f: getFields(tree)) {
 143                     if (TypeBoundKind.class.isAssignableFrom(f.getType())) {
 144                         // not part of public API
 145                         continue;
 146                     }
 147                     try {
 148                         //System.err.println("FIELD: " + f.getName());
 149                         if (tree instanceof JCModuleDecl && f.getName().equals("mods")) {
 150                             // The modifiers will not found by TreeScanner,
 151                             // but the embedded annotations will be.
 152                             reflectiveScan(((JCModuleDecl) tree).mods.annotations);





 153                         } else {
 154                             reflectiveScan(f.get(tree));
 155                         }
 156                     } catch (IllegalAccessException e) {
 157                         error(e.toString());
 158                     }
 159                 }
 160             } else if (o instanceof List) {
 161                 List<?> list = (List<?>) o;
 162                 for (Object item: list)
 163                     reflectiveScan(item);
 164             } else
 165                 error("unexpected item: " + o);
 166         }
 167 
 168         JavaFileObject sourcefile;
 169         Set<Tree> found;
 170         Set<Tree> expect;
 171     }
 172 }
   1 /*
   2  * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  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 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


 136 
 137         /** record all tree nodes found by reflection. */
 138         public void reflectiveScan(Object o) {
 139             if (o == null)
 140                 return;
 141             if (o instanceof JCTree) {
 142                 JCTree tree = (JCTree) o;
 143                 //System.err.println("EXPECT: " + tree.getKind() + " " + trim(tree, 64));
 144                 expect.add(tree);
 145                 for (Field f: getFields(tree)) {
 146                     if (TypeBoundKind.class.isAssignableFrom(f.getType())) {
 147                         // not part of public API
 148                         continue;
 149                     }
 150                     try {
 151                         //System.err.println("FIELD: " + f.getName());
 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 }
< prev index next >