author | hannesw |
Thu, 22 Nov 2018 15:38:20 +0100 | |
changeset 52664 | 15fc92f4ae9a |
parent 52648 | 12956ca371c2 |
child 52871 | c09bff7928e8 |
permissions | -rw-r--r-- |
14952 | 1 |
/* |
43374
d312a15c5fcf
8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents:
43261
diff
changeset
|
2 |
* Copyright (c) 2012, 2017, 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; |
|
52648
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
62 |
import com.sun.source.doctree.IndexTree; |
14952 | 63 |
import com.sun.source.doctree.InheritDocTree; |
52648
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
64 |
import com.sun.source.doctree.InlineTagTree; |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
65 |
import com.sun.source.doctree.LinkTree; |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
66 |
import com.sun.source.doctree.LiteralTree; |
14952 | 67 |
import com.sun.source.doctree.ParamTree; |
42831
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
68 |
import com.sun.source.doctree.ProvidesTree; |
14952 | 69 |
import com.sun.source.doctree.ReferenceTree; |
70 |
import com.sun.source.doctree.ReturnTree; |
|
71 |
import com.sun.source.doctree.SerialDataTree; |
|
72 |
import com.sun.source.doctree.SerialFieldTree; |
|
73 |
import com.sun.source.doctree.SinceTree; |
|
74 |
import com.sun.source.doctree.StartElementTree; |
|
46184
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
75 |
import com.sun.source.doctree.SummaryTree; |
52648
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
76 |
import com.sun.source.doctree.SystemPropertyTree; |
14952 | 77 |
import com.sun.source.doctree.TextTree; |
78 |
import com.sun.source.doctree.ThrowsTree; |
|
21500
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
79 |
import com.sun.source.doctree.UnknownBlockTagTree; |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
80 |
import com.sun.source.doctree.UnknownInlineTagTree; |
42831
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
81 |
import com.sun.source.doctree.UsesTree; |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
82 |
import com.sun.source.doctree.ValueTree; |
14952 | 83 |
import com.sun.source.doctree.VersionTree; |
24069 | 84 |
import com.sun.source.tree.Tree; |
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
85 |
import com.sun.source.util.DocTreePath; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
86 |
import com.sun.source.util.DocTreePathScanner; |
14952 | 87 |
import com.sun.source.util.TreePath; |
88 |
import com.sun.tools.doclint.HtmlTag.AttrKind; |
|
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
89 |
import com.sun.tools.javac.tree.DocPretty; |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
26266
diff
changeset
|
90 |
import com.sun.tools.javac.util.Assert; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
91 |
import com.sun.tools.javac.util.DefinedBy; |
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
92 |
import com.sun.tools.javac.util.DefinedBy.Api; |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
21500
diff
changeset
|
93 |
import com.sun.tools.javac.util.StringUtils; |
42831
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
94 |
|
14952 | 95 |
import static com.sun.tools.doclint.Messages.Group.*; |
96 |
||
97 |
||
98 |
/** |
|
99 |
* Validate a doc comment. |
|
100 |
* |
|
101 |
* <p><b>This is NOT part of any supported API. |
|
102 |
* If you write code that depends on this, you do so at your own |
|
103 |
* risk. This code and its internal interfaces are subject to change |
|
104 |
* or deletion without notice.</b></p> |
|
105 |
*/ |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
106 |
public class Checker extends DocTreePathScanner<Void, Void> { |
14952 | 107 |
final Env env; |
108 |
||
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
109 |
Set<Element> foundParams = new HashSet<>(); |
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
110 |
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
|
111 |
Map<Element, Set<String>> foundAnchors = new HashMap<>(); |
14952 | 112 |
boolean foundInheritDoc = false; |
113 |
boolean foundReturn = false; |
|
46184
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
114 |
boolean hasNonWhitespaceText = false; |
14952 | 115 |
|
15370 | 116 |
public enum Flag { |
14952 | 117 |
TABLE_HAS_CAPTION, |
118 |
HAS_ELEMENT, |
|
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
119 |
HAS_HEADING, |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
120 |
HAS_INLINE_TAG, |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
121 |
HAS_TEXT, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
122 |
REPORTED_BAD_INLINE |
14952 | 123 |
} |
124 |
||
125 |
static class TagStackItem { |
|
126 |
final DocTree tree; // typically, but not always, StartElementTree |
|
127 |
final HtmlTag tag; |
|
128 |
final Set<HtmlTag.Attr> attrs; |
|
129 |
final Set<Flag> flags; |
|
130 |
TagStackItem(DocTree tree, HtmlTag tag) { |
|
131 |
this.tree = tree; |
|
132 |
this.tag = tag; |
|
133 |
attrs = EnumSet.noneOf(HtmlTag.Attr.class); |
|
134 |
flags = EnumSet.noneOf(Flag.class); |
|
135 |
} |
|
136 |
@Override |
|
137 |
public String toString() { |
|
138 |
return String.valueOf(tag); |
|
139 |
} |
|
140 |
} |
|
141 |
||
42831
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
142 |
private final Deque<TagStackItem> tagStack; // TODO: maybe want to record starting tree as well |
14952 | 143 |
private HtmlTag currHeaderTag; |
144 |
||
16799
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
16562
diff
changeset
|
145 |
private final int implicitHeaderLevel; |
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
16562
diff
changeset
|
146 |
|
14952 | 147 |
// <editor-fold defaultstate="collapsed" desc="Top level"> |
148 |
||
149 |
Checker(Env env) { |
|
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
26266
diff
changeset
|
150 |
this.env = Assert.checkNonNull(env); |
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
151 |
tagStack = new LinkedList<>(); |
16799
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
16562
diff
changeset
|
152 |
implicitHeaderLevel = env.implicitHeaderLevel; |
14952 | 153 |
} |
154 |
||
155 |
public Void scan(DocCommentTree tree, TreePath p) { |
|
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
29291
diff
changeset
|
156 |
env.initTypes(); |
14952 | 157 |
env.setCurrent(p, tree); |
158 |
||
159 |
boolean isOverridingMethod = !env.currOverriddenMethods.isEmpty(); |
|
36045
9643bffe2105
8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents:
29957
diff
changeset
|
160 |
JavaFileObject fo = p.getCompilationUnit().getSourceFile(); |
14952 | 161 |
|
24069 | 162 |
if (p.getLeaf().getKind() == Tree.Kind.PACKAGE) { |
163 |
// 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
|
164 |
// package declaration (if any) for the compilation unit. |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
165 |
// 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
|
166 |
// expected in package-info files. |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
167 |
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
|
168 |
if (tree == null) { |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
169 |
if (isPkgInfo) |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
170 |
reportMissing("dc.missing.comment"); |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
171 |
return null; |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
172 |
} else { |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
173 |
if (!isPkgInfo) |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
174 |
reportReference("dc.unexpected.comment"); |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
175 |
} |
36045
9643bffe2105
8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents:
29957
diff
changeset
|
176 |
} else if (tree != null && fo.isNameCompatible("package", JavaFileObject.Kind.HTML)) { |
9643bffe2105
8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents:
29957
diff
changeset
|
177 |
// a package.html file with a DocCommentTree |
9643bffe2105
8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents:
29957
diff
changeset
|
178 |
if (tree.getFullBody().isEmpty()) { |
9643bffe2105
8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents:
29957
diff
changeset
|
179 |
reportMissing("dc.missing.comment"); |
9643bffe2105
8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents:
29957
diff
changeset
|
180 |
return null; |
9643bffe2105
8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents:
29957
diff
changeset
|
181 |
} |
19123
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
182 |
} else { |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
183 |
if (tree == null) { |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
184 |
if (!isSynthetic() && !isOverridingMethod) |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
185 |
reportMissing("dc.missing.comment"); |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
186 |
return null; |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
187 |
} |
14952 | 188 |
} |
189 |
||
190 |
tagStack.clear(); |
|
191 |
currHeaderTag = null; |
|
192 |
||
193 |
foundParams.clear(); |
|
194 |
foundThrows.clear(); |
|
195 |
foundInheritDoc = false; |
|
196 |
foundReturn = false; |
|
46184
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
197 |
hasNonWhitespaceText = false; |
14952 | 198 |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
199 |
scan(new DocTreePath(p, tree), null); |
14952 | 200 |
|
201 |
if (!isOverridingMethod) { |
|
202 |
switch (env.currElement.getKind()) { |
|
203 |
case METHOD: |
|
204 |
case CONSTRUCTOR: { |
|
205 |
ExecutableElement ee = (ExecutableElement) env.currElement; |
|
206 |
checkParamsDocumented(ee.getTypeParameters()); |
|
207 |
checkParamsDocumented(ee.getParameters()); |
|
208 |
switch (ee.getReturnType().getKind()) { |
|
209 |
case VOID: |
|
210 |
case NONE: |
|
211 |
break; |
|
212 |
default: |
|
213 |
if (!foundReturn |
|
214 |
&& !foundInheritDoc |
|
215 |
&& !env.types.isSameType(ee.getReturnType(), env.java_lang_Void)) { |
|
216 |
reportMissing("dc.missing.return"); |
|
217 |
} |
|
218 |
} |
|
219 |
checkThrowsDocumented(ee.getThrownTypes()); |
|
220 |
} |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
return null; |
|
225 |
} |
|
226 |
||
227 |
private void reportMissing(String code, Object... args) { |
|
228 |
env.messages.report(MISSING, Kind.WARNING, env.currPath.getLeaf(), code, args); |
|
229 |
} |
|
230 |
||
19123
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
231 |
private void reportReference(String code, Object... args) { |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
232 |
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
|
233 |
} |
50733e28eaca
8021215: javac gives incorrect doclint warnings on normal package statements
jjg
parents:
19120
diff
changeset
|
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 visitDocComment(DocCommentTree tree, Void ignore) { |
237 |
super.visitDocComment(tree, ignore); |
|
238 |
for (TagStackItem tsi: tagStack) { |
|
21017
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
239 |
warnIfEmpty(tsi, null); |
14952 | 240 |
if (tsi.tree.getKind() == DocTree.Kind.START_ELEMENT |
241 |
&& tsi.tag.endKind == HtmlTag.EndKind.REQUIRED) { |
|
242 |
StartElementTree t = (StartElementTree) tsi.tree; |
|
243 |
env.messages.error(HTML, t, "dc.tag.not.closed", t.getName()); |
|
244 |
} |
|
245 |
} |
|
246 |
return null; |
|
247 |
} |
|
248 |
// </editor-fold> |
|
249 |
||
250 |
// <editor-fold defaultstate="collapsed" desc="Text and entities."> |
|
251 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
252 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 253 |
public Void visitText(TextTree tree, Void ignore) { |
46184
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
254 |
hasNonWhitespaceText = hasNonWhitespace(tree); |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
255 |
if (hasNonWhitespaceText) { |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
256 |
checkAllowsText(tree); |
14952 | 257 |
markEnclosingTag(Flag.HAS_TEXT); |
258 |
} |
|
259 |
return null; |
|
260 |
} |
|
261 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
262 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 263 |
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
|
264 |
checkAllowsText(tree); |
14952 | 265 |
markEnclosingTag(Flag.HAS_TEXT); |
266 |
String name = tree.getName().toString(); |
|
267 |
if (name.startsWith("#")) { |
|
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
21500
diff
changeset
|
268 |
int v = StringUtils.toLowerCase(name).startsWith("#x") |
14952 | 269 |
? Integer.parseInt(name.substring(2), 16) |
270 |
: Integer.parseInt(name.substring(1), 10); |
|
271 |
if (!Entity.isValid(v)) { |
|
272 |
env.messages.error(HTML, tree, "dc.entity.invalid", name); |
|
273 |
} |
|
274 |
} else if (!Entity.isValid(name)) { |
|
275 |
env.messages.error(HTML, tree, "dc.entity.invalid", name); |
|
276 |
} |
|
277 |
return null; |
|
278 |
} |
|
279 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
280 |
void checkAllowsText(DocTree tree) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
281 |
TagStackItem top = tagStack.peek(); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
282 |
if (top != null |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
283 |
&& top.tree.getKind() == DocTree.Kind.START_ELEMENT |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
284 |
&& !top.tag.acceptsText()) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
285 |
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
|
286 |
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
|
287 |
((StartElementTree) top.tree).getName()); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
288 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
289 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
290 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
291 |
|
14952 | 292 |
// </editor-fold> |
293 |
||
294 |
// <editor-fold defaultstate="collapsed" desc="HTML elements"> |
|
295 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
296 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 297 |
public Void visitStartElement(StartElementTree tree, Void ignore) { |
298 |
final Name treeName = tree.getName(); |
|
299 |
final HtmlTag t = HtmlTag.get(treeName); |
|
300 |
if (t == null) { |
|
301 |
env.messages.error(HTML, tree, "dc.tag.unknown", treeName); |
|
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
302 |
} else if (t.allowedVersion != HtmlVersion.ALL && t.allowedVersion != env.htmlVersion) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
303 |
env.messages.error(HTML, tree, "dc.tag.not.supported", treeName); |
14952 | 304 |
} else { |
15707
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
305 |
boolean done = false; |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
306 |
for (TagStackItem tsi: tagStack) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
307 |
if (tsi.tag.accepts(t)) { |
21017
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
308 |
while (tagStack.peek() != tsi) { |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
309 |
warnIfEmpty(tagStack.peek(), null); |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
310 |
tagStack.pop(); |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
311 |
} |
15707
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
312 |
done = true; |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
313 |
break; |
15707
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
314 |
} else if (tsi.tag.endKind != HtmlTag.EndKind.OPTIONAL) { |
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
315 |
done = true; |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
316 |
break; |
15707
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
317 |
} |
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
318 |
} |
7b2411328a5c
8007566: DocLint too aggressive with not allowed here: <p>
jjg
parents:
15371
diff
changeset
|
319 |
if (!done && HtmlTag.BODY.accepts(t)) { |
21017
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
320 |
while (!tagStack.isEmpty()) { |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
321 |
warnIfEmpty(tagStack.peek(), null); |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
322 |
tagStack.pop(); |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
323 |
} |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
324 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
325 |
|
21017
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
326 |
markEnclosingTag(Flag.HAS_ELEMENT); |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
327 |
checkStructure(tree, t); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
328 |
|
14952 | 329 |
// tag specific checks |
330 |
switch (t) { |
|
331 |
// check for out of sequence headers, such as <h1>...</h1> <h3>...</h3> |
|
332 |
case H1: case H2: case H3: case H4: case H5: case H6: |
|
333 |
checkHeader(tree, t); |
|
334 |
break; |
|
335 |
} |
|
336 |
||
337 |
if (t.flags.contains(HtmlTag.Flag.NO_NEST)) { |
|
338 |
for (TagStackItem i: tagStack) { |
|
339 |
if (t == i.tag) { |
|
340 |
env.messages.warning(HTML, tree, "dc.tag.nested.not.allowed", treeName); |
|
341 |
break; |
|
342 |
} |
|
343 |
} |
|
344 |
} |
|
345 |
} |
|
346 |
||
347 |
// check for self closing tags, such as <a id="name"/> |
|
348 |
if (tree.isSelfClosing()) { |
|
349 |
env.messages.error(HTML, tree, "dc.tag.self.closing", treeName); |
|
350 |
} |
|
351 |
||
352 |
try { |
|
353 |
TagStackItem parent = tagStack.peek(); |
|
354 |
TagStackItem top = new TagStackItem(tree, t); |
|
355 |
tagStack.push(top); |
|
356 |
||
357 |
super.visitStartElement(tree, ignore); |
|
358 |
||
359 |
// handle attributes that may or may not have been found in start element |
|
360 |
if (t != null) { |
|
361 |
switch (t) { |
|
362 |
case CAPTION: |
|
363 |
if (parent != null && parent.tag == HtmlTag.TABLE) |
|
364 |
parent.flags.add(Flag.TABLE_HAS_CAPTION); |
|
365 |
break; |
|
366 |
||
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
367 |
case H1: case H2: case H3: case H4: case H5: case H6: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
368 |
if (parent != null && (parent.tag == HtmlTag.SECTION || parent.tag == HtmlTag.ARTICLE)) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
369 |
parent.flags.add(Flag.HAS_HEADING); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
370 |
} |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
371 |
break; |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
372 |
|
14952 | 373 |
case IMG: |
374 |
if (!top.attrs.contains(HtmlTag.Attr.ALT)) |
|
375 |
env.messages.error(ACCESSIBILITY, tree, "dc.no.alt.attr.for.image"); |
|
376 |
break; |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
return null; |
|
381 |
} finally { |
|
382 |
||
383 |
if (t == null || t.endKind == HtmlTag.EndKind.NONE) |
|
384 |
tagStack.pop(); |
|
385 |
} |
|
386 |
} |
|
387 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
388 |
private void checkStructure(StartElementTree tree, HtmlTag t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
389 |
Name treeName = tree.getName(); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
390 |
TagStackItem top = tagStack.peek(); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
391 |
switch (t.blockType) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
392 |
case BLOCK: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
393 |
if (top == null || top.tag.accepts(t)) |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
394 |
return; |
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 |
switch (top.tree.getKind()) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
397 |
case START_ELEMENT: { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
398 |
if (top.tag.blockType == HtmlTag.BlockType.INLINE) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
399 |
Name name = ((StartElementTree) top.tree).getName(); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
400 |
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
|
401 |
treeName, name); |
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 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
405 |
break; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
406 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
407 |
case LINK: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
408 |
case LINK_PLAIN: { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
409 |
String name = top.tree.getKind().tagName; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
410 |
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
|
411 |
treeName, name); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
412 |
return; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
413 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
414 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
415 |
break; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
416 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
417 |
case INLINE: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
418 |
if (top == null || top.tag.accepts(t)) |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
419 |
return; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
420 |
break; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
421 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
422 |
case LIST_ITEM: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
423 |
case TABLE_ITEM: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
424 |
if (top != null) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
425 |
// 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
|
426 |
top.flags.remove(Flag.REPORTED_BAD_INLINE); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
427 |
if (top.tag.accepts(t)) |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
428 |
return; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
429 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
430 |
break; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
431 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
432 |
case OTHER: |
43261 | 433 |
switch (t) { |
434 |
case SCRIPT: |
|
435 |
// <script> may or may not be allowed, depending on --allow-script-in-comments |
|
436 |
// but we allow it here, and rely on a separate scanner to detect all uses |
|
437 |
// of JavaScript, including <script> tags, and use in attributes, etc. |
|
438 |
break; |
|
439 |
||
440 |
default: |
|
441 |
env.messages.error(HTML, tree, "dc.tag.not.allowed", treeName); |
|
442 |
} |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
443 |
return; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
444 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
445 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
446 |
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
|
447 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
448 |
|
14952 | 449 |
private void checkHeader(StartElementTree tree, HtmlTag tag) { |
450 |
// verify the new tag |
|
451 |
if (getHeaderLevel(tag) > getHeaderLevel(currHeaderTag) + 1) { |
|
452 |
if (currHeaderTag == null) { |
|
453 |
env.messages.error(ACCESSIBILITY, tree, "dc.tag.header.sequence.1", tag); |
|
454 |
} else { |
|
455 |
env.messages.error(ACCESSIBILITY, tree, "dc.tag.header.sequence.2", |
|
456 |
tag, currHeaderTag); |
|
457 |
} |
|
458 |
} |
|
459 |
||
460 |
currHeaderTag = tag; |
|
461 |
} |
|
462 |
||
463 |
private int getHeaderLevel(HtmlTag tag) { |
|
464 |
if (tag == null) |
|
16799
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
16562
diff
changeset
|
465 |
return implicitHeaderLevel; |
14952 | 466 |
switch (tag) { |
467 |
case H1: return 1; |
|
468 |
case H2: return 2; |
|
469 |
case H3: return 3; |
|
470 |
case H4: return 4; |
|
471 |
case H5: return 5; |
|
472 |
case H6: return 6; |
|
473 |
default: throw new IllegalArgumentException(); |
|
474 |
} |
|
475 |
} |
|
476 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
477 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 478 |
public Void visitEndElement(EndElementTree tree, Void ignore) { |
479 |
final Name treeName = tree.getName(); |
|
480 |
final HtmlTag t = HtmlTag.get(treeName); |
|
481 |
if (t == null) { |
|
482 |
env.messages.error(HTML, tree, "dc.tag.unknown", treeName); |
|
483 |
} else if (t.endKind == HtmlTag.EndKind.NONE) { |
|
484 |
env.messages.error(HTML, tree, "dc.tag.end.not.permitted", treeName); |
|
485 |
} else { |
|
15363 | 486 |
boolean done = false; |
14952 | 487 |
while (!tagStack.isEmpty()) { |
488 |
TagStackItem top = tagStack.peek(); |
|
489 |
if (t == top.tag) { |
|
490 |
switch (t) { |
|
491 |
case TABLE: |
|
492 |
if (!top.attrs.contains(HtmlTag.Attr.SUMMARY) |
|
493 |
&& !top.flags.contains(Flag.TABLE_HAS_CAPTION)) { |
|
494 |
env.messages.error(ACCESSIBILITY, tree, |
|
495 |
"dc.no.summary.or.caption.for.table"); |
|
496 |
} |
|
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
497 |
break; |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
498 |
|
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
499 |
case SECTION: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
500 |
case ARTICLE: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
501 |
if (env.htmlVersion == HtmlVersion.HTML5 && !top.flags.contains(Flag.HAS_HEADING)) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
502 |
env.messages.error(HTML, tree, "dc.tag.requires.heading", treeName); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
503 |
} |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
504 |
break; |
14952 | 505 |
} |
21017
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
506 |
warnIfEmpty(top, tree); |
14952 | 507 |
tagStack.pop(); |
15363 | 508 |
done = true; |
14952 | 509 |
break; |
510 |
} else if (top.tag == null || top.tag.endKind != HtmlTag.EndKind.REQUIRED) { |
|
511 |
tagStack.pop(); |
|
512 |
} else { |
|
513 |
boolean found = false; |
|
514 |
for (TagStackItem si: tagStack) { |
|
515 |
if (si.tag == t) { |
|
516 |
found = true; |
|
517 |
break; |
|
518 |
} |
|
519 |
} |
|
520 |
if (found && top.tree.getKind() == DocTree.Kind.START_ELEMENT) { |
|
521 |
env.messages.error(HTML, top.tree, "dc.tag.start.unmatched", |
|
522 |
((StartElementTree) top.tree).getName()); |
|
523 |
tagStack.pop(); |
|
524 |
} else { |
|
525 |
env.messages.error(HTML, tree, "dc.tag.end.unexpected", treeName); |
|
15363 | 526 |
done = true; |
14952 | 527 |
break; |
528 |
} |
|
529 |
} |
|
530 |
} |
|
15363 | 531 |
|
532 |
if (!done && tagStack.isEmpty()) { |
|
533 |
env.messages.error(HTML, tree, "dc.tag.end.unexpected", treeName); |
|
534 |
} |
|
14952 | 535 |
} |
536 |
||
537 |
return super.visitEndElement(tree, ignore); |
|
538 |
} |
|
21017
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
539 |
|
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
540 |
void warnIfEmpty(TagStackItem tsi, DocTree endTree) { |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
541 |
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
|
542 |
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
|
543 |
&& !tsi.flags.contains(Flag.HAS_TEXT) |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
544 |
&& !tsi.flags.contains(Flag.HAS_ELEMENT) |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
545 |
&& !tsi.flags.contains(Flag.HAS_INLINE_TAG)) { |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
546 |
DocTree tree = (endTree != null) ? endTree : tsi.tree; |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
547 |
Name treeName = ((StartElementTree) tsi.tree).getName(); |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
548 |
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
|
549 |
} |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
550 |
} |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
551 |
} |
f61558e07e14
8026368: doclint does not report empty tags when tag closed implicitly
jjg
parents:
20256
diff
changeset
|
552 |
|
14952 | 553 |
// </editor-fold> |
554 |
||
555 |
// <editor-fold defaultstate="collapsed" desc="HTML attributes"> |
|
556 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
557 |
@Override @DefinedBy(Api.COMPILER_TREE) @SuppressWarnings("fallthrough") |
14952 | 558 |
public Void visitAttribute(AttributeTree tree, Void ignore) { |
559 |
HtmlTag currTag = tagStack.peek().tag; |
|
560 |
if (currTag != null) { |
|
561 |
Name name = tree.getName(); |
|
562 |
HtmlTag.Attr attr = currTag.getAttr(name); |
|
563 |
if (attr != null) { |
|
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
564 |
if (env.htmlVersion == HtmlVersion.HTML4 && attr.name().contains("-")) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
565 |
env.messages.error(HTML, tree, "dc.attr.not.supported.html4", name); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
566 |
} |
14952 | 567 |
boolean first = tagStack.peek().attrs.add(attr); |
568 |
if (!first) |
|
569 |
env.messages.error(HTML, tree, "dc.attr.repeated", name); |
|
570 |
} |
|
43261 | 571 |
// for now, doclint allows all attribute names beginning with "on" as event handler names, |
572 |
// without checking the validity or applicability of the name |
|
573 |
if (!name.toString().startsWith("on")) { |
|
574 |
AttrKind k = currTag.getAttrKind(name); |
|
575 |
switch (env.htmlVersion) { |
|
576 |
case HTML4: |
|
577 |
validateHtml4Attrs(tree, name, k); |
|
578 |
break; |
|
14952 | 579 |
|
43261 | 580 |
case HTML5: |
581 |
validateHtml5Attrs(tree, name, k); |
|
582 |
break; |
|
583 |
} |
|
14952 | 584 |
} |
585 |
||
586 |
if (attr != null) { |
|
587 |
switch (attr) { |
|
588 |
case NAME: |
|
589 |
if (currTag != HtmlTag.A) { |
|
590 |
break; |
|
591 |
} |
|
15359 | 592 |
// fallthrough |
14952 | 593 |
case ID: |
594 |
String value = getAttrValue(tree); |
|
15359 | 595 |
if (value == null) { |
596 |
env.messages.error(HTML, tree, "dc.anchor.value.missing"); |
|
597 |
} else { |
|
598 |
if (!validName.matcher(value).matches()) { |
|
599 |
env.messages.error(HTML, tree, "dc.invalid.anchor", value); |
|
600 |
} |
|
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
601 |
if (!checkAnchor(value)) { |
15359 | 602 |
env.messages.error(HTML, tree, "dc.anchor.already.defined", value); |
603 |
} |
|
14952 | 604 |
} |
605 |
break; |
|
606 |
||
607 |
case HREF: |
|
608 |
if (currTag == HtmlTag.A) { |
|
609 |
String v = getAttrValue(tree); |
|
610 |
if (v == null || v.isEmpty()) { |
|
611 |
env.messages.error(HTML, tree, "dc.attr.lacks.value"); |
|
612 |
} else { |
|
613 |
Matcher m = docRoot.matcher(v); |
|
614 |
if (m.matches()) { |
|
615 |
String rest = m.group(2); |
|
616 |
if (!rest.isEmpty()) |
|
617 |
checkURI(tree, rest); |
|
618 |
} else { |
|
619 |
checkURI(tree, v); |
|
620 |
} |
|
621 |
} |
|
622 |
} |
|
623 |
break; |
|
18001 | 624 |
|
625 |
case VALUE: |
|
626 |
if (currTag == HtmlTag.LI) { |
|
627 |
String v = getAttrValue(tree); |
|
628 |
if (v == null || v.isEmpty()) { |
|
629 |
env.messages.error(HTML, tree, "dc.attr.lacks.value"); |
|
630 |
} else if (!validNumber.matcher(v).matches()) { |
|
631 |
env.messages.error(HTML, tree, "dc.attr.not.number"); |
|
632 |
} |
|
633 |
} |
|
634 |
break; |
|
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
635 |
|
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
636 |
case BORDER: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
637 |
if (currTag == HtmlTag.TABLE) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
638 |
String v = getAttrValue(tree); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
639 |
try { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
640 |
if (env.htmlVersion == HtmlVersion.HTML5 |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
641 |
&& (v == null || (!v.isEmpty() && Integer.parseInt(v) != 1))) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
642 |
env.messages.error(HTML, tree, "dc.attr.table.border.html5", attr); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
643 |
} |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
644 |
} catch (NumberFormatException ex) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
645 |
env.messages.error(HTML, tree, "dc.attr.table.border.html5", attr); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
646 |
} |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
647 |
} |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
648 |
break; |
14952 | 649 |
} |
650 |
} |
|
651 |
} |
|
652 |
||
653 |
// TODO: basic check on value |
|
654 |
||
655 |
return super.visitAttribute(tree, ignore); |
|
656 |
} |
|
657 |
||
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
658 |
private void validateHtml4Attrs(AttributeTree tree, Name name, AttrKind k) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
659 |
switch (k) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
660 |
case ALL: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
661 |
case HTML4: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
662 |
break; |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
663 |
|
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
664 |
case INVALID: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
665 |
env.messages.error(HTML, tree, "dc.attr.unknown", name); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
666 |
break; |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
667 |
|
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
668 |
case OBSOLETE: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
669 |
env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete", name); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
670 |
break; |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
671 |
|
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
672 |
case USE_CSS: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
673 |
env.messages.warning(ACCESSIBILITY, tree, "dc.attr.obsolete.use.css", name); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
674 |
break; |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
675 |
|
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
676 |
case HTML5: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
677 |
env.messages.error(HTML, tree, "dc.attr.not.supported.html4", name); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
678 |
break; |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
679 |
} |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
680 |
} |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
681 |
|
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
682 |
private void validateHtml5Attrs(AttributeTree tree, Name name, AttrKind k) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
683 |
switch (k) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
684 |
case ALL: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
685 |
case HTML5: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
686 |
break; |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
687 |
|
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
688 |
case INVALID: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
689 |
case OBSOLETE: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
690 |
case USE_CSS: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
691 |
case HTML4: |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
692 |
env.messages.error(HTML, tree, "dc.attr.not.supported.html5", name); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
693 |
break; |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
694 |
} |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
695 |
} |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
696 |
|
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
697 |
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
|
698 |
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
|
699 |
if (e == null) |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
700 |
return true; |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
701 |
Set<String> set = foundAnchors.get(e); |
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
702 |
if (set == null) |
20254
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
703 |
foundAnchors.put(e, set = new HashSet<>()); |
19120
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
704 |
return set.add(name); |
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
705 |
} |
7766f69bffc7
8020313: doclint doesn't reset HTML anchors correctly
jjg
parents:
18001
diff
changeset
|
706 |
|
20254
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
707 |
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
|
708 |
while (e != null) { |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
709 |
switch (e.getKind()) { |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
710 |
case CLASS: |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
711 |
case ENUM: |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
712 |
case INTERFACE: |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
713 |
case PACKAGE: |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
714 |
return e; |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
715 |
default: |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
716 |
e = e.getEnclosingElement(); |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
717 |
} |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
718 |
} |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
719 |
return e; |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
720 |
} |
8246fe4d6638
8025246: [doclint] doclint is showing error on anchor already defined when it's not
jjg
parents:
19125
diff
changeset
|
721 |
|
14952 | 722 |
// http://www.w3.org/TR/html401/types.html#type-name |
723 |
private static final Pattern validName = Pattern.compile("[A-Za-z][A-Za-z0-9-_:.]*"); |
|
724 |
||
18001 | 725 |
private static final Pattern validNumber = Pattern.compile("-?[0-9]+"); |
726 |
||
14952 | 727 |
// pattern to remove leading {@docRoot}/? |
728 |
private static final Pattern docRoot = Pattern.compile("(?i)(\\{@docRoot *\\}/?)?(.*)"); |
|
729 |
||
730 |
private String getAttrValue(AttributeTree tree) { |
|
731 |
if (tree.getValue() == null) |
|
732 |
return null; |
|
733 |
||
734 |
StringWriter sw = new StringWriter(); |
|
735 |
try { |
|
736 |
new DocPretty(sw).print(tree.getValue()); |
|
737 |
} catch (IOException e) { |
|
738 |
// cannot happen |
|
739 |
} |
|
740 |
// ignore potential use of entities for now |
|
741 |
return sw.toString(); |
|
742 |
} |
|
743 |
||
744 |
private void checkURI(AttributeTree tree, String uri) { |
|
43261 | 745 |
// allow URIs beginning with javascript:, which would otherwise be rejected by the URI API. |
746 |
if (uri.startsWith("javascript:")) |
|
747 |
return; |
|
14952 | 748 |
try { |
749 |
URI u = new URI(uri); |
|
750 |
} catch (URISyntaxException e) { |
|
751 |
env.messages.error(HTML, tree, "dc.invalid.uri", uri); |
|
752 |
} |
|
753 |
} |
|
754 |
// </editor-fold> |
|
755 |
||
756 |
// <editor-fold defaultstate="collapsed" desc="javadoc tags"> |
|
757 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
758 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 759 |
public Void visitAuthor(AuthorTree tree, Void ignore) { |
760 |
warnIfEmpty(tree, tree.getName()); |
|
761 |
return super.visitAuthor(tree, ignore); |
|
762 |
} |
|
763 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
764 |
@Override @DefinedBy(Api.COMPILER_TREE) |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
765 |
public Void visitDocRoot(DocRootTree tree, Void ignore) { |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
766 |
markEnclosingTag(Flag.HAS_INLINE_TAG); |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
767 |
return super.visitDocRoot(tree, ignore); |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
768 |
} |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
769 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
770 |
@Override @DefinedBy(Api.COMPILER_TREE) |
52648
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
771 |
public Void visitIndex(IndexTree tree, Void ignore) { |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
772 |
for (TagStackItem tsi : tagStack) { |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
773 |
if (tsi.tag == HtmlTag.A) { |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
774 |
env.messages.warning(HTML, tree, "dc.tag.a.within.a", |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
775 |
"{@" + tree.getTagName() + "}"); |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
776 |
break; |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
777 |
} |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
778 |
} |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
779 |
return super.visitIndex(tree, ignore); |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
780 |
} |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
781 |
|
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
782 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 783 |
public Void visitInheritDoc(InheritDocTree tree, Void ignore) { |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
784 |
markEnclosingTag(Flag.HAS_INLINE_TAG); |
14952 | 785 |
// TODO: verify on overridden method |
786 |
foundInheritDoc = true; |
|
787 |
return super.visitInheritDoc(tree, ignore); |
|
788 |
} |
|
789 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
790 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 791 |
public Void visitLink(LinkTree tree, Void ignore) { |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
792 |
markEnclosingTag(Flag.HAS_INLINE_TAG); |
14952 | 793 |
// simulate inline context on tag stack |
794 |
HtmlTag t = (tree.getKind() == DocTree.Kind.LINK) |
|
795 |
? HtmlTag.CODE : HtmlTag.SPAN; |
|
796 |
tagStack.push(new TagStackItem(tree, t)); |
|
797 |
try { |
|
798 |
return super.visitLink(tree, ignore); |
|
799 |
} finally { |
|
800 |
tagStack.pop(); |
|
801 |
} |
|
802 |
} |
|
803 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
804 |
@Override @DefinedBy(Api.COMPILER_TREE) |
15363 | 805 |
public Void visitLiteral(LiteralTree tree, Void ignore) { |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
806 |
markEnclosingTag(Flag.HAS_INLINE_TAG); |
15363 | 807 |
if (tree.getKind() == DocTree.Kind.CODE) { |
808 |
for (TagStackItem tsi: tagStack) { |
|
809 |
if (tsi.tag == HtmlTag.CODE) { |
|
15366
545307ec740c
8006228: Doclint doesn't detect <code> {@code nested inline} </code>
jjg
parents:
15363
diff
changeset
|
810 |
env.messages.warning(HTML, tree, "dc.tag.code.within.code"); |
15363 | 811 |
break; |
812 |
} |
|
813 |
} |
|
814 |
} |
|
815 |
return super.visitLiteral(tree, ignore); |
|
816 |
} |
|
817 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
818 |
@Override @DefinedBy(Api.COMPILER_TREE) |
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
819 |
@SuppressWarnings("fallthrough") |
14952 | 820 |
public Void visitParam(ParamTree tree, Void ignore) { |
821 |
boolean typaram = tree.isTypeParameter(); |
|
822 |
IdentifierTree nameTree = tree.getName(); |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
823 |
Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null; |
14952 | 824 |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
825 |
if (paramElement == null) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
826 |
switch (env.currElement.getKind()) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
827 |
case CLASS: case INTERFACE: { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
828 |
if (!typaram) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
829 |
env.messages.error(REFERENCE, tree, "dc.invalid.param"); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
830 |
break; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
831 |
} |
14952 | 832 |
} |
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
833 |
case METHOD: case CONSTRUCTOR: { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
834 |
env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found"); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
835 |
break; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
836 |
} |
14952 | 837 |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
838 |
default: |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
839 |
env.messages.error(REFERENCE, tree, "dc.invalid.param"); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
840 |
break; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
841 |
} |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
842 |
} else { |
43374
d312a15c5fcf
8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents:
43261
diff
changeset
|
843 |
boolean unique = foundParams.add(paramElement); |
d312a15c5fcf
8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents:
43261
diff
changeset
|
844 |
|
d312a15c5fcf
8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents:
43261
diff
changeset
|
845 |
if (!unique) { |
d312a15c5fcf
8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents:
43261
diff
changeset
|
846 |
env.messages.warning(REFERENCE, tree, "dc.exists.param", nameTree); |
d312a15c5fcf
8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents:
43261
diff
changeset
|
847 |
} |
14952 | 848 |
} |
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
849 |
|
14952 | 850 |
warnIfEmpty(tree, tree.getDescription()); |
851 |
return super.visitParam(tree, ignore); |
|
852 |
} |
|
853 |
||
854 |
private void checkParamsDocumented(List<? extends Element> list) { |
|
855 |
if (foundInheritDoc) |
|
856 |
return; |
|
857 |
||
858 |
for (Element e: list) { |
|
859 |
if (!foundParams.contains(e)) { |
|
860 |
CharSequence paramName = (e.getKind() == ElementKind.TYPE_PARAMETER) |
|
861 |
? "<" + e.getSimpleName() + ">" |
|
862 |
: e.getSimpleName(); |
|
863 |
reportMissing("dc.missing.param", paramName); |
|
864 |
} |
|
865 |
} |
|
866 |
} |
|
867 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
868 |
@Override @DefinedBy(Api.COMPILER_TREE) |
42831
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
869 |
public Void visitProvides(ProvidesTree tree, Void ignore) { |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
870 |
Element e = env.trees.getElement(env.currPath); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
871 |
if (e.getKind() != ElementKind.MODULE) { |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
872 |
env.messages.error(REFERENCE, tree, "dc.invalid.provides"); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
873 |
} |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
874 |
ReferenceTree serviceType = tree.getServiceType(); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
875 |
Element se = env.trees.getElement(new DocTreePath(getCurrentPath(), serviceType)); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
876 |
if (se == null) { |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
877 |
env.messages.error(REFERENCE, tree, "dc.service.not.found"); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
878 |
} |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
879 |
return super.visitProvides(tree, ignore); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
880 |
} |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
881 |
|
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
882 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 883 |
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
|
884 |
String sig = tree.getSignature(); |
52664
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
885 |
if (sig.contains("<") || sig.contains(">")) { |
20256
9154c5cc0d9f
8002154: [doclint] doclint should check for issues which are errors in javadoc
jjg
parents:
20255
diff
changeset
|
886 |
env.messages.error(REFERENCE, tree, "dc.type.arg.not.allowed"); |
52664
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
887 |
} else if (isArrayType(sig)) { |
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
888 |
env.messages.error(REFERENCE, tree, "dc.array.type.not.allowed"); |
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
889 |
} else { |
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
890 |
Element e = env.trees.getElement(getCurrentPath()); |
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
891 |
if (e == null) |
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
892 |
env.messages.error(REFERENCE, tree, "dc.ref.not.found"); |
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
893 |
} |
14952 | 894 |
return super.visitReference(tree, ignore); |
895 |
} |
|
896 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
897 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 898 |
public Void visitReturn(ReturnTree tree, Void ignore) { |
43374
d312a15c5fcf
8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents:
43261
diff
changeset
|
899 |
if (foundReturn) { |
d312a15c5fcf
8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents:
43261
diff
changeset
|
900 |
env.messages.warning(REFERENCE, tree, "dc.exists.return"); |
d312a15c5fcf
8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents:
43261
diff
changeset
|
901 |
} |
d312a15c5fcf
8081820: javadoc does not report warnings in case of multiple "@param" tags for the same parameter and multiple "@return" tags for the same method.
jjg
parents:
43261
diff
changeset
|
902 |
|
14952 | 903 |
Element e = env.trees.getElement(env.currPath); |
904 |
if (e.getKind() != ElementKind.METHOD |
|
905 |
|| ((ExecutableElement) e).getReturnType().getKind() == TypeKind.VOID) |
|
906 |
env.messages.error(REFERENCE, tree, "dc.invalid.return"); |
|
907 |
foundReturn = true; |
|
908 |
warnIfEmpty(tree, tree.getDescription()); |
|
909 |
return super.visitReturn(tree, ignore); |
|
910 |
} |
|
911 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
912 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 913 |
public Void visitSerialData(SerialDataTree tree, Void ignore) { |
914 |
warnIfEmpty(tree, tree.getDescription()); |
|
915 |
return super.visitSerialData(tree, ignore); |
|
916 |
} |
|
917 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
918 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 919 |
public Void visitSerialField(SerialFieldTree tree, Void ignore) { |
920 |
warnIfEmpty(tree, tree.getDescription()); |
|
921 |
return super.visitSerialField(tree, ignore); |
|
922 |
} |
|
923 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
924 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 925 |
public Void visitSince(SinceTree tree, Void ignore) { |
926 |
warnIfEmpty(tree, tree.getBody()); |
|
927 |
return super.visitSince(tree, ignore); |
|
928 |
} |
|
929 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
930 |
@Override @DefinedBy(Api.COMPILER_TREE) |
46184
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
931 |
public Void visitSummary(SummaryTree node, Void aVoid) { |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
932 |
int idx = env.currDocComment.getFullBody().indexOf(node); |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
933 |
// Warn if the node is preceded by non-whitespace characters, |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
934 |
// or other non-text nodes. |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
935 |
if ((idx == 1 && hasNonWhitespaceText) || idx > 1) { |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
936 |
env.messages.warning(SYNTAX, node, "dc.invalid.summary", node.getTagName()); |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
937 |
} |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
938 |
return super.visitSummary(node, aVoid); |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
939 |
} |
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
940 |
|
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
941 |
@Override @DefinedBy(Api.COMPILER_TREE) |
52648
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
942 |
public Void visitSystemProperty(SystemPropertyTree tree, Void ignore) { |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
943 |
for (TagStackItem tsi : tagStack) { |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
944 |
if (tsi.tag == HtmlTag.A) { |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
945 |
env.messages.warning(HTML, tree, "dc.tag.a.within.a", |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
946 |
"{@" + tree.getTagName() + "}"); |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
947 |
break; |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
948 |
} |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
949 |
} |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
950 |
return super.visitSystemProperty(tree, ignore); |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
951 |
} |
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
952 |
|
12956ca371c2
8213819: doclint should warn against {@index} inside <a> tag
pmuthuswamy
parents:
47216
diff
changeset
|
953 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 954 |
public Void visitThrows(ThrowsTree tree, Void ignore) { |
955 |
ReferenceTree exName = tree.getExceptionName(); |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
16799
diff
changeset
|
956 |
Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); |
14952 | 957 |
if (ex == null) { |
958 |
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
|
959 |
} else if (isThrowable(ex.asType())) { |
14952 | 960 |
switch (env.currElement.getKind()) { |
961 |
case CONSTRUCTOR: |
|
962 |
case METHOD: |
|
963 |
if (isCheckedException(ex.asType())) { |
|
964 |
ExecutableElement ee = (ExecutableElement) env.currElement; |
|
965 |
checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes()); |
|
966 |
} |
|
967 |
break; |
|
968 |
default: |
|
969 |
env.messages.error(REFERENCE, tree, "dc.invalid.throws"); |
|
970 |
} |
|
971 |
} else { |
|
972 |
env.messages.error(REFERENCE, tree, "dc.invalid.throws"); |
|
973 |
} |
|
974 |
warnIfEmpty(tree, tree.getDescription()); |
|
975 |
return scan(tree.getDescription(), ignore); |
|
976 |
} |
|
977 |
||
52664
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
978 |
private boolean isArrayType(String signature) { |
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
979 |
int brackets = signature.indexOf('['); |
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
980 |
int parens = signature.indexOf('('); |
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
981 |
return brackets >= 0 && (parens < 0 || brackets < parens); |
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
982 |
} |
15fc92f4ae9a
8200432: javadoc fails with ClassCastException on {@link byte[]}
hannesw
parents:
52648
diff
changeset
|
983 |
|
19125
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
984 |
private boolean isThrowable(TypeMirror tm) { |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
985 |
switch (tm.getKind()) { |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
986 |
case DECLARED: |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
987 |
case TYPEVAR: |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
988 |
return env.types.isAssignable(tm, env.java_lang_Throwable); |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
989 |
} |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
990 |
return false; |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
991 |
} |
db8cab0ecbd9
8020556: doclint does not check type variables for @throws
jjg
parents:
19123
diff
changeset
|
992 |
|
14952 | 993 |
private void checkThrowsDeclared(ReferenceTree tree, TypeMirror t, List<? extends TypeMirror> list) { |
994 |
boolean found = false; |
|
995 |
for (TypeMirror tl : list) { |
|
996 |
if (env.types.isAssignable(t, tl)) { |
|
997 |
foundThrows.add(tl); |
|
998 |
found = true; |
|
999 |
} |
|
1000 |
} |
|
1001 |
if (!found) |
|
1002 |
env.messages.error(REFERENCE, tree, "dc.exception.not.thrown", t); |
|
1003 |
} |
|
1004 |
||
1005 |
private void checkThrowsDocumented(List<? extends TypeMirror> list) { |
|
1006 |
if (foundInheritDoc) |
|
1007 |
return; |
|
1008 |
||
1009 |
for (TypeMirror tl: list) { |
|
1010 |
if (isCheckedException(tl) && !foundThrows.contains(tl)) |
|
1011 |
reportMissing("dc.missing.throws", tl); |
|
1012 |
} |
|
1013 |
} |
|
1014 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1015 |
@Override @DefinedBy(Api.COMPILER_TREE) |
21500
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1016 |
public Void visitUnknownBlockTag(UnknownBlockTagTree tree, Void ignore) { |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1017 |
checkUnknownTag(tree, tree.getTagName()); |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1018 |
return super.visitUnknownBlockTag(tree, ignore); |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1019 |
} |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1020 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1021 |
@Override @DefinedBy(Api.COMPILER_TREE) |
21500
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1022 |
public Void visitUnknownInlineTag(UnknownInlineTagTree tree, Void ignore) { |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1023 |
checkUnknownTag(tree, tree.getTagName()); |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1024 |
return super.visitUnknownInlineTag(tree, ignore); |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1025 |
} |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1026 |
|
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1027 |
private void checkUnknownTag(DocTree tree, String tagName) { |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1028 |
if (env.customTags != null && !env.customTags.contains(tagName)) |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1029 |
env.messages.error(SYNTAX, tree, "dc.tag.unknown", tagName); |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1030 |
} |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
21017
diff
changeset
|
1031 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1032 |
@Override @DefinedBy(Api.COMPILER_TREE) |
42831
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1033 |
public Void visitUses(UsesTree tree, Void ignore) { |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1034 |
Element e = env.trees.getElement(env.currPath); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1035 |
if (e.getKind() != ElementKind.MODULE) { |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1036 |
env.messages.error(REFERENCE, tree, "dc.invalid.uses"); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1037 |
} |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1038 |
ReferenceTree serviceType = tree.getServiceType(); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1039 |
Element se = env.trees.getElement(new DocTreePath(getCurrentPath(), serviceType)); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1040 |
if (se == null) { |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1041 |
env.messages.error(REFERENCE, tree, "dc.service.not.found"); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1042 |
} |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1043 |
return super.visitUses(tree, ignore); |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1044 |
} |
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1045 |
|
feff6f296019
8160196: Module summary page should display information based on "api" or "detail" mode.
bpatel
parents:
36045
diff
changeset
|
1046 |
@Override @DefinedBy(Api.COMPILER_TREE) |
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
1047 |
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
|
1048 |
ReferenceTree ref = tree.getReference(); |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1049 |
if (ref == null || ref.getSignature().isEmpty()) { |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1050 |
if (!isConstant(env.currElement)) |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1051 |
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
|
1052 |
} else { |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1053 |
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
|
1054 |
if (!isConstant(e)) |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1055 |
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
|
1056 |
} |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1057 |
|
16562
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
1058 |
markEnclosingTag(Flag.HAS_INLINE_TAG); |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
1059 |
return super.visitValue(tree, ignore); |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
1060 |
} |
9f09744e221a
8010317: DocLint incorrectly reports some <pre> tags as empty
jjg
parents:
15707
diff
changeset
|
1061 |
|
20255
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1062 |
private boolean isConstant(Element e) { |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1063 |
if (e == null) |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1064 |
return false; |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1065 |
|
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1066 |
switch (e.getKind()) { |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1067 |
case FIELD: |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1068 |
Object value = ((VariableElement) e).getConstantValue(); |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1069 |
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
|
1070 |
default: |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1071 |
return false; |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1072 |
} |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1073 |
} |
f8be1ea20e1a
8025272: doclint needs to check for valid usage of @value tag
jjg
parents:
20254
diff
changeset
|
1074 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1075 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 1076 |
public Void visitVersion(VersionTree tree, Void ignore) { |
1077 |
warnIfEmpty(tree, tree.getBody()); |
|
1078 |
return super.visitVersion(tree, ignore); |
|
1079 |
} |
|
1080 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1081 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 1082 |
public Void visitErroneous(ErroneousTree tree, Void ignore) { |
1083 |
env.messages.error(SYNTAX, tree, null, tree.getDiagnostic().getMessage(null)); |
|
1084 |
return null; |
|
1085 |
} |
|
1086 |
// </editor-fold> |
|
1087 |
||
1088 |
// <editor-fold defaultstate="collapsed" desc="Utility methods"> |
|
1089 |
||
1090 |
private boolean isCheckedException(TypeMirror t) { |
|
1091 |
return !(env.types.isAssignable(t, env.java_lang_Error) |
|
1092 |
|| env.types.isAssignable(t, env.java_lang_RuntimeException)); |
|
1093 |
} |
|
1094 |
||
1095 |
private boolean isSynthetic() { |
|
1096 |
switch (env.currElement.getKind()) { |
|
1097 |
case CONSTRUCTOR: |
|
1098 |
// A synthetic default constructor has the same pos as the |
|
1099 |
// enclosing class |
|
1100 |
TreePath p = env.currPath; |
|
1101 |
return env.getPos(p) == env.getPos(p.getParentPath()); |
|
1102 |
} |
|
1103 |
return false; |
|
1104 |
} |
|
1105 |
||
1106 |
void markEnclosingTag(Flag flag) { |
|
1107 |
TagStackItem top = tagStack.peek(); |
|
1108 |
if (top != null) |
|
1109 |
top.flags.add(flag); |
|
1110 |
} |
|
1111 |
||
1112 |
String toString(TreePath p) { |
|
1113 |
StringBuilder sb = new StringBuilder("TreePath["); |
|
1114 |
toString(p, sb); |
|
1115 |
sb.append("]"); |
|
1116 |
return sb.toString(); |
|
1117 |
} |
|
1118 |
||
1119 |
void toString(TreePath p, StringBuilder sb) { |
|
1120 |
TreePath parent = p.getParentPath(); |
|
1121 |
if (parent != null) { |
|
1122 |
toString(parent, sb); |
|
1123 |
sb.append(","); |
|
1124 |
} |
|
1125 |
sb.append(p.getLeaf().getKind()).append(":").append(env.getPos(p)).append(":S").append(env.getStartPos(p)); |
|
1126 |
} |
|
1127 |
||
1128 |
void warnIfEmpty(DocTree tree, List<? extends DocTree> list) { |
|
1129 |
for (DocTree d: list) { |
|
1130 |
switch (d.getKind()) { |
|
1131 |
case TEXT: |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
1132 |
if (hasNonWhitespace((TextTree) d)) |
14952 | 1133 |
return; |
1134 |
break; |
|
1135 |
default: |
|
1136 |
return; |
|
1137 |
} |
|
1138 |
} |
|
1139 |
env.messages.warning(SYNTAX, tree, "dc.empty", tree.getKind().tagName); |
|
1140 |
} |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
1141 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
1142 |
boolean hasNonWhitespace(TextTree tree) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
1143 |
String s = tree.getBody(); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
1144 |
for (int i = 0; i < s.length(); i++) { |
46184
f1325703ea85
8173425: Javadoc needs a new tag to specify the summary.
ksrini
parents:
43374
diff
changeset
|
1145 |
Character c = s.charAt(i); |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
1146 |
if (!Character.isWhitespace(s.charAt(i))) |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
1147 |
return true; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
1148 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
1149 |
return false; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
1150 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
1151 |
|
14952 | 1152 |
// </editor-fold> |
1153 |
||
1154 |
} |