Skip to content

Commit 842a369

Browse files
committed
[generator] Upgrade generator from monodroid/c772eca5
Update generator from monodroid/c772eca5. This involves two changes: 1. A code generation fix in InterfaceGen.cs. 2. Project re-architecture. (2) involves adding the new Java.Interop.Tools.Cecil, Java.Interop.Tools.Diagnostics, Java.Interop.Tools.TypeNameMappings, and Xamarin.Android.NamingCustomAttributes projects. These new projects are to facilitate migrating additional monodroid code into the Java.Interop repo.
1 parent 0be498d commit 842a369

34 files changed

+1114
-122
lines changed

Java.Interop.sln

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{4C173212-3
1717
EndProject
1818
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop", "src\Java.Interop\Java.Interop.csproj", "{94BD81F7-B06F-4295-9636-F8A3B6BDC762}"
1919
EndProject
20-
Project("{2857B73E-F847-4B02-9238-064979017E93}") = "java-interop", "src\java-interop\java-interop.mdproj", "{BB0AB9F7-0979-41A7-B7A9-877260655F94}"
20+
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "java-interop", "src\java-interop\java-interop.mdproj", "{BB0AB9F7-0979-41A7-B7A9-877260655F94}"
2121
EndProject
2222
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Dynamic", "src\Java.Interop.Dynamic\Java.Interop.Dynamic.csproj", "{AD4468F8-8883-434B-9D4C-E1801BB3B52A}"
2323
EndProject
@@ -79,6 +79,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build-Tools", "Build-Tools"
7979
EndProject
8080
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jnienv-gen", "build-tools\jnienv-gen\jnienv-gen.csproj", "{6410DA0F-5E14-4FC0-9AEE-F4C542C96C7A}"
8181
EndProject
82+
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Xamarin.Android.NamingCustomAttributes", "src\Xamarin.Android.NamingCustomAttributes\Xamarin.Android.NamingCustomAttributes.shproj", "{74598F5C-B8CC-4CE6-8EE2-AB9CA1400076}"
83+
EndProject
84+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Tools.Cecil", "src\Java.Interop.Tools.Cecil\Java.Interop.Tools.Cecil.csproj", "{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}"
85+
EndProject
86+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Tools.Diagnostics", "src\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics.csproj", "{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}"
87+
EndProject
88+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Tools.TypeNameMappings", "src\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings.shproj", "{E706B6F2-5562-4765-8F07-8CF84A797B30}"
89+
EndProject
8290
Global
8391
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8492
Debug|Any CPU = Debug|Any CPU
@@ -357,6 +365,30 @@ Global
357365
{9ECA2816-41D2-4796-8CA2-758EDCFB5C68}.Debug|Any CPU.Build.0 = Debug|Any CPU
358366
{9ECA2816-41D2-4796-8CA2-758EDCFB5C68}.Release|Any CPU.ActiveCfg = Release|Any CPU
359367
{9ECA2816-41D2-4796-8CA2-758EDCFB5C68}.Release|Any CPU.Build.0 = Release|Any CPU
368+
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
369+
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
370+
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
371+
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}.Release|Any CPU.Build.0 = Release|Any CPU
372+
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}.XAIntegrationDebug|Any CPU.ActiveCfg = Debug|Any CPU
373+
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU
374+
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}.XAIntegrationRelease|Any CPU.ActiveCfg = Debug|Any CPU
375+
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}.XAIntegrationRelease|Any CPU.Build.0 = Debug|Any CPU
376+
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}.Debug|x86.ActiveCfg = Debug|Any CPU
377+
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}.Debug|x86.Build.0 = Debug|Any CPU
378+
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}.Release|x86.ActiveCfg = Release|Any CPU
379+
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}.Release|x86.Build.0 = Release|Any CPU
380+
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
381+
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}.Debug|Any CPU.Build.0 = Debug|Any CPU
382+
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}.Release|Any CPU.ActiveCfg = Release|Any CPU
383+
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}.Release|Any CPU.Build.0 = Release|Any CPU
384+
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}.XAIntegrationDebug|Any CPU.ActiveCfg = Debug|Any CPU
385+
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU
386+
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}.XAIntegrationRelease|Any CPU.ActiveCfg = Debug|Any CPU
387+
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}.XAIntegrationRelease|Any CPU.Build.0 = Debug|Any CPU
388+
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}.Debug|x86.ActiveCfg = Debug|Any CPU
389+
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}.Debug|x86.Build.0 = Debug|Any CPU
390+
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}.Release|x86.ActiveCfg = Release|Any CPU
391+
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}.Release|x86.Build.0 = Release|Any CPU
360392
EndGlobalSection
361393
GlobalSection(NestedProjects) = preSolution
362394
{0C001D50-4176-45AE-BDC8-BA626508B0CC} = {C8F58966-94BF-407F-914A-8654F8B8AE3B}
@@ -390,5 +422,9 @@ Global
390422
{4EEAB1A7-99C1-4302-9C18-01A7B481409B} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
391423
{F3ECB73D-9263-4E42-A5B4-3FC0D1D829F9} = {D5A93398-AEB1-49F3-89DC-3904A47DB0C7}
392424
{6410DA0F-5E14-4FC0-9AEE-F4C542C96C7A} = {172B608B-E6F3-41CC-9949-203A76BA247C}
425+
{74598F5C-B8CC-4CE6-8EE2-AB9CA1400076} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
426+
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
427+
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
428+
{E706B6F2-5562-4765-8F07-8CF84A797B30} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
393429
EndGlobalSection
394430
EndGlobal
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<RootNamespace>Java.Interop.Tools.Cecil</RootNamespace>
11+
<AssemblyName>Java.Interop.Tools.Cecil</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
</PropertyGroup>
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15+
<DebugSymbols>true</DebugSymbols>
16+
<DebugType>full</DebugType>
17+
<Optimize>false</Optimize>
18+
<OutputPath>..\..\bin\Debug</OutputPath>
19+
<DefineConstants>DEBUG;</DefineConstants>
20+
<ErrorReport>prompt</ErrorReport>
21+
<WarningLevel>4</WarningLevel>
22+
<ConsolePause>false</ConsolePause>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<Optimize>true</Optimize>
26+
<OutputPath>..\..\bin\Release</OutputPath>
27+
<ErrorReport>prompt</ErrorReport>
28+
<WarningLevel>4</WarningLevel>
29+
<ConsolePause>false</ConsolePause>
30+
</PropertyGroup>
31+
<ItemGroup>
32+
<Reference Include="System" />
33+
<Reference Include="Mono.Cecil">
34+
<HintPath>..\..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll</HintPath>
35+
</Reference>
36+
<Reference Include="Mono.Cecil.Mdb">
37+
<HintPath>..\..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Mono.Cecil.Pdb">
40+
<HintPath>..\..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
41+
</Reference>
42+
<Reference Include="Mono.Cecil.Rocks">
43+
<HintPath>..\..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
44+
</Reference>
45+
</ItemGroup>
46+
<ItemGroup>
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
<Compile Include="Java.Interop.Tools.Cecil\CustomAttributeProviderRocks.cs" />
49+
<Compile Include="Java.Interop.Tools.Cecil\DirectoryAssemblyResolver.cs" />
50+
<Compile Include="Java.Interop.Tools.Cecil\MethodDefinitionRocks.cs" />
51+
<Compile Include="Java.Interop.Tools.Cecil\TypeDefinitionRocks.cs" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<ProjectReference Include="..\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics.csproj">
55+
<Project>{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}</Project>
56+
<Name>Java.Interop.Tools.Diagnostics</Name>
57+
</ProjectReference>
58+
</ItemGroup>
59+
<ItemGroup>
60+
<None Include="packages.config" />
61+
</ItemGroup>
62+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
63+
</Project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
using Mono.Cecil;
6+
7+
namespace Java.Interop.Tools.Cecil {
8+
9+
public static class CustomAttributeProviderRocks
10+
{
11+
public static IEnumerable<CustomAttribute> GetCustomAttributes (this ICustomAttributeProvider item, Type attribute)
12+
{
13+
return item.GetCustomAttributes (attribute.FullName);
14+
}
15+
16+
public static IEnumerable<CustomAttribute> GetCustomAttributes (this ICustomAttributeProvider item, string attribute_fullname)
17+
{
18+
if (!item.HasCustomAttributes)
19+
yield break;
20+
21+
foreach (CustomAttribute custom_attribute in item.CustomAttributes) {
22+
if (custom_attribute.Constructor.DeclaringType.FullName != attribute_fullname)
23+
continue;
24+
25+
yield return custom_attribute;
26+
}
27+
}
28+
29+
public static IEnumerable<CustomAttribute> GetCustomAttributes (this IEnumerable<ICustomAttributeProvider> items, Type attribute)
30+
{
31+
return items.GetCustomAttributes (attribute.FullName);
32+
}
33+
34+
public static IEnumerable<CustomAttribute> GetCustomAttributes (this IEnumerable<ICustomAttributeProvider> items, string attribute_fullname)
35+
{
36+
return items.SelectMany (e => e.GetCustomAttributes (attribute_fullname));
37+
}
38+
}
39+
}

