Handle multi-line spaces and leading asterisks more correctly
This commit is contained in:
committed by
Simon Ogorodnik
parent
0453c4a7bf
commit
3f104833ba
@@ -18,10 +18,7 @@ package org.jetbrains.kotlin.idea.j2k
|
|||||||
|
|
||||||
import com.intellij.ide.highlighter.HtmlFileType
|
import com.intellij.ide.highlighter.HtmlFileType
|
||||||
import com.intellij.openapi.util.text.StringUtil
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.*
|
||||||
import com.intellij.psi.PsiFileFactory
|
|
||||||
import com.intellij.psi.PsiWhiteSpace
|
|
||||||
import com.intellij.psi.XmlRecursiveElementVisitor
|
|
||||||
import com.intellij.psi.html.HtmlTag
|
import com.intellij.psi.html.HtmlTag
|
||||||
import com.intellij.psi.javadoc.PsiDocComment
|
import com.intellij.psi.javadoc.PsiDocComment
|
||||||
import com.intellij.psi.javadoc.PsiDocTag
|
import com.intellij.psi.javadoc.PsiDocTag
|
||||||
@@ -44,7 +41,10 @@ object IdeaDocCommentConverter : DocCommentConverter {
|
|||||||
when (tag.name) {
|
when (tag.name) {
|
||||||
"deprecated" -> continue@tagsLoop
|
"deprecated" -> continue@tagsLoop
|
||||||
"see" -> append("@see ${convertJavadocLink(tag.content())}\n")
|
"see" -> append("@see ${convertJavadocLink(tag.content())}\n")
|
||||||
else -> appendJavadocElements(tag.children).append("\n")
|
else -> {
|
||||||
|
appendJavadocElements(tag.children)
|
||||||
|
if (!endsWithNewline()) append("\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,12 +67,30 @@ object IdeaDocCommentConverter : DocCommentConverter {
|
|||||||
append(convertInlineDocTag(it))
|
append(convertInlineDocTag(it))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
append(it.text)
|
if (it.node?.elementType != JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS) {
|
||||||
|
append(it.text)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the builder ends with a new-line optionally followed by some spaces
|
||||||
|
*/
|
||||||
|
private fun StringBuilder.endsWithNewline(): Boolean {
|
||||||
|
for (i in length-1 downTo 0) {
|
||||||
|
val c = get(i)
|
||||||
|
if (c.isWhitespace()) {
|
||||||
|
if (c == '\n' || c == '\r') return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun convertInlineDocTag(tag: PsiInlineDocTag) = when (tag.name) {
|
private fun convertInlineDocTag(tag: PsiInlineDocTag) = when (tag.name) {
|
||||||
"code", "literal" -> {
|
"code", "literal" -> {
|
||||||
val text = tag.dataElements.joinToString("") { it.text }
|
val text = tag.dataElements.joinToString("") { it.text }
|
||||||
@@ -131,8 +149,18 @@ object IdeaDocCommentConverter : DocCommentConverter {
|
|||||||
|
|
||||||
if (whitespaceIsPartOfText) {
|
if (whitespaceIsPartOfText) {
|
||||||
appendPendingText()
|
appendPendingText()
|
||||||
markdownBuilder.append(space.text)
|
val lines = space.text.lines()
|
||||||
if (space.textContains('\n')) {
|
if (lines.size == 1) {
|
||||||
|
markdownBuilder.append(space.text)
|
||||||
|
} else {
|
||||||
|
//several lines of spaces:
|
||||||
|
//drop first line - it contains trailing spaces before the first new-line;
|
||||||
|
//do not add star for the last line, it is handled by appendPendingText()
|
||||||
|
//and it is not needed in the end of the comment
|
||||||
|
lines.drop(1).dropLast(1).forEach {
|
||||||
|
markdownBuilder.append("\n * ")
|
||||||
|
}
|
||||||
|
markdownBuilder.append("\n")
|
||||||
afterLineBreak = true
|
afterLineBreak = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,6 +198,7 @@ object IdeaDocCommentConverter : DocCommentConverter {
|
|||||||
|
|
||||||
super.visitXmlTag(tag)
|
super.visitXmlTag(tag)
|
||||||
|
|
||||||
|
//appendPendingText()
|
||||||
markdownBuilder.append(closingMarkdown)
|
markdownBuilder.append(closingMarkdown)
|
||||||
currentListType = oldListType
|
currentListType = oldListType
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,5 +15,17 @@ class A {
|
|||||||
|
|
||||||
protected/*it's protected*/ void foo(char c) { }
|
protected/*it's protected*/ void foo(char c) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description.
|
||||||
|
* Multi-line method description.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param param1 param1 description
|
||||||
|
* @param param2 param2 description
|
||||||
|
*
|
||||||
|
* @param param3 param3 description
|
||||||
|
*/
|
||||||
|
public void foo(String param1, String param2, String param3) {}
|
||||||
|
|
||||||
public/*it's public*/ static/*and static*/ final/*and final*/ int C = 1;
|
public/*it's public*/ static/*and static*/ final/*and final*/ int C = 1;
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,18 @@ internal class A {
|
|||||||
|
|
||||||
protected /*it's protected*/ fun foo(c: Char) {}
|
protected /*it's protected*/ fun foo(c: Char) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description.
|
||||||
|
* Multi-line method description.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param param1 param1 description
|
||||||
|
* @param param2 param2 description
|
||||||
|
*
|
||||||
|
* @param param3 param3 description
|
||||||
|
*/
|
||||||
|
fun foo(param1: String, param2: String, param3: String) {}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
/*it's public*//*and static*//*and final*/ val C = 1
|
/*it's public*//*and static*//*and final*/ val C = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user