author | ksrini |
Tue, 01 Dec 2015 07:10:35 -0800 | |
changeset 34567 | c74f68484156 |
parent 33424 | e6bd5406e2cf |
child 37009 | 476d8d615222 |
permissions | -rw-r--r-- |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
1 |
/* |
33360 | 2 |
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
4 |
* |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
8 |
* |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
14 |
* |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
18 |
* |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
21 |
* questions. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
22 |
*/ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
23 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
24 |
import java.io.File; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
25 |
import java.io.FileWriter; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
26 |
import java.io.IOException; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
27 |
import java.io.PrintWriter; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
28 |
import java.io.StringWriter; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
29 |
import java.io.Writer; |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
30 |
import java.text.BreakIterator; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
31 |
import java.util.ArrayList; |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
32 |
import java.util.Arrays; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
33 |
import java.util.List; |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
34 |
import java.util.Locale; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
35 |
import java.util.regex.Matcher; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
36 |
import java.util.regex.Pattern; |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
37 |
import java.util.stream.Collectors; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
38 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
39 |
import javax.lang.model.element.Name; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
40 |
import javax.tools.JavaFileObject; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
41 |
import javax.tools.StandardJavaFileManager; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
42 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
43 |
import com.sun.source.doctree.*; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
44 |
import com.sun.source.tree.ClassTree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
45 |
import com.sun.source.tree.CompilationUnitTree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
46 |
import com.sun.source.tree.MethodTree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
47 |
import com.sun.source.tree.Tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
48 |
import com.sun.source.tree.VariableTree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
49 |
import com.sun.source.util.DocTreeScanner; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
50 |
import com.sun.source.util.DocTrees; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
51 |
import com.sun.source.util.JavacTask; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
52 |
import com.sun.source.util.TreePath; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
53 |
import com.sun.source.util.TreePathScanner; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
54 |
import com.sun.tools.javac.api.JavacTool; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
55 |
import com.sun.tools.javac.tree.DCTree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
56 |
import com.sun.tools.javac.tree.DCTree.DCDocComment; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
57 |
import com.sun.tools.javac.tree.DCTree.DCErroneous; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
58 |
import com.sun.tools.javac.tree.DocPretty; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
59 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
60 |
public class DocCommentTester { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
61 |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
62 |
public static final String BI_MARKER = "BREAK_ITERATOR"; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
63 |
public final boolean useBreakIterator; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
64 |
|
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
65 |
public DocCommentTester(boolean useBreakIterator) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
66 |
this.useBreakIterator = useBreakIterator; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
67 |
} |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
68 |
public static void main(String... args) throws Exception { |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
69 |
ArrayList<String> list = new ArrayList(Arrays.asList(args)); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
70 |
if (!list.isEmpty() && "-useBreakIterator".equals(list.get(0))) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
71 |
list.remove(0); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
72 |
new DocCommentTester(true).run(list); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
73 |
} else { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
74 |
new DocCommentTester(false).run(list); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
75 |
} |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
76 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
77 |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
78 |
public void run(List<String> args) throws Exception { |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
79 |
String testSrc = System.getProperty("test.src"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
80 |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
81 |
List<File> files = args.stream() |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
82 |
.map(arg -> new File(testSrc, arg)) |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
83 |
.collect(Collectors.toList()); |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
84 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
85 |
JavacTool javac = JavacTool.create(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
86 |
StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
87 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
88 |
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
89 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
90 |
JavacTask t = javac.getTask(null, fm, null, null, null, fos); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
91 |
final DocTrees trees = DocTrees.instance(t); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
92 |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
93 |
if (useBreakIterator) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
94 |
// BreakIterators are locale dependent wrt. behavior |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
95 |
trees.setBreakIterator(BreakIterator.getSentenceInstance(Locale.ENGLISH)); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
96 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
97 |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
98 |
final Checker[] checkers = { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
99 |
new ASTChecker(this, trees), |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
100 |
new PosChecker(this, trees), |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
101 |
new PrettyChecker(this, trees) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
102 |
}; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
103 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
104 |
DeclScanner d = new DeclScanner() { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
105 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
106 |
public Void visitCompilationUnit(CompilationUnitTree tree, Void ignore) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
107 |
for (Checker c: checkers) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
108 |
c.visitCompilationUnit(tree); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
109 |
return super.visitCompilationUnit(tree, ignore); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
110 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
111 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
112 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
113 |
void visitDecl(Tree tree, Name name) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
114 |
TreePath path = getCurrentPath(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
115 |
String dc = trees.getDocComment(path); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
116 |
if (dc != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
117 |
for (Checker c : checkers) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
118 |
try { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
119 |
System.err.println(path.getLeaf().getKind() |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
120 |
+ " " + name |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
121 |
+ " " + c.getClass().getSimpleName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
122 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
123 |
c.check(path, name); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
124 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
125 |
System.err.println(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
126 |
} catch (Exception e) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
127 |
error("Exception " + e); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
128 |
e.printStackTrace(System.err); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
129 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
130 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
131 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
132 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
133 |
}; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
134 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
135 |
Iterable<? extends CompilationUnitTree> units = t.parse(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
136 |
for (CompilationUnitTree unit: units) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
137 |
d.scan(unit, null); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
138 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
139 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
140 |
if (errors > 0) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
141 |
throw new Exception(errors + " errors occurred"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
142 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
143 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
144 |
static abstract class DeclScanner extends TreePathScanner<Void, Void> { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
145 |
abstract void visitDecl(Tree tree, Name name); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
146 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
147 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
148 |
public Void visitClass(ClassTree tree, Void ignore) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
149 |
super.visitClass(tree, ignore); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
150 |
visitDecl(tree, tree.getSimpleName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
151 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
152 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
153 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
154 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
155 |
public Void visitMethod(MethodTree tree, Void ignore) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
156 |
super.visitMethod(tree, ignore); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
157 |
visitDecl(tree, tree.getName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
158 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
159 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
160 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
161 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
162 |
public Void visitVariable(VariableTree tree, Void ignore) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
163 |
super.visitVariable(tree, ignore); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
164 |
visitDecl(tree, tree.getName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
165 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
166 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
167 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
168 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
169 |
/** |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
170 |
* Base class for checkers to check the doc comment on a declaration |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
171 |
* (when present.) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
172 |
*/ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
173 |
abstract class Checker { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
174 |
final DocTrees trees; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
175 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
176 |
Checker(DocTrees trees) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
177 |
this.trees = trees; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
178 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
179 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
180 |
void visitCompilationUnit(CompilationUnitTree tree) { } |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
181 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
182 |
abstract void check(TreePath tree, Name name) throws Exception; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
183 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
184 |
void error(String msg) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
185 |
DocCommentTester.this.error(msg); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
186 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
187 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
188 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
189 |
void error(String msg) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
190 |
System.err.println("Error: " + msg); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
191 |
errors++; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
192 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
193 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
194 |
int errors; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
195 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
196 |
/** |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
197 |
* Verify the structure of the DocTree AST by comparing it against golden text. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
198 |
*/ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
199 |
static class ASTChecker extends Checker { |
14551 | 200 |
static final String NEWLINE = System.getProperty("line.separator"); |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
201 |
Printer printer = new Printer(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
202 |
String source; |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
203 |
DocCommentTester test; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
204 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
205 |
ASTChecker(DocCommentTester test, DocTrees t) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
206 |
test.super(t); |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
207 |
this.test = test; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
208 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
209 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
210 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
211 |
void visitCompilationUnit(CompilationUnitTree tree) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
212 |
try { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
213 |
source = tree.getSourceFile().getCharContent(true).toString(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
214 |
} catch (IOException e) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
215 |
source = ""; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
216 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
217 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
218 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
219 |
void check(TreePath path, Name name) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
220 |
StringWriter out = new StringWriter(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
221 |
DocCommentTree dc = trees.getDocCommentTree(path); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
222 |
printer.print(dc, out); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
223 |
out.flush(); |
14551 | 224 |
String found = out.toString().replace(NEWLINE, "\n"); |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
225 |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
226 |
/* |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
227 |
* Look for the first block comment after the first occurrence |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
228 |
* of name, noting that, block comments with BI_MARKER may |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
229 |
* very well be present. |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
230 |
*/ |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
231 |
int start = test.useBreakIterator |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
232 |
? source.indexOf("\n/*\n" + BI_MARKER + "\n", findName(source, name)) |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
233 |
: source.indexOf("\n/*\n", findName(source, name)); |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
234 |
int end = source.indexOf("\n*/\n", start); |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
235 |
int startlen = start + (test.useBreakIterator ? BI_MARKER.length() + 1 : 0) + 4; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
236 |
String expect = source.substring(startlen, end + 1); |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
237 |
if (!found.equals(expect)) { |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
238 |
if (test.useBreakIterator) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
239 |
System.err.println("Using BreakIterator"); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
240 |
} |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
241 |
System.err.println("Expect:\n" + expect); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
242 |
System.err.println("Found:\n" + found); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
243 |
error("AST mismatch for " + name); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
244 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
245 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
246 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
247 |
/** |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
248 |
* This main program is to set up the golden comments used by this |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
249 |
* checker. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
250 |
* Usage: |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
251 |
* java DocCommentTester$ASTChecker -o dir file... |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
252 |
* The given files are written to the output directory with their |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
253 |
* golden comments updated. The intent is that the files should |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
254 |
* then be compared with the originals, e.g. with meld, and if the |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
255 |
* changes are approved, the new files can be used to replace the old. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
256 |
*/ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
257 |
public static void main(String... args) throws Exception { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
258 |
List<File> files = new ArrayList<File>(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
259 |
File o = null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
260 |
for (int i = 0; i < args.length; i++) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
261 |
String arg = args[i]; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
262 |
if (arg.equals("-o")) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
263 |
o = new File(args[++i]); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
264 |
else if (arg.startsWith("-")) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
265 |
throw new IllegalArgumentException(arg); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
266 |
else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
267 |
files.add(new File(arg)); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
268 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
269 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
270 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
271 |
if (o == null) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
272 |
throw new IllegalArgumentException("no output dir specified"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
273 |
final File outDir = o; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
274 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
275 |
JavacTool javac = JavacTool.create(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
276 |
StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
277 |
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
278 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
279 |
JavacTask t = javac.getTask(null, fm, null, null, null, fos); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
280 |
final DocTrees trees = DocTrees.instance(t); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
281 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
282 |
DeclScanner d = new DeclScanner() { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
283 |
Printer p = new Printer(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
284 |
String source; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
285 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
286 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
287 |
public Void visitCompilationUnit(CompilationUnitTree tree, Void ignore) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
288 |
System.err.println("processing " + tree.getSourceFile().getName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
289 |
try { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
290 |
source = tree.getSourceFile().getCharContent(true).toString(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
291 |
} catch (IOException e) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
292 |
source = ""; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
293 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
294 |
// remove existing gold by removing all block comments after the first '{'. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
295 |
int start = source.indexOf("{"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
296 |
while ((start = source.indexOf("\n/*\n", start)) != -1) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
297 |
int end = source.indexOf("\n*/\n"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
298 |
source = source.substring(0, start + 1) + source.substring(end + 4); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
299 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
300 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
301 |
// process decls in compilation unit |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
302 |
super.visitCompilationUnit(tree, ignore); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
303 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
304 |
// write the modified source |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
305 |
File f = new File(tree.getSourceFile().getName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
306 |
File outFile = new File(outDir, f.getName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
307 |
try { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
308 |
FileWriter out = new FileWriter(outFile); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
309 |
try { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
310 |
out.write(source); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
311 |
} finally { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
312 |
out.close(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
313 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
314 |
} catch (IOException e) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
315 |
System.err.println("Can't write " + tree.getSourceFile().getName() |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
316 |
+ " to " + outFile + ": " + e); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
317 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
318 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
319 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
320 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
321 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
322 |
void visitDecl(Tree tree, Name name) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
323 |
DocTree dc = trees.getDocCommentTree(getCurrentPath()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
324 |
if (dc != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
325 |
StringWriter out = new StringWriter(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
326 |
p.print(dc, out); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
327 |
String found = out.toString(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
328 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
329 |
// Look for the empty line after the first occurrence of name |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
330 |
int pos = source.indexOf("\n\n", findName(source, name)); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
331 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
332 |
// Insert the golden comment |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
333 |
source = source.substring(0, pos) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
334 |
+ "\n/*\n" |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
335 |
+ found |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
336 |
+ "*/" |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
337 |
+ source.substring(pos); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
338 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
339 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
340 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
341 |
}; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
342 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
343 |
Iterable<? extends CompilationUnitTree> units = t.parse(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
344 |
for (CompilationUnitTree unit: units) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
345 |
d.scan(unit, null); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
346 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
347 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
348 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
349 |
static int findName(String source, Name name) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
350 |
Pattern p = Pattern.compile("\\s" + name + "[(;]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
351 |
Matcher m = p.matcher(source); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
352 |
if (!m.find()) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
353 |
throw new Error("cannot find " + name); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
354 |
return m.start(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
355 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
356 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
357 |
static class Printer implements DocTreeVisitor<Void, Void> { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
358 |
PrintWriter out; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
359 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
360 |
void print(DocTree tree, Writer out) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
361 |
this.out = (out instanceof PrintWriter) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
362 |
? (PrintWriter) out : new PrintWriter(out); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
363 |
tree.accept(this, null); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
364 |
this.out.flush(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
365 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
366 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
367 |
public Void visitAttribute(AttributeTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
368 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
369 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
370 |
print("name", node.getName().toString()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
371 |
print("vkind", node.getValueKind().toString()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
372 |
print("value", node.getValue()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
373 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
374 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
375 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
376 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
377 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
378 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
379 |
public Void visitAuthor(AuthorTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
380 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
381 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
382 |
print("name", node.getName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
383 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
384 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
385 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
386 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
387 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
388 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
389 |
public Void visitComment(CommentTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
390 |
header(node, compress(node.getBody())); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
391 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
392 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
393 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
394 |
public Void visitDeprecated(DeprecatedTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
395 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
396 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
397 |
print("body", node.getBody()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
398 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
399 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
400 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
401 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
402 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
403 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
404 |
public Void visitDocComment(DocCommentTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
405 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
406 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
407 |
print("firstSentence", node.getFirstSentence()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
408 |
print("body", node.getBody()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
409 |
print("block tags", node.getBlockTags()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
410 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
411 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
412 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
413 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
414 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
415 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
416 |
public Void visitDocRoot(DocRootTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
417 |
header(node, ""); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
418 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
419 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
420 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
421 |
public Void visitEndElement(EndElementTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
422 |
header(node, node.getName().toString()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
423 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
424 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
425 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
426 |
public Void visitEntity(EntityTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
427 |
header(node, node.getName().toString()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
428 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
429 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
430 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
431 |
public Void visitErroneous(ErroneousTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
432 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
433 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
434 |
print("code", ((DCErroneous) node).diag.getCode()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
435 |
print("body", compress(node.getBody())); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
436 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
437 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
438 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
439 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
440 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
441 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
442 |
public Void visitIdentifier(IdentifierTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
443 |
header(node, compress(node.getName().toString())); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
444 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
445 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
446 |
|
34567
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
447 |
@Override |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
448 |
public Void visitIndex(IndexTree node, Void p) { |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
449 |
header(node); |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
450 |
indent(+1); |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
451 |
print("term", node.getSearchTerm()); |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
452 |
print("description", node.getDescription()); |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
453 |
indent(-1); |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
454 |
indent(); |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
455 |
out.println("]"); |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
456 |
return null; |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
457 |
} |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
458 |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
459 |
public Void visitInheritDoc(InheritDocTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
460 |
header(node, ""); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
461 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
462 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
463 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
464 |
public Void visitLink(LinkTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
465 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
466 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
467 |
print("reference", node.getReference()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
468 |
print("body", node.getLabel()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
469 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
470 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
471 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
472 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
473 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
474 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
475 |
public Void visitLiteral(LiteralTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
476 |
header(node, compress(node.getBody().getBody())); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
477 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
478 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
479 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
480 |
public Void visitParam(ParamTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
481 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
482 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
483 |
print("name", node.getName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
484 |
print("description", node.getDescription()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
485 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
486 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
487 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
488 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
489 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
490 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
491 |
public Void visitReference(ReferenceTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
492 |
header(node, compress(node.getSignature())); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
493 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
494 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
495 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
496 |
public Void visitReturn(ReturnTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
497 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
498 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
499 |
print("description", node.getDescription()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
500 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
501 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
502 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
503 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
504 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
505 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
506 |
public Void visitSee(SeeTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
507 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
508 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
509 |
print("reference", node.getReference()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
510 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
511 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
512 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
513 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
514 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
515 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
516 |
public Void visitSerial(SerialTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
517 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
518 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
519 |
print("description", node.getDescription()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
520 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
521 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
522 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
523 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
524 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
525 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
526 |
public Void visitSerialData(SerialDataTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
527 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
528 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
529 |
print("description", node.getDescription()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
530 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
531 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
532 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
533 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
534 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
535 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
536 |
public Void visitSerialField(SerialFieldTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
537 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
538 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
539 |
print("name", node.getName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
540 |
print("type", node.getType()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
541 |
print("description", node.getDescription()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
542 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
543 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
544 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
545 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
546 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
547 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
548 |
public Void visitSince(SinceTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
549 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
550 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
551 |
print("body", node.getBody()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
552 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
553 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
554 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
555 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
556 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
557 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
558 |
public Void visitStartElement(StartElementTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
559 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
560 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
561 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
562 |
out.println("name:" + node.getName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
563 |
print("attributes", node.getAttributes()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
564 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
565 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
566 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
567 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
568 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
569 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
570 |
public Void visitText(TextTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
571 |
header(node, compress(node.getBody())); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
572 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
573 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
574 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
575 |
public Void visitThrows(ThrowsTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
576 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
577 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
578 |
print("exceptionName", node.getExceptionName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
579 |
print("description", node.getDescription()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
580 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
581 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
582 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
583 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
584 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
585 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
586 |
public Void visitUnknownBlockTag(UnknownBlockTagTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
587 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
588 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
589 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
590 |
out.println("tag:" + node.getTagName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
591 |
print("content", node.getContent()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
592 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
593 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
594 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
595 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
596 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
597 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
598 |
public Void visitUnknownInlineTag(UnknownInlineTagTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
599 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
600 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
601 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
602 |
out.println("tag:" + node.getTagName()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
603 |
print("content", node.getContent()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
604 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
605 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
606 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
607 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
608 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
609 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
610 |
public Void visitValue(ValueTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
611 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
612 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
613 |
print("reference", node.getReference()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
614 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
615 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
616 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
617 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
618 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
619 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
620 |
public Void visitVersion(VersionTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
621 |
header(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
622 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
623 |
print("body", node.getBody()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
624 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
625 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
626 |
out.println("]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
627 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
628 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
629 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
630 |
public Void visitOther(DocTree node, Void p) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
631 |
throw new UnsupportedOperationException("Not supported yet."); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
632 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
633 |
|
34567
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
634 |
/* |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
635 |
* Use this method to start printing a multi-line representation of a |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
636 |
* DocTree node. The representation should be termintated by calling |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
637 |
* out.println("]"). |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
638 |
*/ |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
639 |
void header(DocTree node) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
640 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
641 |
out.println(simpleClassName(node) + "[" + node.getKind() + ", pos:" + ((DCTree) node).pos); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
642 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
643 |
|
34567
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
644 |
/* |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
645 |
* Use this method to print a single-line representation of a DocTree node. |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
646 |
*/ |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
647 |
void header(DocTree node, String rest) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
648 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
649 |
out.println(simpleClassName(node) + "[" + node.getKind() + ", pos:" + ((DCTree) node).pos |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
650 |
+ (rest.isEmpty() ? "" : ", " + rest) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
651 |
+ "]"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
652 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
653 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
654 |
String simpleClassName(DocTree node) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
655 |
return node.getClass().getSimpleName().replaceAll("DC(.*)", "$1"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
656 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
657 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
658 |
void print(String name, DocTree item) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
659 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
660 |
if (item == null) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
661 |
out.println(name + ": null"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
662 |
else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
663 |
out.println(name + ":"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
664 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
665 |
item.accept(this, null); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
666 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
667 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
668 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
669 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
670 |
void print(String name, String s) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
671 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
672 |
out.println(name + ": " + s); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
673 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
674 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
675 |
void print(String name, List<? extends DocTree> list) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
676 |
indent(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
677 |
if (list == null) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
678 |
out.println(name + ": null"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
679 |
else if (list.isEmpty()) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
680 |
out.println(name + ": empty"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
681 |
else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
682 |
out.println(name + ": " + list.size()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
683 |
indent(+1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
684 |
for (DocTree tree: list) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
685 |
tree.accept(this, null); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
686 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
687 |
indent(-1); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
688 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
689 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
690 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
691 |
int indent = 0; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
692 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
693 |
void indent() { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
694 |
for (int i = 0; i < indent; i++) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
695 |
out.print(" "); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
696 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
697 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
698 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
699 |
void indent(int n) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
700 |
indent += n; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
701 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
702 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
703 |
String compress(String s) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
704 |
s = s.replace("\n", "|").replace(" ", "_"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
705 |
return (s.length() < 32) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
706 |
? s |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
707 |
: s.substring(0, 16) + "..." + s.substring(16); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
708 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
709 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
710 |
String quote(String s) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
711 |
if (s.contains("\"")) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
712 |
return "'" + s + "'"; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
713 |
else if (s.contains("'") || s.contains(" ")) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
714 |
return '"' + s + '"'; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
715 |
else |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
716 |
return s; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
717 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
718 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
719 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
720 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
721 |
/** |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
722 |
* Verify the reported tree positions by comparing the characters found |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
723 |
* at and after the reported position with the beginning of the pretty- |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
724 |
* printed text. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
725 |
*/ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
726 |
static class PosChecker extends Checker { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
727 |
PosChecker(DocCommentTester test, DocTrees t) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
728 |
test.super(t); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
729 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
730 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
731 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
732 |
void check(TreePath path, Name name) throws Exception { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
733 |
JavaFileObject fo = path.getCompilationUnit().getSourceFile(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
734 |
final CharSequence cs = fo.getCharContent(true); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
735 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
736 |
final DCDocComment dc = (DCDocComment) trees.getDocCommentTree(path); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
737 |
DCTree t = (DCTree) trees.getDocCommentTree(path); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
738 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
739 |
DocTreeScanner scanner = new DocTreeScanner<Void,Void>() { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
740 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
741 |
public Void scan(DocTree node, Void ignore) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
742 |
if (node != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
743 |
try { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
744 |
String expect = getExpectText(node); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
745 |
long pos = ((DCTree) node).getSourcePosition(dc); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
746 |
String found = getFoundText(cs, (int) pos, expect.length()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
747 |
if (!found.equals(expect)) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
748 |
System.err.println("expect: " + expect); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
749 |
System.err.println("found: " + found); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
750 |
error("mismatch"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
751 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
752 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
753 |
} catch (StringIndexOutOfBoundsException e) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
754 |
error(node.getClass() + ": " + e.toString()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
755 |
e.printStackTrace(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
756 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
757 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
758 |
return super.scan(node, ignore); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
759 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
760 |
}; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
761 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
762 |
scanner.scan(t, null); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
763 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
764 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
765 |
String getExpectText(DocTree t) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
766 |
StringWriter sw = new StringWriter(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
767 |
DocPretty p = new DocPretty(sw); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
768 |
try { p.print(t); } catch (IOException never) { } |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
769 |
String s = sw.toString(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
770 |
if (s.length() <= 1) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
771 |
return s; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
772 |
int ws = s.replaceAll("\\s+", " ").indexOf(" "); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
773 |
if (ws != -1) s = s.substring(0, ws); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
774 |
return (s.length() < 5) ? s : s.substring(0, 5); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
775 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
776 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
777 |
String getFoundText(CharSequence cs, int pos, int len) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
778 |
return (pos == -1) ? "" : cs.subSequence(pos, Math.min(pos + len, cs.length())).toString(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
779 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
780 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
781 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
782 |
/** |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
783 |
* Verify the pretty printed text against a normalized form of the |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
784 |
* original doc comment. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
785 |
*/ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
786 |
static class PrettyChecker extends Checker { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
787 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
788 |
PrettyChecker(DocCommentTester test, DocTrees t) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
789 |
test.super(t); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
790 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
791 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
792 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
793 |
void check(TreePath path, Name name) throws Exception { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
794 |
String raw = trees.getDocComment(path); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
795 |
String normRaw = normalize(raw); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
796 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
797 |
StringWriter out = new StringWriter(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
798 |
DocPretty dp = new DocPretty(out); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
799 |
dp.print(trees.getDocCommentTree(path)); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
800 |
String pretty = out.toString(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
801 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
802 |
if (!pretty.equals(normRaw)) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
803 |
error("mismatch"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
804 |
System.err.println("*** expected:"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
805 |
System.err.println(normRaw.replace(" ", "_")); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
806 |
System.err.println("*** found:"); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
807 |
System.err.println(pretty.replace(" ", "_")); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
808 |
// throw new Error(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
809 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
810 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
811 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
812 |
/** |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
813 |
* Normalize white space in places where the tree does not preserve it. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
814 |
*/ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
815 |
String normalize(String s) { |
33360 | 816 |
s = s.trim() |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
817 |
.replaceFirst("\\.\\s*\\n *@", ".\n@") |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
818 |
.replaceAll("\\{@docRoot\\s+\\}", "{@docRoot}") |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
819 |
.replaceAll("\\{@inheritDoc\\s+\\}", "{@inheritDoc}") |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
820 |
.replaceAll("(\\{@value\\s+[^}]+)\\s+(\\})", "$1$2") |
33360 | 821 |
.replaceAll("\n[ \t]+@", "\n@") |
822 |
.replaceAll("(\\{@code)(\\x20)(\\s+.*)", "$1$3"); |
|
823 |
return s; |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
824 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
825 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
826 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
827 |