-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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.6
- Loading branch information
Showing
6 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+612 Bytes
...Tests/kotlin/InternalClassWithNestedInterface$NestedInterface$DoubleNestedInterface.class
Binary file not shown.
Binary file added
BIN
+599 Bytes
...ndroid.Tools.Bytecode-Tests/kotlin/InternalClassWithNestedInterface$NestedInterface.class
Binary file not shown.
Binary file added
BIN
+627 Bytes
tests/Xamarin.Android.Tools.Bytecode-Tests/kotlin/InternalClassWithNestedInterface.class
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
tests/Xamarin.Android.Tools.Bytecode-Tests/kotlin/InternalClassWithNestedInterface.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
internal class InternalClassWithNestedInterface { | ||
public interface NestedInterface { | ||
public interface DoubleNestedInterface | ||
} | ||
} |