Commit c925b78
authored
[generator] Support varargs arrays in event listener methods (#832)
Fixes: #817
Assume you have a Java event listener interface which accepts a Java
[varargs array][0], e.g.:
// Java
public interface SomeListener {
void onSomeNotification(long a, Object... b);
}
public class Whatever {
public void setSomeListener(SomeListener listener) {…}
}
then `SomeListener` and `Whatever` are bound as expected:
// C# binding
public partial interface ISomeListener {
void OnSomeNotification(long a, params Object[] b);
}
public partial class Whatever {
public void SetSomeListener(ISomeListener listener) {…}
}
*and also*, we ["eventify"][1] the listener interface members, wherein
the listener interface members become events on the using type, with
their `on` prefix removed:
public partial class Whatever {
public event EventHandler<SomeNotificationEventArgs> SomeNotification {…}
}
All parameters on the listener method become constructor parameters
on the `EventArgs` subclass:
public partial class SomeNotificationEventArgs : EventArgs {
public SomeNotificationEventArgs(long a, params Object[] b);
}
Those parameters also become readonly properties:
partial class SomeNotificationEventArgs {
public long A {get;}
}
The bug is that when Java varargs arrays are used, the C# `params`
keyword remains on the declared `EventArgs` subclass property:
partial class SomeNotificationEventArgs {
public params Object[] B {get;}
}
Which results in a CS1519 error:
error CS1519: Invalid token 'params' in class, struct, or interface member declaration
Fix the CS1519 by removing the extraneous `params` output:
partial class SomeNotificationEventArgs {
public Object[] B {get;}
}
[0]: https://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html
[1]: https://docs.microsoft.com/en-us/xamarin/android/internals/api-design#events-and-listeners1 parent 4d0cba6 commit c925b78
File tree
4 files changed
+61
-3
lines changed- tests/generator-Tests/Unit-Tests
- CodeGeneratorExpectedResults
- Common
- XAJavaInterop1-NRT
- tools/generator/Java.Interop.Tools.Generator.CodeGeneration
4 files changed
+61
-3
lines changedLines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1040 | 1040 | | |
1041 | 1041 | | |
1042 | 1042 | | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
1043 | 1069 | | |
1044 | 1070 | | |
1045 | 1071 | | |
| |||
Lines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
598 | 598 | | |
599 | 599 | | |
600 | 600 | | |
601 | | - | |
602 | | - | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
603 | 607 | | |
604 | | - | |
| 608 | + | |
605 | 609 | | |
606 | 610 | | |
607 | 611 | | |
| |||
0 commit comments