|
14 | 14 | using Xamarin.Android.Tools.ApiXmlAdjuster; |
15 | 15 |
|
16 | 16 | using Java.Interop.Tools.Cecil; |
| 17 | +using Java.Interop.Tools.TypeNameMappings; |
17 | 18 |
|
18 | 19 | namespace Xamarin.Android.Binder { |
19 | 20 |
|
@@ -262,8 +263,10 @@ static void Run (CodeGeneratorOptions options, DirectoryAssemblyResolver resolve |
262 | 263 | // For now generator fails to load generic types that have conflicting type e.g. |
263 | 264 | // AdapterView`1 and AdapterView cannot co-exist. |
264 | 265 | // It is mostly because generator primarily targets jar (no real generics land). |
265 | | - if (td.HasGenericParameters && |
266 | | - md.GetType (td.FullName.Substring (0, td.FullName.IndexOf ('`'))) != null) |
| 266 | + var nonGenericOverload = td.HasGenericParameters |
| 267 | + ? md.GetType (td.FullName.Substring (0, td.FullName.IndexOf ('`'))) |
| 268 | + : null; |
| 269 | + if (BindSameType (td, nonGenericOverload)) |
267 | 270 | continue; |
268 | 271 | ProcessReferencedType (td, opt); |
269 | 272 | } |
@@ -366,6 +369,15 @@ static void AddTypeToTable (GenBase gb) |
366 | 369 | AddTypeToTable (nt); |
367 | 370 | } |
368 | 371 |
|
| 372 | + static bool BindSameType (TypeDefinition a, TypeDefinition b) |
| 373 | + { |
| 374 | + if (a == null || b == null) |
| 375 | + return false; |
| 376 | + if (!a.ImplementsInterface ("Android.Runtime.IJavaObject") || !b.ImplementsInterface ("Android.Runtime.IJavaObject")) |
| 377 | + return false; |
| 378 | + return JniType.ToJniName (a) == JniType.ToJniName (b); |
| 379 | + } |
| 380 | + |
369 | 381 | static IEnumerable<GenBase> FlattenNestedTypes (IEnumerable<GenBase> gens) |
370 | 382 | { |
371 | 383 | foreach (var g in gens) { |
@@ -404,7 +416,7 @@ static void Validate (List<GenBase> gens, CodeGenerationOptions opt) |
404 | 416 | } while (removed.Count > 0); |
405 | 417 | } |
406 | 418 |
|
407 | | -#if USE_CECIL |
| 419 | +#if HAVE_CECIL |
408 | 420 | static void ProcessReferencedType (TypeDefinition td, CodeGenerationOptions opt) |
409 | 421 | { |
410 | 422 | if (!td.IsPublic && !td.IsNested) |
@@ -434,7 +446,7 @@ static void ProcessReferencedType (TypeDefinition td, CodeGenerationOptions opt) |
434 | 446 | foreach (var nt in td.NestedTypes) |
435 | 447 | ProcessReferencedType (nt, opt); |
436 | 448 | } |
437 | | -#endif |
| 449 | +#endif // HAVE_CECIL |
438 | 450 |
|
439 | 451 | static void GenerateAnnotationAttributes (List<GenBase> gens, IEnumerable<string> zips) |
440 | 452 | { |
|
0 commit comments