trim leading and trailing spaces from text returned as KDocTag.getContent()
This commit is contained in:
@@ -18,11 +18,11 @@ package org.jetbrains.kotlin.kdoc.psi.impl
|
|||||||
|
|
||||||
import com.intellij.lang.ASTNode
|
import com.intellij.lang.ASTNode
|
||||||
import com.intellij.openapi.util.text.StringUtil
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.TokenType
|
import com.intellij.psi.TokenType
|
||||||
import org.jetbrains.kotlin.kdoc.lexer.KDocTokens
|
import org.jetbrains.kotlin.kdoc.lexer.KDocTokens
|
||||||
import org.jetbrains.kotlin.kdoc.parser.KDocElementTypes
|
import org.jetbrains.kotlin.kdoc.parser.KDocElementTypes
|
||||||
import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
|
import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
|
|
||||||
public open class KDocTag(node: ASTNode) : KDocElementImpl(node) {
|
public open class KDocTag(node: ASTNode) : KDocElementImpl(node) {
|
||||||
|
|
||||||
@@ -49,28 +49,27 @@ public open class KDocTag(node: ASTNode) : KDocElementImpl(node) {
|
|||||||
public fun getSubjectLink(): KDocLink? {
|
public fun getSubjectLink(): KDocLink? {
|
||||||
val children = childrenAfterTagName()
|
val children = childrenAfterTagName()
|
||||||
if (hasSubject(children)) {
|
if (hasSubject(children)) {
|
||||||
return children.firstOrNull()?.getPsi() as? KDocLink
|
return children.firstOrNull()?.psi as? KDocLink
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
public val knownTag: KDocKnownTag?
|
public val knownTag: KDocKnownTag?
|
||||||
get() {
|
get() {
|
||||||
val name = getName()
|
|
||||||
return if (name != null) KDocKnownTag.findByTagName(name) else null
|
return if (name != null) KDocKnownTag.findByTagName(name) else null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hasSubject(contentChildren: List<ASTNode>): Boolean {
|
private fun hasSubject(contentChildren: List<ASTNode>): Boolean {
|
||||||
if (knownTag?.isReferenceRequired() ?: false) {
|
if (knownTag?.isReferenceRequired() ?: false) {
|
||||||
return contentChildren.firstOrNull()?.getElementType() == KDocTokens.MARKDOWN_LINK
|
return contentChildren.firstOrNull()?.elementType == KDocTokens.MARKDOWN_LINK
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun childrenAfterTagName(): List<ASTNode> =
|
private fun childrenAfterTagName(): List<ASTNode> =
|
||||||
getNode().getChildren(null)
|
getNode().getChildren(null)
|
||||||
.dropWhile { it.getElementType() == KDocTokens.TAG_NAME }
|
.dropWhile { it.elementType == KDocTokens.TAG_NAME }
|
||||||
.dropWhile { it.getElementType() == TokenType.WHITE_SPACE }
|
.dropWhile { it.elementType == TokenType.WHITE_SPACE }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the content of this tag (all text following the tag name and the subject if present,
|
* 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)
|
children = children.drop(1)
|
||||||
}
|
}
|
||||||
for (node in children) {
|
for (node in children) {
|
||||||
val type = node.getElementType()
|
val type = node.elementType
|
||||||
if (KDocTokens.CONTENT_TOKENS.contains(type)) {
|
if (KDocTokens.CONTENT_TOKENS.contains(type)) {
|
||||||
|
builder.append(if (!contentStarted || afterAsterisk) node.text.trimStart() else node.text)
|
||||||
contentStarted = true
|
contentStarted = true
|
||||||
builder.append(if (afterAsterisk) StringUtil.trimLeading(node.getText()) else node.getText())
|
|
||||||
afterAsterisk = false
|
afterAsterisk = false
|
||||||
}
|
}
|
||||||
if (type == KDocTokens.LEADING_ASTERISK) {
|
if (type == KDocTokens.LEADING_ASTERISK) {
|
||||||
afterAsterisk = true
|
afterAsterisk = true
|
||||||
}
|
}
|
||||||
if (type == TokenType.WHITE_SPACE && contentStarted) {
|
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) {
|
if (type == KDocElementTypes.KDOC_TAG) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.toString()
|
return builder.toString().trimEnd(' ', '\t')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
open class Foo() {
|
open class Foo() {
|
||||||
/**
|
/** Doc for method xyzzy */
|
||||||
* Doc for method xyzzy
|
|
||||||
*/
|
|
||||||
open fun xyzzy(): Int = 0
|
open fun xyzzy(): Int = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user