author | jlahoda |
Wed, 27 Aug 2014 07:44:00 +0200 | |
changeset 26266 | 2d24bda701dc |
parent 25874 | 83c19f00452c |
child 29291 | 076c277565f7 |
permissions | -rw-r--r-- |
14952 | 1 |
/* |
15359 | 2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
14952 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.doclint; |
|
27 |
||
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
28 |
import java.io.IOException; |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
29 |
import java.io.StringWriter; |
14952 | 30 |
import java.net.URI; |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
31 |
import java.net.URISyntaxException; |
14952 | 32 |
import java.util.Deque; |
33 |
import java.util.EnumSet; |
|
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
34 |
import java.util.HashMap; |
14952 | 35 |
import java.util.HashSet; |
36 |
import java.util.LinkedList; |
|
37 |
import java.util.List; |
|
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
38 |
import java.util.Map; |
14952 | 39 |
import java.util.Set; |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
40 |
import java.util.regex.Matcher; |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
41 |
import java.util.regex.Pattern; |
14952 | 42 |
|
43 |
import javax.lang.model.element.Element; |
|
44 |
import javax.lang.model.element.ElementKind; |
|
45 |
import javax.lang.model.element.ExecutableElement; |
|
46 |
import javax.lang.model.element.Name; |
|
20255
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
47 |
import javax.lang.model.element.VariableElement; |
14952 | 48 |
import javax.lang.model.type.TypeKind; |
49 |
import javax.lang.model.type.TypeMirror; |
|
50 |
import javax.tools.Diagnostic.Kind; |
|
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
51 |
import javax.tools.JavaFileObject; |
14952 | 52 |
|
53 |
import com.sun.source.doctree.AttributeTree; |
|
54 |
import com.sun.source.doctree.AuthorTree; |
|
55 |
import com.sun.source.doctree.DocCommentTree; |
|
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
56 |
import com.sun.source.doctree.DocRootTree; |
14952 | 57 |
import com.sun.source.doctree.DocTree; |
58 |
import com.sun.source.doctree.EndElementTree; |
|
59 |
import com.sun.source.doctree.EntityTree; |
|
60 |
import com.sun.source.doctree.ErroneousTree; |
|
61 |
import com.sun.source.doctree.IdentifierTree; |
|
62 |
import com.sun.source.doctree.InheritDocTree; |
|
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
63 |
import com.sun.source.doctree.LinkTree; |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
64 |
import com.sun.source.doctree.LiteralTree; |
14952 | 65 |
import com.sun.source.doctree.ParamTree; |
66 |
import com.sun.source.doctree.ReferenceTree; |
|
67 |
import com.sun.source.doctree.ReturnTree; |
|
68 |
import com.sun.source.doctree.SerialDataTree; |
|
69 |
import com.sun.source.doctree.SerialFieldTree; |
|
70 |
import com.sun.source.doctree.SinceTree; |
|
71 |
import com.sun.source.doctree.StartElementTree; |
|
72 |
import com.sun.source.doctree.TextTree; |
|
73 |
import com.sun.source.doctree.ThrowsTree; |
|
21500
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
74 |
import com.sun.source.doctree.UnknownBlockTagTree; |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
75 |
import com.sun.source.doctree.UnknownInlineTagTree; |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
76 |
import com.sun.source.doctree.ValueTree; |
14952 | 77 |
import com.sun.source.doctree.VersionTree; |
24069 | 78 |
import com.sun.source.tree.Tree; |
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
79 |
import com.sun.source.util.DocTreePath; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
80 |
import com.sun.source.util.DocTreePathScanner; |
14952 | 81 |
import com.sun.source.util.TreePath; |
82 |
import com.sun.tools.doclint.HtmlTag.AttrKind; |
|
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
83 |
import com.sun.tools.javac.tree.DocPretty; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
84 |
import com.sun.tools.javac.util.DefinedBy; |
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
85 |
import com.sun.tools.javac.util.DefinedBy.Api; |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
21500
diff
changeset
|
86 |
import com.sun.tools.javac.util.StringUtils; |
14952 | 87 |
import static com.sun.tools.doclint.Messages.Group.*; |
88 |
||
89 |
||
90 |
/** |
|
91 |
* Validate a doc comment. |
|
92 |
* |
|
93 |
* <p><b>This is NOT part of any supported API. |
|
94 |
* If you write code that depends on this, you do so at your own |
|
95 |
* risk. This code and its internal interfaces are subject to change |
|
96 |
* or deletion without notice.</b></p> |
|
97 |
*/ |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
98 |
public class Checker extends DocTreePathScanner<Void, Void> { |
14952 | 99 |
final Env env; |
100 |
||
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
101 |
Set<Element> foundParams = new HashSet<>(); |
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
102 |
Set<TypeMirror> foundThrows = new HashSet<>(); |
20254
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
103 |
Map<Element, Set<String>> foundAnchors = new HashMap<>(); |
14952 | 104 |
boolean foundInheritDoc = false; |
105 |
boolean foundReturn = false; |
|
106 |
||
15370 | 107 |
public enum Flag { |
14952 | 108 |
TABLE_HAS_CAPTION, |
109 |
HAS_ELEMENT, |
|
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
110 |
HAS_INLINE_TAG, |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
111 |
HAS_TEXT, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
112 |
REPORTED_BAD_INLINE |
14952 | 113 |
} |
114 |
||
115 |
static class TagStackItem { |
|
116 |
final DocTree tree; // typically, but not always, StartElementTree |
|
117 |
final HtmlTag tag; |
|
118 |
final Set<HtmlTag.Attr> attrs; |
|
119 |
final Set<Flag> flags; |
|
120 |
TagStackItem(DocTree tree, HtmlTag tag) { |
|
121 |
this.tree = tree; |
|
122 |
this.tag = tag; |
|
123 |
attrs = EnumSet.noneOf(HtmlTag.Attr.class); |
|
124 |
flags = EnumSet.noneOf(Flag.class); |
|
125 |
} |
|
126 |
@Override |
|
127 |
public String toString() { |
|
128 |
return String.valueOf(tag); |
|
129 |
} |
|
130 |
} |
|
131 |
||
132 |
private Deque<TagStackItem> tagStack; // TODO: maybe want to record starting tree as well |
|
133 |
private HtmlTag currHeaderTag; |
|
134 |
||
16799
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
16562
diff
changeset
|
135 |
private final int implicitHeaderLevel; |
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
16562
diff
changeset
|
136 |
|
14952 | 137 |
// <editor-fold defaultstate="collapsed" desc="Top level"> |
138 |
||
139 |
Checker(Env env) { |
|
140 |
env.getClass(); |
|
141 |
this.env = env; |
|
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
142 |
tagStack = new LinkedList<>(); |
16799
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
16562
diff
changeset
|
143 |
implicitHeaderLevel = env.implicitHeaderLevel; |
14952 | 144 |
} |
145 |
||
146 |
public Void scan(DocCommentTree tree, TreePath p) { |
|
147 |
env.setCurrent(p, tree); |
|
148 |
||
149 |
boolean isOverridingMethod = !env.currOverriddenMethods.isEmpty(); |
|
150 |
||
24069 | 151 |
if (p.getLeaf().getKind() == Tree.Kind.PACKAGE) { |
152 |
// If p points to a package, the implied declaration is the |
|
19123
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
153 |
// package declaration (if any) for the compilation unit. |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
154 |
// Handle this case specially, because doc comments are only |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
155 |
// expected in package-info files. |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
156 |
JavaFileObject fo = p.getCompilationUnit().getSourceFile(); |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
157 |
boolean isPkgInfo = fo.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE); |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
158 |
if (tree == null) { |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
159 |
if (isPkgInfo) |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
160 |
reportMissing("dc.missing.comment"); |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
161 |
return null; |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
162 |
} else { |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
163 |
if (!isPkgInfo) |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
164 |
reportReference("dc.unexpected.comment"); |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
165 |
} |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
166 |
} else { |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
167 |
if (tree == null) { |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
168 |
if (!isSynthetic() && !isOverridingMethod) |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
169 |
reportMissing("dc.missing.comment"); |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
170 |
return null; |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
171 |
} |
14952 | 172 |
} |
173 |
||
174 |
tagStack.clear(); |
|
175 |
currHeaderTag = null; |
|
176 |
||
177 |
foundParams.clear(); |
|
178 |
foundThrows.clear(); |
|
179 |
foundInheritDoc = false; |
|
180 |
foundReturn = false; |
|
181 |
||
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
182 |
scan(new DocTreePath(p, tree), null); |
14952 | 183 |
|
184 |
if (!isOverridingMethod) { |
|
185 |
switch (env.currElement.getKind()) { |
|
186 |
case METHOD: |
|
187 |
case CONSTRUCTOR: { |
|
188 |
ExecutableElement ee = (ExecutableElement) env.currElement; |
|
189 |
checkParamsDocumented(ee.getTypeParameters()); |
|
190 |
checkParamsDocumented(ee.getParameters()); |
|
191 |
switch (ee.getReturnType().getKind()) { |
|
192 |
case VOID: |
|
193 |
case NONE: |
|
194 |
break; |
|
195 |
default: |
|
196 |
if (!foundReturn |
|
197 |
&& !foundInheritDoc |
|
198 |
&& !env.types.isSameType(ee.getReturnType(), env.java_lang_Void)) { |
|
199 |
reportMissing("dc.missing.return"); |
|
200 |
} |
|
201 |
} |
|
202 |
checkThrowsDocumented(ee.getThrownTypes()); |
|
203 |
} |
|
204 |
} |
|
205 |
} |
|
206 |
||
207 |
return null; |
|
208 |
} |
|
209 |
||
210 |
private void reportMissing(String code, Object... args) { |
|
211 |
env.messages.report(MISSING, Kind.WARNING, env.currPath.getLeaf(), code, args); |
|
212 |
} |
|
213 |
||
19123
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
214 |
private void reportReference(String code, Object... args) { |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
215 |
env.messages.report(REFERENCE, Kind.WARNING, env.currPath.getLeaf(), code, args); |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
216 |
} |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
217 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
218 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 219 |
public Void visitDocComment(DocCommentTree tree, Void ignore) { |
220 |
super.visitDocComment(tree, ignore); |
|
221 |
for (TagStackItem tsi: tagStack) { |
|
21017
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
222 |
warnIfEmpty(tsi, null); |
14952 | 223 |
if (tsi.tree.getKind() == DocTree.Kind.START_ELEMENT |
224 |
&& tsi.tag.endKind == HtmlTag.EndKind.REQUIRED) { |
|
225 |
StartElementTree t = (StartElementTree) tsi.tree; |
|
226 |
env.messages.error(HTML, t, "dc.tag.not.closed", t.getName()); |
|
227 |
} |
|
228 |
} |
|
229 |
return null; |
|
230 |
} |
|
231 |
// </editor-fold> |
|
232 |
||
233 |
// <editor-fold defaultstate="collapsed" desc="Text and entities."> |
|
234 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
235 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 236 |
public Void visitText(TextTree tree, Void ignore) { |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
237 |
if (hasNonWhitespace(tree)) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
238 |
checkAllowsText(tree); |
14952 | 239 |
markEnclosingTag(Flag.HAS_TEXT); |
240 |
} |
|
241 |
return null; |
|
242 |
} |
|
243 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
244 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 245 |
public Void visitEntity(EntityTree tree, Void ignore) { |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
246 |
checkAllowsText(tree); |
14952 | 247 |
markEnclosingTag(Flag.HAS_TEXT); |
248 |
String name = tree.getName().toString(); |
|
249 |
if (name.startsWith("#")) { |
|
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
21500
diff
changeset
|
250 |
int v = StringUtils.toLowerCase(name).startsWith("#x") |
14952 | 251 |
? Integer.parseInt(name.substring(2), 16) |
252 |
: Integer.parseInt(name.substring(1), 10); |
|
253 |
if (!Entity.isValid(v)) { |
|
254 |
env.messages.error(HTML, tree, "dc.entity.invalid", name); |
|
255 |
} |
|
256 |
} else if (!Entity.isValid(name)) { |
|
257 |
env.messages.error(HTML, tree, "dc.entity.invalid", name); |
|
258 |
} |
|
259 |
return null; |
|
260 |
} |
|
261 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
262 |
void checkAllowsText(DocTree tree) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
263 |
TagStackItem top = tagStack.peek(); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
264 |
if (top != null |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
265 |
&& top.tree.getKind() == DocTree.Kind.START_ELEMENT |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
266 |
&& !top.tag.acceptsText()) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
267 |
if (top.flags.add(Flag.REPORTED_BAD_INLINE)) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
268 |
env.messages.error(HTML, tree, "dc.text.not.allowed", |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
269 |
((StartElementTree) top.tree).getName()); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
270 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
271 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
272 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
273 |
|
14952 | 274 |
// </editor-fold> |
275 |
||
276 |
// <editor-fold defaultstate="collapsed" desc="HTML elements"> |
|
277 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
278 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 279 |
public Void visitStartElement(StartElementTree tree, Void ignore) { |
280 |
final Name treeName = tree.getName(); |
|
281 |
final HtmlTag t = HtmlTag.get(treeName); |
|
282 |
if (t == null) { |
|
283 |
env.messages.error(HTML, tree, "dc.tag.unknown", treeName); |
|
284 |
} else { |
|
15707
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
285 |
boolean done = false; |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
286 |
for (TagStackItem tsi: tagStack) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
287 |
if (tsi.tag.accepts(t)) { |
21017
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
288 |
while (tagStack.peek() != tsi) { |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
289 |
warnIfEmpty(tagStack.peek(), null); |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
290 |
tagStack.pop(); |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
291 |
} |
15707
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
292 |
done = true; |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
293 |
break; |
15707
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
294 |
} else if (tsi.tag.endKind != HtmlTag.EndKind.OPTIONAL) { |
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
295 |
done = true; |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
296 |
break; |
15707
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
297 |
} |
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
298 |
} |
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
299 |
if (!done && HtmlTag.BODY.accepts(t)) { |
21017
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
300 |
while (!tagStack.isEmpty()) { |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
301 |
warnIfEmpty(tagStack.peek(), null); |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
302 |
tagStack.pop(); |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
303 |
} |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
304 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
305 |
|
21017
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
306 |
markEnclosingTag(Flag.HAS_ELEMENT); |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
307 |
checkStructure(tree, t); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
308 |
|
14952 | 309 |
// tag specific checks |
310 |
switch (t) { |
|
311 |
// check for out of sequence headers, such as <h1>...</h1> <h3>...</h3> |
|
312 |
case H1: case H2: case H3: case H4: case H5: case H6: |
|
313 |
checkHeader(tree, t); |
|
314 |
break; |
|
315 |
} |
|
316 |
||
317 |
if (t.flags.contains(HtmlTag.Flag.NO_NEST)) { |
|
318 |
for (TagStackItem i: tagStack) { |
|
319 |
if (t == i.tag) { |
|
320 |
env.messages.warning(HTML, tree, "dc.tag.nested.not.allowed", treeName); |
|
321 |
break; |
|
322 |
} |
|
323 |
} |
|
324 |
} |
|
325 |
} |
|
326 |
||
327 |
// check for self closing tags, such as <a id="name"/> |
|
328 |
if (tree.isSelfClosing()) { |
|
329 |
env.messages.error(HTML, tree, "dc.tag.self.closing", treeName); |
|
330 |
} |
|
331 |
||
332 |
try { |
|
333 |
TagStackItem parent = tagStack.peek(); |
|
334 |
TagStackItem top = new TagStackItem(tree, t); |
|
335 |
tagStack.push(top); |
|
336 |
||
337 |
super.visitStartElement(tree, ignore); |
|
338 |
||
339 |
// handle attributes that may or may not have been found in start element |
|
340 |
if (t != null) { |
|
341 |
switch (t) { |
|
342 |
case CAPTION: |
|
343 |
if (parent != null && parent.tag == HtmlTag.TABLE) |
|
344 |
parent.flags.add(Flag.TABLE_HAS_CAPTION); |
|
345 |
break; |
|
346 |
||
347 |
case IMG: |
|
348 |
if (!top.attrs.contains(HtmlTag.Attr.ALT)) |
|
349 |
env.messages.error(ACCESSIBILITY, tree, "dc.no.alt.attr.for.image"); |
|
350 |
break; |
|
351 |
} |
|
352 |
} |
|
353 |
||
354 |
return null; |
|
355 |
} finally { |
|
356 |
||
357 |
if (t == null || t.endKind == HtmlTag.EndKind.NONE) |
|
358 |
tagStack.pop(); |
|
359 |
} |
|
360 |
} |
|
361 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
362 |
private void checkStructure(StartElementTree tree, HtmlTag t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
363 |
Name treeName = tree.getName(); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
364 |
TagStackItem top = tagStack.peek(); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
365 |
switch (t.blockType) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
366 |
case BLOCK: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
367 |
if (top == null || top.tag.accepts(t)) |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
368 |
return; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
369 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
370 |
switch (top.tree.getKind()) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
371 |
case START_ELEMENT: { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
372 |
if (top.tag.blockType == HtmlTag.BlockType.INLINE) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
373 |
Name name = ((StartElementTree) top.tree).getName(); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
374 |
env.messages.error(HTML, tree, "dc.tag.not.allowed.inline.element", |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
375 |
treeName, name); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
376 |
return; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
377 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
378 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
379 |
break; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
380 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
381 |
case LINK: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
382 |
case LINK_PLAIN: { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
383 |
String name = top.tree.getKind().tagName; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
384 |
env.messages.error(HTML, tree, "dc.tag.not.allowed.inline.tag", |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
385 |
treeName, name); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
386 |
return; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
387 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
388 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
389 |
break; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
390 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
391 |
case INLINE: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
392 |
if (top == null || top.tag.accepts(t)) |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
393 |
return; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
394 |
break; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
395 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
396 |
case LIST_ITEM: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
397 |
case TABLE_ITEM: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
398 |
if (top != null) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
399 |
// reset this flag so subsequent bad inline content gets reported |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
400 |
top.flags.remove(Flag.REPORTED_BAD_INLINE); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
401 |
if (top.tag.accepts(t)) |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
402 |
return; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
403 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
404 |
break; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
405 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
406 |
case OTHER: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
407 |
env.messages.error(HTML, tree, "dc.tag.not.allowed", treeName); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
408 |
return; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
409 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
410 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
411 |
env.messages.error(HTML, tree, "dc.tag.not.allowed.here", treeName); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
412 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
413 |
|
14952 | 414 |
private void checkHeader(StartElementTree tree, HtmlTag tag) { |
415 |
// verify the new tag |
|
416 |
if (getHeaderLevel(tag) > getHeaderLevel(currHeaderTag) + 1) { |
|
417 |
if (currHeaderTag == null) { |
|
418 |
env.messages.error(ACCESSIBILITY, tree, "dc.tag.header.sequence.1", tag); |
|
419 |
} else { |
|
420 |
env.messages.error(ACCESSIBILITY, tree, "dc.tag.header.sequence.2", |
|
421 |
tag, currHeaderTag); |
|
422 |
} |
|
423 |
} |
|
424 |
||
425 |
currHeaderTag = tag; |
|
426 |
} |
|
427 |
||
428 |
private int getHeaderLevel(HtmlTag tag) { |
|
429 |
if (tag == null) |
|
16799
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
16562
diff
changeset
|
430 |
return implicitHeaderLevel; |
14952 | 431 |
switch (tag) { |
432 |
case H1: return 1; |
|
433 |
case H2: return 2; |
|
434 |
case H3: return 3; |
|
435 |
case H4: return 4; |
|
436 |
case H5: return 5; |
|
437 |
case H6: return 6; |
|
438 |
default: throw new IllegalArgumentException(); |
|
439 |
} |
|
440 |
} |
|
441 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
442 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 443 |
public Void visitEndElement(EndElementTree tree, Void ignore) { |
444 |
final Name treeName = tree.getName(); |
|
445 |
final HtmlTag t = HtmlTag.get(treeName); |
|
446 |
if (t == null) { |
|
447 |
env.messages.error(HTML, tree, "dc.tag.unknown", treeName); |
|
448 |
} else if (t.endKind == HtmlTag.EndKind.NONE) { |
|
449 |
env.messages.error(HTML, tree, "dc.tag.end.not.permitted", treeName); |
|
450 |
} else { |
|
15363 | 451 |
boolean done = false; |
14952 | 452 |
while (!tagStack.isEmpty()) { |
453 |
TagStackItem top = tagStack.peek(); |
|
454 |
if (t == top.tag) { |
|
455 |
switch (t) { |
|
456 |
case TABLE: |
|
457 |
if (!top.attrs.contains(HtmlTag.Attr.SUMMARY) |
|
458 |
&& !top.flags.contains(Flag.TABLE_HAS_CAPTION)) { |
|
459 |
env.messages.error(ACCESSIBILITY, tree, |
|
460 |
"dc.no.summary.or.caption.for.table"); |
|
461 |
} |
|
462 |
} |
|
21017
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
463 |
warnIfEmpty(top, tree); |
14952 | 464 |
tagStack.pop(); |
15363 | 465 |
done = true; |
14952 | 466 |
break; |
467 |
} else if (top.tag == null || top.tag.endKind != HtmlTag.EndKind.REQUIRED) { |
|
468 |
tagStack.pop(); |
|
469 |
} else { |
|
470 |
boolean found = false; |
|
471 |
for (TagStackItem si: tagStack) { |
|
472 |
if (si.tag == t) { |
|
473 |
found = true; |
|
474 |
break; |
|
475 |
} |
|
476 |
} |
|
477 |
if (found && top.tree.getKind() == DocTree.Kind.START_ELEMENT) { |
|
478 |
env.messages.error(HTML, top.tree, "dc.tag.start.unmatched", |
|
479 |
((StartElementTree) top.tree).getName()); |
|
480 |
tagStack.pop(); |
|
481 |
} else { |
|
482 |
env.messages.error(HTML, tree, "dc.tag.end.unexpected", treeName); |
|
15363 | 483 |
done = true; |
14952 | 484 |
break; |
485 |
} |
|
486 |
} |
|
487 |
} |
|
15363 | 488 |
|
489 |
if (!done && tagStack.isEmpty()) { |
|
490 |
env.messages.error(HTML, tree, "dc.tag.end.unexpected", treeName); |
|
491 |
} |
|
14952 | 492 |
} |
493 |
||
494 |
return super.visitEndElement(tree, ignore); |
|
495 |
} |
|
21017
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
496 |
|
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
497 |
void warnIfEmpty(TagStackItem tsi, DocTree endTree) { |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
498 |
if (tsi.tag != null && tsi.tree instanceof StartElementTree) { |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
499 |
if (tsi.tag.flags.contains(HtmlTag.Flag.EXPECT_CONTENT) |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
500 |
&& !tsi.flags.contains(Flag.HAS_TEXT) |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
501 |
&& !tsi.flags.contains(Flag.HAS_ELEMENT) |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
502 |
&& !tsi.flags.contains(Flag.HAS_INLINE_TAG)) { |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
503 |
DocTree tree = (endTree != null) ? endTree : tsi.tree; |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
504 |
Name treeName = ((StartElementTree) tsi.tree).getName(); |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
505 |
env.messages.warning(HTML, tree, "dc.tag.empty", treeName); |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
506 |
} |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
507 |
} |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
508 |
} |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
509 |
|
14952 | 510 |
// </editor-fold> |
511 |
||
512 |
// <editor-fold defaultstate="collapsed" desc="HTML attributes"> |
|
513 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
514 |
@Override @DefinedBy(Api.COMPILER_TREE) @SuppressWarnings("fallthrough") |
14952 | 515 |
public Void visitAttribute(AttributeTree tree, Void ignore) { |
516 |
HtmlTag currTag = tagStack.peek().tag; |
|
517 |
if (currTag != null) { |
|
518 |
Name name = tree.getName(); |
|
519 |
HtmlTag.Attr attr = currTag.getAttr(name); |
|
520 |
if (attr != null) { |
|
521 |
boolean first = tagStack.peek().attrs.add(attr); |
|
522 |
if (!first) |
|
523 |
env.messages.error(HTML, tree, "dc.attr.repeated", name); |
|
524 |
} |
|
525 |
AttrKind k = currTag.getAttrKind(name); |
|
526 |
switch (k) { |
|
527 |
case OK: |
|
528 |
break; |
|
529 |
||
530 |
case INVALID: |
|
531 |
env.messages.error(HTML, tree, "dc.attr.unknown", name); |
|
532 |
break; |
|
533 |
||
534 |
case OBSOLETE: |
|
535 |
env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete", name); |
|
536 |
break; |
|
537 |
||
538 |
case USE_CSS: |
|
539 |
env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete.use.css", name); |
|
540 |
break; |
|
541 |
} |
|
542 |
||
543 |
if (attr != null) { |
|
544 |
switch (attr) { |
|
545 |
case NAME: |
|
546 |
if (currTag != HtmlTag.A) { |
|
547 |
break; |
|
548 |
} |
|
15359 | 549 |
// fallthrough |
14952 | 550 |
case ID: |
551 |
String value = getAttrValue(tree); |
|
15359 | 552 |
if (value == null) { |
553 |
env.messages.error(HTML, tree, "dc.anchor.value.missing"); |
|
554 |
} else { |
|
555 |
if (!validName.matcher(value).matches()) { |
|
556 |
env.messages.error(HTML, tree, "dc.invalid.anchor", value); |
|
557 |
} |
|
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
558 |
if (!checkAnchor(value)) { |
15359 | 559 |
env.messages.error(HTML, tree, "dc.anchor.already.defined", value); |
560 |
} |
|
14952 | 561 |
} |
562 |
break; |
|
563 |
||
564 |
case HREF: |
|
565 |
if (currTag == HtmlTag.A) { |
|
566 |
String v = getAttrValue(tree); |
|
567 |
if (v == null || v.isEmpty()) { |
|
568 |
env.messages.error(HTML, tree, "dc.attr.lacks.value"); |
|
569 |
} else { |
|
570 |
Matcher m = docRoot.matcher(v); |
|
571 |
if (m.matches()) { |
|
572 |
String rest = m.group(2); |
|
573 |
if (!rest.isEmpty()) |
|
574 |
checkURI(tree, rest); |
|
575 |
} else { |
|
576 |
checkURI(tree, v); |
|
577 |
} |
|
578 |
} |
|
579 |
} |
|
580 |
break; |
|
18001 | 581 |
|
582 |
case VALUE: |
|
583 |
if (currTag == HtmlTag.LI) { |
|
584 |
String v = getAttrValue(tree); |
|
585 |
if (v == null || v.isEmpty()) { |
|
586 |
env.messages.error(HTML, tree, "dc.attr.lacks.value"); |
|
587 |
} else if (!validNumber.matcher(v).matches()) { |
|
588 |
env.messages.error(HTML, tree, "dc.attr.not.number"); |
|
589 |
} |
|
590 |
} |
|
591 |
break; |
|
14952 | 592 |
} |
593 |
} |
|
594 |
} |
|
595 |
||
596 |
// TODO: basic check on value |
|
597 |
||
598 |
return super.visitAttribute(tree, ignore); |
|
599 |
} |
|
600 |
||
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
601 |
private boolean checkAnchor(String name) { |
20254
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
602 |
Element e = getEnclosingPackageOrClass(env.currElement); |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
603 |
if (e == null) |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
604 |
return true; |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
605 |
Set<String> set = foundAnchors.get(e); |
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
606 |
if (set == null) |
20254
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
607 |
foundAnchors.put(e, set = new HashSet<>()); |
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
608 |
return set.add(name); |
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
609 |
} |
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
610 |
|
20254
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
611 |
private Element getEnclosingPackageOrClass(Element e) { |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
612 |
while (e != null) { |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
613 |
switch (e.getKind()) { |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
614 |
case CLASS: |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
615 |
case ENUM: |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
616 |
case INTERFACE: |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
617 |
case PACKAGE: |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
618 |
return e; |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
619 |
default: |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
620 |
e = e.getEnclosingElement(); |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
621 |
} |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
622 |
} |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
623 |
return e; |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
624 |
} |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
625 |
|
14952 | 626 |
// http://www.w3.org/TR/html401/types.html#type-name |
627 |
private static final Pattern validName = Pattern.compile("[A-Za-z][A-Za-z0-9-_:.]*"); |
|
628 |
||
18001 | 629 |
private static final Pattern validNumber = Pattern.compile("-?[0-9]+"); |
630 |
||
14952 | 631 |
// pattern to remove leading {@docRoot}/? |
632 |
private static final Pattern docRoot = Pattern.compile("(?i)(\\{@docRoot *\\}/?)?(.*)"); |
|
633 |
||
634 |
private String getAttrValue(AttributeTree tree) { |
|
635 |
if (tree.getValue() == null) |
|
636 |
return null; |
|
637 |
||
638 |
StringWriter sw = new StringWriter(); |
|
639 |
try { |
|
640 |
new DocPretty(sw).print(tree.getValue()); |
|
641 |
} catch (IOException e) { |
|
642 |
// cannot happen |
|
643 |
} |
|
644 |
// ignore potential use of entities for now |
|
645 |
return sw.toString(); |
|
646 |
} |
|
647 |
||
648 |
private void checkURI(AttributeTree tree, String uri) { |
|
649 |
try { |
|
650 |
URI u = new URI(uri); |
|
651 |
} catch (URISyntaxException e) { |
|
652 |
env.messages.error(HTML, tree, "dc.invalid.uri", uri); |
|
653 |
} |
|
654 |
} |
|
655 |
// </editor-fold> |
|
656 |
||
657 |
// <editor-fold defaultstate="collapsed" desc="javadoc tags"> |
|
658 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
659 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 660 |
public Void visitAuthor(AuthorTree tree, Void ignore) { |
661 |
warnIfEmpty(tree, tree.getName()); |
|
662 |
return super.visitAuthor(tree, ignore); |
|
663 |
} |
|
664 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
665 |
@Override @DefinedBy(Api.COMPILER_TREE) |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
666 |
public Void visitDocRoot(DocRootTree tree, Void ignore) { |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
667 |
markEnclosingTag(Flag.HAS_INLINE_TAG); |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
668 |
return super.visitDocRoot(tree, ignore); |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
669 |
} |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
670 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
671 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 672 |
public Void visitInheritDoc(InheritDocTree tree, Void ignore) { |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
673 |
markEnclosingTag(Flag.HAS_INLINE_TAG); |
14952 | 674 |
// TODO: verify on overridden method |
675 |
foundInheritDoc = true; |
|
676 |
return super.visitInheritDoc(tree, ignore); |
|
677 |
} |
|
678 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
679 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 680 |
public Void visitLink(LinkTree tree, Void ignore) { |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
681 |
markEnclosingTag(Flag.HAS_INLINE_TAG); |
14952 | 682 |
// simulate inline context on tag stack |
683 |
HtmlTag t = (tree.getKind() == DocTree.Kind.LINK) |
|
684 |
? HtmlTag.CODE : HtmlTag.SPAN; |
|
685 |
tagStack.push(new TagStackItem(tree, t)); |
|
686 |
try { |
|
687 |
return super.visitLink(tree, ignore); |
|
688 |
} finally { |
|
689 |
tagStack.pop(); |
|
690 |
} |
|
691 |
} |
|
692 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
693 |
@Override @DefinedBy(Api.COMPILER_TREE) |
15363 | 694 |
public Void visitLiteral(LiteralTree tree, Void ignore) { |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
695 |
markEnclosingTag(Flag.HAS_INLINE_TAG); |
15363 | 696 |
if (tree.getKind() == DocTree.Kind.CODE) { |
697 |
for (TagStackItem tsi: tagStack) { |
|
698 |
if (tsi.tag == HtmlTag.CODE) { |
|
15366
545307ec740c
8006228: Doclint doesn't detect <code> {@code nested inline} </code>
jjg
parents:
15363
diff
changeset
|
699 |
env.messages.warning(HTML, tree, "dc.tag.code.within.code"); |
15363 | 700 |
break; |
701 |
} |
|
702 |
} |
|
703 |
} |
|
704 |
return super.visitLiteral(tree, ignore); |
|
705 |
} |
|
706 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
707 |
@Override @DefinedBy(Api.COMPILER_TREE) |
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
708 |
@SuppressWarnings("fallthrough") |
14952 | 709 |
public Void visitParam(ParamTree tree, Void ignore) { |
710 |
boolean typaram = tree.isTypeParameter(); |
|
711 |
IdentifierTree nameTree = tree.getName(); |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
712 |
Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null; |
14952 | 713 |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
714 |
if (paramElement == null) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
715 |
switch (env.currElement.getKind()) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
716 |
case CLASS: case INTERFACE: { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
717 |
if (!typaram) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
718 |
env.messages.error(REFERENCE, tree, "dc.invalid.param"); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
719 |
break; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
720 |
} |
14952 | 721 |
} |
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
722 |
case METHOD: case CONSTRUCTOR: { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
723 |
env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found"); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
724 |
break; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
725 |
} |
14952 | 726 |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
727 |
default: |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
728 |
env.messages.error(REFERENCE, tree, "dc.invalid.param"); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
729 |
break; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
730 |
} |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
731 |
} else { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
732 |
foundParams.add(paramElement); |
14952 | 733 |
} |
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
734 |
|
14952 | 735 |
warnIfEmpty(tree, tree.getDescription()); |
736 |
return super.visitParam(tree, ignore); |
|
737 |
} |
|
738 |
||
739 |
private void checkParamsDocumented(List<? extends Element> list) { |
|
740 |
if (foundInheritDoc) |
|
741 |
return; |
|
742 |
||
743 |
for (Element e: list) { |
|
744 |
if (!foundParams.contains(e)) { |
|
745 |
CharSequence paramName = (e.getKind() == ElementKind.TYPE_PARAMETER) |
|
746 |
? "<" + e.getSimpleName() + ">" |
|
747 |
: e.getSimpleName(); |
|
748 |
reportMissing("dc.missing.param", paramName); |
|
749 |
} |
|
750 |
} |
|
751 |
} |
|
752 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
753 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 754 |
public Void visitReference(ReferenceTree tree, Void ignore) { |
20256
9154c5cc0d9f
8002154: [doclint] doclint should check for issues which are errors in javadoc
jjg
parents:
20255
diff
changeset
|
755 |
String sig = tree.getSignature(); |
9154c5cc0d9f
8002154: [doclint] doclint should check for issues which are errors in javadoc
jjg
parents:
20255
diff
changeset
|
756 |
if (sig.contains("<") || sig.contains(">")) |
9154c5cc0d9f
8002154: [doclint] doclint should check for issues which are errors in javadoc
jjg
parents:
20255
diff
changeset
|
757 |
env.messages.error(REFERENCE, tree, "dc.type.arg.not.allowed"); |
9154c5cc0d9f
8002154: [doclint] doclint should check for issues which are errors in javadoc
jjg
parents:
20255
diff
changeset
|
758 |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
759 |
Element e = env.trees.getElement(getCurrentPath()); |
14952 | 760 |
if (e == null) |
761 |
env.messages.error(REFERENCE, tree, "dc.ref.not.found"); |
|
762 |
return super.visitReference(tree, ignore); |
|
763 |
} |
|
764 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
765 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 766 |
public Void visitReturn(ReturnTree tree, Void ignore) { |
767 |
Element e = env.trees.getElement(env.currPath); |
|
768 |
if (e.getKind() != ElementKind.METHOD |
|
769 |
|| ((ExecutableElement) e).getReturnType().getKind() == TypeKind.VOID) |
|
770 |
env.messages.error(REFERENCE, tree, "dc.invalid.return"); |
|
771 |
foundReturn = true; |
|
772 |
warnIfEmpty(tree, tree.getDescription()); |
|
773 |
return super.visitReturn(tree, ignore); |
|
774 |
} |
|
775 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
776 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 777 |
public Void visitSerialData(SerialDataTree tree, Void ignore) { |
778 |
warnIfEmpty(tree, tree.getDescription()); |
|
779 |
return super.visitSerialData(tree, ignore); |
|
780 |
} |
|
781 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
782 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 783 |
public Void visitSerialField(SerialFieldTree tree, Void ignore) { |
784 |
warnIfEmpty(tree, tree.getDescription()); |
|
785 |
return super.visitSerialField(tree, ignore); |
|
786 |
} |
|
787 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
788 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 789 |
public Void visitSince(SinceTree tree, Void ignore) { |
790 |
warnIfEmpty(tree, tree.getBody()); |
|
791 |
return super.visitSince(tree, ignore); |
|
792 |
} |
|
793 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
794 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 795 |
public Void visitThrows(ThrowsTree tree, Void ignore) { |
796 |
ReferenceTree exName = tree.getExceptionName(); |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
797 |
Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); |
14952 | 798 |
if (ex == null) { |
799 |
env.messages.error(REFERENCE, tree, "dc.ref.not.found"); |
|
19125
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
800 |
} else if (isThrowable(ex.asType())) { |
14952 | 801 |
switch (env.currElement.getKind()) { |
802 |
case CONSTRUCTOR: |
|
803 |
case METHOD: |
|
804 |
if (isCheckedException(ex.asType())) { |
|
805 |
ExecutableElement ee = (ExecutableElement) env.currElement; |
|
806 |
checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes()); |
|
807 |
} |
|
808 |
break; |
|
809 |
default: |
|
810 |
env.messages.error(REFERENCE, tree, "dc.invalid.throws"); |
|
811 |
} |
|
812 |
} else { |
|
813 |
env.messages.error(REFERENCE, tree, "dc.invalid.throws"); |
|
814 |
} |
|
815 |
warnIfEmpty(tree, tree.getDescription()); |
|
816 |
return scan(tree.getDescription(), ignore); |
|
817 |
} |
|
818 |
||
19125
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
819 |
private boolean isThrowable(TypeMirror tm) { |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
820 |
switch (tm.getKind()) { |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
821 |
case DECLARED: |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
822 |
case TYPEVAR: |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
823 |
return env.types.isAssignable(tm, env.java_lang_Throwable); |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
824 |
} |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
825 |
return false; |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
826 |
} |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
827 |
|
14952 | 828 |
private void checkThrowsDeclared(ReferenceTree tree, TypeMirror t, List<? extends TypeMirror> list) { |
829 |
boolean found = false; |
|
830 |
for (TypeMirror tl : list) { |
|
831 |
if (env.types.isAssignable(t, tl)) { |
|
832 |
foundThrows.add(tl); |
|
833 |
found = true; |
|
834 |
} |
|
835 |
} |
|
836 |
if (!found) |
|
837 |
env.messages.error(REFERENCE, tree, "dc.exception.not.thrown", t); |
|
838 |
} |
|
839 |
||
840 |
private void checkThrowsDocumented(List<? extends TypeMirror> list) { |
|
841 |
if (foundInheritDoc) |
|
842 |
return; |
|
843 |
||
844 |
for (TypeMirror tl: list) { |
|
845 |
if (isCheckedException(tl) && !foundThrows.contains(tl)) |
|
846 |
reportMissing("dc.missing.throws", tl); |
|
847 |
} |
|
848 |
} |
|
849 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
850 |
@Override @DefinedBy(Api.COMPILER_TREE) |
21500
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
851 |
public Void visitUnknownBlockTag(UnknownBlockTagTree tree, Void ignore) { |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
852 |
checkUnknownTag(tree, tree.getTagName()); |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
853 |
return super.visitUnknownBlockTag(tree, ignore); |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
854 |
} |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
855 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
856 |
@Override @DefinedBy(Api.COMPILER_TREE) |
21500
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
857 |
public Void visitUnknownInlineTag(UnknownInlineTagTree tree, Void ignore) { |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
858 |
checkUnknownTag(tree, tree.getTagName()); |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
859 |
return super.visitUnknownInlineTag(tree, ignore); |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
860 |
} |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
861 |
|
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
862 |
private void checkUnknownTag(DocTree tree, String tagName) { |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
863 |
if (env.customTags != null && !env.customTags.contains(tagName)) |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
864 |
env.messages.error(SYNTAX, tree, "dc.tag.unknown", tagName); |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
865 |
} |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
866 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
867 |
@Override @DefinedBy(Api.COMPILER_TREE) |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
868 |
public Void visitValue(ValueTree tree, Void ignore) { |
20255
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
869 |
ReferenceTree ref = tree.getReference(); |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
870 |
if (ref == null || ref.getSignature().isEmpty()) { |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
871 |
if (!isConstant(env.currElement)) |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
872 |
env.messages.error(REFERENCE, tree, "dc.value.not.allowed.here"); |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
873 |
} else { |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
874 |
Element e = env.trees.getElement(new DocTreePath(getCurrentPath(), ref)); |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
875 |
if (!isConstant(e)) |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
876 |
env.messages.error(REFERENCE, tree, "dc.value.not.a.constant"); |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
877 |
} |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
878 |
|
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
879 |
markEnclosingTag(Flag.HAS_INLINE_TAG); |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
880 |
return super.visitValue(tree, ignore); |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
881 |
} |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
882 |
|
20255
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
883 |
private boolean isConstant(Element e) { |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
884 |
if (e == null) |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
885 |
return false; |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
886 |
|
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
887 |
switch (e.getKind()) { |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
888 |
case FIELD: |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
889 |
Object value = ((VariableElement) e).getConstantValue(); |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
890 |
return (value != null); // can't distinguish "not a constant" from "constant is null" |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
891 |
default: |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
892 |
return false; |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
893 |
} |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
894 |
} |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
895 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
896 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 897 |
public Void visitVersion(VersionTree tree, Void ignore) { |
898 |
warnIfEmpty(tree, tree.getBody()); |
|
899 |
return super.visitVersion(tree, ignore); |
|
900 |
} |
|
901 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
902 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 903 |
public Void visitErroneous(ErroneousTree tree, Void ignore) { |
904 |
env.messages.error(SYNTAX, tree, null, tree.getDiagnostic().getMessage(null)); |
|
905 |
return null; |
|
906 |
} |
|
907 |
// </editor-fold> |
|
908 |
||
909 |
// <editor-fold defaultstate="collapsed" desc="Utility methods"> |
|
910 |
||
911 |
private boolean isCheckedException(TypeMirror t) { |
|
912 |
return !(env.types.isAssignable(t, env.java_lang_Error) |
|
913 |
|| env.types.isAssignable(t, env.java_lang_RuntimeException)); |
|
914 |
} |
|
915 |
||
916 |
private boolean isSynthetic() { |
|
917 |
switch (env.currElement.getKind()) { |
|
918 |
case CONSTRUCTOR: |
|
919 |
// A synthetic default constructor has the same pos as the |
|
920 |
// enclosing class |
|
921 |
TreePath p = env.currPath; |
|
922 |
return env.getPos(p) == env.getPos(p.getParentPath()); |
|
923 |
} |
|
924 |
return false; |
|
925 |
} |
|
926 |
||
927 |
void markEnclosingTag(Flag flag) { |
|
928 |
TagStackItem top = tagStack.peek(); |
|
929 |
if (top != null) |
|
930 |
top.flags.add(flag); |
|
931 |
} |
|
932 |
||
933 |
String toString(TreePath p) { |
|
934 |
StringBuilder sb = new StringBuilder("TreePath["); |
|
935 |
toString(p, sb); |
|
936 |
sb.append("]"); |
|
937 |
return sb.toString(); |
|
938 |
} |
|
939 |
||
940 |
void toString(TreePath p, StringBuilder sb) { |
|
941 |
TreePath parent = p.getParentPath(); |
|
942 |
if (parent != null) { |
|
943 |
toString(parent, sb); |
|
944 |
sb.append(","); |
|
945 |
} |
|
946 |
sb.append(p.getLeaf().getKind()).append(":").append(env.getPos(p)).append(":S").append(env.getStartPos(p)); |
|
947 |
} |
|
948 |
||
949 |
void warnIfEmpty(DocTree tree, List<? extends DocTree> list) { |
|
950 |
for (DocTree d: list) { |
|
951 |
switch (d.getKind()) { |
|
952 |
case TEXT: |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
953 |
if (hasNonWhitespace((TextTree) d)) |
14952 | 954 |
return; |
955 |
break; |
|
956 |
default: |
|
957 |
return; |
|
958 |
} |
|
959 |
} |
|
960 |
env.messages.warning(SYNTAX, tree, "dc.empty", tree.getKind().tagName); |
|
961 |
} |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
962 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
963 |
boolean hasNonWhitespace(TextTree tree) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
964 |
String s = tree.getBody(); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
965 |
for (int i = 0; i < s.length(); i++) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
966 |
if (!Character.isWhitespace(s.charAt(i))) |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
967 |
return true; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
968 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
969 |
return false; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
970 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
971 |
|
14952 | 972 |
// </editor-fold> |
973 |
||
974 |
} |