Commit 2c06b3c
authored
[Java.Interop] remove
Context: dotnet/android#9630
Context: ec2813a
As dotnet/android#9630 required new declarations of
`DynamicallyAccessedMemberTypes.Interfaces`, we intestigated to see
*why* these were needed in Java.Interop.
There are two cases that involve `.Interfaces` within
`JniRuntime.JniValueManager.GetValueMarshaler(Type)`:
The first case is around attempts to special-case array marshaling
for builtin types:
var listIface = typeof (IList<>);
var listType =
(from iface in type.GetInterfaces ().Concat (new[]{type})
where (listIface).IsAssignableFrom (iface.IsGenericType ? iface.GetGenericTypeDefinition () : iface)
select iface)
.FirstOrDefault ();
If `IList<T>` is trimmed away (lol), then *we don't care*, as
everything else within `GetValueMarshaler(Type)` still works,
and if we can't get a value marshaler for `int[]` (which implements
`IList<T>`!), then so be it. Suppress this IL2070 message.
The second case is around looking for `[JniValueMarshaler]` on
implemented interface types, from ec2813a:
JniValueMarshalerAttribute? ifaceAttribute = null;
foreach (var iface in type.GetInterfaces ()) {
marshalerAttr = iface.GetCustomAttribute<JniValueMarshalerAttribute> ();
if (marshalerAttr != null) {
if (ifaceAttribute != null)
throw new NotSupportedException ($"There is more than one interface with custom marshaler for type {type}.");
ifaceAttribute = marshalerAttr;
}
}
if (ifaceAttribute != null)
return (JniValueMarshaler) Activator.CreateInstance (ifaceAttribute.MarshalerType)!;
It is to support the scenario
namespace Android.Runtime {
[JniValueMarshaler(typeof(IJavaObjectValueMarshaler))]
partial interface /* Android.RuntimIJavaObject {}
}
namespace Java.Lang {
partial class Object : Android.Runtime.IJavaObject {}
}
to "retrofit" `Java.Lang.Object` and `Java.Lang.Throwable` to use
`IJavaObjectValueMarshaler`.
There are three problems with this case:
1. It's not actually covered by unit tests! Removing the above
`foreach` loop doesn't break any unit tests.
2. While dotnet/android was updated for this scenario, it was only
as part of trying to use `jnimarshalmethod-gen` on
Xamarin.Android projects, which was never finished.
3. It doesn't "scale": the code throws a `NotSupportedException`
if a type implements more than one interface that has
`[JniValueMarshaler]`.
This isn't used, and *shouldn't* be relied upon. Excise it entirely.
With these changes we can remove
`DynamicallyAccessedMemberTypes.Interfaces`.
I also introduced `build-tools/trim-analyzers/trim-analyzers.props`
that will setup the appropriate trimmer MSBuild properties to make
trimmer warnings an error. This should keep us from accidentally
creating warnings. I only use this setting in projects that were
already using `$(EnableAotAnalyzer)`.DynamicallyAccessedMemberTypes.Interfaces (#1285)1 parent f800ea5 commit 2c06b3c
File tree
14 files changed
+146
-113
lines changed- build-tools/trim-analyzers
- src
- Java.Interop.Tools.TypeNameMappings
- Java.Interop
- Java.Interop
14 files changed
+146
-113
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | 6 | | |
10 | 7 | | |
11 | 8 | | |
12 | 9 | | |
| 10 | + | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
25 | 22 | | |
| 23 | + | |
26 | 24 | | |
27 | 25 | | |
28 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
363 | 363 | | |
364 | 364 | | |
365 | 365 | | |
366 | | - | |
| 366 | + | |
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
| 249 | + | |
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
260 | | - | |
| 260 | + | |
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
| |||
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
453 | | - | |
| 453 | + | |
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
| |||
461 | 461 | | |
462 | 462 | | |
463 | 463 | | |
464 | | - | |
| 464 | + | |
465 | 465 | | |
466 | 466 | | |
467 | 467 | | |
| |||
654 | 654 | | |
655 | 655 | | |
656 | 656 | | |
657 | | - | |
| 657 | + | |
658 | 658 | | |
659 | 659 | | |
660 | 660 | | |
| |||
665 | 665 | | |
666 | 666 | | |
667 | 667 | | |
668 | | - | |
| 668 | + | |
669 | 669 | | |
670 | 670 | | |
671 | 671 | | |
| |||
858 | 858 | | |
859 | 859 | | |
860 | 860 | | |
861 | | - | |
| 861 | + | |
862 | 862 | | |
863 | 863 | | |
864 | 864 | | |
| |||
869 | 869 | | |
870 | 870 | | |
871 | 871 | | |
872 | | - | |
| 872 | + | |
873 | 873 | | |
874 | 874 | | |
875 | 875 | | |
| |||
1062 | 1062 | | |
1063 | 1063 | | |
1064 | 1064 | | |
1065 | | - | |
| 1065 | + | |
1066 | 1066 | | |
1067 | 1067 | | |
1068 | 1068 | | |
| |||
1073 | 1073 | | |
1074 | 1074 | | |
1075 | 1075 | | |
1076 | | - | |
| 1076 | + | |
1077 | 1077 | | |
1078 | 1078 | | |
1079 | 1079 | | |
| |||
1266 | 1266 | | |
1267 | 1267 | | |
1268 | 1268 | | |
1269 | | - | |
| 1269 | + | |
1270 | 1270 | | |
1271 | 1271 | | |
1272 | 1272 | | |
| |||
1277 | 1277 | | |
1278 | 1278 | | |
1279 | 1279 | | |
1280 | | - | |
| 1280 | + | |
1281 | 1281 | | |
1282 | 1282 | | |
1283 | 1283 | | |
| |||
1470 | 1470 | | |
1471 | 1471 | | |
1472 | 1472 | | |
1473 | | - | |
| 1473 | + | |
1474 | 1474 | | |
1475 | 1475 | | |
1476 | 1476 | | |
| |||
1481 | 1481 | | |
1482 | 1482 | | |
1483 | 1483 | | |
1484 | | - | |
| 1484 | + | |
1485 | 1485 | | |
1486 | 1486 | | |
1487 | 1487 | | |
| |||
1674 | 1674 | | |
1675 | 1675 | | |
1676 | 1676 | | |
1677 | | - | |
| 1677 | + | |
1678 | 1678 | | |
1679 | 1679 | | |
1680 | 1680 | | |
| |||
1685 | 1685 | | |
1686 | 1686 | | |
1687 | 1687 | | |
1688 | | - | |
| 1688 | + | |
1689 | 1689 | | |
1690 | 1690 | | |
1691 | 1691 | | |
| |||
0 commit comments