Skip to content

Commit

Permalink
Private property in KDoc (#575)
Browse files Browse the repository at this point in the history
* Private property in KDoc

### What's done:
   Fixed bug and added tests
  • Loading branch information
kentr0w authored Nov 27, 2020
1 parent 5426cd4 commit 07829e0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ class KdocComments(private val configRules: List<RulesConfig>) : Rule("kdoc-comm

@Suppress("UnsafeCallOnNullableType")
private fun createKdocBasicKdoc(node: ASTNode) {
KDOC_NO_CONSTRUCTOR_PROPERTY.warnAndFix(configRules, emitWarn, isFixMode,
"add <${node.findChildByType(IDENTIFIER)!!.text}> to KDoc", node.startOffset, node) {
val newKdoc = KotlinParser().createNode("/**\n * @property ${node.findChildByType(IDENTIFIER)!!.text}\n */")
val classNode = node.parent({ it.elementType == CLASS })!!
classNode.addChild(PsiWhiteSpaceImpl("\n"), classNode.firstChildNode)
classNode.addChild(newKdoc.findChildByType(KDOC)!!, classNode.firstChildNode)
if (node.getFirstChildWithType(MODIFIER_LIST).isAccessibleOutside()) {
KDOC_NO_CONSTRUCTOR_PROPERTY.warnAndFix(configRules, emitWarn, isFixMode,
"add <${node.findChildByType(IDENTIFIER)!!.text}> to KDoc", node.startOffset, node) {
val newKdoc = KotlinParser().createNode("/**\n * @property ${node.findChildByType(IDENTIFIER)!!.text}\n */")
val classNode = node.parent({ it.elementType == CLASS })!!
classNode.addChild(PsiWhiteSpaceImpl("\n"), classNode.firstChildNode)
classNode.addChild(newKdoc.findChildByType(KDOC)!!, classNode.firstChildNode)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) {
|}
""".trimMargin(),
LintError(1, 1, ruleId, "${MISSING_KDOC_TOP_LEVEL.warnText()} Example"),
LintError(2, 4, ruleId, "${KDOC_NO_CONSTRUCTOR_PROPERTY.warnText()} add <name> to KDoc", true),
LintError(3, 4, ruleId, "${KDOC_NO_CONSTRUCTOR_PROPERTY.warnText()} add <surname> to KDoc", true)
LintError(2, 4, ruleId, "${KDOC_NO_CONSTRUCTOR_PROPERTY.warnText()} add <name> to KDoc", true)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ class A constructor(
){}

/**
* @property name
* @property lastName
*/
* @property lastName
*/
class A constructor(
private var name: String,
val lastName: String
Expand All @@ -37,3 +36,18 @@ class A constructor(
class A constructor(
val name: String
){}

class Example(private val foo: Int)

/**
* @property g
* @property e
* @property s
*/
class Example constructor(
val g: String,
private var q: String,
@param:JsonProperty("shortName") private val shortName: String,
val e: String,
protected val s: String
){}
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@ class A constructor(
*/
val name: String
){}

class Example(private val foo: Int)

class Example constructor(
val g: String,
private var q: String,
@param:JsonProperty("shortName") private val shortName: String,
val e: String,
protected val s: String
){}

0 comments on commit 07829e0

Please sign in to comment.