sockeqwe / sqlbrite-dao

DAO for SQLBrite
http://hannesdorfmann.com/android/sqlbrite-dao
Apache License 2.0
182 stars 22 forks source link

ObjectMappable fails to find setter for a field named "isFoo" using kotlin kapt #27

Closed orgmir closed 8 years ago

orgmir commented 8 years ago

I have this weird error in Kotlin when I want to annotate a field isFoo the processor gives the following error: Error:The field 'isFoo' in class Feature is private. A corresponding setter method with the name 'setIsFeatured(boolean)' is expected but haven't been found. Please add this setter method, If you have another setter method named differently please annotate your setter method with @Column

This is the class I have:

@ObjectMappable
class Feature {
  @Column("IS_FEATURED")
  var isFeatured : Boolean = false
}

I have looked at the code, but I don't know how to debug this, so I can't understand the issue.

It fails to find the setter for any variable named "is***", and if you add the setter has the error message says, it compiles.

sockeqwe commented 8 years ago

Hi, yes there is an issue with that. In Kotlin backed properties like var featured translates to java code setFeatured() and getFeatured()

So if I add a prefix like:

var setFoo = ""

then kotlin will translate this to setSetFoo() in java. Same for get prefix. However, for the is prefix like isFoo kotlin doesn't translate it to isIsFoo(). I'm not sure if this is a bug of kotlin or by design. I will report that issue on kotlin issues tracker and wait for feedback.

orgmir commented 8 years ago

Got it. Won't it be possible to try to find the isIsFoo() method? Or it doesn't make sense to add something like that?

Either way, It isn't such a big deal, I just manually added the setter. I rather keep the variable name because it maps directly to my JSON object, so the deserialization occours without me messing with it.

sockeqwe commented 8 years ago

the problem is that the method is called isFoo() and not isIsFoo() as with get and set prefix (and currently expected by this library). But that seems to be per design. But yes, i will add this special case for boolean kotlin fields. I will ask the guys at jetbrains to ensure that this is the naming convention for boolean fields in kotlin.

sockeqwe commented 8 years ago

Ok, I have talked to someone of the kotlin team about the special treatment of is prefix. I will fix this issue by catching this special is prefix treatment in the annotation processor.