Fix tests according to new PSI structure; move doc comment text calculation from JetQuickDocumentationProvider to KDocTag.getContent()
This commit is contained in:
@@ -57,7 +57,7 @@ public interface KDocTokens {
|
||||
|
||||
/**
|
||||
* First word following the tag name (@xxx). Depending on the tag name, this can be
|
||||
* either a link (@param xxx) or just a plain text word (@author name).
|
||||
* either a link (@param xxx) or just a plain text word (@since version).
|
||||
* We understand which one it is during parsing.
|
||||
*/
|
||||
KDocToken TEXT_OR_LINK = new KDocToken("KDOC_TEXT_OR_LINK");
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package org.jetbrains.kotlin.kdoc.psi.api;
|
||||
|
||||
import com.intellij.psi.PsiComment;
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection;
|
||||
|
||||
// Don't implement JetElement (or it will be treated as statement)
|
||||
public interface KDoc extends PsiComment {
|
||||
KDocSection getDefaultSection();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.kdoc.psi.impl;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.psi.impl.source.tree.LazyParseablePsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.idea.JetLanguage;
|
||||
import org.jetbrains.kotlin.kdoc.lexer.KDocTokens;
|
||||
@@ -45,4 +46,9 @@ public class KDocImpl extends LazyParseablePsiElement implements KDoc {
|
||||
public IElementType getTokenType() {
|
||||
return JetTokens.DOC_COMMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KDocSection getDefaultSection() {
|
||||
return PsiTreeUtil.getChildOfType(this, KDocSection.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* can have sections for the class itself, its primary constructor and each of the
|
||||
* properties defined in the primary constructor.
|
||||
*/
|
||||
public class KDocSection extends KDocElementImpl {
|
||||
public class KDocSection extends KDocTag {
|
||||
public KDocSection(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@@ -17,11 +17,68 @@
|
||||
package org.jetbrains.kotlin.kdoc.psi.impl;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.kdoc.lexer.KDocTokens;
|
||||
import org.jetbrains.kotlin.kdoc.parser.KDocElementTypes;
|
||||
|
||||
public class KDocTag extends KDocElementImpl {
|
||||
public KDocTag(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
boolean contentStarted = false;
|
||||
boolean afterAsterisk = false;
|
||||
boolean startsWithTagName = false;
|
||||
|
||||
ASTNode[] children = getNode().getChildren(null);
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
ASTNode node = children[i];
|
||||
IElementType type = node.getElementType();
|
||||
if (i == 0 && type == KDocTokens.TAG_NAME) {
|
||||
startsWithTagName = true;
|
||||
}
|
||||
if (KDocTokens.CONTENT_TOKENS.contains(type) || type == KDocElementTypes.KDOC_LINK) {
|
||||
contentStarted = true;
|
||||
builder.append(afterAsterisk ? StringUtil.trimLeading(node.getText()) : node.getText());
|
||||
afterAsterisk = false;
|
||||
}
|
||||
|
||||
if (type == KDocTokens.LEADING_ASTERISK || type == KDocTokens.START) {
|
||||
afterAsterisk = true;
|
||||
}
|
||||
|
||||
if (type == TokenType.WHITE_SPACE) {
|
||||
if (i == 1 && startsWithTagName) {
|
||||
builder.append(node.getText());
|
||||
}
|
||||
else if (contentStarted) {
|
||||
builder.append(StringUtil.repeat("\n", StringUtil.countNewLines(node.getText())));
|
||||
}
|
||||
}
|
||||
|
||||
if (type == KDocElementTypes.KDOC_TAG) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public String getContentWithTags() {
|
||||
StringBuilder content = new StringBuilder(getContent());
|
||||
KDocTag[] subTags = PsiTreeUtil.getChildrenOfType(this, KDocTag.class);
|
||||
if (subTags != null) {
|
||||
for (KDocTag tag : subTags) {
|
||||
content.append(tag.getContentWithTags()).append("\n");
|
||||
}
|
||||
}
|
||||
return content.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user