author | ksrini |
Tue, 01 Dec 2015 07:10:35 -0800 | |
changeset 34567 | c74f68484156 |
parent 33424 | e6bd5406e2cf |
child 35346 | c0614a805fad |
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) 2011, 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. Oracle designates this |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
10 |
* |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
11 |
* 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
|
12 |
* 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
|
13 |
* 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
|
14 |
* 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
|
15 |
* accompanied this code). |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
16 |
* |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
17 |
* 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
|
18 |
* 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
|
19 |
* 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
|
20 |
* |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
21 |
* 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
|
22 |
* 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
|
23 |
* questions. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
24 |
*/ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
25 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
26 |
package com.sun.tools.javac.tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
27 |
|
33360 | 28 |
import java.text.BreakIterator; |
29 |
import java.util.ArrayList; |
|
30 |
import java.util.Collection; |
|
31 |
import java.util.EnumSet; |
|
32 |
import java.util.ListIterator; |
|
33 |
||
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
34 |
import com.sun.source.doctree.AttributeTree.ValueKind; |
33360 | 35 |
import com.sun.source.doctree.DocTree; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
36 |
import com.sun.source.doctree.DocTree.Kind; |
33360 | 37 |
import com.sun.source.doctree.EndElementTree; |
38 |
import com.sun.source.doctree.StartElementTree; |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
39 |
import com.sun.source.doctree.TextTree; |
33360 | 40 |
import com.sun.tools.doclint.HtmlTag; |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
41 |
import com.sun.tools.javac.api.JavacTrees; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
42 |
import com.sun.tools.javac.parser.Tokens.Comment; |
33360 | 43 |
import com.sun.tools.javac.tree.DCTree.DCAttribute; |
44 |
import com.sun.tools.javac.tree.DCTree.DCAuthor; |
|
45 |
import com.sun.tools.javac.tree.DCTree.DCComment; |
|
46 |
import com.sun.tools.javac.tree.DCTree.DCDeprecated; |
|
47 |
import com.sun.tools.javac.tree.DCTree.DCDocComment; |
|
48 |
import com.sun.tools.javac.tree.DCTree.DCDocRoot; |
|
49 |
import com.sun.tools.javac.tree.DCTree.DCEndElement; |
|
50 |
import com.sun.tools.javac.tree.DCTree.DCEntity; |
|
51 |
import com.sun.tools.javac.tree.DCTree.DCErroneous; |
|
52 |
import com.sun.tools.javac.tree.DCTree.DCIdentifier; |
|
34567
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
53 |
import com.sun.tools.javac.tree.DCTree.DCIndex; |
33360 | 54 |
import com.sun.tools.javac.tree.DCTree.DCInheritDoc; |
55 |
import com.sun.tools.javac.tree.DCTree.DCLink; |
|
56 |
import com.sun.tools.javac.tree.DCTree.DCLiteral; |
|
57 |
import com.sun.tools.javac.tree.DCTree.DCParam; |
|
58 |
import com.sun.tools.javac.tree.DCTree.DCReference; |
|
59 |
import com.sun.tools.javac.tree.DCTree.DCReturn; |
|
60 |
import com.sun.tools.javac.tree.DCTree.DCSee; |
|
61 |
import com.sun.tools.javac.tree.DCTree.DCSerial; |
|
62 |
import com.sun.tools.javac.tree.DCTree.DCSerialData; |
|
63 |
import com.sun.tools.javac.tree.DCTree.DCSerialField; |
|
64 |
import com.sun.tools.javac.tree.DCTree.DCSince; |
|
65 |
import com.sun.tools.javac.tree.DCTree.DCStartElement; |
|
66 |
import com.sun.tools.javac.tree.DCTree.DCText; |
|
67 |
import com.sun.tools.javac.tree.DCTree.DCThrows; |
|
68 |
import com.sun.tools.javac.tree.DCTree.DCUnknownBlockTag; |
|
69 |
import com.sun.tools.javac.tree.DCTree.DCUnknownInlineTag; |
|
70 |
import com.sun.tools.javac.tree.DCTree.DCValue; |
|
71 |
import com.sun.tools.javac.tree.DCTree.DCVersion; |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
72 |
import com.sun.tools.javac.util.Context; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
73 |
import com.sun.tools.javac.util.DiagnosticSource; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
74 |
import com.sun.tools.javac.util.JCDiagnostic; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
75 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
76 |
import com.sun.tools.javac.util.List; |
33360 | 77 |
import com.sun.tools.javac.util.ListBuffer; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
78 |
import com.sun.tools.javac.util.Name; |
33360 | 79 |
import com.sun.tools.javac.util.Pair; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
80 |
import com.sun.tools.javac.util.Position; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
81 |
|
33360 | 82 |
import static com.sun.tools.doclint.HtmlTag.*; |
83 |
||
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 |
* |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
86 |
* <p><b>This is NOT part of any supported API. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
87 |
* If you write code that depends on this, you do so at your own risk. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
88 |
* This code and its internal interfaces are subject to change or |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
89 |
* deletion without notice.</b> |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
90 |
*/ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
91 |
public class DocTreeMaker { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
92 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
93 |
/** The context key for the tree factory. */ |
22163 | 94 |
protected static final Context.Key<DocTreeMaker> treeMakerKey = new Context.Key<>(); |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
95 |
|
33360 | 96 |
// A subset of block tags, which acts as sentence breakers, appearing |
97 |
// anywhere but the zero'th position in the first sentence. |
|
98 |
final EnumSet<HtmlTag> sentenceBreakTags; |
|
99 |
||
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
100 |
/** Get the TreeMaker instance. */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
101 |
public static DocTreeMaker instance(Context context) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
102 |
DocTreeMaker instance = context.get(treeMakerKey); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
103 |
if (instance == null) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
104 |
instance = new DocTreeMaker(context); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
105 |
return instance; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
106 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
107 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
108 |
/** The position at which subsequent trees will be created. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
109 |
*/ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
110 |
public int pos = Position.NOPOS; |
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 |
/** Access to diag factory for ErroneousTrees. */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
113 |
private final JCDiagnostic.Factory diags; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
114 |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
115 |
private final JavacTrees trees; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
116 |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
117 |
/** Create a tree maker with NOPOS as initial position. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
118 |
*/ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
119 |
protected DocTreeMaker(Context context) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
120 |
context.put(treeMakerKey, this); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
121 |
diags = JCDiagnostic.Factory.instance(context); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
122 |
this.pos = Position.NOPOS; |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
123 |
trees = JavacTrees.instance(context); |
33360 | 124 |
sentenceBreakTags = EnumSet.of(H1, H2, H3, H4, H5, H6, PRE, P); |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
125 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
126 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
127 |
/** Reassign current position. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
128 |
*/ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
129 |
public DocTreeMaker at(int pos) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
130 |
this.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
131 |
return this; |
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 |
/** Reassign current position. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
135 |
*/ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
136 |
public DocTreeMaker at(DiagnosticPosition pos) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
137 |
this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
138 |
return this; |
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 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
141 |
public DCAttribute Attribute(Name name, ValueKind vkind, List<DCTree> value) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
142 |
DCAttribute tree = new DCAttribute(name, vkind, value); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
143 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
144 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
145 |
} |
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 |
public DCAuthor Author(List<DCTree> name) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
148 |
DCAuthor tree = new DCAuthor(name); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
149 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
150 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
151 |
} |
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 |
public DCLiteral Code(DCText text) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
154 |
DCLiteral tree = new DCLiteral(Kind.CODE, text); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
155 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
156 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
157 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
158 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
159 |
public DCComment Comment(String text) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
160 |
DCComment tree = new DCComment(text); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
161 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
162 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
163 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
164 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
165 |
public DCDeprecated Deprecated(List<DCTree> text) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
166 |
DCDeprecated tree = new DCDeprecated(text); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
167 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
168 |
return tree; |
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 |
|
33360 | 171 |
public DCDocComment DocComment(Comment comment, List<DCTree> fullBody, List<DCTree> tags) { |
172 |
Pair<List<DCTree>, List<DCTree>> pair = splitBody(fullBody); |
|
173 |
DCDocComment tree = new DCDocComment(comment, fullBody, pair.fst, pair.snd, tags); |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
174 |
tree.pos = pos; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
175 |
return tree; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
176 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
177 |
|
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
178 |
/* |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
179 |
* Primarily to produce a DocCommenTree when given a |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
180 |
* first sentence and a body, this is useful, in cases |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
181 |
* where the trees are being synthesized by a tool. |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
182 |
*/ |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
183 |
public DCDocComment DocComment(List<DCTree> firstSentence, List<DCTree> body, List<DCTree> tags) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
184 |
ListBuffer<DCTree> lb = new ListBuffer<>(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
185 |
lb.addAll(firstSentence); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
186 |
lb.addAll(body); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
187 |
List<DCTree> fullBody = lb.toList(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
188 |
DCDocComment tree = new DCDocComment(null, fullBody, firstSentence, body, tags); |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
189 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
190 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
191 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
192 |
public DCDocRoot DocRoot() { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
193 |
DCDocRoot tree = new DCDocRoot(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
194 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
195 |
return tree; |
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 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
198 |
public DCEndElement EndElement(Name name) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
199 |
DCEndElement tree = new DCEndElement(name); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
200 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
201 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
202 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
203 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
204 |
public DCEntity Entity(Name name) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
205 |
DCEntity tree = new DCEntity(name); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
206 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
207 |
return tree; |
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 |
public DCErroneous Erroneous(String text, DiagnosticSource diagSource, String code, Object... args) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
211 |
DCErroneous tree = new DCErroneous(text, diags, diagSource, code, args); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
212 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
213 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
214 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
215 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
216 |
public DCThrows Exception(DCReference name, List<DCTree> description) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
217 |
DCThrows tree = new DCThrows(Kind.EXCEPTION, name, description); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
218 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
219 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
220 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
221 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
222 |
public DCIdentifier Identifier(Name name) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
223 |
DCIdentifier tree = new DCIdentifier(name); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
224 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
225 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
226 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
227 |
|
34567
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
228 |
public DCIndex Index(DCTree term, List<DCTree> description) { |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
229 |
DCIndex tree = new DCIndex(term, description); |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
230 |
tree.pos = pos; |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
231 |
return tree; |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
232 |
} |
c74f68484156
8144287: Enhance DocTree API to support @index javadoc tags.
ksrini
parents:
33424
diff
changeset
|
233 |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
234 |
public DCInheritDoc InheritDoc() { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
235 |
DCInheritDoc tree = new DCInheritDoc(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
236 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
237 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
238 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
239 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
240 |
public DCLink Link(DCReference ref, List<DCTree> label) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
241 |
DCLink tree = new DCLink(Kind.LINK, ref, label); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
242 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
243 |
return tree; |
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 |
public DCLink LinkPlain(DCReference ref, List<DCTree> label) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
247 |
DCLink tree = new DCLink(Kind.LINK_PLAIN, ref, label); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
248 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
249 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
250 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
251 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
252 |
public DCLiteral Literal(DCText text) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
253 |
DCLiteral tree = new DCLiteral(Kind.LITERAL, text); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
254 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
255 |
return tree; |
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 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
258 |
public DCParam Param(boolean isTypeParameter, DCIdentifier name, List<DCTree> description) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
259 |
DCParam tree = new DCParam(isTypeParameter, name, description); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
260 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
261 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
262 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
263 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
264 |
public DCReference Reference(String signature, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
265 |
JCTree qualExpr, Name member, List<JCTree> paramTypes) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
266 |
DCReference tree = new DCReference(signature, qualExpr, member, paramTypes); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
267 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
268 |
return tree; |
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 |
public DCReturn Return(List<DCTree> description) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
272 |
DCReturn tree = new DCReturn(description); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
273 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
274 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
275 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
276 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
277 |
public DCSee See(List<DCTree> reference) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
278 |
DCSee tree = new DCSee(reference); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
279 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
280 |
return tree; |
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 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
283 |
public DCSerial Serial(List<DCTree> description) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
284 |
DCSerial tree = new DCSerial(description); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
285 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
286 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
287 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
288 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
289 |
public DCSerialData SerialData(List<DCTree> description) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
290 |
DCSerialData tree = new DCSerialData(description); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
291 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
292 |
return tree; |
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 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
295 |
public DCSerialField SerialField(DCIdentifier name, DCReference type, List<DCTree> description) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
296 |
DCSerialField tree = new DCSerialField(name, type, description); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
297 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
298 |
return tree; |
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 |
public DCSince Since(List<DCTree> text) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
302 |
DCSince tree = new DCSince(text); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
303 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
304 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
305 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
306 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
307 |
public DCStartElement StartElement(Name name, List<DCTree> attrs, boolean selfClosing) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
308 |
DCStartElement tree = new DCStartElement(name, attrs, selfClosing); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
309 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
310 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
311 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
312 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
313 |
public DCText Text(String text) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
314 |
DCText tree = new DCText(text); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
315 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
316 |
return tree; |
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 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
319 |
public DCThrows Throws(DCReference name, List<DCTree> description) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
320 |
DCThrows tree = new DCThrows(Kind.THROWS, name, description); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
321 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
322 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
323 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
324 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
325 |
public DCUnknownBlockTag UnknownBlockTag(Name name, List<DCTree> content) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
326 |
DCUnknownBlockTag tree = new DCUnknownBlockTag(name, content); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
327 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
328 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
329 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
330 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
331 |
public DCUnknownInlineTag UnknownInlineTag(Name name, List<DCTree> content) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
332 |
DCUnknownInlineTag tree = new DCUnknownInlineTag(name, content); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
333 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
334 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
335 |
} |
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 |
public DCValue Value(DCReference ref) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
338 |
DCValue tree = new DCValue(ref); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
339 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
340 |
return tree; |
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 |
public DCVersion Version(List<DCTree> text) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
344 |
DCVersion tree = new DCVersion(text); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
345 |
tree.pos = pos; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
346 |
return tree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
347 |
} |
33360 | 348 |
|
349 |
public java.util.List<DocTree> getFirstSentence(java.util.List<? extends DocTree> list) { |
|
350 |
Pair<List<DCTree>, List<DCTree>> pair = splitBody(list); |
|
351 |
return new ArrayList<>(pair.fst); |
|
352 |
} |
|
353 |
||
354 |
/* |
|
355 |
* Breaks up the body tags into the first sentence and its successors. |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
356 |
* The first sentence is determined with the presence of a period, |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
357 |
* block tag, or a sentence break, as returned by the BreakIterator. |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
358 |
* Trailing whitespaces are trimmed. |
33360 | 359 |
*/ |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
360 |
private Pair<List<DCTree>, List<DCTree>> splitBody(Collection<? extends DocTree> list) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
361 |
// pos is modified as we create trees, therefore |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
362 |
// we save the pos and restore it later. |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
363 |
final int savedpos = this.pos; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
364 |
try { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
365 |
ListBuffer<DCTree> body = new ListBuffer<>(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
366 |
// split body into first sentence and body |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
367 |
ListBuffer<DCTree> fs = new ListBuffer<>(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
368 |
if (list.isEmpty()) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
369 |
return new Pair<>(fs.toList(), body.toList()); |
33360 | 370 |
} |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
371 |
boolean foundFirstSentence = false; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
372 |
ArrayList<DocTree> alist = new ArrayList<>(list); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
373 |
ListIterator<DocTree> itr = alist.listIterator(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
374 |
while (itr.hasNext()) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
375 |
boolean isFirst = !itr.hasPrevious(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
376 |
DocTree dt = itr.next(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
377 |
int spos = ((DCTree) dt).pos; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
378 |
if (foundFirstSentence) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
379 |
body.add((DCTree) dt); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
380 |
continue; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
381 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
382 |
switch (dt.getKind()) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
383 |
case TEXT: |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
384 |
DCText tt = (DCText) dt; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
385 |
String s = tt.getBody(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
386 |
DocTree peekedNext = itr.hasNext() |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
387 |
? alist.get(itr.nextIndex()) |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
388 |
: null; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
389 |
int sbreak = getSentenceBreak(s, peekedNext); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
390 |
if (sbreak > 0) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
391 |
s = removeTrailingWhitespace(s.substring(0, sbreak)); |
33360 | 392 |
DCText text = this.at(spos).Text(s); |
393 |
fs.add(text); |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
394 |
foundFirstSentence = true; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
395 |
int nwPos = skipWhiteSpace(tt.getBody(), sbreak); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
396 |
if (nwPos > 0) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
397 |
DCText text2 = this.at(spos + nwPos).Text(tt.getBody().substring(nwPos)); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
398 |
body.add(text2); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
399 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
400 |
continue; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
401 |
} else if (itr.hasNext()) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
402 |
// if the next doctree is a break, remove trailing spaces |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
403 |
peekedNext = alist.get(itr.nextIndex()); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
404 |
boolean sbrk = isSentenceBreak(peekedNext, false); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
405 |
if (sbrk) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
406 |
DocTree next = itr.next(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
407 |
s = removeTrailingWhitespace(s); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
408 |
DCText text = this.at(spos).Text(s); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
409 |
fs.add(text); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
410 |
body.add((DCTree) next); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
411 |
foundFirstSentence = true; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
412 |
continue; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
413 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
414 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
415 |
break; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
416 |
default: |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
417 |
if (isSentenceBreak(dt, isFirst)) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
418 |
body.add((DCTree) dt); |
33360 | 419 |
foundFirstSentence = true; |
420 |
continue; |
|
421 |
} |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
422 |
break; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
423 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
424 |
fs.add((DCTree) dt); |
33360 | 425 |
} |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
426 |
return new Pair<>(fs.toList(), body.toList()); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
427 |
} finally { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
428 |
this.pos = savedpos; |
33360 | 429 |
} |
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
430 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
431 |
|
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
432 |
private boolean isTextTree(DocTree tree) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
433 |
return tree.getKind() == Kind.TEXT; |
33360 | 434 |
} |
435 |
||
436 |
/* |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
437 |
* Computes the first sentence break, a simple dot-space algorithm. |
33360 | 438 |
*/ |
439 |
int defaultSentenceBreak(String s) { |
|
440 |
// scan for period followed by whitespace |
|
441 |
int period = -1; |
|
442 |
for (int i = 0; i < s.length(); i++) { |
|
443 |
switch (s.charAt(i)) { |
|
444 |
case '.': |
|
445 |
period = i; |
|
446 |
break; |
|
447 |
||
448 |
case ' ': |
|
449 |
case '\f': |
|
450 |
case '\n': |
|
451 |
case '\r': |
|
452 |
case '\t': |
|
453 |
if (period >= 0) { |
|
454 |
return i; |
|
455 |
} |
|
456 |
break; |
|
457 |
||
458 |
default: |
|
459 |
period = -1; |
|
460 |
break; |
|
461 |
} |
|
462 |
} |
|
463 |
return -1; |
|
464 |
} |
|
465 |
||
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
466 |
/* |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
467 |
* Computes the first sentence, if using a default breaker, |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
468 |
* the break is returned, if not then a -1, indicating that |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
469 |
* more doctree elements are required to be examined. |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
470 |
* |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
471 |
* BreakIterator.next points to the the start of the following sentence, |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
472 |
* and does not provide an easy way to disambiguate between "sentence break", |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
473 |
* "possible sentence break" and "not a sentence break" at the end of the input. |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
474 |
* For example, BreakIterator.next returns the index for the end |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
475 |
* of the string for all of these examples, |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
476 |
* using vertical bars to delimit the bounds of the example text |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
477 |
* |Abc| (not a valid end of sentence break, if followed by more text) |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
478 |
* |Abc.| (maybe a valid end of sentence break, depending on the following text) |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
479 |
* |Abc. | (maybe a valid end of sentence break, depending on the following text) |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
480 |
* |"Abc." | (maybe a valid end of sentence break, depending on the following text) |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
481 |
* |Abc. | (definitely a valid end of sentence break) |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
482 |
* |"Abc." | (definitely a valid end of sentence break) |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
483 |
* Therefore, we have to probe further to determine whether |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
484 |
* there really is a sentence break or not at the end of this run of text. |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
485 |
*/ |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
486 |
int getSentenceBreak(String s, DocTree dt) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
487 |
BreakIterator breakIterator = trees.getBreakIterator(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
488 |
if (breakIterator == null) { |
33360 | 489 |
return defaultSentenceBreak(s); |
490 |
} |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
491 |
breakIterator.setText(s); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
492 |
final int sbrk = breakIterator.next(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
493 |
// This is the last doctree, found the droid we are looking for |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
494 |
if (dt == null) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
495 |
return sbrk; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
496 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
497 |
|
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
498 |
// If the break is well within the span of the string ie. not |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
499 |
// at EOL, then we have a clear break. |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
500 |
if (sbrk < s.length() - 1) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
501 |
return sbrk; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
502 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
503 |
|
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
504 |
if (isTextTree(dt)) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
505 |
// Two adjacent text trees, a corner case, perhaps |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
506 |
// produced by a tool synthesizing a doctree. In |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
507 |
// this case, does the break lie within the first span, |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
508 |
// then we have the droid, otherwise allow the callers |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
509 |
// logic to handle the break in the adjacent doctree. |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
510 |
TextTree ttnext = (TextTree) dt; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
511 |
String combined = s + ttnext.getBody(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
512 |
breakIterator.setText(combined); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
513 |
int sbrk2 = breakIterator.next(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
514 |
if (sbrk < sbrk2) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
515 |
return sbrk; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
516 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
517 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
518 |
|
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
519 |
// Is the adjacent tree a sentence breaker ? |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
520 |
if (isSentenceBreak(dt, false)) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
521 |
return sbrk; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
522 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
523 |
|
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
524 |
// At this point the adjacent tree is either a javadoc tag ({@..), |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
525 |
// html tag (<..) or an entity (&..). Perform a litmus test, by |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
526 |
// concatenating a sentence, to validate the break earlier identified. |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
527 |
String combined = s + "Dummy Sentence."; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
528 |
breakIterator.setText(combined); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
529 |
int sbrk2 = breakIterator.next(); |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
530 |
if (sbrk2 <= sbrk) { |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
531 |
return sbrk2; |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
532 |
} |
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
533 |
return -1; // indeterminate at this time |
33360 | 534 |
} |
535 |
||
536 |
boolean isSentenceBreak(javax.lang.model.element.Name tagName) { |
|
537 |
return sentenceBreakTags.contains(get(tagName)); |
|
538 |
} |
|
539 |
||
540 |
boolean isSentenceBreak(DocTree dt, boolean isFirstDocTree) { |
|
541 |
switch (dt.getKind()) { |
|
542 |
case START_ELEMENT: |
|
543 |
StartElementTree set = (StartElementTree)dt; |
|
544 |
return !isFirstDocTree && ((DCTree) dt).pos > 1 && isSentenceBreak(set.getName()); |
|
545 |
case END_ELEMENT: |
|
546 |
EndElementTree eet = (EndElementTree)dt; |
|
547 |
return !isFirstDocTree && ((DCTree) dt).pos > 1 && isSentenceBreak(eet.getName()); |
|
548 |
default: |
|
549 |
return false; |
|
550 |
} |
|
551 |
} |
|
552 |
||
553 |
/* |
|
554 |
* Returns the position of the the first non-white space |
|
555 |
*/ |
|
556 |
int skipWhiteSpace(String s, int start) { |
|
557 |
for (int i = start; i < s.length(); i++) { |
|
558 |
char c = s.charAt(i); |
|
559 |
if (!Character.isWhitespace(c)) { |
|
560 |
return i; |
|
561 |
} |
|
562 |
} |
|
563 |
return -1; |
|
564 |
} |
|
565 |
||
566 |
String removeTrailingWhitespace(String s) { |
|
33424
e6bd5406e2cf
8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents:
33360
diff
changeset
|
567 |
for (int i = s.length() - 1 ; i >= 0 ; i--) { |
33360 | 568 |
char ch = s.charAt(i); |
569 |
if (!Character.isWhitespace(ch)) { |
|
570 |
return s.substring(0, i + 1); |
|
571 |
} |
|
572 |
} |
|
573 |
return s; |
|
574 |
} |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
diff
changeset
|
575 |
} |