35 * This code and its internal interfaces are subject to change or |
37 * This code and its internal interfaces are subject to change or |
36 * deletion without notice.</b> |
38 * deletion without notice.</b> |
37 * |
39 * |
38 */ |
40 */ |
39 public class DocPaths { |
41 public class DocPaths { |
|
42 private final boolean useModuleDirectories; |
|
43 private final String moduleSeparator; |
|
44 private final Utils utils; |
|
45 |
|
46 public DocPaths(Utils utils, boolean useModuleDirectories) { |
|
47 this.utils = utils; |
|
48 this.useModuleDirectories = useModuleDirectories; |
|
49 moduleSeparator = useModuleDirectories ? "/module-" : "-"; |
|
50 } |
|
51 |
40 /** The name of the file for all classes, without using frames, when --no-frames is specified. */ |
52 /** The name of the file for all classes, without using frames, when --no-frames is specified. */ |
41 public static final DocPath ALLCLASSES = DocPath.create("allclasses.html"); |
53 public static final DocPath ALLCLASSES = DocPath.create("allclasses.html"); |
42 |
54 |
43 /** The name of the file for all classes, using frames. */ |
55 /** The name of the file for all classes, using frames. */ |
44 public static final DocPath ALLCLASSES_FRAME = DocPath.create("allclasses-frame.html"); |
56 public static final DocPath ALLCLASSES_FRAME = DocPath.create("allclasses-frame.html"); |
171 public static final DocPath PACKAGE_TREE = DocPath.create("package-tree.html"); |
187 public static final DocPath PACKAGE_TREE = DocPath.create("package-tree.html"); |
172 |
188 |
173 /** The name of the file for the package usage info. */ |
189 /** The name of the file for the package usage info. */ |
174 public static final DocPath PACKAGE_USE = DocPath.create("package-use.html"); |
190 public static final DocPath PACKAGE_USE = DocPath.create("package-use.html"); |
175 |
191 |
176 /** The name of the output directory for module documentation files. */ |
192 /** |
177 public static DocPath moduleDocFiles(ModuleElement mdle) { |
193 * Returns the path for a type element. |
178 return DocPath.create(mdle.getQualifiedName() + "-doc-files"); |
194 * For example, if the type element is {@code java.lang.Object}, |
179 } |
195 * the path is {@code java/lang/Object.html}. |
180 |
196 * |
181 /** The name of the file for the module frame. */ |
197 * @param typeElement the type element |
182 public static DocPath moduleFrame(ModuleElement mdle) { |
198 * @return the path |
183 return DocPath.create(mdle.getQualifiedName() + "-frame.html"); |
199 */ |
184 } |
200 public DocPath forClass(TypeElement typeElement) { |
185 |
201 return (typeElement == null) |
186 /** The name of the file for the module summary. */ |
202 ? DocPath.empty |
187 public static DocPath moduleSummary(ModuleElement mdle) { |
203 : forPackage(utils.containingPackage(typeElement)).resolve(forName(typeElement)); |
188 return DocPaths.moduleSummary(mdle.getQualifiedName().toString()); |
204 } |
189 } |
205 |
190 |
206 /** |
191 /** The name of the file for the module summary. */ |
207 * Returns the path for the simple name of a type element. |
192 public static DocPath moduleSummary(String mdleName) { |
208 * For example, if the type element is {@code java.lang.Object}, |
193 return DocPath.create(mdleName + "-summary.html"); |
209 * the path is {@code Object.html}. |
194 } |
210 * |
195 |
211 * @param typeElement the type element |
196 /** The name of the file for the module frame. */ |
212 * @return the path |
197 public static DocPath moduleTypeFrame(ModuleElement mdle) { |
213 */ |
198 return DocPath.create(mdle.getQualifiedName() + "-type-frame.html"); |
214 public DocPath forName(TypeElement typeElement) { |
|
215 return (typeElement == null) |
|
216 ? DocPath.empty |
|
217 : new DocPath(utils.getSimpleName(typeElement) + ".html"); |
|
218 } |
|
219 |
|
220 public static DocPath forModule(ModuleElement mdle) { |
|
221 return mdle == null || mdle.isUnnamed() |
|
222 ? DocPath.empty |
|
223 : DocPath.create(mdle.getQualifiedName().toString()); |
|
224 } |
|
225 |
|
226 /** |
|
227 * Returns the path for the package of a type element. |
|
228 * For example, if the type element is {@code java.lang.Object}, |
|
229 * the path is {@code java/lang}. |
|
230 * |
|
231 * @param typeElement the type element |
|
232 * @return the path |
|
233 */ |
|
234 public DocPath forPackage(TypeElement typeElement) { |
|
235 return (typeElement == null) |
|
236 ? DocPath.empty |
|
237 : forPackage(utils.containingPackage(typeElement)); |
|
238 } |
|
239 |
|
240 /** |
|
241 * Returns the path for a package. |
|
242 * For example, if the package is {@code java.lang}, |
|
243 * the path is {@code java/lang}. |
|
244 * |
|
245 * @param pkgElement the package element |
|
246 * @return the path |
|
247 */ |
|
248 public DocPath forPackage(PackageElement pkgElement) { |
|
249 if (pkgElement == null || pkgElement.isUnnamed()) { |
|
250 return DocPath.empty; |
|
251 } |
|
252 |
|
253 DocPath pkgPath = DocPath.create(pkgElement.getQualifiedName().toString().replace('.', '/')); |
|
254 if (useModuleDirectories) { |
|
255 ModuleElement mdle = (ModuleElement) pkgElement.getEnclosingElement(); |
|
256 return forModule(mdle).resolve(pkgPath); |
|
257 } else { |
|
258 return pkgPath; |
|
259 } |
|
260 } |
|
261 |
|
262 /** |
|
263 * Returns the inverse path for a package. |
|
264 * For example, if the package is {@code java.lang}, |
|
265 * the inverse path is {@code ../..}. |
|
266 * |
|
267 * @param pkgElement the package element |
|
268 * @return the path |
|
269 */ |
|
270 public static DocPath forRoot(PackageElement pkgElement) { |
|
271 String name = (pkgElement == null || pkgElement.isUnnamed()) |
|
272 ? "" |
|
273 : pkgElement.getQualifiedName().toString(); |
|
274 return new DocPath(name.replace('.', '/').replaceAll("[^/]+", "..")); |
|
275 } |
|
276 |
|
277 /** |
|
278 * Returns a relative path from one package to another. |
|
279 * |
|
280 * @param from the origin of the relative path |
|
281 * @param to the destination of the relative path |
|
282 * @return the path |
|
283 */ |
|
284 public DocPath relativePath(PackageElement from, PackageElement to) { |
|
285 return forRoot(from).resolve(forPackage(to)); |
|
286 } |
|
287 |
|
288 /** |
|
289 * The path for the output directory for module documentation files. |
|
290 * @param mdle the module |
|
291 * @return the path |
|
292 */ |
|
293 public DocPath moduleDocFiles(ModuleElement mdle) { |
|
294 return createModulePath(mdle, "doc-files"); |
|
295 } |
|
296 |
|
297 /** |
|
298 * The path for the file for a module's frame page. |
|
299 * @param mdle the module |
|
300 * @return the path |
|
301 */ |
|
302 public DocPath moduleFrame(ModuleElement mdle) { |
|
303 return createModulePath(mdle, "frame.html"); |
|
304 } |
|
305 |
|
306 /** |
|
307 * The path for the file for a module's summary page. |
|
308 * @param mdle the module |
|
309 * @return the path |
|
310 */ |
|
311 public DocPath moduleSummary(ModuleElement mdle) { |
|
312 return createModulePath(mdle, "summary.html"); |
|
313 } |
|
314 |
|
315 /** |
|
316 * The path for the file for a module's summary page. |
|
317 * @param mdleName the module |
|
318 * @return the path |
|
319 */ |
|
320 public DocPath moduleSummary(String mdleName) { |
|
321 return createModulePath(mdleName, "summary.html"); |
|
322 } |
|
323 |
|
324 /** |
|
325 * The path for the file for a module's type frame page. |
|
326 * @param mdle the module |
|
327 * @return the path |
|
328 */ |
|
329 public DocPath moduleTypeFrame(ModuleElement mdle) { |
|
330 return createModulePath(mdle, "type-frame.html"); |
|
331 } |
|
332 |
|
333 private DocPath createModulePath(ModuleElement mdle, String path) { |
|
334 return DocPath.create(mdle.getQualifiedName() + moduleSeparator + path); |
|
335 } |
|
336 |
|
337 private DocPath createModulePath(String moduleName, String path) { |
|
338 return DocPath.create(moduleName + moduleSeparator + path); |
199 } |
339 } |
200 |
340 |
201 /** The name of the file for the module overview frame. */ |
341 /** The name of the file for the module overview frame. */ |
202 public static final DocPath MODULE_OVERVIEW_FRAME = DocPath.create("module-overview-frame.html"); |
342 public static final DocPath MODULE_OVERVIEW_FRAME = DocPath.create("module-overview-frame.html"); |
203 |
343 |