Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.errorprone.bugpatterns.BugChecker.VariableTreeMatcher;
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.util.ErrorProneComment.ErrorProneCommentStyle;
import com.sun.source.doctree.DocTree;
import com.sun.source.doctree.EndElementTree;
import com.sun.source.doctree.ErroneousTree;
Expand Down Expand Up @@ -109,9 +110,13 @@ private Description handle(@Nullable DocTreePath path, VisitorState state) {
if (path == null) {
return NO_MATCH;
}
Comment comment = ((DCDocComment) path.getDocComment()).comment;
// javac's markdown javadoc parser doesn't produce ErroneousTree for <, >, or &.
if (ErrorProneCommentStyle.from(comment.getStyle()) == ErrorProneCommentStyle.JAVADOC_LINE) {
return NO_MATCH;
}
RangesFinder rangesFinder = new RangesFinder(state);
rangesFinder.scan(path, null);
Comment comment = ((DCDocComment) path.getDocComment()).comment;
Matcher matcher = GENERIC_PATTERN.matcher(comment.getText());
RangeSet<Integer> generics = TreeRangeSet.create();
while (matcher.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,48 @@ interface Test {}
.doTest();
}

@Test
public void markdownJavadoc_ampersand() {
assume().that(Runtime.version().feature()).isAtLeast(23);
helper
.addSourceLines(
"Test.java",
"""
/// Foo & bar
interface Test {}
""")
.doTest();
}

@Test
public void markdownJavadoc_htmlTags() {
assume().that(Runtime.version().feature()).isAtLeast(23);
helper
.addSourceLines(
"Test.java",
"""
/// <em>important</em> stuff
interface Test {}
""")
.doTest();
}

@Test
public void markdownJavadoc_codeBlock() {
assume().that(Runtime.version().feature()).isAtLeast(23);
helper
.addSourceLines(
"Test.java",
"""
/// Example:
/// ```
/// List<Foo> list = new ArrayList<>();
/// ```
interface Test {}
""")
.doTest();
}

@Test
public void nestedGenericType_properlyEscaped() {
refactoring
Expand Down