23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package jdk.javadoc.internal.doclets.formats.html; |
26 package jdk.javadoc.internal.doclets.formats.html; |
27 |
27 |
28 import java.io.*; |
|
29 import java.util.*; |
28 import java.util.*; |
30 |
29 |
31 import javax.lang.model.element.ModuleElement; |
30 import javax.lang.model.element.ModuleElement; |
32 import javax.lang.model.element.PackageElement; |
31 import javax.lang.model.element.PackageElement; |
33 import javax.lang.model.element.TypeElement; |
32 import javax.lang.model.element.TypeElement; |
34 |
33 |
35 import jdk.javadoc.doclet.Doclet.Option; |
34 import jdk.javadoc.doclet.Doclet.Option; |
36 import jdk.javadoc.doclet.DocletEnvironment; |
35 import jdk.javadoc.doclet.DocletEnvironment; |
37 import jdk.javadoc.doclet.Reporter; |
36 import jdk.javadoc.doclet.Reporter; |
38 import jdk.javadoc.internal.doclets.toolkit.AbstractDoclet; |
37 import jdk.javadoc.internal.doclets.toolkit.AbstractDoclet; |
39 import jdk.javadoc.internal.doclets.toolkit.Configuration; |
38 import jdk.javadoc.internal.doclets.toolkit.DocletException; |
40 import jdk.javadoc.internal.doclets.toolkit.Messages; |
39 import jdk.javadoc.internal.doclets.toolkit.Messages; |
41 import jdk.javadoc.internal.doclets.toolkit.builders.AbstractBuilder; |
40 import jdk.javadoc.internal.doclets.toolkit.builders.AbstractBuilder; |
42 import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; |
41 import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; |
43 import jdk.javadoc.internal.doclets.toolkit.util.DocFile; |
42 import jdk.javadoc.internal.doclets.toolkit.util.DocFile; |
|
43 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; |
44 import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
44 import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
45 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
45 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
46 import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException; |
|
47 import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder; |
46 import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder; |
48 |
47 |
49 /** |
48 /** |
50 * The class with "start" method, calls individual Writers. |
49 * The class with "start" method, calls individual Writers. |
51 * |
50 * |
90 |
89 |
91 /** |
90 /** |
92 * Create the configuration instance. |
91 * Create the configuration instance. |
93 * Override this method to use a different |
92 * Override this method to use a different |
94 * configuration. |
93 * configuration. |
95 */ |
94 * @return the configuration for this doclet |
96 @Override // defined by AbstractDoclet |
95 */ |
97 public Configuration configuration() { |
96 @Override // defined by AbstractDoclet |
|
97 public ConfigurationImpl configuration() { |
98 return configuration; |
98 return configuration; |
99 } |
99 } |
100 |
100 |
101 /** |
101 /** |
102 * Start the generation of files. Call generate methods in the individual |
102 * Start the generation of files. Call generate methods in the individual |
103 * writers, which will in turn genrate the documentation files. Call the |
103 * writers, which will in turn generate the documentation files. Call the |
104 * TreeWriter generation first to ensure the Class Hierarchy is built |
104 * TreeWriter generation first to ensure the Class Hierarchy is built |
105 * first and then can be used in the later generation. |
105 * first and then can be used in the later generation. |
106 * |
106 * |
107 * For new format. |
107 * For new format. |
108 * |
108 * |
|
109 * @throws DocletException if there is a problem while writing the other files |
109 * @see jdk.doclet.DocletEnvironment |
110 * @see jdk.doclet.DocletEnvironment |
110 */ |
111 */ |
111 @Override // defined by AbstractDoclet |
112 @Override // defined by AbstractDoclet |
112 protected void generateOtherFiles(DocletEnvironment docEnv, ClassTree classtree) |
113 protected void generateOtherFiles(DocletEnvironment docEnv, ClassTree classtree) |
113 throws Exception { |
114 throws DocletException { |
114 super.generateOtherFiles(docEnv, classtree); |
115 super.generateOtherFiles(docEnv, classtree); |
115 if (configuration.linksource) { |
116 if (configuration.linksource) { |
116 SourceToHTMLConverter.convertRoot(configuration, |
117 SourceToHTMLConverter.convertRoot(configuration, |
117 docEnv, DocPaths.SOURCE_OUTPUT); |
118 docEnv, DocPaths.SOURCE_OUTPUT); |
118 } |
119 } |
230 |
231 |
231 /** |
232 /** |
232 * {@inheritDoc} |
233 * {@inheritDoc} |
233 */ |
234 */ |
234 @Override // defined by AbstractDoclet |
235 @Override // defined by AbstractDoclet |
235 protected void generateClassFiles(SortedSet<TypeElement> arr, ClassTree classtree) { |
236 protected void generateClassFiles(SortedSet<TypeElement> arr, ClassTree classtree) |
|
237 throws DocletException { |
236 List<TypeElement> list = new ArrayList<>(arr); |
238 List<TypeElement> list = new ArrayList<>(arr); |
237 ListIterator<TypeElement> iterator = list.listIterator(); |
239 ListIterator<TypeElement> iterator = list.listIterator(); |
238 TypeElement klass = null; |
240 TypeElement klass = null; |
239 while (iterator.hasNext()) { |
241 while (iterator.hasNext()) { |
240 TypeElement prev = iterator.hasPrevious() ? klass : null; |
242 TypeElement prev = iterator.hasPrevious() ? klass : null; |
241 klass = iterator.next(); |
243 klass = iterator.next(); |
242 TypeElement next = iterator.nextIndex() == list.size() |
244 TypeElement next = iterator.nextIndex() == list.size() |
243 ? null : list.get(iterator.nextIndex()); |
245 ? null : list.get(iterator.nextIndex()); |
|
246 |
244 if (utils.isHidden(klass) || |
247 if (utils.isHidden(klass) || |
245 !(configuration.isGeneratedDoc(klass) && utils.isIncluded(klass))) { |
248 !(configuration.isGeneratedDoc(klass) && utils.isIncluded(klass))) { |
246 continue; |
249 continue; |
247 } |
250 } |
248 try { |
251 |
249 if (utils.isAnnotationType(klass)) { |
252 if (utils.isAnnotationType(klass)) { |
250 AbstractBuilder annotationTypeBuilder = |
253 AbstractBuilder annotationTypeBuilder = |
251 configuration.getBuilderFactory() |
254 configuration.getBuilderFactory() |
252 .getAnnotationTypeBuilder(klass, |
255 .getAnnotationTypeBuilder(klass, |
253 prev == null ? null : prev.asType(), |
256 prev == null ? null : prev.asType(), |
254 next == null ? null : next.asType()); |
257 next == null ? null : next.asType()); |
255 annotationTypeBuilder.build(); |
258 annotationTypeBuilder.build(); |
256 } else { |
259 } else { |
257 AbstractBuilder classBuilder = |
260 AbstractBuilder classBuilder = |
258 configuration.getBuilderFactory().getClassBuilder(klass, |
261 configuration.getBuilderFactory().getClassBuilder(klass, |
259 prev, next, classtree); |
262 prev, next, classtree); |
260 classBuilder.build(); |
263 classBuilder.build(); |
261 } |
|
262 } catch (IOException e) { |
|
263 throw new DocletAbortException(e); |
|
264 } catch (DocletAbortException de) { |
|
265 de.printStackTrace(); |
|
266 throw de; |
|
267 } catch (Exception e) { |
|
268 e.printStackTrace(); |
|
269 throw new DocletAbortException(e); |
|
270 } |
264 } |
271 } |
265 } |
272 } |
266 } |
273 |
267 |
274 /** |
268 /** |
275 * {@inheritDoc} |
269 * {@inheritDoc} |
276 */ |
270 */ |
277 @Override // defined by AbstractDoclet |
271 @Override // defined by AbstractDoclet |
278 protected void generateModuleFiles() throws Exception { |
272 protected void generateModuleFiles() throws DocletException { |
279 if (configuration.showModules) { |
273 if (configuration.showModules) { |
280 if (configuration.frames) { |
274 if (configuration.frames) { |
281 ModuleIndexFrameWriter.generate(configuration); |
275 ModuleIndexFrameWriter.generate(configuration); |
282 } |
276 } |
283 ModuleElement prevModule = null, nextModule; |
277 ModuleElement prevModule = null, nextModule; |
354 @Override // defined by Doclet |
348 @Override // defined by Doclet |
355 public Set<Option> getSupportedOptions() { |
349 public Set<Option> getSupportedOptions() { |
356 return configuration.getSupportedOptions(); |
350 return configuration.getSupportedOptions(); |
357 } |
351 } |
358 |
352 |
359 private void performCopy(String filename) { |
353 private void performCopy(String filename) throws DocFileIOException { |
360 if (filename.isEmpty()) |
354 if (filename.isEmpty()) |
361 return; |
355 return; |
362 |
356 |
363 try { |
357 DocFile fromfile = DocFile.createFileForInput(configuration, filename); |
364 DocFile fromfile = DocFile.createFileForInput(configuration, filename); |
358 DocPath path = DocPath.create(fromfile.getName()); |
365 DocPath path = DocPath.create(fromfile.getName()); |
359 DocFile toFile = DocFile.createFileForOutput(configuration, path); |
366 DocFile toFile = DocFile.createFileForOutput(configuration, path); |
360 if (toFile.isSameFile(fromfile)) |
367 if (toFile.isSameFile(fromfile)) |
361 return; |
368 return; |
362 |
369 |
363 messages.notice("doclet.Copying_File_0_To_File_1", |
370 messages.notice("doclet.Copying_File_0_To_File_1", |
364 fromfile.toString(), path.getPath()); |
371 fromfile.toString(), path.getPath()); |
365 toFile.copyFile(fromfile); |
372 toFile.copyFile(fromfile); |
|
373 } catch (IOException exc) { |
|
374 messages.error("doclet.perform_copy_exception_encountered", |
|
375 exc.toString()); |
|
376 throw new DocletAbortException(exc); |
|
377 } |
|
378 } |
366 } |
379 } |
367 } |