Skip to content

Commit 835aaf7

Browse files
atsushienojonpryor
authored andcommitted
[generator] Remove fields and methods that have '$' in the name. (#116)
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 d5989b1 commit 835aaf7

13 files changed

+129
-5
lines changed

Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,23 @@ run-test-jnimarshal: bin/Test$(CONFIGURATION)/Java.Interop.Export-Tests.dll bin/
161161

162162
GENERATOR_EXPECTED_TARGETS = tools/generator/Tests/expected.targets
163163

164-
# $(call GEN_CORE_OUTPUT, outdir)
164+
# $(call GEN_CORE_OUTPUT, outdir, suffix, extra)
165165
define GEN_CORE_OUTPUT
166166
-$(RM) -Rf $(1)
167167
mkdir -p $(1)
168-
$(RUNTIME) bin/Test$(CONFIGURATION)/generator.exe -o $(1) $(2) --api-level=20 tools/generator/Tests-Core/api.xml \
169-
--enummethods=tools/generator/Tests-Core/methods.xml \
170-
--enumfields=tools/generator/Tests-Core/fields.xml \
168+
$(RUNTIME) bin/Test$(CONFIGURATION)/generator.exe -o $(1) $(3) --api-level=20 tools/generator/Tests-Core/api$(2).xml \
169+
--enummethods=tools/generator/Tests-Core/methods$(2).xml \
170+
--enumfields=tools/generator/Tests-Core/fields$(2).xml \
171171
--enumdir=$(1)
172172
endef
173173

174174
run-test-generator-core: bin/Test$(CONFIGURATION)/generator.exe
175175
$(call GEN_CORE_OUTPUT,bin/Test$(CONFIGURATION)/generator-core)
176176
diff -rup tools/generator/Tests-Core/expected bin/Test$(CONFIGURATION)/generator-core
177-
$(call GEN_CORE_OUTPUT,bin/Test$(CONFIGURATION)/generator-core,--codegen-target=JavaInterop1)
177+
$(call GEN_CORE_OUTPUT,bin/Test$(CONFIGURATION)/generator-core,,--codegen-target=JavaInterop1)
178178
diff -rup tools/generator/Tests-Core/expected.ji bin/Test$(CONFIGURATION)/generator-core
179+
$(call GEN_CORE_OUTPUT,bin/Test$(CONFIGURATION)/generator-core,-cp)
180+
diff -rup tools/generator/Tests-Core/expected.cp bin/Test$(CONFIGURATION)/generator-core
179181

180182
bin/Test$(CONFIGURATION)/generator.exe: bin/$(CONFIGURATION)/generator.exe
181183
cp $<* `dirname "$@"`
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
@@ -42,6 +42,7 @@
4242
<Compile Include="JavaApiTypeResolverExtensions.cs" />
4343
<Compile Include="JavaApiOverrideMarkerExtensions.cs" />
4444
<Compile Include="JavaApiGeneralExtensions.cs" />
45+
<Compile Include="JavaApiNonBindableStripper.cs" />
4546
<Compile Include="JavaApi.RelationAnalysisModel.cs" />
4647
<Compile Include="JavaTypeReference.cs" />
4748
<Compile Include="JavaApiGenericInheritanceMapperExtensions.cs" />

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-cp.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<api api-source="class-parse">
3+
<package name="java.lang">
4+
<class abstract="false" deprecated="not deprecated" final="false" name="Object" static="false" visibility="public">
5+
</class>
6+
</package>
7+
<package name="xamarin.test.invalidnames">
8+
<class abstract="false" deprecated="not deprecated" extends="java.lang.Object" extends-generic-aware="java.lang.Object" final="false" name="InvalidNameMembers" static="false" visibility="public">
9+
<field deprecated="not deprecated" final="true" name="INVALID_$CONSTANT" static="true" transient="false" type="int" type-generic-aware="int" value="1" visibility="public" volatile="false">
10+
</field>
11+
<field deprecated="not deprecated" final="true" name="INVALID_$FIELD" static="false" transient="false" type="int" type-generic-aware="int" visibility="public" volatile="false">
12+
</field>
13+
<method abstract="false" deprecated="not deprecated" final="false" name="invalid$name" native="false" return="int" static="false" synchronized="false" visibility="public">
14+
</method>
15+
</class>
16+
</package>
17+
</api>
18+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<DefineConstants>$(DefineConstants);ANDROID_1;ANDROID_2;ANDROID_3;ANDROID_4;ANDROID_5;ANDROID_6;ANDROID_7;ANDROID_8;ANDROID_9;ANDROID_10;ANDROID_11;ANDROID_12;ANDROID_13;ANDROID_14;ANDROID_15;ANDROID_16;ANDROID_17;ANDROID_18;ANDROID_19;ANDROID_20</DefineConstants>
5+
</PropertyGroup>
6+
<!-- Classes -->
7+
<ItemGroup>
8+
<Compile Include="$(MSBuildThisFileDirectory)\Java.Interop.__TypeRegistrations.cs" />
9+
<Compile Include="$(MSBuildThisFileDirectory)\Java.Lang.Object.cs" />
10+
<Compile Include="$(MSBuildThisFileDirectory)\Xamarin.Test.Invalidnames.InvalidNameMembers.cs" />
11+
<Compile Include="$(MSBuildThisFileDirectory)\__NamespaceMapping__.cs" />
12+
</ItemGroup>
13+
<!-- Enums -->
14+
<ItemGroup />
15+
</Project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Android.Runtime;
4+
5+
namespace Java.Interop {
6+
7+
partial class __TypeRegistrations {
8+
9+
public static void RegisterPackages ()
10+
{
11+
#if MONODROID_TIMING
12+
var start = DateTime.Now;
13+
Android.Util.Log.Info ("MonoDroid-Timing", "RegisterPackages start: " + (start - new DateTime (1970, 1, 1)).TotalMilliseconds);
14+
#endif // def MONODROID_TIMING
15+
Java.Interop.TypeManager.RegisterPackages (
16+
new string[]{
17+
},
18+
new Converter<string, Type>[]{
19+
});
20+
#if MONODROID_TIMING
21+
var end = DateTime.Now;
22+
Android.Util.Log.Info ("MonoDroid-Timing", "RegisterPackages time: " + (end - new DateTime (1970, 1, 1)).TotalMilliseconds + " [elapsed: " + (end - start).TotalMilliseconds + " ms]");
23+
#endif // def MONODROID_TIMING
24+
}
25+
26+
static Type Lookup (string[] mappings, string javaType)
27+
{
28+
string managedType = Java.Interop.TypeManager.LookupTypeMapping (mappings, javaType);
29+
if (managedType == null)
30+
return null;
31+
return Type.GetType (managedType);
32+
}
33+
}
34+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Android.Runtime;
4+
5+
namespace Java.Lang {
6+
7+
// Metadata.xml XPath class reference: path="/api/package[@name='java.lang']/class[@name='Object']"
8+
[global::Android.Runtime.Register ("java/lang/Object", DoNotGenerateAcw=true)]
9+
public partial class Object {
10+
11+
}
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Android.Runtime;
4+
5+
namespace Xamarin.Test.Invalidnames {
6+
7+
// Metadata.xml XPath class reference: path="/api/package[@name='xamarin.test.invalidnames']/class[@name='InvalidNameMembers']"
8+
[global::Android.Runtime.Register ("xamarin/test/invalidnames/InvalidNameMembers", DoNotGenerateAcw=true)]
9+
public partial class InvalidNameMembers : Java.Lang.Object {
10+
11+
protected InvalidNameMembers (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {}
12+
13+
}
14+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[assembly:global::Android.Runtime.NamespaceMapping (Java = "java.lang", Managed="Java.Lang")]
2+
[assembly:global::Android.Runtime.NamespaceMapping (Java = "xamarin.test.invalidnames", Managed="Xamarin.Test.Invalidnames")]

tools/generator/Tests-Core/expected.cp/enumlist

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<enum-field-mappings>
2+
</enum-field-mappings>
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<enum-method-mappings>
2+
</enum-method-mappings>
3+

0 commit comments

Comments
 (0)