Skip to content

Commit 59e9700

Browse files
8252717: Integrate/merge legacy standard doclet diagnostics and doclint
Reviewed-by: erikj, prappo
1 parent 28c112f commit 59e9700

File tree

11 files changed

+246
-39
lines changed

11 files changed

+246
-39
lines changed

make/Docs.gmk

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ JAVADOC_DISABLED_DOCLINT_PACKAGES := org.w3c.* javax.smartcardio
104104

105105
# The initial set of options for javadoc
106106
JAVADOC_OPTIONS := -use -keywords -notimestamp \
107-
-serialwarn -encoding ISO-8859-1 -docencoding UTF-8 -breakiterator \
107+
-encoding ISO-8859-1 -docencoding UTF-8 -breakiterator \
108108
-splitIndex --system none -javafx --expand-requires transitive \
109109
--override-methods=summary
110110

111111
# The reference options must stay stable to allow for comparisons across the
112112
# development cycle.
113113
REFERENCE_OPTIONS := -XDignore.symbol.file=true -use -keywords -notimestamp \
114-
-serialwarn -encoding ISO-8859-1 -breakiterator -splitIndex --system none \
114+
-encoding ISO-8859-1 -breakiterator -splitIndex --system none \
115115
-html5 -javafx --expand-requires transitive
116116

117117
# Should we add DRAFT stamps to the generated javadoc?

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java

-10
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,6 @@ public JavaFileManager getFileManager() {
403403
return docEnv.getJavaFileManager();
404404
}
405405

