test/tools/javac/treepostests/TreePosTest.java

changeset 493
7d9e3a15d2b3
parent 486
41ed86f86585
equal deleted inserted replaced
489:4b4e282a3146 493:7d9e3a15d2b3
96 96
97 /* 97 /*
98 * @test 98 * @test
99 * @bug 6919889 99 * @bug 6919889
100 * @summary assorted position errors in compiler syntax trees 100 * @summary assorted position errors in compiler syntax trees
101 * @run main TreePosTest -q -r -ef ./tools/javac/typeAnnotations -ef ./tools/javap/typeAnnotations . 101 * @run main TreePosTest -q -r -ef ./tools/javac/typeAnnotations -ef ./tools/javap/typeAnnotations -et ANNOTATED_TYPE .
102 */ 102 */
103 public class TreePosTest { 103 public class TreePosTest {
104 /** 104 /**
105 * Main entry point. 105 * Main entry point.
106 * If test.src is set, program runs in jtreg mode, and will throw an Error 106 * If test.src is set, program runs in jtreg mode, and will throw an Error
148 verbose = true; 148 verbose = true;
149 else if (arg.equals("-t") && i + 1 < args.length) 149 else if (arg.equals("-t") && i + 1 < args.length)
150 tags.add(args[++i]); 150 tags.add(args[++i]);
151 else if (arg.equals("-ef") && i + 1 < args.length) 151 else if (arg.equals("-ef") && i + 1 < args.length)
152 excludeFiles.add(new File(baseDir, args[++i])); 152 excludeFiles.add(new File(baseDir, args[++i]));
153 else if (arg.equals("-et") && i + 1 < args.length)
154 excludeTags.add(args[++i]);
153 else if (arg.equals("-r")) { 155 else if (arg.equals("-r")) {
154 if (excludeFiles.size() > 0) 156 if (excludeFiles.size() > 0)
155 throw new Error("-r must be used before -ef"); 157 throw new Error("-r must be used before -ef");
156 File d = baseDir; 158 File d = baseDir;
157 while (!new File(d, "TEST.ROOT").exists()) { 159 while (!new File(d, "TEST.ROOT").exists()) {
197 out.println("-q Quiet: don't report on inapplicable files"); 199 out.println("-q Quiet: don't report on inapplicable files");
198 out.println("-v Verbose: report on files as they are being read"); 200 out.println("-v Verbose: report on files as they are being read");
199 out.println("-t tag Limit checks to tree nodes with this tag"); 201 out.println("-t tag Limit checks to tree nodes with this tag");
200 out.println(" Can be repeated if desired"); 202 out.println(" Can be repeated if desired");
201 out.println("-ef file Exclude file or directory"); 203 out.println("-ef file Exclude file or directory");
204 out.println("-et tag Exclude tree nodes with given tag name");
202 out.println(""); 205 out.println("");
203 out.println("files may be directories or files"); 206 out.println("files may be directories or files");
204 out.println("directories will be scanned recursively"); 207 out.println("directories will be scanned recursively");
205 out.println("non java files, or java files which cannot be parsed, will be ignored"); 208 out.println("non java files, or java files which cannot be parsed, will be ignored");
206 out.println(""); 209 out.println("");
302 /** The set of tags for tree nodes to be analyzed; if empty, all tree nodes 305 /** The set of tags for tree nodes to be analyzed; if empty, all tree nodes
303 * are analyzed. */ 306 * are analyzed. */
304 Set<String> tags = new HashSet<String>(); 307 Set<String> tags = new HashSet<String>();
305 /** Set of files and directories to be excluded from analysis. */ 308 /** Set of files and directories to be excluded from analysis. */
306 Set<File> excludeFiles = new HashSet<File>(); 309 Set<File> excludeFiles = new HashSet<File>();
310 /** Set of tag names to be excluded from analysis. */
311 Set<String> excludeTags = new HashSet<String>();
307 /** Table of printable names for tree tag values. */ 312 /** Table of printable names for tree tag values. */
308 TagNames tagNames = new TagNames(); 313 TagNames tagNames = new TagNames();
309 314
310 /** 315 /**
311 * Main class for testing assertions concerning tree positions for tree nodes. 316 * Main class for testing assertions concerning tree positions for tree nodes.
322 public void scan(JCTree tree) { 327 public void scan(JCTree tree) {
323 if (tree == null) 328 if (tree == null)
324 return; 329 return;
325 330
326 Info self = new Info(tree, endPosTable); 331 Info self = new Info(tree, endPosTable);
327 if (check(self)) { 332 if (check(encl, self)) {
328 // Modifiers nodes are present throughout the tree even where 333 // Modifiers nodes are present throughout the tree even where
329 // there is no corresponding source text. 334 // there is no corresponding source text.
330 // Redundant semicolons in a class definition can cause empty 335 // Redundant semicolons in a class definition can cause empty
331 // initializer blocks with no positions. 336 // initializer blocks with no positions.
332 if ((self.tag == JCTree.MODIFIERS || self.tag == JCTree.BLOCK) 337 if ((self.tag == JCTree.MODIFIERS || self.tag == JCTree.BLOCK)
390 } 395 }
391 } else 396 } else
392 super.visitVarDef(tree); 397 super.visitVarDef(tree);
393 } 398 }
394 399
395 boolean check(Info x) { 400 boolean check(Info encl, Info self) {
396 return tags.size() == 0 || tags.contains(tagNames.get(x.tag)); 401 if (excludeTags.size() > 0) {
402 if (encl != null && excludeTags.contains(tagNames.get(encl.tag))
403 || excludeTags.contains(tagNames.get(self.tag)))
404 return false;
405 }
406 return tags.size() == 0 || tags.contains(tagNames.get(self.tag));
397 } 407 }
398 408
399 void check(String label, Info encl, Info self, boolean ok) { 409 void check(String label, Info encl, Info self, boolean ok) {
400 if (!ok) { 410 if (!ok) {
401 if (gui) { 411 if (gui) {

mercurial