Bug 58403 - Mismatching listener types/members generated broken event name
Summary: Mismatching listener types/members generated broken event name
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 7.4 (15.3)
Hardware: PC Mac OS
: --- normal
Target Milestone: 15.5
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2017-07-25 22:16 UTC by Matthew Leibowitz
Modified: 2017-09-11 16:49 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Binding project (125.75 KB, application/zip)
2017-07-25 22:16 UTC, Matthew Leibowitz
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Matthew Leibowitz 2017-07-25 22:16:47 UTC
Created attachment 23801 [details]
Binding project

I have a method on my Java class:

  public class MenuView extends LinearLayout {
    public void setOnVisibleWidthChanged(OnVisibleWidthChangedListener listener) {
      this.mOnVisibleWidthChangedListener = listener;
    }
    public interface OnVisibleWidthChangedListener {
        void onItemsMenuVisibleWidthChanged(int newVisibleWidth);
    }
  }

When the generator runs, it creates an event named:

  VisibleWidt

I believe the correct event name should have been:

  VisibleWidthChanged

As you can see, the event name hass basically the length of "Listener" cropped off.

A workaround is to add this:

  <attr 
    path="/api/package[@name='com.arlib.floatingsearchview.util.view']/class[@name='MenuView']/method[@name='setOnVisibleWidthChanged']"
    name="managedName">SetOnVisibleWidthChangedListener</attr>

Java source: https://github.com/arimorty/floatingsearchview
Comment 1 Jon Douglas [MSFT] 2017-07-26 02:17:43 UTC
I can CONFIRM this behavior:

http://i.imgur.com/QUntDX9.png

I am also in agreement that the correct name should be "VisibleWidthChanged". The fact that it removes 8 characters the same amount in "Listener" seems to be coincidence perhaps? Perhaps this is a class-parse bug?
Comment 2 Atsushi Eno 2017-09-05 18:03:09 UTC
Jon is right on "Listener" part: it is a bug that this should not result in any event listener generation because it does not match the expected pattern. Anything that does not follow the pattern should not be handled. It is a generator issue (not class-parse; the resulting `api.xml` should contain the expected description).

The expected behavior is for example, `setOnClickListener` should become `Click` (removing `setOn` and `Listener`).
Comment 3 Atsushi Eno 2017-09-05 18:55:53 UTC
Removing those non-set-Listener methods actually results in Mono.Android ABI breakage (which can be manually fixed). It is expected and should be acceptable.

Though another solution to just treat set-"non-listener" methods as potential events turned out to not be that bad because the constraint on the arguments (only one parameter of Listener type is acceptable) is strong enough to not explode chances to add events, so I'd rather go for that approach.

PR is created based on this option: https://github.com/xamarin/java.interop/pull/181

(There was no ABI changes, even no additions.)

jonp will ask for tests which is quite annoying to create at this state, so the PR won't be applied anytime soon.
Comment 4 Jonathan Pryor 2017-09-11 16:49:12 UTC
Fixed in:

https://github.com/xamarin/java.interop/commit/2986b248f96119771adabe4cf2cf2c71d23c5c7e
https://github.com/xamarin/xamarin-android/commit/595186928ae4d79fab396dc05e7dc2750e808544
monodroid/master/bd7fb78d

Should be fixed in Xamarin.Android 8.0.99.10 or later, which includes all 8.1.x releases.