Commit b656f7f
authored
[generator] Add support for
Context: #1264
Context: 73ebad2
Context: a7e09b7
Context: dotnet/android@00256b6
Consider [`java.util.List<E>`][0], which implements
[`java.util.SequencedCollection<E>`][1] and provides an interface
default method to implement `SequencedCollection<E>.reversed()`:
// Java
package java.util;
public /* partial */ interface SequencedCollection<E> implements Collection<E> {
SequencedCollection<E> reverse ();
}
public /* partial */ interface List<E> implements SequencedCollection<E> {
default List<E> reversed() { … }
}
We then *bind* the above, along with some manual fixups in
dotnet/android@00256b69:
// C# bindings
public partial interface ISequencedCollection {
[Register ("reversed", "()Ljava/util/SequencedCollection;", "GetReversedHandler:Java.Util.ISequencedCollectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince = 35)]
ISequencedCollection? Reversed ();
}
public partial interface IList : ISequencedCollection {
[Register ("reversed", "()Ljava/util/List;", "GetReversedHandler:Java.Util.IList, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince = 35)]
unsafe Java.Util.ISequencedCollection Java.Util.ISequencedCollection.Reversed () => …
}
Next, we try to bind [`androidx.paging:paging-common-android`][2].
[`androidx.paging.ItemSnapshotList`][3] inherits from
[`kotlin.collections.AbstractList`][4]:
// Kotlin
package kotlin.collections;
public abstract /* partial */ class AbstractList<out E> protected constructor() :
kotlin.collections.AbstractCollection<E>(), java.util.List<E> {
}
In a scenario that rhymes with 73ebad2, `generator` with
`Mono.Android.dll` (bindings for `Java.Util.IList`) cannot determine
that the `Kotlin.Collections.AbstractList` type has a `Reversed()`
method (via `Java.Util.IList`), and so re-declares it:
// C#
public partial class AbstractList : Kotlin.Collections.AbstractCollection, Java.Util.IList {
public abstract ISequencedCollection Reversed ();
}
We fear that a complete fix for this may be complicated, as we would
have to determine if each interface method has a compatible default
interface method on any other interface in scope.
Introduce new `skipInterfaceMethods` metadata, with identical
semantics to `skipInvokerMethods` (73ebad2), to allow specifying
`interface`-derived methods which should be *skipped* when generating
bindings:
<attr
path="/api/package[@name='kotlin.collections']/class[@name='AbstractList']"
name="skipInterfaceMethods">
java/util/SequencedCollection.reversed()Ljava/util/SequencedCollection;
</attr>
The above fragment would prevent `Reversed()` from being declared in
the binding for `Kotlin.Collections.AbstractList`.
[0]: https://developer.android.com/reference/java/util/List
[1]: https://developer.android.com/reference/java/util/SequencedCollection
[2]: https://maven.google.com/web/index.html?q=paging#androidx.paging:paging-common-android
[3]: https://developer.android.com/reference/androidx/paging/ItemSnapshotList
[4]: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-abstract-list/skipInterfaceMethods (#1265)1 parent 9d99723 commit b656f7f
File tree
4 files changed
+37
-0
lines changed- tests/generator-Tests/Unit-Tests
- tools/generator
- Java.Interop.Tools.Generator.Importers
- Java.Interop.Tools.Generator.ObjectModel
- SourceWriters
4 files changed
+37
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
382 | 410 | | |
383 | 411 | | |
384 | 412 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
150 | 154 | | |
151 | 155 | | |
152 | 156 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
355 | 356 | | |
356 | 357 | | |
357 | 358 | | |
| 359 | + | |
| 360 | + | |
358 | 361 | | |
359 | 362 | | |
360 | 363 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
| 224 | + | |
| 225 | + | |
224 | 226 | | |
225 | 227 | | |
226 | 228 | | |
| |||
0 commit comments