fixed up the kdoc comments to exclude the * on lines between /** and */

This commit is contained in:
James Strachan
2012-03-05 12:44:06 +00:00
parent 71194b7eca
commit 0b60105824
2 changed files with 30 additions and 8 deletions
@@ -296,10 +296,32 @@ class KModel(var context: BindingContext, var title: String = "Documentation", v
if (node?.getElementType() != JetTokens.DOC_COMMENT) return ""
var text = node?.getText() ?: ""
// lets remove the comment tokens
//val lines = text.trim().split("\\n")
text = text.trim().trim("/").trim("*").trim()
// TODO convert any macros or wiki text!
return text
val lines = text.trim().split("\\n")
if (lines != null) {
// lets remove the /** ... * ... */ tokens
val buffer = StringBuilder()
val last = lines.size - 1
for (i in 0.upto(last)) {
var text = lines[i] ?: ""
text = text.trim()
if (i == 0) {
text = text.trimLeading("/**").trimLeading("/*")
} else {
buffer.append("\n")
}
if (i >= last) {
text = text.trimTrailing("*/")
} else if (i > 0) {
text = text.trimLeading("* ")
if (text == "*") text = ""
}
buffer.append(text)
}
// TODO convert any macros or wiki text!
return buffer.toString() ?: ""
} else {
return text
}
}
return ""
}
+4 -4
View File
@@ -26,19 +26,19 @@ inline fun String.trim(text: String) = trimLeading(text).trimTrailing(text)
/** Returns the string with the prefix and postfix text trimmed */
inline fun String.trim(prefix: String, postfix: String) = trimLeading(prefix).trimTrailing(postfix)
/** Returns the string with all leading occurrences of the given string removed */
/** Returns the string with the leading prefix of this string removed */
inline fun String.trimLeading(prefix: String): String {
var answer = this
while (answer.startsWith(prefix)) {
if (answer.startsWith(prefix)) {
answer = answer.substring(prefix.length())
}
return answer
}
/** Returns the string with the all the trailing occurrences of the given string removed */
/** Returns the string with the trailing postfix of this string removed */
inline fun String.trimTrailing(postfix: String): String {
var answer = this
while (answer.endsWith(postfix)) {
if (answer.endsWith(postfix)) {
answer = answer.substring(0, length() - postfix.length())
}
return answer