Commit 4ef5081
authored
[Xamarin.Android.Tools.Bytecode] hide Kotlin internal nested types (#827)
Fixes: #826
Context: #682
Given the following Kotlin code:
internal class MyClass {
public interface MyInterface { }
}
The default Java representation of this would be:
public MyClass {
public MyInterface { }
}
In order to prevent this from being bound, our Kotlin fixups
attempted to change the Java representation to:
private class MyClass {
private interface MyInterface { }
}
However there was a bug preventing the internal interface from being
marked as `private`, because we are setting the visibility on the
parent type's `InnerClassAccessFlags`, *not* the nested type itself.
When we output the XML we use use the declaring class'
`InnerClassAccessFlags`, we instead look at the flags on the nested
type's `.class` file, which was still `public`:
<class name="MyClass" visibility="private" … />
<class name="MyClass.MyInterface" visibility="public" … />
This would result in a `generator` warning when trying to bind
`MyClass.MyInterface`, as the parent `MyClass` type is skipped:
warning BG8604: top ancestor MyClass not found for nested type MyClass.MyInterface
Fix this by finding the appropriate inner class `.class` file and
updating the access flags there, recursively:
<class name="MyClass" visibility="private" … />
<class name="MyClass.MyInterface" visibility="private" … />
Note: the [`InnerClasses` Attribute][0] for an inner class may
contain the declaring class. For example, the `InnerClasses` for
`InternalClassWithNestedInterface$NestedInterface` contains
`InternalClassWithNestedInterface$NestedInterface`.
We must thus protect recursive `HideInternalInnerClass()` invocations
from processing the current type, to avoid infinite recursion.
[0]: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.61 parent df4c5e7 commit 4ef5081
File tree
6 files changed
+48
-6
lines changed- src/Xamarin.Android.Tools.Bytecode/Kotlin
- tests/Xamarin.Android.Tools.Bytecode-Tests
- kotlin
6 files changed
+48
-6
lines changedLines changed: 24 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 86 | + | |
| 87 | + | |
90 | 88 | | |
91 | 89 | | |
92 | 90 | | |
93 | 91 | | |
94 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
95 | 113 | | |
96 | 114 | | |
97 | 115 | | |
| |||
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
313 | 332 | | |
314 | 333 | | |
Binary file not shown.
Binary file not shown.
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
0 commit comments