< prev index next >

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WorkArounds.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -25,14 +25,15 @@
 
 package jdk.javadoc.internal.doclets.toolkit;
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
 import javax.lang.model.element.AnnotationMirror;
 import javax.lang.model.element.Element;

@@ -109,41 +110,76 @@
         if (doclint != null && shouldCheck.computeIfAbsent(unit, doclint::shouldCheck)) {
             doclint.scan(path);
         }
     }
 
-    // TODO: fix this up correctly
-    public void initDocLint(Collection<String> opts, Collection<String> customTagNames) {
-        ArrayList<String> doclintOpts = new ArrayList<>();
-        boolean msgOptionSeen = false;
-
+    /**
+     * Initializes doclint, if appropriate, depending on options derived
+     * from the doclet command-line options, and the set of custom tags
+     * that should be ignored by doclint.
+     *
+     * DocLint is not enabled if the option {@code -Xmsgs:none} is given,
+     * and it is not followed by any options to enable any groups.
+     * Note that arguments for {@code -Xmsgs:} can be given individually
+     * in separate {@code -Xmsgs:} options, or in a comma-separated list
+     * for a single option. For example, the following are equivalent:
+     * <ul>
+     *     <li>{@code -Xmsgs:all} {@code -Xmsgs:-html}
+     *     <li>{@code -Xmsgs:all,-html}
+     * </ul>
+     *
+     * @param opts  options for doclint, derived from the corresponding doclet
+     *              command-line options
+     * @param customTagNames the names of custom tags, to be ignored by doclint
+     */
+    public void initDocLint(List<String> opts, Set<String> customTagNames) {
+        List<String> doclintOpts = new ArrayList<>();
+
+        // basic analysis of -Xmsgs and -Xmsgs: options to see if doclint is enabled
+        Set<String> groups = new HashSet<>();
+        boolean seenXmsgs = false;
         for (String opt : opts) {
-            if (opt.startsWith(DocLint.XMSGS_OPTION)) {
-                if (opt.equals(DocLint.XMSGS_CUSTOM_PREFIX + "none"))
-                    return;
-                msgOptionSeen = true;
+            if (opt.equals(DocLint.XMSGS_OPTION)) {
+                groups.add("all");
+                seenXmsgs = true;
+            } else if (opt.startsWith(DocLint.XMSGS_CUSTOM_PREFIX)) {
+                String[] args = opt.substring(DocLint.XMSGS_CUSTOM_PREFIX.length())
+                        .split(DocLint.SEPARATOR);
+                for (String a : args) {
+                    if (a.equals("none")) {
+                        groups.clear();
+                    } else if (a.startsWith("-")) {
+                        groups.remove(a.substring(1));
+                    } else {
+                        groups.add(a);
+                    }
+                }
+                seenXmsgs = true;
             }
             doclintOpts.add(opt);
         }
 
-        if (!msgOptionSeen) {
+        if (seenXmsgs) {
+            if (groups.isEmpty()) {
+                // no groups enabled; do not init doclint
+                return;
+            }
+        } else {
+            // no -Xmsgs options of any kind, use default
             doclintOpts.add(DocLint.XMSGS_OPTION);
         }
 
-        String sep = "";
-        StringBuilder customTags = new StringBuilder();
-        for (String customTag : customTagNames) {
-            customTags.append(sep);
-            customTags.append(customTag);
-            sep = DocLint.SEPARATOR;
+        if (!customTagNames.isEmpty()) {
+            String customTags = String.join(DocLint.SEPARATOR, customTagNames);
+            doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags);
         }
-        doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString());
+
         doclintOpts.add(DocLint.XHTML_VERSION_PREFIX + "html5");
 
         JavacTask t = BasicJavacTask.instance(toolEnv.context);
         doclint = new DocLint();
-        doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false);
+        doclint.init(t, doclintOpts.toArray(new String[0]), false);
     }
 
     // TODO: fix this up correctly
     public boolean haveDocLint() {
         return (doclint == null);

@@ -420,11 +456,11 @@
 
                 ExecutableElement md = findMethod(te, "readExternal", Arrays.asList(readExternalParamArr));
                 if (md != null) {
                     methods.add(md);
                 }
-                md = findMethod((ClassSymbol) te, "writeExternal", Arrays.asList(writeExternalParamArr));
+                md = findMethod(te, "writeExternal", Arrays.asList(writeExternalParamArr));
                 if (md != null) {
                     methods.add(md);
                 }
             } else if (utils.isSerializable(te)) {
                 VarSymbol dsf = getDefinedSerializableFields((ClassSymbol) te);

@@ -432,11 +468,11 @@
                     /* Define serializable fields with array of ObjectStreamField.
                      * Each ObjectStreamField should be documented by a
                      * serialField tag.
                      */
                     definesSerializableFields = true;
-                    fields.add((VariableElement) dsf);
+                    fields.add(dsf);
                 } else {
 
                     /* Calculate default Serializable fields as all
                      * non-transient, non-static fields.
                      * Fields should be documented by serial tag.

@@ -571,11 +607,10 @@
      * @return an abbreviated PackageElement
      */
     public PackageElement getAbbreviatedPackageElement(PackageElement pkg) {
         String parsedPackageName = utils.parsePackageName(pkg);
         ModuleElement encl = (ModuleElement) pkg.getEnclosingElement();
-        PackageElement abbrevPkg = encl == null
+        return encl == null
                 ? utils.elementUtils.getPackageElement(parsedPackageName)
                 : ((JavacElements) utils.elementUtils).getPackageElement(encl, parsedPackageName);
-        return abbrevPkg;
     }
 }
< prev index next >