author | jlahoda |
Fri, 09 Mar 2018 09:42:10 +0100 | |
changeset 49197 | cc2673fa8c20 |
parent 47216 | 71c04702a3d5 |
child 52043 | 50dc6dd40e6a |
permissions | -rw-r--r-- |
10 | 1 |
/* |
43269
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
41451
diff
changeset
|
2 |
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
25 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
32163
diff
changeset
|
26 |
package jdk.javadoc.internal.tool; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
32163
diff
changeset
|
27 |
|
10 | 28 |
|
1869 | 29 |
import java.io.File; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
32163
diff
changeset
|
30 |
import java.util.ArrayList; |
23116
4c134ccd6b8d
8029145: javadoc fails with java.lang.IllegalStateException: endPosTable already set
ksrini
parents:
22163
diff
changeset
|
31 |
import java.util.HashSet; |
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
32 |
import java.util.LinkedHashSet; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
32163
diff
changeset
|
33 |
import java.util.List; |
1869 | 34 |
import java.util.Map; |
35 |
import java.util.Set; |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
23973
diff
changeset
|
36 |
|
1869 | 37 |
import javax.tools.JavaFileObject; |
38 |
import javax.tools.StandardJavaFileManager; |
|
10 | 39 |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
23973
diff
changeset
|
40 |
import com.sun.tools.javac.code.ClassFinder; |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
47216
diff
changeset
|
41 |
import com.sun.tools.javac.code.DeferredCompletionFailureHandler; |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
25874
diff
changeset
|
42 |
import com.sun.tools.javac.code.Symbol.Completer; |
1869 | 43 |
import com.sun.tools.javac.code.Symbol.CompletionFailure; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
23973
diff
changeset
|
44 |
import com.sun.tools.javac.comp.Enter; |
1869 | 45 |
import com.sun.tools.javac.tree.JCTree; |
46 |
import com.sun.tools.javac.tree.JCTree.JCClassDecl; |
|
47 |
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; |
|
48 |
import com.sun.tools.javac.util.Abort; |
|
49 |
import com.sun.tools.javac.util.Context; |
|
50 |
import com.sun.tools.javac.util.ListBuffer; |
|
51 |
import com.sun.tools.javac.util.Position; |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
32163
diff
changeset
|
52 |
import jdk.javadoc.doclet.DocletEnvironment; |
10 | 53 |
|
41451 | 54 |
import static jdk.javadoc.internal.tool.Main.Result.*; |
55 |
||
10 | 56 |
/** |
57 |
* This class could be the main entry point for Javadoc when Javadoc is used as a |
|
58 |
* component in a larger software system. It provides operations to |
|
59 |
* construct a new javadoc processor, and to run it on a set of source |
|
60 |
* files. |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
61 |
* |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
62 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
63 |
* If you write code that depends on this, you do so at your own risk. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
64 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
65 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
66 |
* |
10 | 67 |
* @author Neal Gafter |
68 |
*/ |
|
69 |
public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler { |
|
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
38619
diff
changeset
|
70 |
ToolEnvironment toolEnv; |
10 | 71 |
|
72 |
final Messager messager; |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
23973
diff
changeset
|
73 |
final ClassFinder javadocFinder; |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
47216
diff
changeset
|
74 |
final DeferredCompletionFailureHandler dcfh; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
23973
diff
changeset
|
75 |
final Enter javadocEnter; |
23973
4b5f3a297142
8037484: [javadoc] fails with java.lang.IllegalStateException: endPosTable already set
ksrini
parents:
23116
diff
changeset
|
76 |
final Set<JavaFileObject> uniquefiles; |
10 | 77 |
|
78 |
/** |
|
79 |
* Construct a new JavaCompiler processor, using appropriately |
|
80 |
* extended phases of the underlying compiler. |
|
81 |
*/ |
|
82 |
protected JavadocTool(Context context) { |
|
83 |
super(context); |
|
84 |
messager = Messager.instance0(context); |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
23973
diff
changeset
|
85 |
javadocFinder = JavadocClassFinder.instance(context); |
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
47216
diff
changeset
|
86 |
dcfh = DeferredCompletionFailureHandler.instance(context); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
23973
diff
changeset
|
87 |
javadocEnter = JavadocEnter.instance(context); |
23973
4b5f3a297142
8037484: [javadoc] fails with java.lang.IllegalStateException: endPosTable already set
ksrini
parents:
23116
diff
changeset
|
88 |
uniquefiles = new HashSet<>(); |
10 | 89 |
} |
90 |
||
91 |
/** |
|
92 |
* For javadoc, the parser needs to keep comments. Overrides method from JavaCompiler. |
|
93 |
*/ |
|
36526 | 94 |
@Override |
10 | 95 |
protected boolean keepComments() { |
96 |
return true; |
|
97 |
} |
|
98 |
||
99 |
/** |
|
100 |
* Construct a new javadoc tool. |
|
101 |
*/ |
|
102 |
public static JavadocTool make0(Context context) { |
|
103 |
Messager messager = null; |
|
104 |
try { |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
23973
diff
changeset
|
105 |
// force the use of Javadoc's class finder |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
23973
diff
changeset
|
106 |
JavadocClassFinder.preRegister(context); |
10 | 107 |
|
108 |
// force the use of Javadoc's own enter phase |
|
109 |
JavadocEnter.preRegister(context); |
|
110 |
||
111 |
// force the use of Javadoc's own member enter phase |
|
112 |
JavadocMemberEnter.preRegister(context); |
|
113 |
||
114 |
// force the use of Javadoc's own todo phase |
|
115 |
JavadocTodo.preRegister(context); |
|
116 |
||
117 |
// force the use of Messager as a Log |
|
118 |
messager = Messager.instance0(context); |
|
119 |
||
120 |
return new JavadocTool(context); |
|
121 |
} catch (CompletionFailure ex) { |
|
122 |
messager.error(Position.NOPOS, ex.getMessage()); |
|
123 |
return null; |
|
124 |
} |
|
125 |
} |
|
126 |
||
41451 | 127 |
public DocletEnvironment getEnvironment(Map<ToolOption, |
128 |
Object> jdtoolOpts, |
|
129 |
List<String> javaNames, |
|
130 |
Iterable<? extends JavaFileObject> fileObjects) throws ToolException { |
|
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
38619
diff
changeset
|
131 |
toolEnv = ToolEnvironment.instance(context); |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
132 |
toolEnv.initialize(jdtoolOpts); |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
133 |
ElementsTable etable = new ElementsTable(context, jdtoolOpts); |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
134 |
javadocFinder.sourceCompleter = etable.xclasses |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
135 |
? Completer.NULL_COMPLETER |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
136 |
: sourceCompleter; |
10 | 137 |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
138 |
if (etable.xclasses) { |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
139 |
// If -Xclasses is set, the args should be a list of class names |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
140 |
for (String arg: javaNames) { |
41451 | 141 |
if (!isValidPackageName(arg)) { // checks |
142 |
String text = messager.getText("main.illegal_class_name", arg); |
|
143 |
throw new ToolException(CMDERR, text); |
|
144 |
} |
|
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
145 |
} |
41451 | 146 |
if (messager.hasErrors()) { |
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
147 |
return null; |
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
148 |
} |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
149 |
etable.setClassArgList(javaNames); |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
150 |
// prepare, force the data structures to be analyzed |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
151 |
etable.analyze(); |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
152 |
return new DocEnvImpl(toolEnv, etable); |
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
153 |
} |
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
154 |
|
22163 | 155 |
ListBuffer<JCCompilationUnit> classTrees = new ListBuffer<>(); |
10 | 156 |
|
157 |
try { |
|
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
38619
diff
changeset
|
158 |
StandardJavaFileManager fm = toolEnv.fileManager instanceof StandardJavaFileManager |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
159 |
? (StandardJavaFileManager) toolEnv.fileManager |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
160 |
: null; |
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
161 |
Set<String> packageNames = new LinkedHashSet<>(); |
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
162 |
// Normally, the args should be a series of package names or file names. |
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
163 |
// Parse the files and collect the package names. |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
164 |
for (String arg: javaNames) { |
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
165 |
if (fm != null && arg.endsWith(".java") && new File(arg).exists()) { |
44288
c33a416cfcf8
8176539: javadoc ignores module-info files on the command line
ksrini
parents:
44287
diff
changeset
|
166 |
parse(fm.getJavaFileObjects(arg), classTrees, true); |
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
167 |
} else if (isValidPackageName(arg)) { |
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
168 |
packageNames.add(arg); |
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
169 |
} else if (arg.endsWith(".java")) { |
41451 | 170 |
if (fm == null) { |
171 |
String text = messager.getText("main.assertion.error", "fm == null"); |
|
172 |
throw new ToolException(ABNORMAL, text); |
|
173 |
} else { |
|
174 |
String text = messager.getText("main.file_not_found", arg); |
|
175 |
throw new ToolException(ERROR, text); |
|
176 |
} |
|
10 | 177 |
} else { |
41451 | 178 |
String text = messager.getText("main.illegal_package_name", arg); |
179 |
throw new ToolException(CMDERR, text); |
|
10 | 180 |
} |
181 |
} |
|
182 |
||
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
183 |
// Parse file objects provide via the DocumentationTool API |
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
184 |
parse(fileObjects, classTrees, true); |
36526 | 185 |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
186 |
etable.packages(packageNames) |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
187 |
.classTrees(classTrees.toList()) |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
188 |
.scanSpecifiedItems(); |
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
189 |
|
44181
2075fecdcce1
8175860: javadoc crashes with incorrect module sourcepath
ksrini
parents:
43269
diff
changeset
|
190 |
// abort, if errors were encountered during modules initialization |
2075fecdcce1
8175860: javadoc crashes with incorrect module sourcepath
ksrini
parents:
43269
diff
changeset
|
191 |
if (messager.hasErrors()) { |
2075fecdcce1
8175860: javadoc crashes with incorrect module sourcepath
ksrini
parents:
43269
diff
changeset
|
192 |
return null; |
2075fecdcce1
8175860: javadoc crashes with incorrect module sourcepath
ksrini
parents:
43269
diff
changeset
|
193 |
} |
2075fecdcce1
8175860: javadoc crashes with incorrect module sourcepath
ksrini
parents:
43269
diff
changeset
|
194 |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
195 |
// Parse the files in the packages and subpackages to be documented |
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
196 |
ListBuffer<JCCompilationUnit> packageTrees = new ListBuffer<>(); |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
197 |
parse(etable.getFilesToParse(), packageTrees, false); |
36526 | 198 |
modules.enter(packageTrees.toList(), null); |
10 | 199 |
|
41451 | 200 |
if (messager.hasErrors()) { |
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
201 |
return null; |
10 | 202 |
} |
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
203 |
|
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
204 |
// Enter symbols for all files |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
38619
diff
changeset
|
205 |
toolEnv.notice("main.Building_tree"); |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
206 |
javadocEnter.main(classTrees.toList().appendList(packageTrees)); |
44287
829205b133d4
8175219: javadoc should exit when it encounters compilation errors.
ksrini
parents:
44181
diff
changeset
|
207 |
|
829205b133d4
8175219: javadoc should exit when it encounters compilation errors.
ksrini
parents:
44181
diff
changeset
|
208 |
if (messager.hasErrors()) { |
829205b133d4
8175219: javadoc should exit when it encounters compilation errors.
ksrini
parents:
44181
diff
changeset
|
209 |
return null; |
829205b133d4
8175219: javadoc should exit when it encounters compilation errors.
ksrini
parents:
44181
diff
changeset
|
210 |
} |
829205b133d4
8175219: javadoc should exit when it encounters compilation errors.
ksrini
parents:
44181
diff
changeset
|
211 |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
212 |
etable.setClassDeclList(listClasses(classTrees.toList())); |
36526 | 213 |
|
49197
cc2673fa8c20
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents:
47216
diff
changeset
|
214 |
dcfh.setHandler(dcfh.userCodeHandler); |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
215 |
etable.analyze(); |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
216 |
} catch (CompletionFailure cf) { |
41451 | 217 |
throw new ToolException(ABNORMAL, cf.getMessage(), cf); |
218 |
} catch (Abort abort) { |
|
219 |
if (messager.hasErrors()) { |
|
220 |
// presumably a message has been emitted, keep silent |
|
221 |
throw new ToolException(ABNORMAL, "", abort); |
|
222 |
} else { |
|
223 |
String text = messager.getText("main.internal.error"); |
|
224 |
Throwable t = abort.getCause() == null ? abort : abort.getCause(); |
|
225 |
throw new ToolException(ABNORMAL, text, t); |
|
226 |
} |
|
227 |
} |
|
10 | 228 |
|
41451 | 229 |
if (messager.hasErrors()) |
1869 | 230 |
return null; |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
231 |
|
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
232 |
toolEnv.docEnv = new DocEnvImpl(toolEnv, etable); |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
38619
diff
changeset
|
233 |
return toolEnv.docEnv; |
10 | 234 |
} |
235 |
||
236 |
/** Is the given string a valid package name? */ |
|
237 |
boolean isValidPackageName(String s) { |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
238 |
if (s.contains("/")) { |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
239 |
String[] a = s.split("/"); |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
240 |
if (a.length == 2) { |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
241 |
return isValidPackageName0(a[0]) && isValidPackageName0(a[1]); |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
242 |
} |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
243 |
return false; |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
244 |
} |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
245 |
return isValidPackageName0(s); |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
246 |
} |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
247 |
|
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
248 |
private boolean isValidPackageName0(String s) { |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
249 |
for (int index = s.indexOf('.') ; index != -1; index = s.indexOf('.')) { |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
250 |
if (!isValidClassName(s.substring(0, index))) { |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
251 |
return false; |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
252 |
} |
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
253 |
s = s.substring(index + 1); |
10 | 254 |
} |
255 |
return isValidClassName(s); |
|
256 |
} |
|
257 |
||
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
258 |
private void parse(Iterable<? extends JavaFileObject> files, ListBuffer<JCCompilationUnit> trees, |
23973
4b5f3a297142
8037484: [javadoc] fails with java.lang.IllegalStateException: endPosTable already set
ksrini
parents:
23116
diff
changeset
|
259 |
boolean trace) { |
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
260 |
for (JavaFileObject fo: files) { |
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
261 |
if (uniquefiles.add(fo)) { // ignore duplicates |
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
262 |
if (trace) |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
38619
diff
changeset
|
263 |
toolEnv.notice("main.Loading_source_file", fo.getName()); |
32163
2bdcabf14e91
8133223: Clean up package handling code in JavadocTool
jjg
parents:
30066
diff
changeset
|
264 |
trees.append(parse(fo)); |
1869 | 265 |
} |
266 |
} |
|
267 |
} |
|
268 |
||
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
269 |
/** Are surrogates supported? */ |
10 | 270 |
final static boolean surrogatesSupported = surrogatesSupported(); |
271 |
private static boolean surrogatesSupported() { |
|
272 |
try { |
|
273 |
boolean b = Character.isHighSurrogate('a'); |
|
274 |
return true; |
|
275 |
} catch (NoSuchMethodError ex) { |
|
276 |
return false; |
|
277 |
} |
|
278 |
} |
|
279 |
||
280 |
/** |
|
281 |
* Return true if given file name is a valid class name |
|
282 |
* (including "package-info"). |
|
14259 | 283 |
* @param s the name of the class to check. |
10 | 284 |
* @return true if given class name is a valid class name |
285 |
* and false otherwise. |
|
286 |
*/ |
|
287 |
public static boolean isValidClassName(String s) { |
|
288 |
if (s.length() < 1) return false; |
|
289 |
if (s.equals("package-info")) return true; |
|
290 |
if (surrogatesSupported) { |
|
291 |
int cp = s.codePointAt(0); |
|
292 |
if (!Character.isJavaIdentifierStart(cp)) |
|
293 |
return false; |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
294 |
for (int j = Character.charCount(cp); j < s.length(); j += Character.charCount(cp)) { |
10 | 295 |
cp = s.codePointAt(j); |
296 |
if (!Character.isJavaIdentifierPart(cp)) |
|
297 |
return false; |
|
298 |
} |
|
299 |
} else { |
|
300 |
if (!Character.isJavaIdentifierStart(s.charAt(0))) |
|
301 |
return false; |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40311
diff
changeset
|
302 |
for (int j = 1; j < s.length(); j++) |
10 | 303 |
if (!Character.isJavaIdentifierPart(s.charAt(j))) |
304 |
return false; |
|
305 |
} |
|
306 |
return true; |
|
307 |
} |
|
308 |
||
309 |
/** |
|
310 |
* From a list of top level trees, return the list of contained class definitions |
|
311 |
*/ |
|
312 |
List<JCClassDecl> listClasses(List<JCCompilationUnit> trees) { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
32163
diff
changeset
|
313 |
List<JCClassDecl> result = new ArrayList<>(); |
10 | 314 |
for (JCCompilationUnit t : trees) { |
315 |
for (JCTree def : t.defs) { |
|
10950 | 316 |
if (def.hasTag(JCTree.Tag.CLASSDEF)) |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
32163
diff
changeset
|
317 |
result.add((JCClassDecl)def); |
10 | 318 |
} |
319 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
32163
diff
changeset
|
320 |
return result; |
10 | 321 |
} |
322 |
} |