406-
@Override
407-
public boolean showMessage(DocTreePath path, String key) {
408-
return (path == null || !haveDocLint());
409-
}
410-
411-
@Override
412-
public boolean showMessage(Element e, String key) {
413-
return (e == null || !haveDocLint());
414-
}
415-
416406
@Override
417407
protected boolean finishOptionSettings0() throws DocletException {
418408
if (options.docEncoding() == null) {

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java

+14-8
Original file line numberDiff line numberDiff line change
@@ -1054,10 +1054,12 @@ public Content seeTagToContent(Element element, DocTree see, TagletWriterImpl.Co
10541054
(labelContent.isEmpty() ? text : labelContent));
10551055
} else {
10561056
// No cross link found so print warning
1057-
messages.warning(ch.getDocTreePath(see),
1058-
"doclet.see.class_or_package_not_found",
1059-
"@" + tagName,
1060-
seeText);
1057+
if (!configuration.isDocLintReferenceGroupEnabled()) {
1058+
messages.warning(ch.getDocTreePath(see),
1059+
"doclet.see.class_or_package_not_found",
1060+
"@" + tagName,
1061+
seeText);
1062+
}
10611063
return invalidTagOutput(resources.getText("doclet.tag.invalid", tagName),
10621064
Optional.of(labelContent.isEmpty() ? text: labelContent));
10631065
}
@@ -1107,9 +1109,11 @@ public Content seeTagToContent(Element element, DocTree see, TagletWriterImpl.Co
11071109
ch.getDocTreePath(see), "doclet.see.class_or_package_not_accessible",
11081110
tagName, utils.getFullyQualifiedName(containing));
11091111
} else {
1110-
messages.warning(
1111-
ch.getDocTreePath(see), "doclet.see.class_or_package_not_found",
1112-
tagName, seeText);
1112+
if (!configuration.isDocLintReferenceGroupEnabled()) {
1113+
messages.warning(
1114+
ch.getDocTreePath(see), "doclet.see.class_or_package_not_found",
1115+
tagName, seeText);
1116+
}
11131117
}
11141118
}
11151119
if (configuration.currentTypeElement != containing) {
@@ -1599,7 +1603,9 @@ public Boolean visitErroneous(ErroneousTree node, Content c) {
15991603
Matcher m = Pattern.compile("(?i)\\{@([a-z]+).*").matcher(body);
16001604
String tagName = m.matches() ? m.group(1) : null;
16011605
if (tagName == null) {
1602-
messages.warning(dtp, "doclet.tag.invalid_input", body);
1606+
if (!configuration.isDocLintSyntaxGroupEnabled()) {
1607+
messages.warning(dtp, "doclet.tag.invalid_input", body);
1608+
}
16031609
result.add(invalidTagOutput(resources.getText("doclet.tag.invalid_input", body),
16041610
Optional.empty()));
16051611
} else {

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

+15-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
import java.io.File;
3030
import java.io.IOException;
31-
import java.io.InputStream;
3231
import java.nio.file.InvalidPathException;
3332
import java.nio.file.Path;
3433
import java.util.ArrayList;
@@ -60,7 +59,6 @@
6059
import javax.tools.StandardJavaFileManager;
6160

6261
import com.sun.source.tree.CompilationUnitTree;
63-
import com.sun.source.util.DocTreePath;
6462
import com.sun.source.util.TreePath;
6563
import com.sun.tools.javac.util.DefinedBy;
6664
import com.sun.tools.javac.util.DefinedBy.Api;
@@ -74,7 +72,6 @@
7472
import jdk.javadoc.internal.doclets.toolkit.util.Comparators;
7573
import jdk.javadoc.internal.doclets.toolkit.util.DocFile;
7674
import jdk.javadoc.internal.doclets.toolkit.util.DocFileFactory;
77-
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
7875
import jdk.javadoc.internal.doclets.toolkit.util.Extern;
7976
import jdk.javadoc.internal.doclets.toolkit.util.Group;
8077
import jdk.javadoc.internal.doclets.toolkit.util.MetaKeywords;
@@ -85,6 +82,7 @@
8582
import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberCache;
8683
import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable;
8784
import jdk.javadoc.internal.doclint.DocLint;
85+
import jdk.javadoc.internal.doclint.Env;
8886

8987
/**
9088
* Configure the output based on the options. Doclets should subclass
@@ -640,10 +638,6 @@ public boolean isGeneratedDoc(TypeElement te) {
640638
*/
641639
public abstract JavaFileManager getFileManager();
642640

643-
public abstract boolean showMessage(DocTreePath path, String key);
644-
645-
public abstract boolean showMessage(Element e, String key);
646-
647641
/*
648642
* Splits the elements in a collection to its individual
649643
* collection.
@@ -803,8 +797,20 @@ public void initDocLint(List<String> opts, Set<String> customTagNames) {
803797
doclintOpts.toArray(new String[0]));
804798
}
805799

806-
public boolean haveDocLint() {
807-
return (doclint != null);
800+
public boolean isDocLintReferenceGroupEnabled() {
801+
return isDocLintGroupEnabled(jdk.javadoc.internal.doclint.Messages.Group.REFERENCE);
802+
}
803+
804+
public boolean isDocLintSyntaxGroupEnabled() {
805+
return isDocLintGroupEnabled(jdk.javadoc.internal.doclint.Messages.Group.SYNTAX);
806+
}
807+
808+
private boolean isDocLintGroupEnabled(jdk.javadoc.internal.doclint.Messages.Group group) {
809+
// Use AccessKind.PUBLIC as a stand-in, since it is not common to
810+
// set DocLint options per access kind (as is common with javac.)
811+
// A more sophisticated solution might be to derive the access kind from the
812+
// element owning the comment, and its enclosing elements.
813+
return doclint != null && doclint.isGroupEnabled(group, Env.AccessKind.PUBLIC);
808814
}
809815
//</editor-fold>
810816
}

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ public void warning(String key, Object... args) {
143143
* @param args optional arguments to be replaced in the message
144144
*/
145145
public void warning(DocTreePath path, String key, Object... args) {
146-
if (configuration.showMessage(path, key)) {
147-
report(WARNING, path, resources.getText(key, args));
148-
}
146+
report(WARNING, path, resources.getText(key, args));
149147
}
150148

151149
/**
@@ -170,9 +168,7 @@ public void warning(DocTreePath path, int start, int pos, int end, String key, O
170168
* @param args optional arguments to be replaced in the message
171169
*/
172170
public void warning(Element e, String key, Object... args) {
173-
if (configuration.showMessage(e, key)) {
174-
report(WARNING, e, resources.getText(key, args));
175-
}
171+
report(WARNING, e, resources.getText(key, args));
176172
}
177173

178174
/**

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ParamTaglet.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ private Content processParamTags(Element e,
222222
case TYPE_PARAMETER -> "doclet.TypeParameters_warn";
223223
case RECORD_COMPONENT -> "doclet.RecordComponents_warn";
224224
};
225-
messages.warning(ch.getDocTreePath(dt), key, paramName);
225+
if (!writer.configuration().isDocLintReferenceGroupEnabled()) {
226+
messages.warning(ch.getDocTreePath(dt), key, paramName);
227+
}
226228
}
227229
String rank = rankMap.get(name);
228230
if (rank != null) {
@@ -232,7 +234,9 @@ private Content processParamTags(Element e,
232234
case TYPE_PARAMETER -> "doclet.TypeParameters_dup_warn";
233235
case RECORD_COMPONENT -> "doclet.RecordComponents_dup_warn";
234236
};
235-
messages.warning(ch.getDocTreePath(dt), key, paramName);
237+
if (!writer.configuration().isDocLintReferenceGroupEnabled()) {
238+
messages.warning(ch.getDocTreePath(dt), key, paramName);
239+
}
236240
} else {
237241
documented.put(rank, dt);
238242
}

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ReturnTaglet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public Content getAllBlockTagOutput(Element holder, TagletWriter writer) {
9696
// Make sure we are not using @return tag on method with void return type.
9797
TypeMirror returnType = utils.getReturnType(writer.getCurrentPageElement(), (ExecutableElement) holder);
9898
if (returnType != null && utils.isVoid(returnType)) {
99-
if (!tags.isEmpty()) {
99+
if (!tags.isEmpty() && !writer.configuration().isDocLintReferenceGroupEnabled()) {
100100
messages.warning(holder, "doclet.Return_tag_on_void_method");
101101
}
102102
return null;

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/DocLint.java

+4
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ public boolean isValidOption(String opt) {
384384
return false;
385385
}
386386

387+
public boolean isGroupEnabled(Messages.Group group, Env.AccessKind accessKind) {
388+
return env.messages.isEnabled(group, accessKind);
389+
}
390+
387391
private String localize(String code, Object... args) {
388392
Messages m = (env != null) ? env.messages : new Messages(null);
389393
return m.localize(code, args);

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/Messages.java

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ void setStatsEnabled(boolean b) {
104104
stats.setEnabled(b);
105105
}
106106

107+
boolean isEnabled(Group group, Env.AccessKind ak) {
108+
return options.isEnabled(group, ak);
109+
}
110+
107111
void reportStats(PrintWriter out) {
108112
stats.report(out);
109113
}

0 commit comments

Comments
 (0)