Ignoring multiline annotations is non-functional in Kotlin
realdadfish opened this issue · 3 comments
This is my configuration:
configure<CpdExtension> {
language = "kotlin"
toolVersion = "6.25.0"
isIgnoreAnnotations = true
minimumTokenCount = 50
}
This is an example Android Room Annotation:
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
@Entity(
tableName = "bar",
foreignKeys = [
ForeignKey(
entity = FooEntity::class,
parentColumns = ["id"],
childColumns = ["foo_id"],
onDelete = ForeignKey.CASCADE
)
],
indices = [
Index(value = ["foo_id"])
]
)
data class BarEntity(...)
Still, when I analyze it with the plugin, I get
Found a 14 line (54 tokens) duplication in the following files:
Starting at line 14 of /path/to/BarEntity.kt
Starting at line 14 of /path/to/OtherBarEntity.kt
tableName = "bar",
foreignKeys = [
ForeignKey(
entity = FooEntity::class,
parentColumns = ["id"],
childColumns = ["foo_id"],
onDelete = ForeignKey.CASCADE
)
],
indices = [
Index(value = ["foo_id"])
]
)
data class BarEntity constructor(
Could it be that multi-line annotations like the above one are not recognized by the option?
Thanks for the large description @realdadfish. Hm ... seems like an issue with the kotlin
tokenizer as it is not aware of ignoreAnnotations
setting if you look into https://github.com/pmd/pmd/blob/master/pmd-kotlin/src/main/java/net/sourceforge/pmd/cpd/KotlinTokenizer.java. For comparison the java tokenizer uses it: https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/cpd/JavaTokenizer.java
That's bad luck then :(
Maybe but also maybe an issue on the pmd
repo will get it implemented ...
I will close it as it also already documented in https://github.com/aaschmid/gradle-cpd-plugin#options. Don't hesitate to reopen it.