Skip to content
Permalink
Browse files

8236949: javadoc -Xdoclint does not accumulate options correctly

Reviewed-by: prappo
  • Loading branch information
jonathan-gibbons committed Jan 30, 2020
1 parent b5bf0d6 commit 85f5e328ed844c3a370baf905862b1d246956e4c
@@ -188,7 +188,7 @@ public boolean finishOptionSettings() {
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 @@
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 @@
* 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,21 +408,7 @@ public boolean process(String opt, List<String> args) {
new XOption(resources, "-Xdoclint") {
@Override
public boolean process(String opt, List<String> args) {
doclintOpts.put(this, DocLint.XMSGS_OPTION);
return true;
}
},

new XOption(resources, "-Xdocrootparent", 1) {
@Override
public boolean process(String opt, List<String> args) {
docrootParent = args.get(0);
try {
new URL(docrootParent);
} catch (MalformedURLException e) {
reporter.print(ERROR, resources.getText("doclet.MalformedURL", docrootParent));
return false;
}
doclintOpts.add(DocLint.XMSGS_OPTION);
return true;
}
},
@@ -434,7 +417,6 @@ public boolean process(String opt, List<String> args) {
@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;
@@ -443,6 +425,7 @@ public boolean process(String opt, List<String> args) {
reporter.print(ERROR, resources.getText("doclet.Option_doclint_invalid_arg"));
return false;
}
doclintOpts.add(dopt);
return true;
}
},
@@ -451,11 +434,25 @@ public boolean process(String opt, List<String> args) {
@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;
}
doclintOpts.add(dopt);
return true;
}
},

new XOption(resources, "-Xdocrootparent", 1) {
@Override
public boolean process(String opt, List<String> args) {
docrootParent = args.get(0);
try {
new URL(docrootParent);
} catch (MalformedURLException e) {
reporter.print(ERROR, resources.getText("doclet.MalformedURL", docrootParent));
return false;
}
return true;
}
},
@@ -589,7 +586,7 @@ public boolean createTree() {
* 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 @@

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 void runDocLint(TreePath 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
@@ -422,7 +458,7 @@ public boolean definesSerializableFields(TypeElement typeElem) {
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 boolean definesSerializableFields(TypeElement typeElem) {
* serialField tag.
*/
definesSerializableFields = true;
fields.add((VariableElement) dsf);
fields.add(dsf);
} else {

/* Calculate default Serializable fields as all
@@ -573,9 +609,8 @@ public ExecutableElement findMethod(TypeElement te, String methodName,
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;
}
}

0 comments on commit 85f5e32

Please sign in to comment.