src/utils/DirectoryAssemblyResolver.cs renamed to src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@
3434
using System.Linq;
3535
using System.Reflection;
3636

37+
using Java.Interop.Tools.Diagnostics;
38+
3739
using Mono.Cecil;
3840

39-
namespace Xamarin.Android.Tuner {
41+
namespace Java.Interop.Tools.Cecil {
4042

41-
static class AssemblyResolverCoda {
43+
public static class AssemblyResolverCoda {
4244

4345
public static AssemblyDefinition GetAssembly (this IAssemblyResolver resolver, string fileName)
4446
{
@@ -54,15 +56,15 @@ public static AssemblyDefinition GetAssembly (this IAssemblyResolver resolver, s
5456
* mscorlib.dll and tries a directory based on
5557
* `typeof (object).Module.FullyQualifiedName`, which will never be valid.
5658
*/
57-
class DirectoryAssemblyResolver : IAssemblyResolver {
59+
public class DirectoryAssemblyResolver : IAssemblyResolver {
5860

5961
public ICollection<string> SearchDirectories {get; private set;}
60-
62+
6163
Dictionary<string, AssemblyDefinition> cache;
6264
bool loadDebugSymbols;
63-
Action<string> logWarnings;
65+
Action<string, object[]> logWarnings;
6466

65-
public DirectoryAssemblyResolver (Action<string> logWarnings, bool loadDebugSymbols)
67+
public DirectoryAssemblyResolver (Action<string, object[]> logWarnings, bool loadDebugSymbols)
6668
{
6769
if (logWarnings == null)
6870
throw new ArgumentNullException (nameof (logWarnings));
@@ -109,8 +111,10 @@ protected virtual AssemblyDefinition ReadAssembly (string file)
109111
try {
110112
return AssemblyDefinition.ReadAssembly (file, reader_parameters);
111113
} catch (Exception ex) {
112-
logWarnings (string.Format ("Failed to read '{0}' with debugging symbols. Retrying to load it without it. Error details are logged below.", file));
113-
logWarnings (ex.ToString ());
114+
logWarnings (
115+
"Failed to read '{0}' with debugging symbols. Retrying to load it without it. Error details are logged below.",
116+
new [] { file });
117+
logWarnings ("{0}", new [] { ex.ToString () });
114118
reader_parameters.ReadSymbols = false;
115119
return AssemblyDefinition.ReadAssembly (file, reader_parameters);
116120
}
@@ -125,7 +129,7 @@ public AssemblyDefinition Resolve (string fullName)
125129
{
126130
return Resolve (fullName, null);
127131
}
128-
132+
129133
public AssemblyDefinition Resolve (string fullName, ReaderParameters parameters)
130134
{
131135
return Resolve (AssemblyNameReference.Parse (fullName), parameters);
@@ -135,7 +139,7 @@ public AssemblyDefinition Resolve (AssemblyNameReference reference)
135139
{
136140
return Resolve (reference, null);
137141
}
138-
142+
139143
public string FindAssemblyFile (string fullName)
140144
{
141145
return FindAssemblyFile (AssemblyNameReference.Parse (fullName));
@@ -149,15 +153,15 @@ public string FindAssemblyFile (AssemblyNameReference reference)
149153
foreach (var dir in SearchDirectories)
150154
if ((assembly = SearchDirectory (name, dir)) != null)
151155
return assembly;
152-
156+
153157
throw new System.IO.FileNotFoundException (
154158
string.Format ("Could not load assembly '{0}, Version={1}, Culture={2}, PublicKeyToken={3}'. Perhaps it doesn't exist in the Mono for Android profile?",
155-
name,
156-
reference.Version,
157-
string.IsNullOrEmpty (reference.Culture) ? "neutral" : reference.Culture,
158-
reference.PublicKeyToken == null
159-
? "null"
160-
: string.Join ("", reference.PublicKeyToken.Select(b => b.ToString ("x2")))),
159+
name,
160+
reference.Version,
161+
string.IsNullOrEmpty (reference.Culture) ? "neutral" : reference.Culture,
162+
reference.PublicKeyToken == null
163+
? "null"
164+
: string.Join ("", reference.PublicKeyToken.Select(b => b.ToString ("x2")))),
161165
name + ".dll");
162166
}
163167

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
using Mono.Cecil;
6+
using Mono.Collections.Generic;
7+
8+
namespace Java.Interop.Tools.Cecil {
9+
10+
public static class MethodDefinitionRocks
11+
{
12+
public static MethodDefinition GetBaseDefinition (this MethodDefinition method)
13+
{
14+
if (method.IsStatic || method.IsNewSlot || !method.IsVirtual)
15+
return method;
16+
var baseMethod = method.DeclaringType.GetBaseTypes ()
17+
.SelectMany (t => t.Methods)
18+
.Where (m => !m.IsConstructor &&
19+
m.Name == method.Name &&
20+
(m.IsVirtual || m.IsAbstract) &&
21+
m.HasParameters == method.HasParameters &&
22+
(!m.HasParameters
23+
? true
24+
: AreParametersCompatibleWith (m.Parameters, method.Parameters)))
25+
.FirstOrDefault ();
26+
return baseMethod ?? method;
27+
}
28+
29+
public static IEnumerable<MethodDefinition> GetOverriddenMethods (MethodDefinition method, bool inherit)
30+
{
31+
yield return method;
32+
if (inherit) {
33+
MethodDefinition baseMethod = method;
34+
while ((baseMethod = method.GetBaseDefinition ()) != null && baseMethod != method) {
35+
yield return method;
36+
method = baseMethod;
37+
}
38+
}
39+
}
40+
41+
public static bool AreParametersCompatibleWith (this Collection<ParameterDefinition> a, Collection<ParameterDefinition> b)
42+
{
43+
if (a.Count != b.Count)
44+
return false;
45+
46+
if (a.Count == 0)
47+
return true;
48+
49+
for (int i = 0; i < a.Count; i++)
50+
if (!IsParameterCompatibleWith (a [i].ParameterType, b [i].ParameterType))
51+
return false;
52+
53+
return true;
54+
}
55+
56+
static bool IsParameterCompatibleWith (IModifierType a, IModifierType b)
57+
{
58+
if (!IsParameterCompatibleWith (a.ModifierType, b.ModifierType))
59+
return false;
60+
61+
return IsParameterCompatibleWith (a.ElementType, b.ElementType);
62+
}
63+
64+
static bool IsParameterCompatibleWith (TypeSpecification a, TypeSpecification b)
65+
{
66+
if (a is GenericInstanceType)
67+
return IsParameterCompatibleWith ((GenericInstanceType) a, (GenericInstanceType) b);
68+
69+
if (a is IModifierType)
70+
return IsParameterCompatibleWith ((IModifierType) a, (IModifierType) b);
71+
72+
return IsParameterCompatibleWith (a.ElementType, b.ElementType);
73+
}
74+
75+
static bool IsParameterCompatibleWith (GenericInstanceType a, GenericInstanceType b)
76+
{
77+
if (!IsParameterCompatibleWith (a.ElementType, b.ElementType))
78+
return false;
79+
80+
if (a.GenericArguments.Count != b.GenericArguments.Count)
81+
return false;
82+
83+
if (a.GenericArguments.Count == 0)
84+
return true;
85+
86+
for (int i = 0; i < a.GenericArguments.Count; i++)
87+
if (!IsParameterCompatibleWith (a.GenericArguments [i], b.GenericArguments [i]))
88+
return false;
89+
90+
return true;
91+
}
92+
93+
static bool IsParameterCompatibleWith (GenericParameter a, GenericParameter b)
94+
{
95+
return a.Position == b.Position;
96+
}
97+
98+
static bool IsParameterCompatibleWith (TypeReference a, TypeReference b)
99+
{
100+
if (a is TypeSpecification || b is TypeSpecification) {
101+
if (a.GetType () != b.GetType ())
102+
return false;
103+
104+
return IsParameterCompatibleWith ((TypeSpecification) a, (TypeSpecification) b);
105+
}
106+
107+
if (a.IsGenericParameter) {
108+
if (b.IsGenericParameter && a.Name == b.Name)
109+
return true;
110+
var gpa = (GenericParameter) a;
111+
foreach (var c in gpa.Constraints) {
112+
if (!c.IsAssignableFrom (b))
113+
return false;
114+
}
115+
return true;
116+
}
117+
118+
return a.FullName == b.FullName;
119+
}
120+
}
121+
}
122+

0 commit comments

Comments
 (0)