8286338: suppress warnings about bad @author tags when author info is not generated.

Reviewed-by: prappo
This commit is contained in:
Jonathan Gibbons 2022-05-17 20:38:18 +00:00
parent a25b9bc89b
commit 141ef68f82
4 changed files with 89 additions and 13 deletions
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets
test/langtools/jdk/javadoc/doclet
testAuthor
testSimpleTagInherit
testVersionTag

@ -381,9 +381,15 @@ public class TagletManager {
final Taglet taglet = allTaglets.get(name);
// Check and verify tag usage
if (taglet != null) {
if (taglet instanceof SimpleTaglet st && !st.enabled) {
// taglet has been disabled
return;
}
if (inlineTrees && !taglet.isInlineTag()) {
printTagMisuseWarn(ch, taglet, tag, "inline");
}
// nothing more to do
if (element == null) {
return;

@ -31,6 +31,7 @@
* @run main TestAuthor
*/
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -81,6 +82,45 @@ public class TestAuthor extends JavadocTester {
checkAuthor(false);
}
@Test
public void testBadAuthor_NoWarning(Path base) throws IOException {
testBadAuthor(base, false);
}
@Test
public void testBadAuthor_Warning(Path base) throws IOException {
testBadAuthor(base, true);
}
public void testBadAuthor(Path base, boolean useAuthorOption) throws IOException {
Path src = base.resolve("src");
tb.writeJavaFiles(src,
"""
package pkg;
/** Comment. */
public class Test {
private Test() { }
/**
* Comment.
* @author anonymous
*/
public void m() { }
}""");
javadoc("-d", base.resolve("out").toString(),
"-sourcepath", src.toString(),
"-Xdoclint:none",
(useAuthorOption ? "-author" : "-XDdummy=dummy"),
"pkg");
checkExit(Exit.OK);
// bad tags never cause corresponding output, whether the option is enabled or not
checkAuthor(false);
checkOutput(Output.OUT, useAuthorOption,
"warning: Tag @author cannot be used in method documentation.");
}
void checkAuthor(boolean on) {
checkOutput("pkg/Test.html", on,
"""

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2022, 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
@ -35,16 +35,6 @@ import javadoc.tester.JavadocTester;
public class TestSimpleTagInherit extends JavadocTester {
//Javadoc arguments.
private static final String[] ARGS = new String[] {
};
//Input for string search tests.
private static final String[][] TEST = {
{ }
};
public static void main(String... args) throws Exception {
TestSimpleTagInherit tester = new TestSimpleTagInherit();
tester.runTests();

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, 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
@ -31,6 +31,7 @@
* @run main TestVersionTag
*/
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -53,7 +54,7 @@ public class TestVersionTag extends JavadocTester {
tb.writeJavaFiles(src,
"""
package pkg;
/** Introduction.\s
/** Introduction.
* @version 1.2.3
*/
public class Test { }
@ -81,6 +82,45 @@ public class TestVersionTag extends JavadocTester {
checkVersion(false);
}
@Test
public void testBadVersion_NoWarning(Path base) throws IOException {
testBadVersion(base, false);
}
@Test
public void testBadVersion_Warning(Path base) throws IOException {
testBadVersion(base, true);
}
public void testBadVersion(Path base, boolean useVersionOption) throws IOException {
Path src = base.resolve("src");
tb.writeJavaFiles(src,
"""
package pkg;
/** Comment. */
public class Test {
private Test() { }
/**
* Comment.
* @version 1.2.3
*/
public void m() { }
}""");
javadoc("-d", base.resolve("out").toString(),
"-sourcepath", src.toString(),
"-Xdoclint:none",
(useVersionOption ? "-version" : "-XDdummy=dummy"),
"pkg");
checkExit(Exit.OK);
// bad tags never cause corresponding output, whether the option is enabled or not
checkVersion(false);
checkOutput(Output.OUT, useVersionOption,
"warning: Tag @version cannot be used in method documentation.");
}
void checkVersion(boolean on) {
checkOutput("pkg/Test.html", on,
"""