52 import javax.swing.DefaultComboBoxModel;
53 import javax.swing.JComboBox;
54 import javax.swing.JComponent;
55 import javax.swing.JFrame;
56 import javax.swing.JLabel;
57 import javax.swing.JPanel;
58 import javax.swing.JScrollPane;
59 import javax.swing.JTextArea;
60 import javax.swing.JTextField;
61 import javax.swing.SwingUtilities;
62 import javax.swing.event.CaretEvent;
63 import javax.swing.event.CaretListener;
64 import javax.swing.text.BadLocationException;
65 import javax.swing.text.DefaultHighlighter;
66 import javax.swing.text.Highlighter;
67 import javax.tools.Diagnostic;
68 import javax.tools.DiagnosticListener;
69 import javax.tools.JavaFileObject;
70 import javax.tools.StandardJavaFileManager;
71
72 import com.sun.source.tree.CompilationUnitTree;
73 import com.sun.source.util.JavacTask;
74 import com.sun.tools.javac.api.JavacTool;
75 import com.sun.tools.javac.code.Flags;
76 import com.sun.tools.javac.tree.EndPosTable;
77 import com.sun.tools.javac.tree.JCTree;
78 import com.sun.tools.javac.tree.JCTree.JCAnnotatedType;
79 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
80 import com.sun.tools.javac.tree.JCTree.JCNewClass;
81 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
82 import com.sun.tools.javac.tree.TreeInfo;
83 import com.sun.tools.javac.tree.TreeScanner;
84
85 import static com.sun.tools.javac.tree.JCTree.Tag.*;
86 import static com.sun.tools.javac.util.Position.NOPOS;
87
88 /**
89 * Utility and test program to check validity of tree positions for tree nodes.
90 * The program can be run standalone, or as a jtreg test. In standalone mode,
91 * errors can be displayed in a gui viewer. For info on command line args,
92 * run program with no args.
93 *
94 * <p>
95 * jtreg: Note that by using the -r switch in the test description below, this test
96 * will process all java files in the langtools/test directory, thus implicitly
97 * covering any new language features that may be tested in this test suite.
98 */
421 public void visitVarDef(JCVariableDecl tree) {
422 // enum member declarations are desugared in the parser and have
423 // ill-defined semantics for tree positions, so for now, we
424 // skip the synthesized bits and just check parts which came from
425 // the original source text
426 if ((tree.mods.flags & Flags.ENUM) != 0) {
427 scan(tree.mods);
428 if (tree.init != null) {
429 if (tree.init.hasTag(NEWCLASS)) {
430 JCNewClass init = (JCNewClass) tree.init;
431 if (init.args != null && init.args.nonEmpty()) {
432 scan(init.args);
433 }
434 if (init.def != null && init.def.defs != null) {
435 scan(init.def.defs);
436 }
437 }
438 }
439 } else
440 super.visitVarDef(tree);
441 }
442
443 boolean check(Info encl, Info self) {
444 if (excludeTags.size() > 0) {
445 if (encl != null && excludeTags.contains(getTagName(encl.tag))
446 || excludeTags.contains(getTagName(self.tag)))
447 return false;
448 }
449 return tags.size() == 0 || tags.contains(getTagName(self.tag));
450 }
451
452 void check(String label, Info encl, Info self, boolean ok) {
453 if (!ok) {
454 if (gui) {
455 if (viewer == null)
456 viewer = new Viewer();
457 viewer.addEntry(sourcefile, label, encl, self);
458 }
459
460 String s = "encl: " + encl.tree.toString() +
|
52 import javax.swing.DefaultComboBoxModel;
53 import javax.swing.JComboBox;
54 import javax.swing.JComponent;
55 import javax.swing.JFrame;
56 import javax.swing.JLabel;
57 import javax.swing.JPanel;
58 import javax.swing.JScrollPane;
59 import javax.swing.JTextArea;
60 import javax.swing.JTextField;
61 import javax.swing.SwingUtilities;
62 import javax.swing.event.CaretEvent;
63 import javax.swing.event.CaretListener;
64 import javax.swing.text.BadLocationException;
65 import javax.swing.text.DefaultHighlighter;
66 import javax.swing.text.Highlighter;
67 import javax.tools.Diagnostic;
68 import javax.tools.DiagnosticListener;
69 import javax.tools.JavaFileObject;
70 import javax.tools.StandardJavaFileManager;
71
72 import com.sun.source.tree.CaseTree.CaseKind;
73 import com.sun.source.tree.CompilationUnitTree;
74 import com.sun.source.util.JavacTask;
75 import com.sun.tools.javac.api.JavacTool;
76 import com.sun.tools.javac.code.Flags;
77 import com.sun.tools.javac.tree.EndPosTable;
78 import com.sun.tools.javac.tree.JCTree;
79 import com.sun.tools.javac.tree.JCTree.JCAnnotatedType;
80 import com.sun.tools.javac.tree.JCTree.JCCase;
81 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
82 import com.sun.tools.javac.tree.JCTree.JCNewClass;
83 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
84 import com.sun.tools.javac.tree.TreeInfo;
85 import com.sun.tools.javac.tree.TreeScanner;
86
87 import static com.sun.tools.javac.tree.JCTree.Tag.*;
88 import static com.sun.tools.javac.util.Position.NOPOS;
89
90 /**
91 * Utility and test program to check validity of tree positions for tree nodes.
92 * The program can be run standalone, or as a jtreg test. In standalone mode,
93 * errors can be displayed in a gui viewer. For info on command line args,
94 * run program with no args.
95 *
96 * <p>
97 * jtreg: Note that by using the -r switch in the test description below, this test
98 * will process all java files in the langtools/test directory, thus implicitly
99 * covering any new language features that may be tested in this test suite.
100 */
423 public void visitVarDef(JCVariableDecl tree) {
424 // enum member declarations are desugared in the parser and have
425 // ill-defined semantics for tree positions, so for now, we
426 // skip the synthesized bits and just check parts which came from
427 // the original source text
428 if ((tree.mods.flags & Flags.ENUM) != 0) {
429 scan(tree.mods);
430 if (tree.init != null) {
431 if (tree.init.hasTag(NEWCLASS)) {
432 JCNewClass init = (JCNewClass) tree.init;
433 if (init.args != null && init.args.nonEmpty()) {
434 scan(init.args);
435 }
436 if (init.def != null && init.def.defs != null) {
437 scan(init.def.defs);
438 }
439 }
440 }
441 } else
442 super.visitVarDef(tree);
443 }
444
445 @Override
446 public void visitCase(JCCase tree) {
447 if (tree.getCaseKind() == CaseKind.RULE) {
448 scan(tree.getBody());
449 } else {
450 super.visitCase(tree);
451 }
452 }
453
454 boolean check(Info encl, Info self) {
455 if (excludeTags.size() > 0) {
456 if (encl != null && excludeTags.contains(getTagName(encl.tag))
457 || excludeTags.contains(getTagName(self.tag)))
458 return false;
459 }
460 return tags.size() == 0 || tags.contains(getTagName(self.tag));
461 }
462
463 void check(String label, Info encl, Info self, boolean ok) {
464 if (!ok) {
465 if (gui) {
466 if (viewer == null)
467 viewer = new Viewer();
468 viewer.addEntry(sourcefile, label, encl, self);
469 }
470
471 String s = "encl: " + encl.tree.toString() +
|