airbnb / epoxy

Epoxy is an Android library for building complex screens in a RecyclerView
https://goo.gl/eIK82p
Apache License 2.0
8.51k stars 727 forks source link

Kotlin Epoxy Processor Exception #431

Closed lawrencebautista closed 6 years ago

lawrencebautista commented 6 years ago

Hi, this is driving me crazy. I can't seem to build my app because I get the following exception: e: error: Epoxy Processor Exception: EpoxyAttribute annotations must not be on private fields without proper getter and setter methods. (class: HomeQuickLinksModel, field: quickLinks)

Here is the model class:

@EpoxyModelClass(layout = R.layout.quick_links_expanded_layout)
abstract class HomeQuickLinksModel :
    EpoxyModelWithHolder<HomeQuickLinksModel.Holder>() {

    class Holder : EpoxyHolder() {
        var recyclerView: RecyclerView? = null
        var itemView: View? = null

        override fun bindView(itemView: View) {
            recyclerView = itemView.quick_links_recycler_view
            this.itemView = itemView
        }
    }

    @EpoxyAttribute var quickLinks: List<QuickLink> = listOf()
    ...

From what I understand, Kotlin should be generating the getters and setters for the quickLinks field. I verified this by trying to call them from java code. But the processor still doesn't like it! I am using epoxy version 2.10.0

lawrencebautista commented 6 years ago

Changing @EpoxyAttribute var quickLinks: List<QuickLink> = listOf() to @EpoxyAttribute var quickLinks: ArrayList<QuickLink> = ArrayList() fixes it.

Can anyone explain what's going on?

lawrencebautista commented 6 years ago

Looks like declaring the field as a generic List in Kotlin will generate a setter with set(List<? extends QuickLink> quickLinks) which the annotation processor does not recognize.

The workaround is to use the @JvmSuppressWildcards annotation. for example: @EpoxyAttribute var quickLinks: List<@JvmSuppressWildcards QuickLink> = listOf()

I wonder if the annotation processor can be changed to not require this?

elihart commented 6 years ago

Thanks for digging into this. The annotation processor should be able to handle wild cards. I'll try to get around to it soon, but thanks for posting the workaround in the meantime.

elihart commented 6 years ago

@lawrencebautista why close this? if you want the change made you can leave it open until it actually happens so we can track it

elihart commented 6 years ago

Fixed with https://github.com/airbnb/epoxy/pull/451