author | jjg |
Tue, 23 Oct 2012 13:20:37 -0700 | |
changeset 14357 | faf9cde2817b |
parent 14265 | 4e8e488eeae0 |
child 14366 | af625e568667 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
14260 | 2 |
* Copyright (c) 1999, 2012, 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 |
||
26 |
package com.sun.tools.doclets.internal.toolkit.util; |
|
27 |
||
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1864
diff
changeset
|
28 |
import java.io.*; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1864
diff
changeset
|
29 |
import java.util.*; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1864
diff
changeset
|
30 |
|
10 | 31 |
import com.sun.javadoc.*; |
32 |
import com.sun.tools.doclets.internal.toolkit.*; |
|
33 |
||
34 |
/** |
|
35 |
* Utilities Class for Doclets. |
|
36 |
* |
|
14260 | 37 |
* <p><b>This is NOT part of any supported API. |
38 |
* If you write code that depends on this, you do so at your own risk. |
|
39 |
* This code and its internal interfaces are subject to change or |
|
40 |
* deletion without notice.</b> |
|
10 | 41 |
* |
42 |
* @author Atul M Dambalkar |
|
43 |
* @author Jamie Ho |
|
44 |
*/ |
|
45 |
public class Util { |
|
46 |
||
47 |
/** |
|
48 |
* A mapping between characters and their |
|
49 |
* corresponding HTML escape character. |
|
50 |
*/ |
|
51 |
public static final String[][] HTML_ESCAPE_CHARS = |
|
52 |
{{"&", "&"}, {"<", "<"}, {">", ">"}}; |
|
53 |
||
54 |
/** |
|
55 |
* Return array of class members whose documentation is to be generated. |
|
56 |
* If the member is deprecated do not include such a member in the |
|
57 |
* returned array. |
|
58 |
* |
|
59 |
* @param members Array of members to choose from. |
|
60 |
* @return ProgramElementDoc[] Array of eligible members for whom |
|
61 |
* documentation is getting generated. |
|
62 |
*/ |
|
63 |
public static ProgramElementDoc[] excludeDeprecatedMembers( |
|
64 |
ProgramElementDoc[] members) { |
|
65 |
return |
|
66 |
toProgramElementDocArray(excludeDeprecatedMembersAsList(members)); |
|
67 |
} |
|
68 |
||
69 |
/** |
|
70 |
* Return array of class members whose documentation is to be generated. |
|
71 |
* If the member is deprecated do not include such a member in the |
|
72 |
* returned array. |
|
73 |
* |
|
74 |
* @param members Array of members to choose from. |
|
75 |
* @return List List of eligible members for whom |
|
76 |
* documentation is getting generated. |
|
77 |
*/ |
|
868 | 78 |
public static List<ProgramElementDoc> excludeDeprecatedMembersAsList( |
10 | 79 |
ProgramElementDoc[] members) { |
868 | 80 |
List<ProgramElementDoc> list = new ArrayList<ProgramElementDoc>(); |
10 | 81 |
for (int i = 0; i < members.length; i++) { |
82 |
if (members[i].tags("deprecated").length == 0) { |
|
83 |
list.add(members[i]); |
|
84 |
} |
|
85 |
} |
|
86 |
Collections.sort(list); |
|
87 |
return list; |
|
88 |
} |
|
89 |
||
90 |
/** |
|
91 |
* Return the list of ProgramElementDoc objects as Array. |
|
92 |
*/ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
93 |
public static ProgramElementDoc[] toProgramElementDocArray(List<ProgramElementDoc> list) { |
10 | 94 |
ProgramElementDoc[] pgmarr = new ProgramElementDoc[list.size()]; |
95 |
for (int i = 0; i < list.size(); i++) { |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
96 |
pgmarr[i] = list.get(i); |
10 | 97 |
} |
98 |
return pgmarr; |
|
99 |
} |
|
100 |
||
101 |
/** |
|
102 |
* Return true if a non-public member found in the given array. |
|
103 |
* |
|
104 |
* @param members Array of members to look into. |
|
105 |
* @return boolean True if non-public member found, false otherwise. |
|
106 |
*/ |
|
107 |
public static boolean nonPublicMemberFound(ProgramElementDoc[] members) { |
|
108 |
for (int i = 0; i < members.length; i++) { |
|
109 |
if (!members[i].isPublic()) { |
|
110 |
return true; |
|
111 |
} |
|
112 |
} |
|
113 |
return false; |
|
114 |
} |
|
115 |
||
116 |
/** |
|
117 |
* Search for the given method in the given class. |
|
118 |
* |
|
119 |
* @param cd Class to search into. |
|
120 |
* @param method Method to be searched. |
|
121 |
* @return MethodDoc Method found, null otherwise. |
|
122 |
*/ |
|
123 |
public static MethodDoc findMethod(ClassDoc cd, MethodDoc method) { |
|
124 |
MethodDoc[] methods = cd.methods(); |
|
125 |
for (int i = 0; i < methods.length; i++) { |
|
126 |
if (executableMembersEqual(method, methods[i])) { |
|
127 |
return methods[i]; |
|
128 |
||
129 |
} |
|
130 |
} |
|
131 |
return null; |
|
132 |
} |
|
133 |
||
134 |
/** |
|
135 |
* @param member1 the first method to compare. |
|
136 |
* @param member2 the second method to compare. |
|
137 |
* @return true if member1 overrides/hides or is overriden/hidden by member2. |
|
138 |
*/ |
|
139 |
public static boolean executableMembersEqual(ExecutableMemberDoc member1, |
|
140 |
ExecutableMemberDoc member2) { |
|
141 |
if (! (member1 instanceof MethodDoc && member2 instanceof MethodDoc)) |
|
142 |
return false; |
|
143 |
||
144 |
MethodDoc method1 = (MethodDoc) member1; |
|
145 |
MethodDoc method2 = (MethodDoc) member2; |
|
146 |
if (method1.isStatic() && method2.isStatic()) { |
|
147 |
Parameter[] targetParams = method1.parameters(); |
|
148 |
Parameter[] currentParams; |
|
149 |
if (method1.name().equals(method2.name()) && |
|
150 |
(currentParams = method2.parameters()).length == |
|
151 |
targetParams.length) { |
|
152 |
int j; |
|
153 |
for (j = 0; j < targetParams.length; j++) { |
|
154 |
if (! (targetParams[j].typeName().equals( |
|
155 |
currentParams[j].typeName()) || |
|
156 |
currentParams[j].type() instanceof TypeVariable || |
|
157 |
targetParams[j].type() instanceof TypeVariable)) { |
|
158 |
break; |
|
159 |
} |
|
160 |
} |
|
161 |
if (j == targetParams.length) { |
|
162 |
return true; |
|
163 |
} |
|
164 |
} |
|
165 |
return false; |
|
166 |
} else { |
|
167 |
return method1.overrides(method2) || |
|
168 |
method2.overrides(method1) || |
|
169 |
member1 == member2; |
|
170 |
} |
|
171 |
} |
|
172 |
||
173 |
/** |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
8631
diff
changeset
|
174 |
* According to |
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
8631
diff
changeset
|
175 |
* <cite>The Java™ Language Specification</cite>, |
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
8631
diff
changeset
|
176 |
* all the outer classes and static inner classes are core classes. |
10 | 177 |
*/ |
178 |
public static boolean isCoreClass(ClassDoc cd) { |
|
179 |
return cd.containingClass() == null || cd.isStatic(); |
|
180 |
} |
|
181 |
||
182 |
public static boolean matches(ProgramElementDoc doc1, |
|
183 |
ProgramElementDoc doc2) { |
|
184 |
if (doc1 instanceof ExecutableMemberDoc && |
|
185 |
doc2 instanceof ExecutableMemberDoc) { |
|
186 |
ExecutableMemberDoc ed1 = (ExecutableMemberDoc)doc1; |
|
187 |
ExecutableMemberDoc ed2 = (ExecutableMemberDoc)doc2; |
|
188 |
return executableMembersEqual(ed1, ed2); |
|
189 |
} else { |
|
190 |
return doc1.name().equals(doc2.name()); |
|
191 |
} |
|
192 |
} |
|
193 |
||
194 |
/** |
|
195 |
* Copy source file to destination file. |
|
196 |
* |
|
197 |
* @throws SecurityException |
|
198 |
* @throws IOException |
|
199 |
*/ |
|
200 |
public static void copyFile(File destfile, File srcfile) |
|
201 |
throws IOException { |
|
202 |
byte[] bytearr = new byte[512]; |
|
203 |
int len = 0; |
|
204 |
FileInputStream input = new FileInputStream(srcfile); |
|
205 |
File destDir = destfile.getParentFile(); |
|
206 |
destDir.mkdirs(); |
|
207 |
FileOutputStream output = new FileOutputStream(destfile); |
|
208 |
try { |
|
209 |
while ((len = input.read(bytearr)) != -1) { |
|
210 |
output.write(bytearr, 0, len); |
|
7641
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
211 |
} |
10 | 212 |
} catch (FileNotFoundException exc) { |
213 |
} catch (SecurityException exc) { |
|
7641
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
214 |
} finally { |
10 | 215 |
input.close(); |
216 |
output.close(); |
|
7641
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
217 |
} |
10 | 218 |
} |
219 |
||
220 |
/** |
|
221 |
* Copy the given directory contents from the source package directory |
|
222 |
* to the generated documentation directory. For example for a package |
|
223 |
* java.lang this method find out the source location of the package using |
|
224 |
* {@link SourcePath} and if given directory is found in the source |
|
225 |
* directory structure, copy the entire directory, to the generated |
|
226 |
* documentation hierarchy. |
|
227 |
* |
|
228 |
* @param configuration The configuration of the current doclet. |
|
229 |
* @param path The relative path to the directory to be copied. |
|
230 |
* @param dir The original directory name to copy from. |
|
231 |
* @param overwrite Overwrite files if true. |
|
232 |
*/ |
|
233 |
public static void copyDocFiles(Configuration configuration, |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
234 |
File path, DocPath dir, boolean overwrite) { |
10 | 235 |
if (checkCopyDocFilesErrors(configuration, path, dir)) { |
236 |
return; |
|
237 |
} |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
238 |
File srcdir = new File(path, dir.getPath()); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
239 |
File destdir = new File(configuration.docFileDestDirName, dir.getPath()); |
10 | 240 |
try { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
241 |
createDirectory(configuration, destdir); |
10 | 242 |
String[] files = srcdir.list(); |
243 |
for (int i = 0; i < files.length; i++) { |
|
244 |
File srcfile = new File(srcdir, files[i]); |
|
245 |
File destfile = new File(destdir, files[i]); |
|
246 |
if (srcfile.isFile()) { |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
247 |
if (destfile.exists() && ! overwrite) { |
10 | 248 |
configuration.message.warning((SourcePosition) null, |
249 |
"doclet.Copy_Overwrite_warning", |
|
250 |
srcfile.toString(), destdir.toString()); |
|
251 |
} else { |
|
252 |
configuration.message.notice( |
|
253 |
"doclet.Copying_File_0_To_Dir_1", |
|
254 |
srcfile.toString(), destdir.toString()); |
|
255 |
Util.copyFile(destfile, srcfile); |
|
256 |
} |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
257 |
} else if (srcfile.isDirectory()) { |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
258 |
if (configuration.copydocfilesubdirs |
10 | 259 |
&& ! configuration.shouldExcludeDocFileDir( |
260 |
srcfile.getName())){ |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
261 |
copyDocFiles(configuration, path, dir.resolve(files[i]), |
10 | 262 |
overwrite); |
263 |
} |
|
264 |
} |
|
265 |
} |
|
266 |
} catch (SecurityException exc) { |
|
267 |
throw new DocletAbortException(); |
|
268 |
} catch (IOException exc) { |
|
269 |
throw new DocletAbortException(); |
|
270 |
} |
|
271 |
} |
|
272 |
||
273 |
/** |
|
274 |
* Given the parameters for copying doc-files, check for errors. |
|
275 |
* |
|
276 |
* @param configuration The configuration of the current doclet. |
|
277 |
* @param path The relative path to the directory to be copied. |
|
278 |
* @param dirName The original directory name to copy from. |
|
279 |
*/ |
|
280 |
private static boolean checkCopyDocFilesErrors (Configuration configuration, |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
281 |
File path, DocPath dirName) { |
10 | 282 |
if ((configuration.sourcepath == null || configuration.sourcepath.length() == 0) && |
283 |
(configuration.destDirName == null || configuration.destDirName.length() == 0)) { |
|
284 |
//The destination path and source path are definitely equal. |
|
285 |
return true; |
|
286 |
} |
|
287 |
File sourcePath, destPath = new File(configuration.destDirName); |
|
288 |
StringTokenizer pathTokens = new StringTokenizer( |
|
289 |
configuration.sourcepath == null ? "" : configuration.sourcepath, |
|
290 |
File.pathSeparator); |
|
291 |
//Check if the destination path is equal to the source path. If yes, |
|
292 |
//do not copy doc-file directories. |
|
293 |
while(pathTokens.hasMoreTokens()){ |
|
294 |
sourcePath = new File(pathTokens.nextToken()); |
|
295 |
if(destPath.equals(sourcePath)){ |
|
296 |
return true; |
|
297 |
} |
|
298 |
} |
|
299 |
//Make sure the doc-file being copied exists. |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
300 |
File srcdir = new File(path, dirName.getPath()); |
10 | 301 |
if (! srcdir.exists()) { |
302 |
return true; |
|
303 |
} |
|
304 |
return false; |
|
305 |
} |
|
306 |
||
307 |
/** |
|
308 |
* Copy a file in the resources directory to the destination |
|
309 |
* directory (if it is not there already). If |
|
310 |
* <code>overwrite</code> is true and the destination file |
|
311 |
* already exists, overwrite it. |
|
312 |
* |
|
313 |
* @param configuration Holds the destination directory and error message |
|
314 |
* @param resourcefile The name of the resource file to copy |
|
315 |
* @param overwrite A flag to indicate whether the file in the |
|
316 |
* destination directory will be overwritten if |
|
317 |
* it already exists. |
|
318 |
*/ |
|
319 |
public static void copyResourceFile(Configuration configuration, |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
320 |
String resourcefile, boolean overwrite) { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
321 |
copyFile(configuration, resourcefile, DocPaths.RESOURCES, DocPaths.RESOURCES, |
7641
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
322 |
overwrite, false); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
323 |
} |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
324 |
|
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
325 |
/** |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
326 |
* Copy a file from a source directory to a destination directory |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
327 |
* (if it is not there already). If <code>overwrite</code> is true and |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
328 |
* the destination file already exists, overwrite it. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
329 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
330 |
* @param configuration Holds the error message |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
331 |
* @param file The name of the file to copy |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
332 |
* @param source The source directory |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
333 |
* @param destination The destination directory where the file needs to be copied |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
334 |
* @param overwrite A flag to indicate whether the file in the |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
335 |
* destination directory will be overwritten if |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
336 |
* it already exists. |
7641
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
337 |
* @param replaceNewLine true if the newline needs to be replaced with platform- |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
338 |
* specific newline. |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
339 |
*/ |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
340 |
public static void copyFile(Configuration configuration, String file, DocPath source, |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
341 |
DocPath destination, boolean overwrite, boolean replaceNewLine) { |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
342 |
copyFile(configuration, file, source.getPath(), destination.getPath(), |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
343 |
overwrite, replaceNewLine); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
344 |
} |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
345 |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
346 |
public static void copyFile(Configuration configuration, String file, String source, |
7641
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
347 |
String destination, boolean overwrite, boolean replaceNewLine) { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
348 |
File destdir = configuration.destDirName.isEmpty() ? |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
349 |
(destination.isEmpty() ? null : new File(destination)) : |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
350 |
new File(configuration.destDirName, destination); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
351 |
File destfile = (destdir == null) ? new File(file) : new File(destdir, file); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
352 |
createDirectory(configuration, destfile.getParentFile()); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
353 |
if (destfile.exists() && (! overwrite)) return; |
10 | 354 |
try { |
355 |
InputStream in = Configuration.class.getResourceAsStream( |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
356 |
source + '/' + file); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
357 |
if (in == null) return; |
10 | 358 |
OutputStream out = new FileOutputStream(destfile); |
7641
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
359 |
try { |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
360 |
if (!replaceNewLine) { |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
361 |
byte[] buf = new byte[2048]; |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
362 |
int n; |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
363 |
while((n = in.read(buf))>0) out.write(buf,0,n); |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
364 |
} else { |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
365 |
BufferedReader reader = new BufferedReader(new InputStreamReader(in)); |
14261 | 366 |
BufferedWriter writer; |
367 |
if (configuration.docencoding == null) { |
|
368 |
writer = new BufferedWriter(new OutputStreamWriter(out)); |
|
369 |
} else { |
|
370 |
writer = new BufferedWriter(new OutputStreamWriter(out, |
|
371 |
configuration.docencoding)); |
|
372 |
} |
|
7641
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
373 |
try { |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
374 |
String line; |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
375 |
while ((line = reader.readLine()) != null) { |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
376 |
writer.write(line); |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
377 |
writer.write(DocletConstants.NL); |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
378 |
} |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
379 |
} finally { |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
380 |
reader.close(); |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
381 |
writer.close(); |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
382 |
} |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
383 |
} |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
384 |
} finally { |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
385 |
in.close(); |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
386 |
out.close(); |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
387 |
} |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
388 |
} catch (IOException ie) { |
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
389 |
ie.printStackTrace(System.err); |
7641
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
390 |
throw new DocletAbortException(); |
8b552db25f99
7006270: Several javadoc regression tests are failing on windows
bpatel
parents:
7614
diff
changeset
|
391 |
} |
10 | 392 |
} |
393 |
||
394 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
395 |
* Given a path string create all the directories in the path. For example, |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
396 |
* if the path string is "java/applet", the method will create directory |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
397 |
* "java" and then "java/applet" if they don't exist. The file separator |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
398 |
* string "/" is platform dependent system property. |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
399 |
* |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
400 |
* @param path Directory path string. |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
401 |
*/ |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
402 |
public static void createDirectory(Configuration configuration, File dir) { |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
403 |
if (dir == null) { |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
404 |
return; |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
405 |
} |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
406 |
if (dir.exists()) { |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
407 |
return; |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
408 |
} else { |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
409 |
if (dir.mkdirs()) { |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
410 |
return; |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
411 |
} else { |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
412 |
configuration.message.error( |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
413 |
"doclet.Unable_to_create_directory_0", dir.getPath()); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
414 |
throw new DocletAbortException(); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
415 |
} |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
416 |
} |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
417 |
} |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
418 |
|
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
419 |
/** |
10 | 420 |
* Given a PackageDoc, return the source path for that package. |
421 |
* @param configuration The Configuration for the current Doclet. |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
422 |
* @param pkgDoc The package to search the path for. |
10 | 423 |
* @return A string representing the path to the given package. |
424 |
*/ |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
425 |
public static File getPackageSourcePath(Configuration configuration, |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
426 |
PackageDoc pkgDoc) { |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
427 |
DocPath pkgPath = DocPath.forPackage(pkgDoc); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
428 |
File pkgDir = new SourcePath(configuration.sourcepath).getDirectory(pkgPath); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
429 |
if (pkgDir == null) |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
430 |
return null; |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
431 |
//Make sure that both paths are using the same separators. |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
432 |
String completePath = Util.replaceText(pkgDir.getPath(), File.separator, "/"); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
433 |
String pathForPkg = completePath.substring(0, completePath.lastIndexOf(pkgPath.getPath())); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
434 |
return new File(pathForPkg); |
10 | 435 |
} |
436 |
||
437 |
/** |
|
438 |
* We want the list of types in alphabetical order. However, types are not |
|
439 |
* comparable. We need a comparator for now. |
|
440 |
*/ |
|
868 | 441 |
private static class TypeComparator implements Comparator<Type> { |
442 |
public int compare(Type type1, Type type2) { |
|
443 |
return type1.qualifiedTypeName().toLowerCase().compareTo( |
|
444 |
type2.qualifiedTypeName().toLowerCase()); |
|
10 | 445 |
} |
446 |
} |
|
447 |
||
448 |
/** |
|
449 |
* For the class return all implemented interfaces including the |
|
450 |
* superinterfaces of the implementing interfaces, also iterate over for |
|
451 |
* all the superclasses. For interface return all the extended interfaces |
|
452 |
* as well as superinterfaces for those extended interfaces. |
|
453 |
* |
|
454 |
* @param type type whose implemented or |
|
455 |
* super interfaces are sought. |
|
456 |
* @param configuration the current configuration of the doclet. |
|
457 |
* @param sort if true, return list of interfaces sorted alphabetically. |
|
458 |
* @return List of all the required interfaces. |
|
459 |
*/ |
|
868 | 460 |
public static List<Type> getAllInterfaces(Type type, |
10 | 461 |
Configuration configuration, boolean sort) { |
868 | 462 |
Map<ClassDoc,Type> results = sort ? new TreeMap<ClassDoc,Type>() : new LinkedHashMap<ClassDoc,Type>(); |
10 | 463 |
Type[] interfaceTypes = null; |
464 |
Type superType = null; |
|
465 |
if (type instanceof ParameterizedType) { |
|
466 |
interfaceTypes = ((ParameterizedType) type).interfaceTypes(); |
|
467 |
superType = ((ParameterizedType) type).superclassType(); |
|
468 |
} else if (type instanceof ClassDoc) { |
|
469 |
interfaceTypes = ((ClassDoc) type).interfaceTypes(); |
|
470 |
superType = ((ClassDoc) type).superclassType(); |
|
471 |
} else { |
|
472 |
interfaceTypes = type.asClassDoc().interfaceTypes(); |
|
473 |
superType = type.asClassDoc().superclassType(); |
|
474 |
} |
|
475 |
||
476 |
for (int i = 0; i < interfaceTypes.length; i++) { |
|
477 |
Type interfaceType = interfaceTypes[i]; |
|
478 |
ClassDoc interfaceClassDoc = interfaceType.asClassDoc(); |
|
479 |
if (! (interfaceClassDoc.isPublic() || |
|
480 |
(configuration == null || |
|
481 |
isLinkable(interfaceClassDoc, configuration)))) { |
|
482 |
continue; |
|
483 |
} |
|
484 |
results.put(interfaceClassDoc, interfaceType); |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
485 |
List<Type> superInterfaces = getAllInterfaces(interfaceType, configuration, sort); |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
486 |
for (Iterator<Type> iter = superInterfaces.iterator(); iter.hasNext(); ) { |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
487 |
Type t = iter.next(); |
10 | 488 |
results.put(t.asClassDoc(), t); |
489 |
} |
|
490 |
} |
|
491 |
if (superType == null) |
|
868 | 492 |
return new ArrayList<Type>(results.values()); |
10 | 493 |
//Try walking the tree. |
494 |
addAllInterfaceTypes(results, |
|
495 |
superType, |
|
496 |
superType instanceof ClassDoc ? |
|
497 |
((ClassDoc) superType).interfaceTypes() : |
|
498 |
((ParameterizedType) superType).interfaceTypes(), |
|
499 |
false, configuration); |
|
868 | 500 |
List<Type> resultsList = new ArrayList<Type>(results.values()); |
10 | 501 |
if (sort) { |
502 |
Collections.sort(resultsList, new TypeComparator()); |
|
503 |
} |
|
504 |
return resultsList; |
|
505 |
} |
|
506 |
||
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
507 |
public static List<Type> getAllInterfaces(Type type, Configuration configuration) { |
10 | 508 |
return getAllInterfaces(type, configuration, true); |
509 |
} |
|
510 |
||
868 | 511 |
private static void findAllInterfaceTypes(Map<ClassDoc,Type> results, ClassDoc c, boolean raw, |
10 | 512 |
Configuration configuration) { |
513 |
Type superType = c.superclassType(); |
|
514 |
if (superType == null) |
|
515 |
return; |
|
516 |
addAllInterfaceTypes(results, superType, |
|
517 |
superType instanceof ClassDoc ? |
|
518 |
((ClassDoc) superType).interfaceTypes() : |
|
519 |
((ParameterizedType) superType).interfaceTypes(), |
|
520 |
raw, configuration); |
|
521 |
} |
|
522 |
||
868 | 523 |
private static void findAllInterfaceTypes(Map<ClassDoc,Type> results, ParameterizedType p, |
10 | 524 |
Configuration configuration) { |
525 |
Type superType = p.superclassType(); |
|
526 |
if (superType == null) |
|
527 |
return; |
|
528 |
addAllInterfaceTypes(results, superType, |
|
529 |
superType instanceof ClassDoc ? |
|
530 |
((ClassDoc) superType).interfaceTypes() : |
|
531 |
((ParameterizedType) superType).interfaceTypes(), |
|
532 |
false, configuration); |
|
533 |
} |
|
534 |
||
868 | 535 |
private static void addAllInterfaceTypes(Map<ClassDoc,Type> results, Type type, |
10 | 536 |
Type[] interfaceTypes, boolean raw, |
537 |
Configuration configuration) { |
|
538 |
for (int i = 0; i < interfaceTypes.length; i++) { |
|
539 |
Type interfaceType = interfaceTypes[i]; |
|
540 |
ClassDoc interfaceClassDoc = interfaceType.asClassDoc(); |
|
541 |
if (! (interfaceClassDoc.isPublic() || |
|
542 |
(configuration != null && |
|
543 |
isLinkable(interfaceClassDoc, configuration)))) { |
|
544 |
continue; |
|
545 |
} |
|
546 |
if (raw) |
|
547 |
interfaceType = interfaceType.asClassDoc(); |
|
548 |
results.put(interfaceClassDoc, interfaceType); |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
549 |
List<Type> superInterfaces = getAllInterfaces(interfaceType, configuration); |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
550 |
for (Iterator<Type> iter = superInterfaces.iterator(); iter.hasNext(); ) { |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
551 |
Type superInterface = iter.next(); |
10 | 552 |
results.put(superInterface.asClassDoc(), superInterface); |
553 |
} |
|
554 |
} |
|
555 |
if (type instanceof ParameterizedType) |
|
556 |
findAllInterfaceTypes(results, (ParameterizedType) type, configuration); |
|
557 |
else if (((ClassDoc) type).typeParameters().length == 0) |
|
558 |
findAllInterfaceTypes(results, (ClassDoc) type, raw, configuration); |
|
559 |
else |
|
560 |
findAllInterfaceTypes(results, (ClassDoc) type, true, configuration); |
|
561 |
} |
|
562 |
||
563 |
/** |
|
564 |
* Enclose in quotes, used for paths and filenames that contains spaces |
|
565 |
*/ |
|
566 |
public static String quote(String filepath) { |
|
567 |
return ("\"" + filepath + "\""); |
|
568 |
} |
|
569 |
||
570 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
571 |
* Given a package, return its name. |
10 | 572 |
* @param packageDoc the package to check. |
573 |
* @return the name of the given package. |
|
574 |
*/ |
|
575 |
public static String getPackageName(PackageDoc packageDoc) { |
|
576 |
return packageDoc == null || packageDoc.name().length() == 0 ? |
|
577 |
DocletConstants.DEFAULT_PACKAGE_NAME : packageDoc.name(); |
|
578 |
} |
|
579 |
||
580 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
581 |
* Given a package, return its file name without the extension. |
10 | 582 |
* @param packageDoc the package to check. |
583 |
* @return the file name of the given package. |
|
584 |
*/ |
|
585 |
public static String getPackageFileHeadName(PackageDoc packageDoc) { |
|
586 |
return packageDoc == null || packageDoc.name().length() == 0 ? |
|
587 |
DocletConstants.DEFAULT_PACKAGE_FILE_NAME : packageDoc.name(); |
|
588 |
} |
|
589 |
||
590 |
/** |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
591 |
* Given a string, replace all occurrences of 'newStr' with 'oldStr'. |
10 | 592 |
* @param originalStr the string to modify. |
593 |
* @param oldStr the string to replace. |
|
594 |
* @param newStr the string to insert in place of the old string. |
|
595 |
*/ |
|
596 |
public static String replaceText(String originalStr, String oldStr, |
|
597 |
String newStr) { |
|
598 |
if (oldStr == null || newStr == null || oldStr.equals(newStr)) { |
|
599 |
return originalStr; |
|
600 |
} |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
601 |
return originalStr.replace(oldStr, newStr); |
10 | 602 |
} |
603 |
||
604 |
/** |
|
605 |
* Given a string, escape all special html characters and |
|
606 |
* return the result. |
|
607 |
* |
|
608 |
* @param s The string to check. |
|
609 |
* @return the original string with all of the HTML characters |
|
610 |
* escaped. |
|
611 |
* |
|
612 |
* @see #HTML_ESCAPE_CHARS |
|
613 |
*/ |
|
614 |
public static String escapeHtmlChars(String s) { |
|
615 |
String result = s; |
|
616 |
for (int i = 0; i < HTML_ESCAPE_CHARS.length; i++) { |
|
617 |
result = Util.replaceText(result, |
|
618 |
HTML_ESCAPE_CHARS[i][0], HTML_ESCAPE_CHARS[i][1]); |
|
619 |
} |
|
620 |
return result; |
|
621 |
} |
|
622 |
||
623 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
624 |
* Given a string, strips all html characters and |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
625 |
* return the result. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
626 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
627 |
* @param rawString The string to check. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
628 |
* @return the original string with all of the HTML characters |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
629 |
* stripped. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
630 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
631 |
*/ |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
632 |
public static String stripHtml(String rawString) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
633 |
// remove HTML tags |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
634 |
rawString = rawString.replaceAll("\\<.*?>", " "); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
635 |
// consolidate multiple spaces between a word to a single space |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
636 |
rawString = rawString.replaceAll("\\b\\s{2,}\\b", " "); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
637 |
// remove extra whitespaces |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
638 |
return rawString.trim(); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
639 |
} |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
640 |
|
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
641 |
/** |
10 | 642 |
* Create the directory path for the file to be generated, construct |
643 |
* FileOutputStream and OutputStreamWriter depending upon docencoding. |
|
644 |
* |
|
645 |
* @param path The directory path to be created for this file. |
|
646 |
* @param filename File Name to which the PrintWriter will do the Output. |
|
647 |
* @param docencoding Encoding to be used for this file. |
|
648 |
* @exception IOException Exception raised by the FileWriter is passed on |
|
649 |
* to next level. |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1864
diff
changeset
|
650 |
* @exception UnsupportedEncodingException Exception raised by the |
10 | 651 |
* OutputStreamWriter is passed on to next level. |
652 |
* @return Writer Writer for the file getting generated. |
|
653 |
* @see java.io.FileOutputStream |
|
654 |
* @see java.io.OutputStreamWriter |
|
655 |
*/ |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
656 |
public static Writer genWriter(Configuration configuration, DocPath path) |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
657 |
throws IOException, UnsupportedEncodingException { |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
658 |
File file = path.resolveAgainst(configuration.destDirName); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
659 |
createDirectory(configuration, file.getParentFile()); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
660 |
FileOutputStream fos = new FileOutputStream(file); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
661 |
if (configuration.docencoding == null) { |
14265
4e8e488eeae0
8000666: javadoc should write directly to Writer instead of composing strings
jjg
parents:
14261
diff
changeset
|
662 |
return new BufferedWriter(new OutputStreamWriter(fos)); |
10 | 663 |
} else { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14265
diff
changeset
|
664 |
return new BufferedWriter(new OutputStreamWriter(fos, configuration.docencoding)); |
10 | 665 |
} |
666 |
} |
|
667 |
||
668 |
/** |
|
669 |
* Given an annotation, return true if it should be documented and false |
|
670 |
* otherwise. |
|
671 |
* |
|
672 |
* @param annotationDoc the annotation to check. |
|
673 |
* |
|
674 |
* @return true return true if it should be documented and false otherwise. |
|
675 |
*/ |
|
676 |
public static boolean isDocumentedAnnotation(AnnotationTypeDoc annotationDoc) { |
|
677 |
AnnotationDesc[] annotationDescList = annotationDoc.annotations(); |
|
678 |
for (int i = 0; i < annotationDescList.length; i++) { |
|
679 |
if (annotationDescList[i].annotationType().qualifiedName().equals( |
|
680 |
java.lang.annotation.Documented.class.getName())){ |
|
681 |
return true; |
|
682 |
} |
|
683 |
} |
|
684 |
return false; |
|
685 |
} |
|
686 |
||
687 |
/** |
|
688 |
* Given a string, return an array of tokens. The separator can be escaped |
|
689 |
* with the '\' character. The '\' character may also be escaped by the |
|
690 |
* '\' character. |
|
691 |
* |
|
692 |
* @param s the string to tokenize. |
|
693 |
* @param separator the separator char. |
|
694 |
* @param maxTokens the maxmimum number of tokens returned. If the |
|
695 |
* max is reached, the remaining part of s is appended |
|
696 |
* to the end of the last token. |
|
697 |
* |
|
698 |
* @return an array of tokens. |
|
699 |
*/ |
|
700 |
public static String[] tokenize(String s, char separator, int maxTokens) { |
|
868 | 701 |
List<String> tokens = new ArrayList<String>(); |
10 | 702 |
StringBuilder token = new StringBuilder (); |
703 |
boolean prevIsEscapeChar = false; |
|
704 |
for (int i = 0; i < s.length(); i += Character.charCount(i)) { |
|
705 |
int currentChar = s.codePointAt(i); |
|
706 |
if (prevIsEscapeChar) { |
|
707 |
// Case 1: escaped character |
|
708 |
token.appendCodePoint(currentChar); |
|
709 |
prevIsEscapeChar = false; |
|
710 |
} else if (currentChar == separator && tokens.size() < maxTokens-1) { |
|
711 |
// Case 2: separator |
|
712 |
tokens.add(token.toString()); |
|
713 |
token = new StringBuilder(); |
|
714 |
} else if (currentChar == '\\') { |
|
715 |
// Case 3: escape character |
|
716 |
prevIsEscapeChar = true; |
|
717 |
} else { |
|
718 |
// Case 4: regular character |
|
719 |
token.appendCodePoint(currentChar); |
|
720 |
} |
|
721 |
} |
|
722 |
if (token.length() > 0) { |
|
723 |
tokens.add(token.toString()); |
|
724 |
} |
|
868 | 725 |
return tokens.toArray(new String[] {}); |
10 | 726 |
} |
727 |
||
728 |
/** |
|
729 |
* Return true if this class is linkable and false if we can't link to the |
|
730 |
* desired class. |
|
731 |
* <br> |
|
732 |
* <b>NOTE:</b> You can only link to external classes if they are public or |
|
733 |
* protected. |
|
734 |
* |
|
735 |
* @param classDoc the class to check. |
|
736 |
* @param configuration the current configuration of the doclet. |
|
737 |
* |
|
738 |
* @return true if this class is linkable and false if we can't link to the |
|
739 |
* desired class. |
|
740 |
*/ |
|
741 |
public static boolean isLinkable(ClassDoc classDoc, |
|
742 |
Configuration configuration) { |
|
743 |
return |
|
744 |
((classDoc.isIncluded() && configuration.isGeneratedDoc(classDoc))) || |
|
745 |
(configuration.extern.isExternal(classDoc) && |
|
746 |
(classDoc.isPublic() || classDoc.isProtected())); |
|
747 |
} |
|
748 |
||
749 |
/** |
|
750 |
* Given a class, return the closest visible super class. |
|
751 |
* |
|
752 |
* @param classDoc the class we are searching the parent for. |
|
753 |
* @param configuration the current configuration of the doclet. |
|
754 |
* @return the closest visible super class. Return null if it cannot |
|
755 |
* be found (i.e. classDoc is java.lang.Object). |
|
756 |
*/ |
|
757 |
public static Type getFirstVisibleSuperClass(ClassDoc classDoc, |
|
758 |
Configuration configuration) { |
|
759 |
if (classDoc == null) { |
|
760 |
return null; |
|
761 |
} |
|
762 |
Type sup = classDoc.superclassType(); |
|
763 |
ClassDoc supClassDoc = classDoc.superclass(); |
|
764 |
while (sup != null && |
|
765 |
(! (supClassDoc.isPublic() || |
|
766 |
isLinkable(supClassDoc, configuration))) ) { |
|
767 |
if (supClassDoc.superclass().qualifiedName().equals(supClassDoc.qualifiedName())) |
|
768 |
break; |
|
769 |
sup = supClassDoc.superclassType(); |
|
770 |
supClassDoc = supClassDoc.superclass(); |
|
771 |
} |
|
772 |
if (classDoc.equals(supClassDoc)) { |
|
773 |
return null; |
|
774 |
} |
|
775 |
return sup; |
|
776 |
} |
|
777 |
||
778 |
/** |
|
779 |
* Given a class, return the closest visible super class. |
|
780 |
* |
|
781 |
* @param classDoc the class we are searching the parent for. |
|
782 |
* @param configuration the current configuration of the doclet. |
|
783 |
* @return the closest visible super class. Return null if it cannot |
|
784 |
* be found (i.e. classDoc is java.lang.Object). |
|
785 |
*/ |
|
786 |
public static ClassDoc getFirstVisibleSuperClassCD(ClassDoc classDoc, |
|
787 |
Configuration configuration) { |
|
788 |
if (classDoc == null) { |
|
789 |
return null; |
|
790 |
} |
|
791 |
ClassDoc supClassDoc = classDoc.superclass(); |
|
792 |
while (supClassDoc != null && |
|
793 |
(! (supClassDoc.isPublic() || |
|
794 |
isLinkable(supClassDoc, configuration))) ) { |
|
795 |
supClassDoc = supClassDoc.superclass(); |
|
796 |
} |
|
797 |
if (classDoc.equals(supClassDoc)) { |
|
798 |
return null; |
|
799 |
} |
|
800 |
return supClassDoc; |
|
801 |
} |
|
802 |
||
803 |
/** |
|
804 |
* Given a ClassDoc, return the name of its type (Class, Interface, etc.). |
|
805 |
* |
|
806 |
* @param cd the ClassDoc to check. |
|
807 |
* @param lowerCaseOnly true if you want the name returned in lower case. |
|
808 |
* If false, the first letter of the name is capatilized. |
|
809 |
* @return |
|
810 |
*/ |
|
811 |
public static String getTypeName(Configuration config, |
|
812 |
ClassDoc cd, boolean lowerCaseOnly) { |
|
813 |
String typeName = ""; |
|
814 |
if (cd.isOrdinaryClass()) { |
|
815 |
typeName = "doclet.Class"; |
|
816 |
} else if (cd.isInterface()) { |
|
817 |
typeName = "doclet.Interface"; |
|
818 |
} else if (cd.isException()) { |
|
819 |
typeName = "doclet.Exception"; |
|
820 |
} else if (cd.isError()) { |
|
821 |
typeName = "doclet.Error"; |
|
822 |
} else if (cd.isAnnotationType()) { |
|
823 |
typeName = "doclet.AnnotationType"; |
|
824 |
} else if (cd.isEnum()) { |
|
825 |
typeName = "doclet.Enum"; |
|
826 |
} |
|
827 |
return config.getText( |
|
828 |
lowerCaseOnly ? typeName.toLowerCase() : typeName); |
|
829 |
} |
|
830 |
||
831 |
/** |
|
832 |
* Given a string, replace all tabs with the appropriate |
|
833 |
* number of spaces. |
|
834 |
* @param tabLength the length of each tab. |
|
835 |
* @param s the String to scan. |
|
836 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
837 |
public static void replaceTabs(int tabLength, StringBuilder s) { |
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
838 |
if (whitespace == null || whitespace.length() < tabLength) |
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
839 |
whitespace = String.format("%" + tabLength + "s", " "); |
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
840 |
int index = 0; |
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
841 |
while ((index = s.indexOf("\t", index)) != -1) { |
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
842 |
int spaceCount = tabLength - index % tabLength; |
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
843 |
s.replace(index, index+1, whitespace.substring(0, spaceCount)); |
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
844 |
index += spaceCount; |
10 | 845 |
} |
846 |
} |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
847 |
private static String whitespace; |
10 | 848 |
|
849 |
/** |
|
850 |
* The documentation for values() and valueOf() in Enums are set by the |
|
851 |
* doclet. |
|
852 |
*/ |
|
853 |
public static void setEnumDocumentation(Configuration configuration, |
|
854 |
ClassDoc classDoc) { |
|
855 |
MethodDoc[] methods = classDoc.methods(); |
|
856 |
for (int j = 0; j < methods.length; j++) { |
|
857 |
MethodDoc currentMethod = methods[j]; |
|
858 |
if (currentMethod.name().equals("values") && |
|
859 |
currentMethod.parameters().length == 0) { |
|
860 |
currentMethod.setRawCommentText( |
|
861 |
configuration.getText("doclet.enum_values_doc", classDoc.name())); |
|
862 |
} else if (currentMethod.name().equals("valueOf") && |
|
863 |
currentMethod.parameters().length == 1) { |
|
864 |
Type paramType = currentMethod.parameters()[0].type(); |
|
865 |
if (paramType != null && |
|
866 |
paramType.qualifiedTypeName().equals(String.class.getName())) { |
|
867 |
currentMethod.setRawCommentText( |
|
868 |
configuration.getText("doclet.enum_valueof_doc")); |
|
869 |
} |
|
870 |
} |
|
871 |
} |
|
872 |
} |
|
873 |
||
874 |
/** |
|
875 |
* Return true if the given Doc is deprecated. |
|
876 |
* |
|
877 |
* @param doc the Doc to check. |
|
878 |
* @return true if the given Doc is deprecated. |
|
879 |
*/ |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
880 |
public static boolean isDeprecated(Doc doc) { |
10 | 881 |
if (doc.tags("deprecated").length > 0) { |
882 |
return true; |
|
883 |
} |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
884 |
AnnotationDesc[] annotationDescList; |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
885 |
if (doc instanceof PackageDoc) |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
886 |
annotationDescList = ((PackageDoc)doc).annotations(); |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
887 |
else |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
9303
diff
changeset
|
888 |
annotationDescList = ((ProgramElementDoc)doc).annotations(); |
10 | 889 |
for (int i = 0; i < annotationDescList.length; i++) { |
890 |
if (annotationDescList[i].annotationType().qualifiedName().equals( |
|
891 |
java.lang.Deprecated.class.getName())){ |
|
892 |
return true; |
|
893 |
} |
|
894 |
} |
|
895 |
return false; |
|
896 |
} |
|
897 |
} |