airbnb / epoxy

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

Resolve unchecked call warning for WrappedEpoxyModelClickListener #1337

Closed SubhrajyotiSen closed 1 year ago

SubhrajyotiSen commented 1 year ago

Generated classes that contain a View.ClickListener attribute has a method similar to the following:

public DateViewHolder_ clickListener(
      @NonNull final OnModelClickListener<DateViewHolder_, ViewBindingHolder> clickListener) {
    onMutation();
    if (clickListener == null) {
      super.setClickListener(null);
    }
    else {
      super.setClickListener(new WrappedEpoxyModelClickListener(clickListener));
    }
    return this;
  }

The code new WrappedEpoxyModelClickListener(clickListener) causes a warning similar to

 warning: [unchecked] unchecked call to WrappedEpoxyModelClickListener(OnModelClickListener<T,V>) as a member of the raw type WrappedEpoxyModelClickListener
            super.setClickListener(new WrappedEpoxyModelClickListener(clickListener));
                                   ^
  where T,V are type-variables:
    T extends EpoxyModel<?> declared in class WrappedEpoxyModelClickListener
    V extends Object declared in class WrappedEpoxyModelClickListener

This PR resolves the warning by writing super.setClickListener(new WrappedEpoxyModelClickListener<>(clickListener)); to the generated code instead of super.setClickListener(new WrappedEpoxyModelClickListener(clickListener));

Also, XTypeElement.superType is Deprecated. Hence replacing it with XTypeElement.superClass

SubhrajyotiSen commented 1 year ago

@elihart Tagging you here since I'm unable to request reviews on this PR. I hope that's okay.

elihart commented 1 year ago

Thanks for the fix!