From ae36981a0fd957314bacc3d416c774832384af74 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 8 Sep 2015 14:52:17 +0200 Subject: [PATCH] trim leading and trailing spaces from text returned as KDocTag.getContent() --- .../jetbrains/kotlin/kdoc/psi/impl/KDocTag.kt | 19 +++++++++---------- idea/testData/kdoc/finder/Overridden.kt | 4 +--- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/kdoc/psi/impl/KDocTag.kt b/compiler/frontend/src/org/jetbrains/kotlin/kdoc/psi/impl/KDocTag.kt index 7a3cc025176..a390649de3b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/kdoc/psi/impl/KDocTag.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/kdoc/psi/impl/KDocTag.kt @@ -18,11 +18,11 @@ package org.jetbrains.kotlin.kdoc.psi.impl import com.intellij.lang.ASTNode import com.intellij.openapi.util.text.StringUtil +import com.intellij.psi.PsiElement import com.intellij.psi.TokenType import org.jetbrains.kotlin.kdoc.lexer.KDocTokens import org.jetbrains.kotlin.kdoc.parser.KDocElementTypes import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag -import com.intellij.psi.PsiElement public open class KDocTag(node: ASTNode) : KDocElementImpl(node) { @@ -49,28 +49,27 @@ public open class KDocTag(node: ASTNode) : KDocElementImpl(node) { public fun getSubjectLink(): KDocLink? { val children = childrenAfterTagName() if (hasSubject(children)) { - return children.firstOrNull()?.getPsi() as? KDocLink + return children.firstOrNull()?.psi as? KDocLink } return null } public val knownTag: KDocKnownTag? get() { - val name = getName() return if (name != null) KDocKnownTag.findByTagName(name) else null } private fun hasSubject(contentChildren: List): Boolean { if (knownTag?.isReferenceRequired() ?: false) { - return contentChildren.firstOrNull()?.getElementType() == KDocTokens.MARKDOWN_LINK + return contentChildren.firstOrNull()?.elementType == KDocTokens.MARKDOWN_LINK } return false } private fun childrenAfterTagName(): List = getNode().getChildren(null) - .dropWhile { it.getElementType() == KDocTokens.TAG_NAME } - .dropWhile { it.getElementType() == TokenType.WHITE_SPACE } + .dropWhile { it.elementType == KDocTokens.TAG_NAME } + .dropWhile { it.elementType == TokenType.WHITE_SPACE } /** * Returns the content of this tag (all text following the tag name and the subject if present, @@ -87,23 +86,23 @@ public open class KDocTag(node: ASTNode) : KDocElementImpl(node) { children = children.drop(1) } for (node in children) { - val type = node.getElementType() + val type = node.elementType if (KDocTokens.CONTENT_TOKENS.contains(type)) { + builder.append(if (!contentStarted || afterAsterisk) node.text.trimStart() else node.text) contentStarted = true - builder.append(if (afterAsterisk) StringUtil.trimLeading(node.getText()) else node.getText()) afterAsterisk = false } if (type == KDocTokens.LEADING_ASTERISK) { afterAsterisk = true } if (type == TokenType.WHITE_SPACE && contentStarted) { - builder.append(StringUtil.repeat("\n", StringUtil.countNewLines(node.getText()))) + builder.append("\n".repeat(StringUtil.countNewLines(node.text))) } if (type == KDocElementTypes.KDOC_TAG) { break } } - return builder.toString() + return builder.toString().trimEnd(' ', '\t') } } diff --git a/idea/testData/kdoc/finder/Overridden.kt b/idea/testData/kdoc/finder/Overridden.kt index 9d936f1c305..5a3bae1f51a 100644 --- a/idea/testData/kdoc/finder/Overridden.kt +++ b/idea/testData/kdoc/finder/Overridden.kt @@ -1,7 +1,5 @@ open class Foo() { - /** - * Doc for method xyzzy - */ + /** Doc for method xyzzy */ open fun xyzzy(): Int = 0 }