mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-191421 wrong Javadoc display for @literal tag inside @code tag
This commit is contained in:
@@ -1279,14 +1279,24 @@ public class JavaDocInfoGenerator {
|
||||
|
||||
private void generateCodeValue(PsiInlineDocTag tag, StringBuilder buffer) {
|
||||
buffer.append("<code>");
|
||||
int pos = buffer.length();
|
||||
generateLiteralValue(buffer, tag);
|
||||
buffer.append("</code>");
|
||||
if (buffer.charAt(pos) == '\n') buffer.insert(pos, ' '); // line break immediately after opening tag is ignored by JEditorPane
|
||||
}
|
||||
|
||||
private void generateLiteralValue(StringBuilder buffer, PsiDocTag tag) {
|
||||
StringBuilder tmpBuffer = new StringBuilder();
|
||||
for (PsiElement element : tag.getDataElements()) {
|
||||
appendPlainText(StringUtil.escapeXml(element.getText()), tmpBuffer);
|
||||
PsiElement[] children = tag.getChildren();
|
||||
for (int i = 2; i < children.length - 1; i++) { // process all children except tag opening/closing elements
|
||||
PsiElement child = children[i];
|
||||
if (child instanceof PsiDocToken && ((PsiDocToken)child).getTokenType() == JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS) continue;
|
||||
String elementText = child.getText();
|
||||
if (child instanceof PsiWhiteSpace) {
|
||||
int pos = elementText.lastIndexOf('\n');
|
||||
if (pos >= 0) elementText = elementText.substring(0, pos + 1); // skip whitespace before leading asterisk
|
||||
}
|
||||
appendPlainText(StringUtil.escapeXml(elementText), tmpBuffer);
|
||||
}
|
||||
if ((mySdkVersion == null || mySdkVersion.isAtLeast(JavaSdkVersion.JDK_1_8)) && isInPre(tag)) {
|
||||
buffer.append(tmpBuffer);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<html><head><base href="placeholder"></head><body><div class='definition'><pre><a href="psi_element://Foo"><code>Foo</code></a><br>int <b>foo</b></pre></div><div class='content'>
|
||||
<pre>
|
||||
<code>
|
||||
class Clazzz {
|
||||
def f[U](u: U) {}
|
||||
|
||||
val a = 1
|
||||
}
|
||||
</code>
|
||||
<code>
|
||||
class Clazzz {
|
||||
def f[U](u: U) {}
|
||||
|
||||
val a = 1
|
||||
}
|
||||
</code>
|
||||
</pre>
|
||||
</div><table class='sections'><p></table>
|
||||
@@ -0,0 +1,9 @@
|
||||
<html><head><base href="placeholder"></head><body><div class='definition'><pre>class <b>Foo</b>
|
||||
extends <a href="psi_element://java.lang.Object"><code>Object</code></a></pre></div><div class='content'>
|
||||
<pre>
|
||||
<code>
|
||||
{@literal @Inject}
|
||||
public class Foo
|
||||
</code>
|
||||
</pre>
|
||||
</div><table class='sections'><p></table>
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* <pre>
|
||||
* {@code
|
||||
* {@literal @Inject}
|
||||
* public class Foo
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
class Foo {}
|
||||
+5
@@ -457,6 +457,11 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
|
||||
verifyJavaDoc(aPackage);
|
||||
}
|
||||
|
||||
public void testLiteralInsideCode() throws Exception {
|
||||
useJava8();
|
||||
doTestClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
|
||||
Reference in New Issue
Block a user