moxy-community / Moxy

Moxy is MVP library for Android with incremental annotation processor and ktx features
MIT License
324 stars 33 forks source link

Problem with enum in viewState #105

Open rost-dev opened 4 years ago

rost-dev commented 4 years ago

Sometime moxy generated viewState with wrong type for enums. In my case:

  1. I have a class Salary with inner Enum classes.
  2. I have an interface of view SalaryBaseView inherited from BaseView

    @StateStrategyType(OneExecutionStateStrategy::class)
    interface SalaryBaseView: BaseView{
    fun showBottomDialog(salaryId: Long, type: Salary.Type, items: List<SalaryReferenceMethod>)
    
    fun openInputEmailDialog(id: String)
    }
  3. From SalaryBaseView inherited SalaryPaymentDetailView
@StateStrategyType(AddToEndSingleStrategy::class)
interface SalaryPaymentDetailView : SalaryBaseView {

    fun initListeners()

    fun setTitleToolbar(name: String)
....e.t.c.

SalaryPaymentDetailView doesn't use Salary in functions.

Problem appears in generated viewState SalaryPaymentDetailView$$State, Salary.Type replaced on Salary$Type in compile time.

Trace of error: ....\presentation\view\SalaryPaymentDetailView$$State.java:11: error: cannot find symbol import ....\model.Salary$Type; ^ symbol: class Salary$Type location: package ...\presentation\view\SalaryPaymentDetailView$$State.java:289: error: cannot find symbol public void showBottomDialog(long arg0, Salary$Type arg1, ^ symbol: class Salary$Type location: class SalaryPaymentDetailView$$State...\presentation\view\SalaryPaymentDetailView$$State.java:698: error: cannot find symbol public final Salary$Type arg1; ^ symbol: class Salary$Type location: class SalaryPaymentDetailView$$State.ShowBottomDialogCommand...\presentation\view\SalaryPaymentDetailView$$State.java:702: error: cannot find symbol ShowBottomDialogCommand(long arg0, Salary$Type arg1, List<? extends SalaryReferenceMethod> arg2) { ^ symbol: class Salary$Type location: class SalaryPaymentDetailView$$State.ShowBottomDialogCommand...\presentation\view\SalaryCardDetailView$$State.java:10: error: cannot find symbol

Same error was in 2.0.2 and 2.1.2

alaershov commented 4 years ago

This is definitely a cool bug, will fix that in the next version, thanks for reporting!

alexredko commented 3 years ago

The same behaviour appears when we use kotlin nested classes (not only enums) For example, we have such method in a view: fun drawPolygonGeoZone(zone: GeoZone.Polygon) Sometimes the dot is replaced with "$": drawPolygonGeoZone(GeoZone$Polygon arg0) in the generated viewState