-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package siosio.kodkod | ||
|
||
import com.intellij.psi.* | ||
import org.jetbrains.kotlin.psi.* | ||
|
||
interface KDocGenerator { | ||
|
||
companion object { | ||
const val LF = "\n" | ||
} | ||
|
||
fun generate(): String | ||
|
||
fun toParamsKdoc(keyword: String = "@param", params: List<PsiNameIdentifierOwner>): String = | ||
params.map { "$keyword ${it.name}" } | ||
.joinToString(LF, transform = { "* $it" }) | ||
|
||
fun StringBuilder.appendLine(text: String): StringBuilder = append(text).append(LF) | ||
} | ||
|
||
class NamedFunctionKDocGenerator(private val function: KtNamedFunction) : KDocGenerator { | ||
override fun generate(): String { | ||
val builder = StringBuilder() | ||
builder.appendLine("/**") | ||
.appendLine("* TODO") | ||
.appendLine("*") | ||
if (function.typeParameters.isNotEmpty()) { | ||
builder.appendLine(toParamsKdoc(params = function.typeParameters)) | ||
} | ||
if (function.valueParameters.isNotEmpty()) { | ||
builder.appendLine(toParamsKdoc(params = function.valueParameters)) | ||
} | ||
builder.appendLine("*/") | ||
return builder.toString() | ||
} | ||
} | ||
data class Hoge(val hoge:String) | ||
|
||
class ClassKDocGenerator(private val klass: KtClass) : KDocGenerator { | ||
override fun generate(): String { | ||
val builder = StringBuilder() | ||
builder.appendLine("/**") | ||
.appendLine("* TODO") | ||
.appendLine("*") | ||
|
||
if (klass.typeParameters.isNotEmpty()) { | ||
builder.appendLine(toParamsKdoc(params = klass.typeParameters)) | ||
} | ||
|
||
val (properties, parameters) = klass.primaryConstructor?.valueParameters?.partition { | ||
it.hasValOrVar() | ||
} ?: Pair(emptyList(), emptyList()) | ||
|
||
if (properties.isNotEmpty()) { | ||
builder.appendLine(toParamsKdoc(keyword = "@property", params = properties)) | ||
} | ||
|
||
if (parameters.isNotEmpty()) { | ||
builder.appendLine("* @constructor") | ||
.appendLine("* TODO") | ||
.appendLine("*") | ||
.appendLine(toParamsKdoc(params = parameters)) | ||
} | ||
|
||
builder.appendLine("*/") | ||
return builder.toString() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ | |
<name>kodkod</name> | ||
<vendor email="[email protected]" url="https://github.com/siosio">siosio</vendor> | ||
|
||
<description><![CDATA[ | ||
<description> | ||
<![CDATA[ | ||
generate kdoc plugin. | ||
]]></description> | ||
|
||
|