|
25 | 25 |
|
26 | 26 | package jdk.javadoc.internal.doclets.toolkit;
|
27 | 27 |
|
28 |
| -import java.io.*; |
29 |
| -import java.util.*; |
30 | 28 |
|
| 29 | +import java.io.IOException; |
| 30 | +import java.io.InputStream; |
| 31 | +import java.util.ArrayList; |
| 32 | +import java.util.Collections; |
| 33 | +import java.util.HashMap; |
| 34 | +import java.util.HashSet; |
| 35 | +import java.util.LinkedHashSet; |
| 36 | +import java.util.List; |
| 37 | +import java.util.Locale; |
| 38 | +import java.util.Map; |
| 39 | +import java.util.Set; |
| 40 | +import java.util.SortedMap; |
| 41 | +import java.util.SortedSet; |
| 42 | +import java.util.TreeMap; |
| 43 | +import java.util.TreeSet; |
| 44 | + |
| 45 | +import javax.lang.model.SourceVersion; |
31 | 46 | import javax.lang.model.element.Element;
|
32 | 47 | import javax.lang.model.element.ModuleElement;
|
33 | 48 | import javax.lang.model.element.PackageElement;
|
34 | 49 | import javax.lang.model.element.TypeElement;
|
| 50 | +import javax.lang.model.util.Elements; |
35 | 51 | import javax.lang.model.util.SimpleElementVisitor14;
|
36 | 52 | import javax.tools.JavaFileManager;
|
37 | 53 | import javax.tools.JavaFileObject;
|
38 | 54 |
|
| 55 | +import com.sun.source.tree.CompilationUnitTree; |
39 | 56 | import com.sun.source.util.DocTreePath;
|
| 57 | +import com.sun.source.util.TreePath; |
40 | 58 | import com.sun.tools.javac.util.DefinedBy;
|
41 | 59 | import com.sun.tools.javac.util.DefinedBy.Api;
|
42 | 60 | import jdk.javadoc.doclet.Doclet;
|
43 | 61 | import jdk.javadoc.doclet.DocletEnvironment;
|
44 | 62 | import jdk.javadoc.doclet.Reporter;
|
45 | 63 | import jdk.javadoc.doclet.StandardDoclet;
|
46 | 64 | import jdk.javadoc.doclet.Taglet;
|
47 |
| -import jdk.javadoc.internal.doclets.formats.html.HtmlDoclet; |
48 | 65 | import jdk.javadoc.internal.doclets.toolkit.builders.BuilderFactory;
|
49 | 66 | import jdk.javadoc.internal.doclets.toolkit.taglets.TagletManager;
|
50 | 67 | import jdk.javadoc.internal.doclets.toolkit.util.Comparators;
|
|
60 | 77 | import jdk.javadoc.internal.doclets.toolkit.util.Utils.Pair;
|
61 | 78 | import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberCache;
|
62 | 79 | import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable;
|
| 80 | +import jdk.javadoc.internal.doclint.DocLint; |
63 | 81 |
|
64 | 82 | /**
|
65 | 83 | * Configure the output based on the options. Doclets should sub-class
|
@@ -201,7 +219,7 @@ public abstract class BaseConfiguration {
|
201 | 219 | * @apiNote The {@code doclet} parameter is used when
|
202 | 220 | * {@link Taglet#init(DocletEnvironment, Doclet) initializing tags}.
|
203 | 221 | * Some doclets (such as the {@link StandardDoclet}), may delegate to another
|
204 |
| - * (such as the {@link HtmlDoclet}). In such cases, the primary doclet (i.e |
| 222 | + * (such as the {@code HtmlDoclet}). In such cases, the primary doclet (i.e |
205 | 223 | * {@code StandardDoclet}) should be provided here, and not any internal
|
206 | 224 | * class like {@code HtmlDoclet}.
|
207 | 225 | *
|
@@ -367,7 +385,16 @@ protected boolean finishOptionSettings0() throws DocletException {
|
367 | 385 | group.checkPackageGroups(grp.first, grp.second);
|
368 | 386 | }
|
369 | 387 | });
|
370 |
| - overviewElement = new OverviewElement(workArounds.getUnnamedPackage(), getOverviewPath()); |
| 388 | + |
| 389 | + PackageElement unnamedPackage; |
| 390 | + Elements elementUtils = utils.elementUtils; |
| 391 | + if (docEnv.getSourceVersion().compareTo(SourceVersion.RELEASE_9) >= 0) { |
| 392 | + ModuleElement unnamedModule = elementUtils.getModuleElement(""); |
| 393 | + unnamedPackage = elementUtils.getPackageElement(unnamedModule, ""); |
| 394 | + } else { |
| 395 | + unnamedPackage = elementUtils.getPackageElement(""); |
| 396 | + } |
| 397 | + overviewElement = new OverviewElement(unnamedPackage, getOverviewPath()); |
371 | 398 | return true;
|
372 | 399 | }
|
373 | 400 |
|
@@ -690,4 +717,91 @@ public boolean isJavaFXMode() {
|
690 | 717 | || javafxModule.isUnnamed()
|
691 | 718 | || javafxModule.getQualifiedName().contentEquals("javafx.base");
|
692 | 719 | }
|
| 720 | + |
| 721 | + |
| 722 | + //<editor-fold desc="DocLint support"> |
| 723 | + |
| 724 | + private DocLint doclint; |
| 725 | + |
| 726 | + Map<CompilationUnitTree, Boolean> shouldCheck = new HashMap<>(); |
| 727 | + |
| 728 | + public void runDocLint(TreePath path) { |
| 729 | + CompilationUnitTree unit = path.getCompilationUnit(); |
| 730 | + if (doclint != null && shouldCheck.computeIfAbsent(unit, doclint::shouldCheck)) { |
| 731 | + doclint.scan(path); |
| 732 | + } |
| 733 | + } |
| 734 | + |
| 735 | + /** |
| 736 | + * Initializes DocLint, if appropriate, depending on options derived |
| 737 | + * from the doclet command-line options, and the set of custom tags |
| 738 | + * that should be ignored by DocLint. |
| 739 | + * |
| 740 | + * DocLint is not enabled if the option {@code -Xmsgs:none} is given, |
| 741 | + * and it is not followed by any options to enable any groups. |
| 742 | + * Note that arguments for {@code -Xmsgs:} can be given individually |
| 743 | + * in separate {@code -Xmsgs:} options, or in a comma-separated list |
| 744 | + * for a single option. For example, the following are equivalent: |
| 745 | + * <ul> |
| 746 | + * <li>{@code -Xmsgs:all} {@code -Xmsgs:-html} |
| 747 | + * <li>{@code -Xmsgs:all,-html} |
| 748 | + * </ul> |
| 749 | + * |
| 750 | + * @param opts options for DocLint, derived from the corresponding doclet |
| 751 | + * command-line options |
| 752 | + * @param customTagNames the names of custom tags, to be ignored by doclint |
| 753 | + */ |
| 754 | + public void initDocLint(List<String> opts, Set<String> customTagNames) { |
| 755 | + List<String> doclintOpts = new ArrayList<>(); |
| 756 | + |
| 757 | + // basic analysis of -Xmsgs and -Xmsgs: options to see if doclint is enabled |
| 758 | + Set<String> groups = new HashSet<>(); |
| 759 | + boolean seenXmsgs = false; |
| 760 | + for (String opt : opts) { |
| 761 | + if (opt.equals(DocLint.XMSGS_OPTION)) { |
| 762 | + groups.add("all"); |
| 763 | + seenXmsgs = true; |
| 764 | + } else if (opt.startsWith(DocLint.XMSGS_CUSTOM_PREFIX)) { |
| 765 | + String[] args = opt.substring(DocLint.XMSGS_CUSTOM_PREFIX.length()) |
| 766 | + .split(DocLint.SEPARATOR); |
| 767 | + for (String a : args) { |
| 768 | + if (a.equals("none")) { |
| 769 | + groups.clear(); |
| 770 | + } else if (a.startsWith("-")) { |
| 771 | + groups.remove(a.substring(1)); |
| 772 | + } else { |
| 773 | + groups.add(a); |
| 774 | + } |
| 775 | + } |
| 776 | + seenXmsgs = true; |
| 777 | + } |
| 778 | + doclintOpts.add(opt); |
| 779 | + } |
| 780 | + |
| 781 | + if (seenXmsgs) { |
| 782 | + if (groups.isEmpty()) { |
| 783 | + // no groups enabled; do not init doclint |
| 784 | + return; |
| 785 | + } |
| 786 | + } else { |
| 787 | + // no -Xmsgs options of any kind, use default |
| 788 | + doclintOpts.add(DocLint.XMSGS_OPTION); |
| 789 | + } |
| 790 | + |
| 791 | + if (!customTagNames.isEmpty()) { |
| 792 | + String customTags = String.join(DocLint.SEPARATOR, customTagNames); |
| 793 | + doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags); |
| 794 | + } |
| 795 | + |
| 796 | + doclintOpts.add(DocLint.XHTML_VERSION_PREFIX + "html5"); |
| 797 | + |
| 798 | + doclint = new DocLint(); |
| 799 | + doclint.init(docEnv.getDocTrees(), docEnv.getElementUtils(), docEnv.getTypeUtils(), |
| 800 | + doclintOpts.toArray(new String[0])); |
| 801 | + } |
| 802 | + |
| 803 | + public boolean haveDocLint() { |
| 804 | + return (doclint != null); |
| 805 | + } |
| 806 | + //</editor-fold> |
693 | 807 | }
|
0 commit comments