author | rkennke |
Fri, 12 Oct 2018 16:25:24 +0200 | |
changeset 52107 | 0c1e44da019c |
parent 48441 | 9c37fbceb579 |
child 54135 | 67f72165dca5 |
permissions | -rw-r--r-- |
14952 | 1 |
/* |
48441
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2012, 2018, 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 |
||
28 |
import java.io.File; |
|
29 |
import java.io.IOException; |
|
30 |
import java.io.PrintWriter; |
|
31 |
import java.util.ArrayList; |
|
20235
7834123e35dc
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents:
19123
diff
changeset
|
32 |
import java.util.LinkedList; |
14952 | 33 |
import java.util.List; |
20235
7834123e35dc
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents:
19123
diff
changeset
|
34 |
import java.util.Queue; |
14952 | 35 |
|
36 |
import javax.lang.model.element.Name; |
|
37 |
import javax.tools.StandardLocation; |
|
38 |
||
39 |
import com.sun.source.doctree.DocCommentTree; |
|
48441
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
40 |
import com.sun.source.tree.BlockTree; |
14952 | 41 |
import com.sun.source.tree.ClassTree; |
42 |
import com.sun.source.tree.CompilationUnitTree; |
|
48441
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
43 |
import com.sun.source.tree.LambdaExpressionTree; |
40507
4413083331c7
8162576: Missing doclint check missing for modules
sadayapalam
parents:
36526
diff
changeset
|
44 |
import com.sun.source.tree.ModuleTree; |
24069 | 45 |
import com.sun.source.tree.PackageTree; |
14952 | 46 |
import com.sun.source.tree.MethodTree; |
47 |
import com.sun.source.tree.Tree; |
|
48 |
import com.sun.source.tree.VariableTree; |
|
49 |
import com.sun.source.util.JavacTask; |
|
50 |
import com.sun.source.util.Plugin; |
|
51 |
import com.sun.source.util.TaskEvent; |
|
52 |
import com.sun.source.util.TaskListener; |
|
53 |
import com.sun.source.util.TreePath; |
|
54 |
import com.sun.source.util.TreePathScanner; |
|
55 |
import com.sun.tools.javac.api.JavacTaskImpl; |
|
56 |
import com.sun.tools.javac.api.JavacTool; |
|
57 |
import com.sun.tools.javac.file.JavacFileManager; |
|
58 |
import com.sun.tools.javac.main.JavaCompiler; |
|
59 |
import com.sun.tools.javac.util.Context; |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
26264
diff
changeset
|
60 |
import com.sun.tools.javac.util.DefinedBy; |
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
26264
diff
changeset
|
61 |
import com.sun.tools.javac.util.DefinedBy.Api; |
14952 | 62 |
|
63 |
/** |
|
64 |
* Multi-function entry point for the doc check utility. |
|
65 |
* |
|
66 |
* This class can be invoked in the following ways: |
|
67 |
* <ul> |
|
68 |
* <li>From the command line |
|
69 |
* <li>From javac, as a plugin |
|
70 |
* <li>Directly, via a simple API |
|
71 |
* </ul> |
|
72 |
* |
|
73 |
* <p><b>This is NOT part of any supported API. |
|
74 |
* If you write code that depends on this, you do so at your own |
|
75 |
* risk. This code and its internal interfaces are subject to change |
|
76 |
* or deletion without notice.</b></p> |
|
77 |
*/ |
|
78 |
public class DocLint implements Plugin { |
|
79 |
||
80 |
public static final String XMSGS_OPTION = "-Xmsgs"; |
|
81 |
public static final String XMSGS_CUSTOM_PREFIX = "-Xmsgs:"; |
|
82 |
private static final String STATS = "-stats"; |
|
16799
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
15370
diff
changeset
|
83 |
public static final String XIMPLICIT_HEADERS = "-XimplicitHeaders:"; |
21500
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
20235
diff
changeset
|
84 |
public static final String XCUSTOM_TAGS_PREFIX = "-XcustomTags:"; |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
85 |
public static final String XHTML_VERSION_PREFIX = "-XhtmlVersion:"; |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
86 |
public static final String XCHECK_PACKAGE = "-XcheckPackage:"; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
87 |
public static final String SEPARATOR = ","; |
14952 | 88 |
|
89 |
// <editor-fold defaultstate="collapsed" desc="Command-line entry point"> |
|
90 |
public static void main(String... args) { |
|
18004
dcf9d59b1635
8006615: [doclint] move remaining messages into resource bundle
jjg
parents:
16799
diff
changeset
|
91 |
DocLint dl = new DocLint(); |
14952 | 92 |
try { |
18004
dcf9d59b1635
8006615: [doclint] move remaining messages into resource bundle
jjg
parents:
16799
diff
changeset
|
93 |
dl.run(args); |
14952 | 94 |
} catch (BadArgs e) { |
95 |
System.err.println(e.getMessage()); |
|
96 |
System.exit(1); |
|
97 |
} catch (IOException e) { |
|
18004
dcf9d59b1635
8006615: [doclint] move remaining messages into resource bundle
jjg
parents:
16799
diff
changeset
|
98 |
System.err.println(dl.localize("dc.main.ioerror", e.getLocalizedMessage())); |
14952 | 99 |
System.exit(2); |
100 |
} |
|
101 |
} |
|
102 |
||
103 |
// </editor-fold> |
|
104 |
||
105 |
// <editor-fold defaultstate="collapsed" desc="Simple API"> |
|
106 |
||
18004
dcf9d59b1635
8006615: [doclint] move remaining messages into resource bundle
jjg
parents:
16799
diff
changeset
|
107 |
public class BadArgs extends Exception { |
14952 | 108 |
private static final long serialVersionUID = 0; |
109 |
BadArgs(String code, Object... args) { |
|
18004
dcf9d59b1635
8006615: [doclint] move remaining messages into resource bundle
jjg
parents:
16799
diff
changeset
|
110 |
super(localize(code, args)); |
14952 | 111 |
this.code = code; |
112 |
this.args = args; |
|
113 |
} |
|
114 |
||
115 |
final String code; |
|
116 |
final Object[] args; |
|
117 |
} |
|
118 |
||
119 |
/** |
|
120 |
* Simple API entry point. |
|
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
121 |
* @param args Options and operands for doclint |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
122 |
* @throws BadArgs if an error is detected in any args |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
123 |
* @throws IOException if there are problems with any of the file arguments |
14952 | 124 |
*/ |
125 |
public void run(String... args) throws BadArgs, IOException { |
|
126 |
PrintWriter out = new PrintWriter(System.out); |
|
127 |
try { |
|
128 |
run(out, args); |
|
129 |
} finally { |
|
130 |
out.flush(); |
|
131 |
} |
|
132 |
} |
|
133 |
||
134 |
public void run(PrintWriter out, String... args) throws BadArgs, IOException { |
|
135 |
env = new Env(); |
|
136 |
processArgs(args); |
|
137 |
||
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
138 |
boolean noFiles = javacFiles.isEmpty(); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
139 |
if (needHelp) { |
14952 | 140 |
showHelp(out); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
141 |
if (noFiles) |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
142 |
return; |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
143 |
} else if (noFiles) { |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
144 |
out.println(localize("dc.main.no.files.given")); |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
145 |
return; |
14952 | 146 |
} |
147 |
||
148 |
JavacTool tool = JavacTool.create(); |
|
149 |
||
150 |
JavacFileManager fm = new JavacFileManager(new Context(), false, null); |
|
151 |
fm.setSymbolFileEnabled(false); |
|
44822 | 152 |
if (javacBootClassPath != null) { |
153 |
fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, javacBootClassPath); |
|
154 |
} |
|
155 |
if (javacClassPath != null) { |
|
156 |
fm.setLocation(StandardLocation.CLASS_PATH, javacClassPath); |
|
157 |
} |
|
158 |
if (javacSourcePath != null) { |
|
159 |
fm.setLocation(StandardLocation.SOURCE_PATH, javacSourcePath); |
|
160 |
} |
|
14952 | 161 |
|
162 |
JavacTask task = tool.getTask(out, fm, null, javacOpts, null, |
|
163 |
fm.getJavaFileObjectsFromFiles(javacFiles)); |
|
164 |
Iterable<? extends CompilationUnitTree> units = task.parse(); |
|
165 |
((JavacTaskImpl) task).enter(); |
|
166 |
||
167 |
env.init(task); |
|
168 |
checker = new Checker(env); |
|
169 |
||
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
170 |
DeclScanner ds = new DeclScanner(env) { |
14952 | 171 |
@Override |
172 |
void visitDecl(Tree tree, Name name) { |
|
173 |
TreePath p = getCurrentPath(); |
|
174 |
DocCommentTree dc = env.trees.getDocCommentTree(p); |
|
175 |
||
176 |
checker.scan(dc, p); |
|
177 |
} |
|
178 |
}; |
|
179 |
||
180 |
ds.scan(units, null); |
|
181 |
||
182 |
reportStats(out); |
|
183 |
||
184 |
Context ctx = ((JavacTaskImpl) task).getContext(); |
|
185 |
JavaCompiler c = JavaCompiler.instance(ctx); |
|
186 |
c.printCount("error", c.errorCount()); |
|
187 |
c.printCount("warn", c.warningCount()); |
|
188 |
} |
|
189 |
||
190 |
void processArgs(String... args) throws BadArgs { |
|
19121
c626ed0c6ab0
8020664: doclint gives incorrect warnings on normal package statements
jjg
parents:
18908
diff
changeset
|
191 |
javacOpts = new ArrayList<>(); |
c626ed0c6ab0
8020664: doclint gives incorrect warnings on normal package statements
jjg
parents:
18908
diff
changeset
|
192 |
javacFiles = new ArrayList<>(); |
14952 | 193 |
|
194 |
if (args.length == 0) |
|
195 |
needHelp = true; |
|
196 |
||
197 |
for (int i = 0; i < args.length; i++) { |
|
198 |
String arg = args[i]; |
|
199 |
if (arg.matches("-Xmax(errs|warns)") && i + 1 < args.length) { |
|
200 |
if (args[++i].matches("[0-9]+")) { |
|
201 |
javacOpts.add(arg); |
|
202 |
javacOpts.add(args[i]); |
|
203 |
} else { |
|
204 |
throw new BadArgs("dc.bad.value.for.option", arg, args[i]); |
|
205 |
} |
|
36526 | 206 |
} else if ((arg.equals("-target") || arg.equals("-source")) && i + 1 < args.length) { |
207 |
javacOpts.add(arg); |
|
208 |
javacOpts.add(args[++i]); |
|
14952 | 209 |
} else if (arg.equals(STATS)) { |
210 |
env.messages.setStatsEnabled(true); |
|
15370 | 211 |
} else if (arg.equals("-bootclasspath") && i + 1 < args.length) { |
14952 | 212 |
javacBootClassPath = splitPath(args[++i]); |
15370 | 213 |
} else if (arg.equals("-classpath") && i + 1 < args.length) { |
14952 | 214 |
javacClassPath = splitPath(args[++i]); |
18898
0eab5f5e3d1d
8009924: some langtools tools do not accept -cp as an alias for -classpath
vromero
parents:
18004
diff
changeset
|
215 |
} else if (arg.equals("-cp") && i + 1 < args.length) { |
0eab5f5e3d1d
8009924: some langtools tools do not accept -cp as an alias for -classpath
vromero
parents:
18004
diff
changeset
|
216 |
javacClassPath = splitPath(args[++i]); |
15370 | 217 |
} else if (arg.equals("-sourcepath") && i + 1 < args.length) { |
14952 | 218 |
javacSourcePath = splitPath(args[++i]); |
219 |
} else if (arg.equals(XMSGS_OPTION)) { |
|
220 |
env.messages.setOptions(null); |
|
221 |
} else if (arg.startsWith(XMSGS_CUSTOM_PREFIX)) { |
|
222 |
env.messages.setOptions(arg.substring(arg.indexOf(":") + 1)); |
|
21500
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
20235
diff
changeset
|
223 |
} else if (arg.startsWith(XCUSTOM_TAGS_PREFIX)) { |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
20235
diff
changeset
|
224 |
env.setCustomTags(arg.substring(arg.indexOf(":") + 1)); |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
225 |
} else if (arg.startsWith(XHTML_VERSION_PREFIX)) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
226 |
String argsVersion = arg.substring(arg.indexOf(":") + 1); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
227 |
HtmlVersion htmlVersion = HtmlVersion.getHtmlVersion(argsVersion); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
228 |
if (htmlVersion != null) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
229 |
env.setHtmlVersion(htmlVersion); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
230 |
} else { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
231 |
throw new BadArgs("dc.bad.value.for.option", arg, argsVersion); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
232 |
} |
14952 | 233 |
} else if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help") |
234 |
|| arg.equals("-?") || arg.equals("-usage")) { |
|
235 |
needHelp = true; |
|
236 |
} else if (arg.startsWith("-")) { |
|
237 |
throw new BadArgs("dc.bad.option", arg); |
|
238 |
} else { |
|
239 |
while (i < args.length) |
|
240 |
javacFiles.add(new File(args[i++])); |
|
241 |
} |
|
242 |
} |
|
243 |
} |
|
244 |
||
245 |
void showHelp(PrintWriter out) { |
|
18004
dcf9d59b1635
8006615: [doclint] move remaining messages into resource bundle
jjg
parents:
16799
diff
changeset
|
246 |
String msg = localize("dc.main.usage"); |
dcf9d59b1635
8006615: [doclint] move remaining messages into resource bundle
jjg
parents:
16799
diff
changeset
|
247 |
for (String line: msg.split("\n")) |
dcf9d59b1635
8006615: [doclint] move remaining messages into resource bundle
jjg
parents:
16799
diff
changeset
|
248 |
out.println(line); |
14952 | 249 |
} |
250 |
||
251 |
List<File> splitPath(String path) { |
|
19121
c626ed0c6ab0
8020664: doclint gives incorrect warnings on normal package statements
jjg
parents:
18908
diff
changeset
|
252 |
List<File> files = new ArrayList<>(); |
15370 | 253 |
for (String f: path.split(File.pathSeparator)) { |
14952 | 254 |
if (f.length() > 0) |
255 |
files.add(new File(f)); |
|
256 |
} |
|
257 |
return files; |
|
258 |
} |
|
259 |
||
260 |
List<File> javacBootClassPath; |
|
261 |
List<File> javacClassPath; |
|
262 |
List<File> javacSourcePath; |
|
263 |
List<String> javacOpts; |
|
264 |
List<File> javacFiles; |
|
265 |
boolean needHelp = false; |
|
266 |
||
267 |
// </editor-fold> |
|
268 |
||
269 |
// <editor-fold defaultstate="collapsed" desc="javac Plugin"> |
|
270 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
26264
diff
changeset
|
271 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 272 |
public String getName() { |
273 |
return "doclint"; |
|
274 |
} |
|
275 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
26264
diff
changeset
|
276 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14955
8fe779a6d616
8005137: Rename DocLint.call to DocLint.init which overrides Plugin.init
mchung
parents:
14952
diff
changeset
|
277 |
public void init(JavacTask task, String... args) { |
14952 | 278 |
init(task, args, true); |
279 |
} |
|
280 |
||
281 |
// </editor-fold> |
|
282 |
||
283 |
// <editor-fold defaultstate="collapsed" desc="Embedding API"> |
|
284 |
||
285 |
public void init(JavacTask task, String[] args, boolean addTaskListener) { |
|
286 |
env = new Env(); |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
21500
diff
changeset
|
287 |
for (String arg : args) { |
14952 | 288 |
if (arg.equals(XMSGS_OPTION)) { |
289 |
env.messages.setOptions(null); |
|
290 |
} else if (arg.startsWith(XMSGS_CUSTOM_PREFIX)) { |
|
291 |
env.messages.setOptions(arg.substring(arg.indexOf(":") + 1)); |
|
16799
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
15370
diff
changeset
|
292 |
} else if (arg.matches(XIMPLICIT_HEADERS + "[1-6]")) { |
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
15370
diff
changeset
|
293 |
char ch = arg.charAt(arg.length() - 1); |
fbe4d27b8791
8006346: doclint should make allowance for headers generated by standard doclet
jjg
parents:
15370
diff
changeset
|
294 |
env.setImplicitHeaders(Character.digit(ch, 10)); |
21500
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
20235
diff
changeset
|
295 |
} else if (arg.startsWith(XCUSTOM_TAGS_PREFIX)) { |
475e59d3b40c
8006248: Since addition of -Xdoclint, javadoc ignores unknown tags
bpatel
parents:
20235
diff
changeset
|
296 |
env.setCustomTags(arg.substring(arg.indexOf(":") + 1)); |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
297 |
} else if (arg.startsWith(XHTML_VERSION_PREFIX)) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
298 |
String argsVersion = arg.substring(arg.indexOf(":") + 1); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
299 |
HtmlVersion htmlVersion = HtmlVersion.getHtmlVersion(argsVersion); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
300 |
if (htmlVersion != null) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
301 |
env.setHtmlVersion(htmlVersion); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
302 |
} else { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
303 |
throw new IllegalArgumentException(argsVersion); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
29427
diff
changeset
|
304 |
} |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
305 |
} else if (arg.startsWith(XCHECK_PACKAGE)) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
306 |
env.setCheckPackages(arg.substring(arg.indexOf(":") + 1)); |
14952 | 307 |
} else |
308 |
throw new IllegalArgumentException(arg); |
|
309 |
} |
|
310 |
env.init(task); |
|
311 |
||
312 |
checker = new Checker(env); |
|
313 |
||
314 |
if (addTaskListener) { |
|
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
315 |
final DeclScanner ds = new DeclScanner(env) { |
14952 | 316 |
@Override |
317 |
void visitDecl(Tree tree, Name name) { |
|
318 |
TreePath p = getCurrentPath(); |
|
319 |
DocCommentTree dc = env.trees.getDocCommentTree(p); |
|
320 |
||
321 |
checker.scan(dc, p); |
|
322 |
} |
|
323 |
}; |
|
324 |
||
325 |
TaskListener tl = new TaskListener() { |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
26264
diff
changeset
|
326 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 327 |
public void started(TaskEvent e) { |
20235
7834123e35dc
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents:
19123
diff
changeset
|
328 |
switch (e.getKind()) { |
7834123e35dc
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents:
19123
diff
changeset
|
329 |
case ANALYZE: |
7834123e35dc
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents:
19123
diff
changeset
|
330 |
CompilationUnitTree tree; |
7834123e35dc
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents:
19123
diff
changeset
|
331 |
while ((tree = todo.poll()) != null) |
7834123e35dc
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents:
19123
diff
changeset
|
332 |
ds.scan(tree, null); |
7834123e35dc
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents:
19123
diff
changeset
|
333 |
break; |
7834123e35dc
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents:
19123
diff
changeset
|
334 |
} |
14952 | 335 |
} |
336 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
26264
diff
changeset
|
337 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 338 |
public void finished(TaskEvent e) { |
339 |
switch (e.getKind()) { |
|
20235
7834123e35dc
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents:
19123
diff
changeset
|
340 |
case PARSE: |
7834123e35dc
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents:
19123
diff
changeset
|
341 |
todo.add(e.getCompilationUnit()); |
7834123e35dc
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents:
19123
diff
changeset
|
342 |
break; |
14952 | 343 |
} |
344 |
} |
|
20235
7834123e35dc
8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
jjg
parents:
19123
diff
changeset
|
345 |
|
22163 | 346 |
Queue<CompilationUnitTree> todo = new LinkedList<>(); |
14952 | 347 |
}; |
348 |
||
349 |
task.addTaskListener(tl); |
|
350 |
} |
|
351 |
} |
|
352 |
||
353 |
public void scan(TreePath p) { |
|
354 |
DocCommentTree dc = env.trees.getDocCommentTree(p); |
|
355 |
checker.scan(dc, p); |
|
356 |
} |
|
357 |
||
31752 | 358 |
public boolean shouldCheck(CompilationUnitTree unit) { |
359 |
return env.shouldCheck(unit); |
|
360 |
} |
|
361 |
||
14952 | 362 |
public void reportStats(PrintWriter out) { |
363 |
env.messages.reportStats(out); |
|
364 |
} |
|
365 |
||
366 |
// </editor-fold> |
|
367 |
||
368 |
Env env; |
|
369 |
Checker checker; |
|
370 |
||
371 |
public static boolean isValidOption(String opt) { |
|
372 |
if (opt.equals(XMSGS_OPTION)) |
|
373 |
return true; |
|
374 |
if (opt.startsWith(XMSGS_CUSTOM_PREFIX)) |
|
375 |
return Messages.Options.isValidOptions(opt.substring(XMSGS_CUSTOM_PREFIX.length())); |
|
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
376 |
if (opt.startsWith(XCHECK_PACKAGE)) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
377 |
return Env.validatePackages(opt.substring(opt.indexOf(":") + 1)); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
378 |
} |
14952 | 379 |
return false; |
380 |
} |
|
381 |
||
18004
dcf9d59b1635
8006615: [doclint] move remaining messages into resource bundle
jjg
parents:
16799
diff
changeset
|
382 |
private String localize(String code, Object... args) { |
dcf9d59b1635
8006615: [doclint] move remaining messages into resource bundle
jjg
parents:
16799
diff
changeset
|
383 |
Messages m = (env != null) ? env.messages : new Messages(null); |
dcf9d59b1635
8006615: [doclint] move remaining messages into resource bundle
jjg
parents:
16799
diff
changeset
|
384 |
return m.localize(code, args); |
dcf9d59b1635
8006615: [doclint] move remaining messages into resource bundle
jjg
parents:
16799
diff
changeset
|
385 |
} |
dcf9d59b1635
8006615: [doclint] move remaining messages into resource bundle
jjg
parents:
16799
diff
changeset
|
386 |
|
14952 | 387 |
// <editor-fold defaultstate="collapsed" desc="DeclScanner"> |
388 |
||
389 |
static abstract class DeclScanner extends TreePathScanner<Void, Void> { |
|
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
390 |
final Env env; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
391 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
392 |
public DeclScanner(Env env) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
393 |
this.env = env; |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
394 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
395 |
|
14952 | 396 |
abstract void visitDecl(Tree tree, Name name); |
397 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
26264
diff
changeset
|
398 |
@Override @DefinedBy(Api.COMPILER_TREE) |
24069 | 399 |
public Void visitPackage(PackageTree tree, Void ignore) { |
400 |
visitDecl(tree, null); |
|
401 |
return super.visitPackage(tree, ignore); |
|
18908 | 402 |
} |
48441
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
403 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
26264
diff
changeset
|
404 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 405 |
public Void visitClass(ClassTree tree, Void ignore) { |
406 |
visitDecl(tree, tree.getSimpleName()); |
|
407 |
return super.visitClass(tree, ignore); |
|
408 |
} |
|
409 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
26264
diff
changeset
|
410 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 411 |
public Void visitMethod(MethodTree tree, Void ignore) { |
412 |
visitDecl(tree, tree.getName()); |
|
413 |
return null; |
|
414 |
} |
|
415 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
26264
diff
changeset
|
416 |
@Override @DefinedBy(Api.COMPILER_TREE) |
40507
4413083331c7
8162576: Missing doclint check missing for modules
sadayapalam
parents:
36526
diff
changeset
|
417 |
public Void visitModule(ModuleTree tree, Void ignore) { |
4413083331c7
8162576: Missing doclint check missing for modules
sadayapalam
parents:
36526
diff
changeset
|
418 |
visitDecl(tree, null); |
4413083331c7
8162576: Missing doclint check missing for modules
sadayapalam
parents:
36526
diff
changeset
|
419 |
return super.visitModule(tree, ignore); |
4413083331c7
8162576: Missing doclint check missing for modules
sadayapalam
parents:
36526
diff
changeset
|
420 |
} |
4413083331c7
8162576: Missing doclint check missing for modules
sadayapalam
parents:
36526
diff
changeset
|
421 |
|
4413083331c7
8162576: Missing doclint check missing for modules
sadayapalam
parents:
36526
diff
changeset
|
422 |
@Override @DefinedBy(Api.COMPILER_TREE) |
14952 | 423 |
public Void visitVariable(VariableTree tree, Void ignore) { |
424 |
visitDecl(tree, tree.getName()); |
|
425 |
return super.visitVariable(tree, ignore); |
|
426 |
} |
|
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
427 |
|
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
428 |
@Override @DefinedBy(Api.COMPILER_TREE) |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
429 |
public Void visitCompilationUnit(CompilationUnitTree node, Void p) { |
31752 | 430 |
if (!env.shouldCheck(node)) { |
431 |
return null; |
|
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
432 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
433 |
return super.visitCompilationUnit(node, p); |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
434 |
} |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
26266
diff
changeset
|
435 |
|
48441
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
436 |
@Override @DefinedBy(Api.COMPILER_TREE) |
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
437 |
public Void visitBlock(BlockTree tree, Void ignore) { |
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
438 |
return null; |
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
439 |
} |
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
440 |
|
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
441 |
@Override @DefinedBy(Api.COMPILER_TREE) |
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
442 |
public Void visitLambdaExpression(LambdaExpressionTree tree, Void ignore) { |
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
443 |
return null; |
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
444 |
} |
9c37fbceb579
8194069: doclint throws missing comment warnings on lines which can't even have javadoc
jjg
parents:
47216
diff
changeset
|
445 |
|
14952 | 446 |
} |
447 |
||
448 |
// </editor-fold> |
|
449 |
||
450 |
} |