diff --git a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java index 51b945a598a8..edf2b93752b6 100644 --- a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java +++ b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java @@ -2387,29 +2387,36 @@ public class JavaDocInfoGenerator { return buffer.toString().trim(); } - private static @Nullable PsiElement getRefElement(PsiElement[] tagElements) { + private @Nullable PsiElement getRefElement(PsiElement[] tagElements) { for (PsiElement element : tagElements) { if (element instanceof PsiWhiteSpace) { continue; } - - if (element instanceof PsiDocMethodOrFieldRef) { - return element; - } - // JavaDoc references - if (element instanceof TreeElement treeElement && treeElement.getTokenType() == JavaDocElementType.DOC_REFERENCE_HOLDER) { - return element; - } - // JavaDoc module references - if (element instanceof PsiDocTagValue docTagValue) { - PsiElement firstChild = docTagValue.getFirstChild(); - if (firstChild instanceof PsiJavaModuleReferenceElement || firstChild instanceof PsiJavaModuleReference) { - return element; - } - } + if (isRefElement(element)) return element; break; } return null; } + /** + * @return true if {@code element} is the reference from a link. E.g. {@code String} in {@code {@link String myLink}}. + */ + protected boolean isRefElement(PsiElement element) { + if (element instanceof PsiDocMethodOrFieldRef) { + return true; + } + // JavaDoc references + if (element instanceof TreeElement treeElement && treeElement.getTokenType() == JavaDocElementType.DOC_REFERENCE_HOLDER) { + return true; + } + // JavaDoc module references + if (element instanceof PsiDocTagValue docTagValue) { + PsiElement firstChild = docTagValue.getFirstChild(); + if (firstChild instanceof PsiJavaModuleReferenceElement || firstChild instanceof PsiJavaModuleReference) { + return true; + } + } + return false; + } + /** * Returns true if the link has a custom label. */ diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/GroovyDocInfoGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/GroovyDocInfoGenerator.java index c3039b6c8321..60a74830750d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/GroovyDocInfoGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/documentation/GroovyDocInfoGenerator.java @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.plugins.groovy.lang.documentation; import com.intellij.codeInsight.javadoc.JavaDocInfoGenerator; @@ -8,6 +8,7 @@ import com.intellij.psi.PsiRecursiveElementWalkingVisitor; import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocReferenceElement; import static org.jetbrains.plugins.groovy.lang.groovydoc.lexer.GroovyDocTokenTypes.*; @@ -57,4 +58,10 @@ public class GroovyDocInfoGenerator extends JavaDocInfoGenerator { } }); } + + @Override + protected boolean isRefElement(PsiElement element) { + if (element instanceof GrDocReferenceElement) return true; + return super.isRefElement(element); + } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyDocumentationTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyDocumentationTest.java index 48bbb020e1ed..31df24d2ec8a 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyDocumentationTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyDocumentationTest.java @@ -47,7 +47,7 @@ public class GroovyDocumentationTest extends LightJavaCodeInsightFixtureTestCase """, """
 Gr
void foo()
- Use #bar() from class Gr instead + Use #bar() from class Gr instead
"""); } @@ -62,7 +62,7 @@ public class GroovyDocumentationTest extends LightJavaCodeInsightFixtureTestCase """, """
 _
Object docs()
- check this out character sequences + check this out character sequences
"""); } @@ -71,7 +71,7 @@ public class GroovyDocumentationTest extends LightJavaCodeInsightFixtureTestCase """ class Main { /** - * Link 1: {@link #foo(String[])}\s + * Link 1: {@link #foo(String[])} *

* Link 2: {@link #bar(String[])} *

@@ -86,11 +86,11 @@ public class GroovyDocumentationTest extends LightJavaCodeInsightFixtureTestCase """, """

 Main
static void docs()
- Link 1: foo(String[])\s + Link 1: #foo(String[])

- Link 2: bar(String[]) + Link 2: #bar(String[])

- Link 3: bar(String[], Integer) + Link 3: #bar(String[],Integer)

"""); }