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