aaschmid / gradle-cpd-plugin

Gradle plugin to find duplicate code using PMDs copy/paste detection (= CPD).
Apache License 2.0
96 stars 12 forks source link

Ignoring multiline annotations is non-functional in Kotlin #51

Closed realdadfish closed 4 years ago

realdadfish commented 4 years ago

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?

aaschmid commented 4 years ago

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

realdadfish commented 4 years ago

That's bad luck then :(

aaschmid commented 4 years ago

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.