mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 06:51:17 +07:00
[javadoc] Fix link generation in Groovy javadoc
GitOrigin-RevId: c65de562fa8819ed9ce1f21d9d518ce7393b7be0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c70e15ab13
commit
3b41193c33
@@ -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.
|
||||
*/
|
||||
|
||||
+8
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class GroovyDocumentationTest extends LightJavaCodeInsightFixtureTestCase
|
||||
""",
|
||||
"""
|
||||
<div class="bottom"><icon src="AllIcons.Nodes.Class"> <a href="psi_element://Gr"><code><span style="color:#000000;">Gr</span></code></a></div><div class='definition'><pre><span style="color:#000043;font-weight:bold;">void</span> <span style="color:#000000;">foo</span><span style="">(</span><span style="">)</span></pre></div><div class='content'>
|
||||
Use <a href="psi_element://Gr#bar()"><code>#bar()</code></a> from class <a href="psi_element://Gr"><code>Gr</code></a> instead
|
||||
Use <a href="psi_element://Gr#bar()"><code>#bar()</code></a> from class <a href="psi_element://Gr"><code><span style="color:#0000ff;">Gr</span></code></a> instead
|
||||
</div><table class='sections'></table>""");
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class GroovyDocumentationTest extends LightJavaCodeInsightFixtureTestCase
|
||||
""",
|
||||
"""
|
||||
<div class="bottom"><icon src="AllIcons.Nodes.Class"> <a href="psi_element://_"><code><span style="color:#000000;">_</span></code></a></div><div class='definition'><pre><a href="psi_element://java.lang.Object"><code><span style="color:#000000;">Object</span></code></a> <span style="color:#000000;">docs</span><span style="">(</span><span style="">)</span></pre></div><div class='content'>
|
||||
check this out <a href="psi_element://java.lang.CharSequence"><code><span style="color:#0000ff;">character sequences</span></code></a>
|
||||
check this out <a href="psi_element://java.lang.CharSequence"><code>character sequences</code></a>
|
||||
</div><table class='sections'></table>""");
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class GroovyDocumentationTest extends LightJavaCodeInsightFixtureTestCase
|
||||
"""
|
||||
class Main {
|
||||
/**
|
||||
* Link 1: {@link #foo(String[])}\s
|
||||
* Link 1: {@link #foo(String[])}
|
||||
* <p>
|
||||
* Link 2: {@link #bar(String[])}
|
||||
* <p>
|
||||
@@ -86,11 +86,11 @@ public class GroovyDocumentationTest extends LightJavaCodeInsightFixtureTestCase
|
||||
""",
|
||||
"""
|
||||
<div class="bottom"><icon src="AllIcons.Nodes.Class"> <a href="psi_element://Main"><code><span style="color:#000000;">Main</span></code></a></div><div class='definition'><pre><span style="color:#000043;font-weight:bold;">static</span> <span style="color:#000043;font-weight:bold;">void</span> <span style="color:#000000;">docs</span><span style="">(</span><span style="">)</span></pre></div><div class='content'>
|
||||
Link 1: <a href="psi_element://Main#foo(java.lang.String[])"><code><span style="color:#0000ff;">foo</span><span style="">(String[])</span></code></a>\s
|
||||
Link 1: <a href="psi_element://Main#foo(java.lang.String[])"><code>#foo(String[])</code></a>
|
||||
<p>
|
||||
Link 2: <a href="psi_element://Main#bar(java.lang.String[])"><code><span style="color:#0000ff;">bar</span><span style="">(String[])</span></code></a>
|
||||
Link 2: <a href="psi_element://Main#bar(java.lang.String[])"><code>#bar(String[])</code></a>
|
||||
<p>
|
||||
Link 3: <a href="psi_element://Main#bar(java.lang.String[], java.lang.Integer)"><code><span style="color:#0000ff;">bar</span><span style="">(String[], Integer)</span></code></a>
|
||||
Link 3: <a href="psi_element://Main#bar(java.lang.String[], java.lang.Integer)"><code>#bar(String[],Integer)</code></a>
|
||||
</div><table class='sections'></table>""");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user