author | jjg |
Mon, 15 Feb 2016 14:02:57 -0800 | |
changeset 36037 | 688096b6bcc4 |
parent 35426 | 374342e56a56 |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
14544 | 1 |
/* |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
2 |
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. |
14544 | 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 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.toolkit.util; |
14544 | 27 |
|
28 |
import java.io.BufferedInputStream; |
|
29 |
import java.io.BufferedOutputStream; |
|
30 |
import java.io.BufferedWriter; |
|
31 |
import java.io.IOException; |
|
32 |
import java.io.InputStream; |
|
33 |
import java.io.OutputStream; |
|
34 |
import java.io.OutputStreamWriter; |
|
35 |
import java.io.UnsupportedEncodingException; |
|
36 |
import java.io.Writer; |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
37 |
import java.nio.file.DirectoryStream; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
38 |
import java.nio.file.Files; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
39 |
import java.nio.file.Path; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
40 |
import java.nio.file.Paths; |
14544 | 41 |
import java.util.ArrayList; |
42 |
import java.util.Arrays; |
|
43 |
import java.util.LinkedHashSet; |
|
44 |
import java.util.List; |
|
45 |
import java.util.Set; |
|
46 |
||
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
47 |
import javax.tools.DocumentationTool; |
14544 | 48 |
import javax.tools.FileObject; |
49 |
import javax.tools.JavaFileManager.Location; |
|
50 |
import javax.tools.JavaFileObject; |
|
51 |
import javax.tools.StandardJavaFileManager; |
|
52 |
import javax.tools.StandardLocation; |
|
53 |
||
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
54 |
import com.sun.tools.javac.util.Assert; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
55 |
import jdk.javadoc.internal.doclets.toolkit.Configuration; |
14544 | 56 |
|
57 |
/** |
|
58 |
* Implementation of DocFileFactory using a {@link StandardJavaFileManager}. |
|
59 |
* |
|
60 |
* <p><b>This is NOT part of any supported API. |
|
61 |
* If you write code that depends on this, you do so at your own risk. |
|
62 |
* This code and its internal interfaces are subject to change or |
|
63 |
* deletion without notice.</b> |
|
64 |
* |
|
65 |
*/ |
|
66 |
class StandardDocFileFactory extends DocFileFactory { |
|
67 |
private final StandardJavaFileManager fileManager; |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
68 |
private Path destDir; |
14544 | 69 |
|
70 |
public StandardDocFileFactory(Configuration configuration) { |
|
71 |
super(configuration); |
|
72 |
fileManager = (StandardJavaFileManager) configuration.getFileManager(); |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
73 |
} |
14544 | 74 |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
75 |
private Path getDestDir() { |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
76 |
if (destDir == null) { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
77 |
if (!configuration.destDirName.isEmpty() |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
78 |
|| !fileManager.hasLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT)) { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
79 |
try { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
80 |
String dirName = configuration.destDirName.isEmpty() ? "." : configuration.destDirName; |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
81 |
Path dir = Paths.get(dirName); |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
82 |
fileManager.setLocationFromPaths(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(dir)); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
83 |
} catch (IOException e) { |
19667
fdfce85627a9
8001669: javadoc internal DocletAbortException should set cause when appropriate
jjg
parents:
14545
diff
changeset
|
84 |
throw new DocletAbortException(e); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
85 |
} |
14544 | 86 |
} |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
87 |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
88 |
destDir = fileManager.getLocationAsPaths(DocumentationTool.Location.DOCUMENTATION_OUTPUT).iterator().next(); |
14544 | 89 |
} |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
90 |
return destDir; |
14544 | 91 |
} |
92 |
||
93 |
public DocFile createFileForDirectory(String file) { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
94 |
return new StandardDocFile(Paths.get(file)); |
14544 | 95 |
} |
96 |
||
97 |
public DocFile createFileForInput(String file) { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
98 |
return new StandardDocFile(Paths.get(file)); |
14544 | 99 |
} |
100 |
||
101 |
public DocFile createFileForOutput(DocPath path) { |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
102 |
return new StandardDocFile(DocumentationTool.Location.DOCUMENTATION_OUTPUT, path); |
14544 | 103 |
} |
104 |
||
105 |
@Override |
|
106 |
Iterable<DocFile> list(Location location, DocPath path) { |
|
107 |
if (location != StandardLocation.SOURCE_PATH) |
|
108 |
throw new IllegalArgumentException(); |
|
109 |
||
22163 | 110 |
Set<DocFile> files = new LinkedHashSet<>(); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
111 |
Location l = fileManager.hasLocation(StandardLocation.SOURCE_PATH) |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
112 |
? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH; |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
113 |
for (Path f: fileManager.getLocationAsPaths(l)) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
114 |
if (Files.isDirectory(f)) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
115 |
f = f.resolve(path.getPath()); |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
116 |
if (Files.exists(f)) |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
117 |
files.add(new StandardDocFile(f)); |
14544 | 118 |
} |
119 |
} |
|
120 |
return files; |
|
121 |
} |
|
122 |
||
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
123 |
private static Path newFile(Path dir, String path) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
124 |
return (dir == null) ? Paths.get(path) : dir.resolve(path); |
14544 | 125 |
} |
126 |
||
127 |
class StandardDocFile extends DocFile { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
128 |
private Path file; |
14544 | 129 |
|
130 |
/** Create a StandardDocFile for a given file. */ |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
131 |
private StandardDocFile(Path file) { |
14544 | 132 |
super(configuration); |
133 |
this.file = file; |
|
134 |
} |
|
135 |
||
136 |
/** Create a StandardDocFile for a given location and relative path. */ |
|
137 |
private StandardDocFile(Location location, DocPath path) { |
|
138 |
super(configuration, location, path); |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
139 |
Assert.check(location == DocumentationTool.Location.DOCUMENTATION_OUTPUT); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
140 |
this.file = newFile(getDestDir(), path.getPath()); |
14544 | 141 |
} |
142 |
||
143 |
/** Open an input stream for the file. */ |
|
144 |
public InputStream openInputStream() throws IOException { |
|
145 |
JavaFileObject fo = getJavaFileObjectForInput(file); |
|
146 |
return new BufferedInputStream(fo.openInputStream()); |
|
147 |
} |
|
148 |
||
149 |
/** |
|
150 |
* Open an output stream for the file. |
|
151 |
* The file must have been created with a location of |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
152 |
* {@link DocumentationTool.Location#DOCUMENTATION_OUTPUT} and a corresponding relative path. |
14544 | 153 |
*/ |
154 |
public OutputStream openOutputStream() throws IOException, UnsupportedEncodingException { |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
155 |
if (location != DocumentationTool.Location.DOCUMENTATION_OUTPUT) |
14544 | 156 |
throw new IllegalStateException(); |
157 |
||
158 |
OutputStream out = getFileObjectForOutput(path).openOutputStream(); |
|
159 |
return new BufferedOutputStream(out); |
|
160 |
} |
|
161 |
||
162 |
/** |
|
163 |
* Open an writer for the file, using the encoding (if any) given in the |
|
164 |
* doclet configuration. |
|
165 |
* The file must have been created with a location of |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
166 |
* {@link DocumentationTool.Location#DOCUMENTATION_OUTPUT} and a corresponding relative path. |
14544 | 167 |
*/ |
168 |
public Writer openWriter() throws IOException, UnsupportedEncodingException { |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
169 |
if (location != DocumentationTool.Location.DOCUMENTATION_OUTPUT) |
14544 | 170 |
throw new IllegalStateException(); |
171 |
||
172 |
OutputStream out = getFileObjectForOutput(path).openOutputStream(); |
|
173 |
if (configuration.docencoding == null) { |
|
174 |
return new BufferedWriter(new OutputStreamWriter(out)); |
|
175 |
} else { |
|
176 |
return new BufferedWriter(new OutputStreamWriter(out, configuration.docencoding)); |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
/** Return true if the file can be read. */ |
|
181 |
public boolean canRead() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
182 |
return Files.isReadable(file); |
14544 | 183 |
} |
184 |
||
185 |
/** Return true if the file can be written. */ |
|
186 |
public boolean canWrite() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
187 |
return Files.isWritable(file); |
14544 | 188 |
} |
189 |
||
190 |
/** Return true if the file exists. */ |
|
191 |
public boolean exists() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
192 |
return Files.exists(file); |
14544 | 193 |
} |
194 |
||
195 |
/** Return the base name (last component) of the file name. */ |
|
196 |
public String getName() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
197 |
return file.getFileName().toString(); |
14544 | 198 |
} |
199 |
||
200 |
/** Return the file system path for this file. */ |
|
201 |
public String getPath() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
202 |
return file.toString(); |
14544 | 203 |
} |
204 |
||
205 |
/** Return true is file has an absolute path name. */ |
|
206 |
public boolean isAbsolute() { |
|
207 |
return file.isAbsolute(); |
|
208 |
} |
|
209 |
||
210 |
/** Return true is file identifies a directory. */ |
|
211 |
public boolean isDirectory() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
212 |
return Files.isDirectory(file); |
14544 | 213 |
} |
214 |
||
215 |
/** Return true is file identifies a file. */ |
|
216 |
public boolean isFile() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
217 |
return Files.isRegularFile(file); |
14544 | 218 |
} |
219 |
||
220 |
/** Return true if this file is the same as another. */ |
|
221 |
public boolean isSameFile(DocFile other) { |
|
222 |
if (!(other instanceof StandardDocFile)) |
|
223 |
return false; |
|
224 |
||
225 |
try { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
226 |
return Files.isSameFile(file, ((StandardDocFile) other).file); |
14544 | 227 |
} catch (IOException e) { |
228 |
return false; |
|
229 |
} |
|
230 |
} |
|
231 |
||
232 |
/** If the file is a directory, list its contents. */ |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
233 |
public Iterable<DocFile> list() throws IOException { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
234 |
List<DocFile> files = new ArrayList<DocFile>(); |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
235 |
try (DirectoryStream<Path> ds = Files.newDirectoryStream(file)) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
236 |
for (Path f: ds) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
237 |
files.add(new StandardDocFile(f)); |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
238 |
} |
14544 | 239 |
} |
240 |
return files; |
|
241 |
} |
|
242 |
||
243 |
/** Create the file as a directory, including any parent directories. */ |
|
244 |
public boolean mkdirs() { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
245 |
try { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
246 |
Files.createDirectories(file); |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
247 |
return true; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
248 |
} catch (IOException e) { |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
249 |
return false; |
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
250 |
} |
14544 | 251 |
} |
252 |
||
253 |
/** |
|
254 |
* Derive a new file by resolving a relative path against this file. |
|
255 |
* The new file will inherit the configuration and location of this file |
|
256 |
* If this file has a path set, the new file will have a corresponding |
|
257 |
* new path. |
|
258 |
*/ |
|
259 |
public DocFile resolve(DocPath p) { |
|
260 |
return resolve(p.getPath()); |
|
261 |
} |
|
262 |
||
263 |
/** |
|
264 |
* Derive a new file by resolving a relative path against this file. |
|
265 |
* The new file will inherit the configuration and location of this file |
|
266 |
* If this file has a path set, the new file will have a corresponding |
|
267 |
* new path. |
|
268 |
*/ |
|
269 |
public DocFile resolve(String p) { |
|
270 |
if (location == null && path == null) { |
|
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
271 |
return new StandardDocFile(file.resolve(p)); |
14544 | 272 |
} else { |
273 |
return new StandardDocFile(location, path.resolve(p)); |
|
274 |
} |
|
275 |
} |
|
276 |
||
277 |
/** |
|
278 |
* Resolve a relative file against the given output location. |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
279 |
* @param locn Currently, only |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
280 |
* {@link DocumentationTool.Location.DOCUMENTATION_OUTPUT} is supported. |
14544 | 281 |
*/ |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
282 |
public DocFile resolveAgainst(Location locn) { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
14544
diff
changeset
|
283 |
if (locn != DocumentationTool.Location.DOCUMENTATION_OUTPUT) |
14544 | 284 |
throw new IllegalArgumentException(); |
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
285 |
return new StandardDocFile(getDestDir().resolve(file)); |
14544 | 286 |
} |
287 |
||
288 |
/** Return a string to identify the contents of this object, |
|
289 |
* for debugging purposes. |
|
290 |
*/ |
|
291 |
@Override |
|
292 |
public String toString() { |
|
293 |
StringBuilder sb = new StringBuilder(); |
|
294 |
sb.append("StandardDocFile["); |
|
295 |
if (location != null) |
|
296 |
sb.append("locn:").append(location).append(","); |
|
297 |
if (path != null) |
|
298 |
sb.append("path:").append(path.getPath()).append(","); |
|
299 |
sb.append("file:").append(file); |
|
300 |
sb.append("]"); |
|
301 |
return sb.toString(); |
|
302 |
} |
|
303 |
||
36037
688096b6bcc4
8149773: StandardDocFileFactory should be converted to use java.nio.file.Path
jjg
parents:
35426
diff
changeset
|
304 |
private JavaFileObject getJavaFileObjectForInput(Path file) { |
14544 | 305 |
return fileManager.getJavaFileObjects(file).iterator().next(); |
306 |
} |
|
307 |
||
308 |
private FileObject getFileObjectForOutput(DocPath path) throws IOException { |
|
309 |
// break the path into a package-part and the rest, by finding |
|
310 |
// the position of the last '/' before an invalid character for a |
|
311 |
// package name, such as the "." before an extension or the "-" |
|
312 |
// in filenames like package-summary.html, doc-files or src-html. |
|
313 |
String p = path.getPath(); |
|
314 |
int lastSep = -1; |
|
315 |
for (int i = 0; i < p.length(); i++) { |
|
316 |
char ch = p.charAt(i); |
|
317 |
if (ch == '/') { |
|
318 |
lastSep = i; |
|
319 |
} else if (i == lastSep + 1 && !Character.isJavaIdentifierStart(ch) |
|
320 |
|| !Character.isJavaIdentifierPart(ch)) { |
|
321 |
break; |
|
322 |
} |
|
323 |
} |
|
324 |
String pkg = (lastSep == -1) ? "" : p.substring(0, lastSep); |
|
325 |
String rest = p.substring(lastSep + 1); |
|
326 |
return fileManager.getFileForOutput(location, pkg, rest, null); |
|
327 |
} |
|
328 |
} |
|
329 |
} |