24 */ |
24 */ |
25 |
25 |
26 package jdk.javadoc.internal.doclets.toolkit; |
26 package jdk.javadoc.internal.doclets.toolkit; |
27 |
27 |
28 import java.io.*; |
28 import java.io.*; |
29 import java.lang.ref.*; |
|
30 import java.util.*; |
29 import java.util.*; |
31 |
30 |
32 import javax.lang.model.element.Element; |
31 import javax.lang.model.element.Element; |
33 import javax.lang.model.element.ModuleElement; |
32 import javax.lang.model.element.ModuleElement; |
34 import javax.lang.model.element.PackageElement; |
33 import javax.lang.model.element.PackageElement; |
54 import jdk.javadoc.internal.doclets.toolkit.util.MetaKeywords; |
53 import jdk.javadoc.internal.doclets.toolkit.util.MetaKeywords; |
55 import jdk.javadoc.internal.doclets.toolkit.util.SimpleDocletException; |
54 import jdk.javadoc.internal.doclets.toolkit.util.SimpleDocletException; |
56 import jdk.javadoc.internal.doclets.toolkit.util.TypeElementCatalog; |
55 import jdk.javadoc.internal.doclets.toolkit.util.TypeElementCatalog; |
57 import jdk.javadoc.internal.doclets.toolkit.util.Utils; |
56 import jdk.javadoc.internal.doclets.toolkit.util.Utils; |
58 import jdk.javadoc.internal.doclets.toolkit.util.Utils.Pair; |
57 import jdk.javadoc.internal.doclets.toolkit.util.Utils.Pair; |
59 import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap; |
58 import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberCache; |
60 import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap.GetterSetter; |
59 import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable; |
61 import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap.Kind; |
|
62 |
60 |
63 import static javax.tools.Diagnostic.Kind.*; |
61 import static javax.tools.Diagnostic.Kind.*; |
64 |
62 |
65 /** |
63 /** |
66 * Configure the output based on the options. Doclets should sub-class |
64 * Configure the output based on the options. Doclets should sub-class |
297 |
295 |
298 public boolean dumpOnError = false; |
296 public boolean dumpOnError = false; |
299 |
297 |
300 private List<Pair<String, String>> groupPairs; |
298 private List<Pair<String, String>> groupPairs; |
301 |
299 |
302 private final Map<TypeElement, EnumMap<Kind, Reference<VisibleMemberMap>>> typeElementMemberCache; |
|
303 |
|
304 public abstract Messages getMessages(); |
300 public abstract Messages getMessages(); |
305 |
301 |
306 public abstract Resources getResources(); |
302 public abstract Resources getResources(); |
307 |
303 |
308 /** |
304 /** |
329 */ |
325 */ |
330 public SortedSet<PackageElement> packages = null; |
326 public SortedSet<PackageElement> packages = null; |
331 |
327 |
332 public OverviewElement overviewElement; |
328 public OverviewElement overviewElement; |
333 |
329 |
334 // The following three fields provide caches for use by all instances of VisibleMemberMap. |
|
335 public final Map<TypeElement, List<Element>> propertiesCache = new HashMap<>(); |
|
336 public final Map<Element, Element> classPropertiesMap = new HashMap<>(); |
|
337 public final Map<Element, GetterSetter> getterSetterMap = new HashMap<>(); |
|
338 |
|
339 public DocFileFactory docFileFactory; |
330 public DocFileFactory docFileFactory; |
340 |
331 |
341 /** |
332 /** |
342 * A sorted map, giving the (specified|included|other) packages for each module. |
333 * A sorted map, giving the (specified|included|other) packages for each module. |
343 */ |
334 */ |
348 */ |
339 */ |
349 public SortedSet<ModuleElement> modules; |
340 public SortedSet<ModuleElement> modules; |
350 |
341 |
351 protected static final String sharedResourceBundleName = |
342 protected static final String sharedResourceBundleName = |
352 "jdk.javadoc.internal.doclets.toolkit.resources.doclets"; |
343 "jdk.javadoc.internal.doclets.toolkit.resources.doclets"; |
|
344 |
|
345 /** |
|
346 * Primarily used to disable strict checks in the regression |
|
347 * tests allowing those tests to be executed successfully, for |
|
348 * instance, with OpenJDK builds which may not contain FX libraries. |
|
349 */ |
|
350 public boolean disableJavaFxStrictChecks = false; |
|
351 |
|
352 VisibleMemberCache visibleMemberCache = null; |
|
353 |
|
354 public PropertyUtils propertyUtils = null; |
353 |
355 |
354 /** |
356 /** |
355 * Constructs the configurations needed by the doclet. |
357 * Constructs the configurations needed by the doclet. |
356 * |
358 * |
357 * @param doclet the doclet that created this configuration |
359 * @param doclet the doclet that created this configuration |
361 excludedDocFileDirs = new HashSet<>(); |
363 excludedDocFileDirs = new HashSet<>(); |
362 excludedQualifiers = new HashSet<>(); |
364 excludedQualifiers = new HashSet<>(); |
363 setTabWidth(DocletConstants.DEFAULT_TAB_STOP_LENGTH); |
365 setTabWidth(DocletConstants.DEFAULT_TAB_STOP_LENGTH); |
364 metakeywords = new MetaKeywords(this); |
366 metakeywords = new MetaKeywords(this); |
365 groupPairs = new ArrayList<>(0); |
367 groupPairs = new ArrayList<>(0); |
366 typeElementMemberCache = new HashMap<>(); |
|
367 } |
368 } |
368 |
369 |
369 private boolean initialized = false; |
370 private boolean initialized = false; |
370 |
371 |
371 protected void initConfiguration(DocletEnvironment docEnv) { |
372 protected void initConfiguration(DocletEnvironment docEnv) { |
372 if (initialized) { |
373 if (initialized) { |
373 throw new IllegalStateException("configuration previously initialized"); |
374 throw new IllegalStateException("configuration previously initialized"); |
374 } |
375 } |
375 initialized = true; |
376 initialized = true; |
376 this.docEnv = docEnv; |
377 this.docEnv = docEnv; |
|
378 // Utils needs docEnv, safe to init now. |
|
379 utils = new Utils(this); |
|
380 |
|
381 // Once docEnv and Utils have been initialized, others should be safe. |
|
382 cmtUtils = new CommentUtils(this); |
|
383 workArounds = new WorkArounds(this); |
|
384 visibleMemberCache = new VisibleMemberCache(this); |
|
385 propertyUtils = new PropertyUtils(this); |
|
386 |
377 Splitter specifiedSplitter = new Splitter(docEnv, false); |
387 Splitter specifiedSplitter = new Splitter(docEnv, false); |
378 specifiedModuleElements = Collections.unmodifiableSet(specifiedSplitter.mset); |
388 specifiedModuleElements = Collections.unmodifiableSet(specifiedSplitter.mset); |
379 specifiedPackageElements = Collections.unmodifiableSet(specifiedSplitter.pset); |
389 specifiedPackageElements = Collections.unmodifiableSet(specifiedSplitter.pset); |
380 specifiedTypeElements = Collections.unmodifiableSet(specifiedSplitter.tset); |
390 specifiedTypeElements = Collections.unmodifiableSet(specifiedSplitter.tset); |
381 |
391 |
695 }, |
705 }, |
696 new Option(resources, "--allow-script-in-comments") { |
706 new Option(resources, "--allow-script-in-comments") { |
697 @Override |
707 @Override |
698 public boolean process(String opt, List<String> args) { |
708 public boolean process(String opt, List<String> args) { |
699 allowScriptInComments = true; |
709 allowScriptInComments = true; |
|
710 return true; |
|
711 } |
|
712 }, |
|
713 new Hidden(resources, "--disable-javafx-strict-checks") { |
|
714 @Override |
|
715 public boolean process(String opt, List<String> args) { |
|
716 disableJavaFxStrictChecks = true; |
700 return true; |
717 return true; |
701 } |
718 } |
702 } |
719 } |
703 }; |
720 }; |
704 Set<Doclet.Option> set = new TreeSet<>(); |
721 Set<Doclet.Option> set = new TreeSet<>(); |
1283 */ |
1300 */ |
1284 public boolean isAllowScriptInComments() { |
1301 public boolean isAllowScriptInComments() { |
1285 return allowScriptInComments; |
1302 return allowScriptInComments; |
1286 } |
1303 } |
1287 |
1304 |
1288 public VisibleMemberMap getVisibleMemberMap(TypeElement te, VisibleMemberMap.Kind kind) { |
1305 public synchronized VisibleMemberTable getVisibleMemberTable(TypeElement te) { |
1289 EnumMap<Kind, Reference<VisibleMemberMap>> cacheMap = typeElementMemberCache |
1306 return visibleMemberCache.getVisibleMemberTable(te); |
1290 .computeIfAbsent(te, k -> new EnumMap<>(VisibleMemberMap.Kind.class)); |
|
1291 |
|
1292 Reference<VisibleMemberMap> vmapRef = cacheMap.get(kind); |
|
1293 // recompute, if referent has been garbage collected |
|
1294 VisibleMemberMap vMap = vmapRef == null ? null : vmapRef.get(); |
|
1295 if (vMap == null) { |
|
1296 vMap = new VisibleMemberMap(te, kind, this); |
|
1297 cacheMap.put(kind, new SoftReference<>(vMap)); |
|
1298 } |
|
1299 return vMap; |
|
1300 } |
1307 } |
1301 } |
1308 } |