[java-parser] IDEA-366391 Inconsistent doc comment association after markdown support

GitOrigin-RevId: 072bc109310e3059f3fab309dbd521ca2caad6e6
This commit is contained in:
Mikhail Pyltsin
2025-01-28 17:42:27 +01:00
committed by intellij-monorepo-bot
parent 9063043ec3
commit 207f653b4f
5 changed files with 115 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentAwareTokenSet;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -65,6 +66,15 @@ public class WhiteSpaceAndCommentSetHolder {
if (tokens.isEmpty()) return 0;
// 1. bind doc comment
// now there are markdown comments.
// To preserve previous orders, let's try to find the first non-markdown comment (and skip markdown comments).
// If there is no non-markdown, take the first markdown
for (int idx = tokens.size() - 1; idx >= 0; idx--) {
if (BasicJavaAstTreeUtil.is(tokens.get(idx), BASIC_DOC_COMMENT) && !isDocMarkdownComment(idx, getter)) {
return idx;
}
}
for (int idx = tokens.size() - 1; idx >= 0; idx--) {
if (BasicJavaAstTreeUtil.is(tokens.get(idx), BASIC_DOC_COMMENT)) return idx;
}
@@ -90,6 +100,11 @@ public class WhiteSpaceAndCommentSetHolder {
return result;
}
private static boolean isDocMarkdownComment(int idx, @NotNull TokenTextGetter getter) {
CharSequence sequence = getter.get(idx);
return sequence.length() >= 3 && "///".equals(sequence.subSequence(0, 3).toString());
}
}
private static class TrailingWhitespacesAndCommentsBinder implements WhitespacesAndCommentsBinder {