Skip to content

[generator] Do not generate bindings for package-private nested types [#572] #575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@
public class PublicClass extends PackageClass {
@Override
public void foo();

// This nested type should not be generated because it is package-private
/* package */ static interface OnPressedChangeListener {
void onPressedChanged ();
}
}
-->
<class abstract="false" deprecated="not deprecated" extends="xamarin.test.PackageClass" extends-generic-aware="xamarin.test.PackageClass" final="false" name="PublicClass" static="false" visibility="public">
<constructor deprecated="not deprecated" final="false" name="PublicClass" static="false" visibility="public" />
<method abstract="false" deprecated="not deprecated" final="false" name="foo" native="false" return="void" static="false" synchronized="false" visibility="public">
</method>
</class>
<interface abstract="true" deprecated="not deprecated" final="false" name="PublicClass.OnPressedChangeListener" static="true" visibility="" >
<method abstract="true" deprecated="not deprecated" final="false" name="onPressedChanged" jni-signature="V" bridge="false" native="false" return="void" jni-return="V" static="false" synchronized="false" synthetic="false" visibility="public" />
</interface>
<!--
/* package */ abstract class ExtendPackageClass extends PackageClass {
}
Expand Down
18 changes: 18 additions & 0 deletions tools/generator/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ static void Validate (List<GenBase> gens, CodeGenerationOptions opt, CodeGenerat
{
//int cycle = 1;
List<GenBase> removed = new List<GenBase> ();
var nested_removes = new List<GenBase> ();

// This loop is required because we cannot really split type validation and member
// validation apart (unlike C# compiler), because invalidated members will result
// in the entire interface invalidation (since we cannot implement it), and use of
Expand All @@ -253,6 +255,22 @@ static void Validate (List<GenBase> gens, CodeGenerationOptions opt, CodeGenerat
removed.Add (gen);
}

// Remove any nested types that are package-private
foreach (var gen in gens) {
foreach (var nest in gen.NestedTypes)
if (opt.IgnoreNonPublicType && (nest.RawVisibility != "public" && nest.RawVisibility != "internal")) {
// We still add it to "removed" even though the removal
// code later won't work, so that it triggers a new cycle
removed.Add (nest);
nested_removes.Add (nest);
}

foreach (var nest in nested_removes)
gen.NestedTypes.Remove (nest);

nested_removes.Clear ();
}

foreach (GenBase gen in removed)
gens.Remove (gen);
} while (removed.Count > 0);
Expand Down