javadoc: keep whitespaces in {@code} tags (IDEA-109997)

This commit is contained in:
anna
2013-11-26 18:45:15 +01:00
parent 02cabc4e84
commit d08af6dfed
5 changed files with 41 additions and 9 deletions

View File

@@ -30,6 +30,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.JavaConstantExpressionEvaluator;
import com.intellij.psi.impl.source.javadoc.PsiInlineDocTagImpl;
import com.intellij.psi.impl.source.tree.JavaDocElementType;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.javadoc.PsiDocTag;
@@ -1039,7 +1040,7 @@ public class JavaDocInfoGenerator {
generateLinkValue(tag, buffer, false);
}
else if (tagName.equals(LITERAL_TAG)) {
generateLiteralValue(tag, buffer);
generateLiteralValue(buffer, ((PsiInlineDocTagImpl)tag).getDataElementsIgnoreWhitespaces());
}
else if (tagName.equals(CODE_TAG)) {
generateCodeValue(tag, buffer);
@@ -1073,14 +1074,12 @@ public class JavaDocInfoGenerator {
@SuppressWarnings({"HardCodedStringLiteral"})
private static void generateCodeValue(PsiInlineDocTag tag, StringBuilder buffer) {
buffer.append("<code>");
generateLiteralValue(tag, buffer);
generateLiteralValue(buffer, tag.getDataElements());
buffer.append("</code>");
}
private static void generateLiteralValue(PsiInlineDocTag tag, StringBuilder buffer) {
PsiElement[] elements = tag.getDataElements();
for (PsiElement element : elements) {
private static void generateLiteralValue(StringBuilder buffer, final PsiElement[] dataElements) {
for (PsiElement element : dataElements) {
appendPlainText(element.getText(), buffer);
}
}

View File

@@ -35,10 +35,11 @@ import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
public class PsiInlineDocTagImpl extends CompositePsiElement implements PsiInlineDocTag, Constants {
private static final TokenSet TAG_VALUE_BIT_SET = TokenSet.create(
DOC_TAG_VALUE_ELEMENT, DOC_METHOD_OR_FIELD_REF);
private static final TokenSet VALUE_BIT_SET = TokenSet.orSet(TAG_VALUE_BIT_SET, TokenSet.create(
private static final TokenSet TAG_VALUE_BIT_SET = TokenSet.create(DOC_TAG_VALUE_ELEMENT, DOC_METHOD_OR_FIELD_REF);
private static final TokenSet VALUE_NO_WHITESPACE_BIT_SET = TokenSet.orSet(TAG_VALUE_BIT_SET, TokenSet.create(
JAVA_CODE_REFERENCE, DOC_TAG_VALUE_TOKEN, DOC_COMMENT_DATA, DOC_INLINE_TAG, DOC_REFERENCE_HOLDER, DOC_COMMENT_BAD_CHARACTER));
private static final TokenSet VALUE_BIT_SET = TokenSet.orSet(TAG_VALUE_BIT_SET, TokenSet.create(
JAVA_CODE_REFERENCE, DOC_TAG_VALUE_TOKEN, WHITE_SPACE, DOC_COMMENT_DATA, DOC_INLINE_TAG, DOC_REFERENCE_HOLDER, DOC_COMMENT_BAD_CHARACTER));
public PsiInlineDocTagImpl() {
super(DOC_INLINE_TAG);
@@ -63,6 +64,10 @@ public class PsiInlineDocTagImpl extends CompositePsiElement implements PsiInlin
return getChildrenAsPsiElements(VALUE_BIT_SET, PsiElement.ARRAY_FACTORY);
}
public PsiElement[] getDataElementsIgnoreWhitespaces() {
return getChildrenAsPsiElements(VALUE_NO_WHITESPACE_BIT_SET, PsiElement.ARRAY_FACTORY);
}
@Override
public PsiDocTagValue getValueElement() {
return (PsiDocTagValue)findPsiChildByType(TAG_VALUE_BIT_SET);

View File

@@ -0,0 +1,10 @@
<html><head> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body><small><b><a href="psi_element://Foo"><code>Foo</code></a></b></small><PRE>int <b>foo</b></PRE>
<pre>
<code>
class Clazzz {
def f[U](u: U) {}
val a = 1
}
</code>
</pre></body></html>

View File

@@ -0,0 +1,14 @@
class Foo {
/**
* <pre>
* {@code
* class Clazzz {
* def f[U](u: U) {}
*
* val a = 1
* }
* }
* </pre>
*/
int foo;
}

View File

@@ -72,6 +72,10 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
doTestField();
}
public void testCode() throws Exception {
doTestField();
}
public void testEnumConstantOrdinal() throws Exception {
PsiClass psiClass = getTestClass();
PsiField field = psiClass.getFields() [0];