Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.

Commit 4a02bc3

Browse files
authored
Revert "[Xamarin.Android.Tools.Bytecode] hide nested types (#827)" (#855)
Revert commit 4ef5081. Fixes: #854 Context: 4ef5081 Context: #826 [As noted][0] in [PR #827][1], there is some "weirdness" with what appears in the [`InnerClasses` collection][2]. It turns out this is due to a misunderstanding of what the `InnerClasses` collection contains. As per the [docs][2]]: > If a class has members that are classes or interfaces, its > `constant_pool` table (and hence its `InnerClasses` attribute) must > refer to each such member, even if that member is not otherwise > mentioned by the class. > **These rules imply that a nested class or interface member will > have `InnerClasses` information for each enclosing class and for > each immediate member.** (Emphasis added.) That is, the `PagedList$Config$Builder$Companion` class lists *both* its immediate containing type `PagedList$Config$Builder` and the "parent-parent" containing type `PagedList$Config` within `InnerClasses`. The change made in commit 4ef5081 loops through `InnerClasses`, marking them as `internal`, assuming they are all nested types. This is causing us to hide *declaring* types when we are trying to hide *nested* types. This will require more investigation and the deadline for 16.11 is ~now, so we're just going to revert the original commit. [0]: #827 (comment) [1]: #827 [2]: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.6
1 parent 95c9b79 commit 4a02bc3

6 files changed

Lines changed: 6 additions & 48 deletions

File tree

‎src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinFixups.cs‎

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void Fixup (IList<ClassFile> classes)
3030
varclass_metadata=(metadataasKotlinClass);
3131

3232
if(class_metadata!=null){
33-
FixupClassVisibility(c,class_metadata,classes);
33+
FixupClassVisibility(c,class_metadata);
3434

3535
if(!c.AccessFlags.IsPubliclyVisible())
3636
continue;
@@ -62,7 +62,7 @@ public static void Fixup (IList<ClassFile> classes)
6262
}
6363
}
6464

65-
staticvoidFixupClassVisibility(ClassFileklass,KotlinClassmetadata,IList<ClassFile>classes)
65+
staticvoidFixupClassVisibility(ClassFileklass,KotlinClassmetadata)
6666
{
6767
// Hide class if it isn't Public/Protected
6868
if(klass.AccessFlags.IsPubliclyVisible()&&!metadata.Visibility.IsPubliclyVisible()){
@@ -83,33 +83,15 @@ static void FixupClassVisibility (ClassFile klass, KotlinClass metadata, IList<C
8383
Log.Debug($"Kotlin: Hiding internal class {klass.ThisClass.Name.Value}");
8484
klass.AccessFlags=SetVisibility(klass.AccessFlags,ClassAccessFlags.Private);
8585

86-
foreach(varicinklass.InnerClasses)
87-
HideInternalInnerClass(ic,classes);
86+
foreach(varicinklass.InnerClasses){
87+
Log.Debug($"Kotlin: Hiding nested internal type {ic.InnerClass.Name.Value}");
88+
ic.InnerClassAccessFlags=SetVisibility(ic.InnerClassAccessFlags,ClassAccessFlags.Private);
89+
}
8890

8991
return;
9092
}
9193
}
9294

93-
staticvoidHideInternalInnerClass(InnerClassInfoklass,IList<ClassFile>classes)
94-
{
95-
varexisting=klass.InnerClassAccessFlags;
96-
97-
klass.InnerClassAccessFlags=SetVisibility(existing,ClassAccessFlags.Private);
98-
Log.Debug($"Kotlin: Hiding nested internal type {klass.InnerClass.Name.Value}");
99-
100-
// Setting the inner class access flags above doesn't technically do anything, because we output
101-
// from the inner class's ClassFile, so we need to find that and set it there.
102-
varkf=classes.FirstOrDefault(c =>c.ThisClass.Name.Value==klass.InnerClass.Name.Value);
103-
104-
if(kf!=null){
105-
kf.AccessFlags=SetVisibility(kf.AccessFlags,ClassAccessFlags.Private);
106-
kf.InnerClass.InnerClassAccessFlags=SetVisibility(kf.InnerClass.InnerClassAccessFlags,ClassAccessFlags.Private);
107-
108-
foreach(varinner_classinkf.InnerClasses.Where(c =>c.OuterClass.Name.Value==kf.ThisClass.Name.Value))
109-
HideInternalInnerClass(inner_class,classes);
110-
}
111-
}
112-
11395
// Passing null for 'newVisibility' parameter means 'package-private'
11496
staticClassAccessFlagsSetVisibility(ClassAccessFlagsexisting,ClassAccessFlags?newVisibility)
11597
{

‎tests/Xamarin.Android.Tools.Bytecode-Tests/KotlinFixupsTests.cs‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -310,24 +310,5 @@ public void HandleKotlinNameShadowing ()
310310
Assert.True(klass.Methods.Single(m =>m.Name=="hitCount").AccessFlags.HasFlag(MethodAccessFlags.Public));
311311
Assert.True(klass.Methods.Single(m =>m.Name=="setType").AccessFlags.HasFlag(MethodAccessFlags.Public));
312312
}
313-
314-
[Test]
315-
publicvoidHidePublicInterfaceInInternalClass()
316-
{
317-
varklass=LoadClassFile("InternalClassWithNestedInterface.class");
318-
varinner_interface=LoadClassFile("InternalClassWithNestedInterface$NestedInterface.class");
319-
varinner_inner_interface=LoadClassFile("InternalClassWithNestedInterface$NestedInterface$DoubleNestedInterface.class");
320-
321-
KotlinFixups.Fixup(new[]{klass,inner_interface,inner_inner_interface});
322-
323-
varoutput=newXmlClassDeclarationBuilder(klass).ToXElement().ToString();
324-
Assert.True(output.Contains("visibility=\"public\""));
325-
326-
varoutput2=newXmlClassDeclarationBuilder(inner_interface).ToXElement().ToString();
327-
Assert.True(output2.Contains("visibility=\"private\""));
328-
329-
varoutput3=newXmlClassDeclarationBuilder(inner_inner_interface).ToXElement().ToString();
330-
Assert.True(output3.Contains("visibility=\"private\""));
331-
}
332313
}
333314
}
Binary file not shown.

‎tests/Xamarin.Android.Tools.Bytecode-Tests/kotlin/InternalClassWithNestedInterface.kt‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)