Skip to content
Permalink
Browse files
8286338: suppress warnings about bad @author tags when author info is…
… not generated.

Reviewed-by: prappo
  • Loading branch information
jonathan-gibbons committed May 17, 2022
1 parent a25b9bc commit 141ef68f8250ac0b97d481c2f727628c03ea4943
Showing 4 changed files with 89 additions and 13 deletions.
@@ -381,9 +381,15 @@ public void checkTags(Element element, Iterable<? extends DocTree> trees, boolea
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 void testNoAuthor() {
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 @@

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 static void main(String... args) throws Exception {
tb.writeJavaFiles(src,
"""
package pkg;
/** Introduction.\s
/** Introduction.
* @version 1.2.3
*/
public class Test { }
@@ -81,6 +82,45 @@ public void testNoVersion() {
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,
"""

1 comment on commit 141ef68

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 141ef68 May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.