Kapt: Escape nested comments in doc comments (KT-22469)

This commit is contained in:
Yan Zhulanow
2018-01-24 21:47:59 +03:00
parent abda4bfb57
commit 5fc9c5671c
3 changed files with 47 additions and 2 deletions
@@ -96,7 +96,35 @@ class KDocCommentKeeper(private val kaptContext: KaptContext<*>) {
return
}
docCommentTable.putComment(tree, KDocComment(extractCommentText(docComment)))
docCommentTable.putComment(tree, KDocComment(escapeNestedComments(extractCommentText(docComment))))
}
private fun escapeNestedComments(text: String): String {
val result = StringBuilder()
var index = 0
var commentLevel = 0
while (index < text.length) {
val currentChar = text[index]
fun nextChar() = text.getOrNull(index + 1)
if (currentChar == '/' && nextChar() == '*') {
commentLevel++
index++
result.append("/ *")
} else if (currentChar == '*' && nextChar() == '/') {
commentLevel = maxOf(0, commentLevel - 1)
index++
result.append("* /")
} else {
result.append(currentChar)
}
index++
}
return result.toString()
}
private fun extractCommentText(docComment: KDoc): String {
@@ -59,4 +59,9 @@ enum class EnumError {
};
abstract fun doIt(): String
}
}
/**
* `/* Failure */`
*/
interface TestComponent
@@ -182,3 +182,15 @@ public final class Test4 {
super();
}
}
////////////////////
import java.lang.System;
/**
* * `/ * Failure * /`
*/
@kotlin.Metadata()
public abstract interface TestComponent {
}