mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8236949: javadoc -Xdoclint does not accumulate options correctly
Reviewed-by: prappo
This commit is contained in:
parent
b5bf0d6d2f
commit
85f5e328ed
5 changed files with 291 additions and 64 deletions
|
@ -188,7 +188,7 @@ public class HtmlConfiguration extends BaseConfiguration {
|
|||
docPaths = new DocPaths(utils);
|
||||
setCreateOverview();
|
||||
setTopFile(docEnv);
|
||||
workArounds.initDocLint(options.doclintOpts().values(), tagletManager.getAllTagletNames());
|
||||
workArounds.initDocLint(options.doclintOpts(), tagletManager.getAllTagletNames());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,14 +28,11 @@ package jdk.javadoc.internal.doclets.formats.html;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import com.sun.tools.doclint.DocLint;
|
||||
import jdk.javadoc.doclet.Doclet;
|
||||
import jdk.javadoc.doclet.Reporter;
|
||||
import jdk.javadoc.internal.doclets.toolkit.BaseOptions;
|
||||
import jdk.javadoc.internal.doclets.toolkit.Resources;
|
||||
|
@ -105,7 +102,7 @@ public class HtmlOptions extends BaseOptions {
|
|||
* Arguments for command-line option {@code -Xdoclint} and friends.
|
||||
* Collected set of doclint options.
|
||||
*/
|
||||
private Map<Doclet.Option, String> doclintOpts = new LinkedHashMap<>();
|
||||
private List<String> doclintOpts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Argument for command-line option {@code -Xdocrootparent}.
|
||||
|
@ -411,7 +408,37 @@ public class HtmlOptions extends BaseOptions {
|
|||
new XOption(resources, "-Xdoclint") {
|
||||
@Override
|
||||
public boolean process(String opt, List<String> args) {
|
||||
doclintOpts.put(this, DocLint.XMSGS_OPTION);
|
||||
doclintOpts.add(DocLint.XMSGS_OPTION);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
new XOption(resources, "doclet.usage.xdoclint-extended", "-Xdoclint:", 0) {
|
||||
@Override
|
||||
public boolean process(String opt, List<String> args) {
|
||||
String dopt = opt.replace("-Xdoclint:", DocLint.XMSGS_CUSTOM_PREFIX);
|
||||
if (dopt.contains("/")) {
|
||||
reporter.print(ERROR, resources.getText("doclet.Option_doclint_no_qualifiers"));
|
||||
return false;
|
||||
}
|
||||
if (!DocLint.isValidOption(dopt)) {
|
||||
reporter.print(ERROR, resources.getText("doclet.Option_doclint_invalid_arg"));
|
||||
return false;
|
||||
}
|
||||
doclintOpts.add(dopt);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
new XOption(resources, "doclet.usage.xdoclint-package", "-Xdoclint/package:", 0) {
|
||||
@Override
|
||||
public boolean process(String opt, List<String> args) {
|
||||
String dopt = opt.replace("-Xdoclint/package:", DocLint.XCHECK_PACKAGE);
|
||||
if (!DocLint.isValidOption(dopt)) {
|
||||
reporter.print(ERROR, resources.getText("doclet.Option_doclint_package_invalid_arg"));
|
||||
return false;
|
||||
}
|
||||
doclintOpts.add(dopt);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
@ -430,36 +457,6 @@ public class HtmlOptions extends BaseOptions {
|
|||
}
|
||||
},
|
||||
|
||||
new XOption(resources, "doclet.usage.xdoclint-extended", "-Xdoclint:", 0) {
|
||||
@Override
|
||||
public boolean process(String opt, List<String> args) {
|
||||
String dopt = opt.replace("-Xdoclint:", DocLint.XMSGS_CUSTOM_PREFIX);
|
||||
doclintOpts.put(this, dopt);
|
||||
if (dopt.contains("/")) {
|
||||
reporter.print(ERROR, resources.getText("doclet.Option_doclint_no_qualifiers"));
|
||||
return false;
|
||||
}
|
||||
if (!DocLint.isValidOption(dopt)) {
|
||||
reporter.print(ERROR, resources.getText("doclet.Option_doclint_invalid_arg"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
new XOption(resources, "doclet.usage.xdoclint-package", "-Xdoclint/package:", 0) {
|
||||
@Override
|
||||
public boolean process(String opt, List<String> args) {
|
||||
String dopt = opt.replace("-Xdoclint/package:", DocLint.XCHECK_PACKAGE);
|
||||
doclintOpts.put(this, dopt);
|
||||
if (!DocLint.isValidOption(dopt)) {
|
||||
reporter.print(ERROR, resources.getText("doclet.Option_doclint_package_invalid_arg"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
new XOption(resources, "--no-frames") {
|
||||
@Override
|
||||
public boolean process(String opt, List<String> args) {
|
||||
|
@ -589,7 +586,7 @@ public class HtmlOptions extends BaseOptions {
|
|||
* Arguments for command-line option {@code -Xdoclint} and friends.
|
||||
* Collected set of doclint options.
|
||||
*/
|
||||
Map<Doclet.Option, String> doclintOpts() {
|
||||
List<String> doclintOpts() {
|
||||
return doclintOpts;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* 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
|
||||
|
@ -27,10 +27,11 @@ 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;
|
||||
|
||||
|
@ -111,37 +112,72 @@ public class WorkArounds {
|
|||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
|
@ -422,7 +458,7 @@ public class WorkArounds {
|
|||
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);
|
||||
}
|
||||
|
@ -434,7 +470,7 @@ public class WorkArounds {
|
|||
* serialField tag.
|
||||
*/
|
||||
definesSerializableFields = true;
|
||||
fields.add((VariableElement) dsf);
|
||||
fields.add(dsf);
|
||||
} else {
|
||||
|
||||
/* Calculate default Serializable fields as all
|
||||
|
@ -573,9 +609,8 @@ public class WorkArounds {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue