[java-inspections] Blank line should be replaced with <p>: false positive when multiple blank lines before block tag

IDEA-315871

GitOrigin-RevId: 40520ca3deae8894318cd7ef0fde19c9935a4f64
This commit is contained in:
Andrey Cherkasov
2023-03-21 13:54:48 +00:00
committed by intellij-monorepo-bot
parent 692e481786
commit 7a4cf98cdd
2 changed files with 23 additions and 4 deletions
@@ -74,10 +74,7 @@ public class JavadocBlankLinesInspection extends LocalInspectionTool {
}
private static boolean isBeforeParagraphOrBlockTag(PsiElement element) {
PsiElement nextSibling = element.getNextSibling();
if (!(nextSibling instanceof PsiDocToken)) return true;
if (((PsiDocToken)nextSibling).getTokenType() != JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS) return true;
nextSibling = nextSibling.getNextSibling();
PsiElement nextSibling = skipWhitespacesAndLeadingAsterisksForward(element);
if (nextSibling == null) return true;
String text = nextSibling.getText();
return isNullOrBlockTag(nextSibling) ||
@@ -85,6 +82,16 @@ public class JavadocBlankLinesInspection extends LocalInspectionTool {
isNullOrBlockTag(nextSibling.getNextSibling());
}
private static PsiElement skipWhitespacesAndLeadingAsterisksForward(PsiElement element) {
for (PsiElement e = element.getNextSibling(); e != null; e = e.getNextSibling()) {
if (!(e instanceof PsiWhiteSpace ||
e instanceof PsiDocToken docToken && docToken.getTokenType() == JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS)) {
return e;
}
}
return null;
}
private static boolean startsWithHtmlBlockTag(String text) {
String startTag = HtmlUtil.getStartTag(text);
if (startTag == null) return false;
@@ -0,0 +1,12 @@
// "Insert <p>" "false"
class Test {
/**
* Answer to the ultimate question of life, the universe, and everything
*<caret>
*
* @return The number 42
*/
int answer() {
return 42;
}
}