Skip to content

Commit 31f5b38

Browse files
committed
Some fixes
1 parent 6406358 commit 31f5b38

File tree

5 files changed

+227
-142
lines changed

5 files changed

+227
-142
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ And you will have to include the required dependencies:
2828

2929
```groovy
3030
dependencies {
31-
implementation 'com.github.tobrun.kotlin-data-compat:annotation:0.5.1'
32-
ksp 'com.github.tobrun.kotlin-data-compat:processor:0.5.1'
31+
implementation 'com.github.tobrun.kotlin-data-compat:annotation:0.5.2'
32+
ksp 'com.github.tobrun.kotlin-data-compat:processor:0.5.2'
3333
}
3434
```
3535

@@ -62,6 +62,9 @@ annotation class SampleAnnotation
6262
private data class PersonData(
6363
@Default("\"John\" + Date(1580897313933L).toString()")
6464
val name: String,
65+
/**
66+
* Additional comment.
67+
*/
6568
val nickname: String?,
6669
@Default("42")
6770
val age: Int
@@ -90,20 +93,39 @@ import kotlin.jvm.JvmSynthetic
9093
*/
9194
@SampleAnnotation
9295
public class Person private constructor(
96+
/**
97+
* The full name.
98+
*/
9399
public val name: String,
100+
/**
101+
* The nickname.
102+
* Additional comment.
103+
*/
94104
public val nickname: String?,
105+
/**
106+
* The age.
107+
*/
95108
public val age: Int
96109
) : SampleInterface {
110+
/**
111+
* Overloaded toString function.
112+
*/
97113
public override fun toString() = """Person(name=$name, nickname=$nickname,
98114
age=$age)""".trimIndent()
99115

116+
/**
117+
* Overloaded equals function.
118+
*/
100119
public override fun equals(other: Any?): Boolean {
101120
if (this === other) return true
102121
if (javaClass != other?.javaClass) return false
103122
other as Person
104123
return name == other.name && nickname == other.nickname && age == other.age
105124
}
106125

126+
/**
127+
* Overloaded hashCode function based on all class properties.
128+
*/
107129
public override fun hashCode(): Int = Objects.hash(name, nickname, age)
108130

109131
/**
@@ -121,12 +143,22 @@ public class Person private constructor(
121143
* @property age The age.
122144
*/
123145
public class Builder {
146+
/**
147+
* The full name.
148+
*/
124149
@set:JvmSynthetic
125150
public var name: String? = "John" + Date(1580897313933L).toString()
126151

152+
/**
153+
* The nickname.
154+
* Additional comment.
155+
*/
127156
@set:JvmSynthetic
128157
public var nickname: String? = null
129158

159+
/**
160+
* The age.
161+
*/
130162
@set:JvmSynthetic
131163
public var age: Int? = 42
132164

@@ -143,6 +175,7 @@ public class Person private constructor(
143175

144176
/**
145177
* Set the nickname.
178+
* Additional comment.
146179
*
147180
* @param nickname the nickname.
148181
* @return Builder

example/src/main/kotlin/com/tobrun/data/compat/example/PersonData.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ annotation class SampleAnnotation
1717
private data class PersonData(
1818
@Default("\"John\" + Date(1580897313933L).toString()")
1919
val name: String,
20+
/**
21+
* Additional comment.
22+
*/
2023
val nickname: String?,
2124
@Default("42")
2225
val age: Int

processor/src/main/kotlin/com/tobrun/datacompat/DataCompatProcessor.kt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,13 @@ class DataCompatProcessor(
184184
PropertySpec.builder(entry.key.toString(), entry.value)
185185
.addKdoc(
186186
"""
187-
|Represents ${getKDocProperty(kdocPropertyList, entry.key.toString())}
188-
""".trimMargin()
187+
|${getKDocProperty(kdocPropertyList, entry.key.toString()).replaceFirstChar {
188+
if (it.isLowerCase()) it.titlecase(
189+
Locale.getDefault()
190+
) else it.toString()
191+
}}
192+
|${entry.key.docString?.trimStart(' ', '\n') ?: ""}
193+
""".trimMargin()
189194
)
190195
.initializer(entry.key.toString())
191196
.build()
@@ -217,8 +222,8 @@ class DataCompatProcessor(
217222
.addModifiers(KModifier.OVERRIDE)
218223
.addKdoc(
219224
"""
220-
Overloaded equals function.
221-
""".trimIndent()
225+
Overloaded equals function.
226+
""".trimIndent()
222227
)
223228
.addParameter("other", ANY.copy(nullable = true))
224229
.addStatement("if (this === other) return true")
@@ -296,7 +301,12 @@ class DataCompatProcessor(
296301
)
297302
.addKdoc(
298303
"""
299-
|Represents $kDocProperty
304+
|${kDocProperty.replaceFirstChar {
305+
if (it.isLowerCase()) it.titlecase(
306+
Locale.getDefault()
307+
) else it.toString()
308+
}}
309+
|${property.key.docString?.trimStart(' ', '\n') ?: ""}
300310
""".trimMargin()
301311
)
302312
.addAnnotation(
@@ -318,7 +328,7 @@ class DataCompatProcessor(
318328
.addKdoc(
319329
"""
320330
|Set $kDocProperty
321-
|
331+
|${property.key.docString?.trimStart(' ', '\n') ?: ""}
322332
|@param $propertyName $kDocProperty
323333
|@return Builder
324334
""".trimMargin()

processor/src/test/kotlin/com/tobrun/datacompat/DataCompatProcessorTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ private data class PersonData(
3434
val nickname: String?,
3535
@Default("23")
3636
val age: Int,
37+
/**
38+
* Actually it's a very short description.
39+
*/
3740
val veryLongAndVeryDetailedDescription: String?
3841
) : EmptyInterface, EmptyInterface2
3942
""".trimIndent()

0 commit comments

Comments
 (0)