Skip to content

Commit 8c82e18

Browse files
committed
[generator] strip fields and methods that have '$' in the name.
Related: https://bugzilla.xamarin.com/show_bug.cgi?id=46344#c12 class-parse has brought another problem; it generates fields and methods that are compiler-generated and should not have been written to XML in the first place. class-parse has no idea on how to deal with them, so kill them in api-xml-adjuster instead.
1 parent 39f1744 commit 8c82e18

File tree

9 files changed

+63
-3
lines changed

9 files changed

+63
-3
lines changed

src/Java.Interop.NamingCustomAttributes/Java.Interop.NamingCustomAttributes.projitems

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
55
<HasSharedItems>true</HasSharedItems>
6-
<SharedGUID>{FE789F04-5E95-42C5-AEF1-E33F8DF06B3F}</SharedGUID>
6+
<SharedGUID>{FE789F04-5E95-42C5-AEF1-E33F8DF06B3F}</SharedGUID>
77
</PropertyGroup>
88
<PropertyGroup Label="Configuration">
99
<Import_RootNamespace>Java.Interop.NamingCustomAttributes</Import_RootNamespace>
@@ -21,4 +21,4 @@
2121
<Compile Include="$(MSBuildThisFileDirectory)Android.App\ServiceAttribute.cs" />
2222
<Compile Include="$(MSBuildThisFileDirectory)Android.App\InstrumentationAttribute.cs" />
2323
</ItemGroup>
24-
</Project>
24+
</Project>

src/Java.Interop.NamingCustomAttributes/Java.Interop.NamingCustomAttributes.shproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
1111
<Import Project="Java.Interop.NamingCustomAttributes.projitems" Label="Shared" />
1212
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
13-
</Project>
13+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace Xamarin.Android.Tools.ApiXmlAdjuster
6+
{
7+
public static class JavaApiNonBindableStripper
8+
{
9+
public static void StripNonBindables (this JavaApi api)
10+
{
11+
var invalids = new List<JavaMember> ();
12+
foreach (var member in api.Packages.SelectMany (p => p.Types)
13+
.SelectMany (t => t.Members).Where (m => m.Name != null && m.Name.Contains ('$')))
14+
invalids.Add (member);
15+
foreach (var invalid in invalids)
16+
invalid.Parent.Members.Remove (invalid);
17+
}
18+
}
19+
}

src/Xamarin.Android.Tools.ApiXmlAdjuster/Xamarin.Android.Tools.ApiXmlAdjuster.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<Compile Include="JavaTypeResolutionUtil.cs" />
5151
<Compile Include="JavaApiFixVisibilityExtensions.cs" />
5252
<Compile Include="Log.cs" />
53+
<Compile Include="JavaApiNonBindableStripper.cs" />
5354
</ItemGroup>
5455
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
5556
</Project>

tools/generator/ApiXmlAdjuster.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public void Process (string inputXmlFile, GenBase [] gens, string outputXmlFile,
2323
var api = new JavaApi ();
2424
api.LoadReferences (gens);
2525
api.Load (inputXmlFile);
26+
api.StripNonBindables ();
2627
api.Resolve ();
2728
api.CreateGenericInheritanceMapping ();
2829
api.MarkOverrides ();

tools/generator/Tests-Core/api.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,13 @@
5353
<class abstract="false" deprecated="not deprecated" final="false" name="Object" static="false" visibility="public">
5454
</class>
5555
</package>
56+
<package name="name.validity.tests">
57+
<class abstract="false" deprecated="not deprecated" extends="java.lang.Object" final="false" name="InvalidMembers" static="false" visibility="public">
58+
<field deprecated="not deprecated" final="true" name="INVALID_$1234" static="true" transient="false" type="int" type-generic-aware="int" value="256" visibility="public" volatile="false" />
59+
<field deprecated="not deprecated" final="false" name="invalid$5678" static="true" transient="false" type="int" type-generic-aware="int" visibility="public" volatile="false" />
60+
<method abstract="true" deprecated="not deprecated" final="false" name="also$123invalid" native="false" return="int" static="false" synchronized="false" visibility="public">
61+
</method>
62+
</class>
63+
</package>
5664
</api>
5765

tools/generator/Tests-Core/expected/GeneratedFiles.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<Compile Include="$(MSBuildThisFileDirectory)\Android.Views.View.cs" />
1313
<Compile Include="$(MSBuildThisFileDirectory)\Java.Interop.__TypeRegistrations.cs" />
1414
<Compile Include="$(MSBuildThisFileDirectory)\Java.Lang.Object.cs" />
15+
<Compile Include="$(MSBuildThisFileDirectory)\Name.Validity.Tests.InvalidMembers.cs" />
1516
<Compile Include="$(MSBuildThisFileDirectory)\__NamespaceMapping__.cs" />
1617
</ItemGroup>
1718
<!-- Enums -->
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Android.Runtime;
4+
5+
namespace Name.Validity.Tests {
6+
7+
// Metadata.xml XPath class reference: path="/api/package[@name='name.validity.tests']/class[@name='InvalidMembers']"
8+
[global::Android.Runtime.Register ("name/validity/tests/InvalidMembers", DoNotGenerateAcw=true)]
9+
public partial class InvalidMembers : Java.Lang.Object {
10+
11+
12+
internal static IntPtr java_class_handle;
13+
internal static IntPtr class_ref {
14+
get {
15+
return JNIEnv.FindClass ("name/validity/tests/InvalidMembers", ref java_class_handle);
16+
}
17+
}
18+
19+
protected override IntPtr ThresholdClass {
20+
get { return class_ref; }
21+
}
22+
23+
protected override global::System.Type ThresholdType {
24+
get { return typeof (InvalidMembers); }
25+
}
26+
27+
protected InvalidMembers (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {}
28+
}
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[assembly:global::Android.Runtime.NamespaceMapping (Java = "android.view", Managed="Android.Views")]
22
[assembly:global::Android.Runtime.NamespaceMapping (Java = "android.text", Managed="Android.Text")]
33
[assembly:global::Android.Runtime.NamespaceMapping (Java = "java.lang", Managed="Java.Lang")]
4+
[assembly:global::Android.Runtime.NamespaceMapping (Java = "name.validity.tests", Managed="Name.Validity.Tests")]

0 commit comments

Comments
 (0)