Skip to content

Commit

Permalink
Flag @return on classes.
Browse files Browse the repository at this point in the history
This used to work, and it's really fun why it doesn't right now. `@return` became both an inline and a block tag, so `ReturnTree` implements both _interfaces_ but not both _classes_ (obviously).

PiperOrigin-RevId: 732923855
  • Loading branch information
graememorgan authored and Error Prone Team committed Mar 3, 2025
1 parent c06a352 commit bd9c504
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.errorprone.bugpatterns.BugChecker.VariableTreeMatcher;
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.matchers.Description;
import com.sun.source.doctree.BlockTagTree;
import com.sun.source.doctree.DocTree;
import com.sun.source.doctree.EndElementTree;
import com.sun.source.doctree.ErroneousTree;
Expand All @@ -42,7 +43,6 @@
import com.sun.source.tree.VariableTree;
import com.sun.source.util.DocTreePath;
import com.sun.source.util.DocTreePathScanner;
import com.sun.tools.javac.tree.DCTree.DCBlockTag;
import com.sun.tools.javac.tree.DCTree.DCDocComment;
import com.sun.tools.javac.tree.DCTree.DCErroneous;
import com.sun.tools.javac.util.JCDiagnostic;
Expand Down Expand Up @@ -259,10 +259,10 @@ public Void scan(DocTree docTree, Void unused) {
if (fixedTags.contains(docTree)) {
return null;
}
if (!(docTree instanceof DCBlockTag dCBlockTag)) {
if (!(docTree instanceof BlockTagTree blockTagTree)) {
return null;
}
JavadocTag tag = blockTag(dCBlockTag.getTagName());
JavadocTag tag = blockTag(blockTagTree.getTagName());
if (validTags.contains(tag) || JavadocTag.KNOWN_OTHER_TAGS.contains(tag)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,20 @@ class Test {}
""")
.doTest();
}

@Test
@SuppressWarnings("MisformattedTestData") // asserting the line the bug is on becomes inconvenient
public void returnOnClass() {
helper
.addSourceLines(
"Test.java",
"""
// BUG: Diagnostic contains:
/** @return anything */
interface Test {
void foo();
}
""")
.doTest();
}
}

0 comments on commit bd9c504

Please sign in to comment.