diff --git a/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JniType.cs b/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JniType.cs index 7469a59ff..32461ca4e 100644 --- a/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JniType.cs +++ b/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JniType.cs @@ -9,8 +9,8 @@ #if HAVE_CECIL using Mono.Cecil; using Java.Interop.Tools.Cecil; -#if !GENERATOR using Android.Runtime; +#if !GENERATOR using Java.Interop.Tools.JavaCallableWrappers; #endif // !GENERATOR #endif // HAVE_CECIL @@ -252,7 +252,7 @@ static string GetSpecialExportJniType (string typeName, ExportParameterKind expo return null; } -#if !GEN_JAVA_STUBS && !GENERATOR && !JAVADOC_TO_MDOC +#if !GEN_JAVA_STUBS && !JAVADOC_TO_MDOC // Keep in sync with ToJniNameFromAttributes(TypeDefinition) public static string ToJniNameFromAttributes (Type type) { @@ -384,7 +384,7 @@ static string ToJniNameWhichShouldReplaceExistingToJniName (Type type, ExportPar } #endif -#if HAVE_CECIL && !GENERATOR +#if HAVE_CECIL internal static ExportParameterKind GetExportKind (Mono.Cecil.ICustomAttributeProvider p) { diff --git a/tools/generator/ClassGen.cs b/tools/generator/ClassGen.cs index 90b117730..18a2db4ab 100644 --- a/tools/generator/ClassGen.cs +++ b/tools/generator/ClassGen.cs @@ -15,7 +15,7 @@ using System.Xml.Linq; namespace MonoDroid.Generation { -#if USE_CECIL +#if HAVE_CECIL static class ManagedExtensions { public static string FullNameCorrected (this TypeReference t) @@ -69,7 +69,7 @@ public override bool IsFinal { get { return t.IsSealed; } } } -#endif +#endif // HAVE_CECIL public class XmlClassGen : ClassGen { bool is_abstract; diff --git a/tools/generator/CodeGenerator.cs b/tools/generator/CodeGenerator.cs index 1207f1d61..c64575866 100644 --- a/tools/generator/CodeGenerator.cs +++ b/tools/generator/CodeGenerator.cs @@ -14,6 +14,7 @@ using Xamarin.Android.Tools.ApiXmlAdjuster; using Java.Interop.Tools.Cecil; +using Java.Interop.Tools.TypeNameMappings; namespace Xamarin.Android.Binder { @@ -262,8 +263,10 @@ static void Run (CodeGeneratorOptions options, DirectoryAssemblyResolver resolve // For now generator fails to load generic types that have conflicting type e.g. // AdapterView`1 and AdapterView cannot co-exist. // It is mostly because generator primarily targets jar (no real generics land). - if (td.HasGenericParameters && - md.GetType (td.FullName.Substring (0, td.FullName.IndexOf ('`'))) != null) + var nonGenericOverload = td.HasGenericParameters + ? md.GetType (td.FullName.Substring (0, td.FullName.IndexOf ('`'))) + : null; + if (BindSameType (td, nonGenericOverload)) continue; ProcessReferencedType (td, opt); } @@ -366,6 +369,15 @@ static void AddTypeToTable (GenBase gb) AddTypeToTable (nt); } + static bool BindSameType (TypeDefinition a, TypeDefinition b) + { + if (a == null || b == null) + return false; + if (!a.ImplementsInterface ("Android.Runtime.IJavaObject") || !b.ImplementsInterface ("Android.Runtime.IJavaObject")) + return false; + return JniType.ToJniName (a) == JniType.ToJniName (b); + } + static IEnumerable FlattenNestedTypes (IEnumerable gens) { foreach (var g in gens) { @@ -404,7 +416,7 @@ static void Validate (List gens, CodeGenerationOptions opt) } while (removed.Count > 0); } -#if USE_CECIL +#if HAVE_CECIL static void ProcessReferencedType (TypeDefinition td, CodeGenerationOptions opt) { if (!td.IsPublic && !td.IsNested) @@ -434,7 +446,7 @@ static void ProcessReferencedType (TypeDefinition td, CodeGenerationOptions opt) foreach (var nt in td.NestedTypes) ProcessReferencedType (nt, opt); } -#endif +#endif // HAVE_CECIL static void GenerateAnnotationAttributes (List gens, IEnumerable zips) { diff --git a/tools/generator/Ctor.cs b/tools/generator/Ctor.cs index 092ef0d23..fcbf1c575 100644 --- a/tools/generator/Ctor.cs +++ b/tools/generator/Ctor.cs @@ -8,7 +8,7 @@ using Xamarin.Android.Tools; namespace MonoDroid.Generation { -#if USE_CECIL +#if HAVE_CECIL public class ManagedCtor : Ctor { MethodDefinition m; string name; @@ -53,7 +53,7 @@ public override string CustomAttributes { get { return null; } } } -#endif +#endif // HAVE_CECIL public class XmlCtor : Ctor { string name; diff --git a/tools/generator/Field.cs b/tools/generator/Field.cs index 892ecea4c..4c66716c2 100644 --- a/tools/generator/Field.cs +++ b/tools/generator/Field.cs @@ -11,7 +11,7 @@ using System.Xml.Linq; namespace MonoDroid.Generation { -#if USE_CECIL +#if HAVE_CECIL public class ManagedField : Field { FieldDefinition f; string java_name; @@ -83,7 +83,7 @@ protected override Parameter SetterParameter { } } } -#endif +#endif // HAVE_CECIL public class XmlField : Field { diff --git a/tools/generator/GenBaseSupport.cs b/tools/generator/GenBaseSupport.cs index 6af0841ee..47b9dbf07 100644 --- a/tools/generator/GenBaseSupport.cs +++ b/tools/generator/GenBaseSupport.cs @@ -50,7 +50,7 @@ public static bool IsPrefixableName (string name) } } -#if USE_CECIL +#if HAVE_CECIL public class ManagedGenBaseSupport : GenBaseSupport { TypeDefinition t; @@ -152,7 +152,7 @@ public override string Visibility { get { return t.IsPublic || t.IsNestedPublic ? "public" : "protected internal"; } } } -#endif +#endif // HAVE_CECIL public class XmlGenBaseSupport : GenBaseSupport { diff --git a/tools/generator/InterfaceGen.cs b/tools/generator/InterfaceGen.cs index 87e5d40a6..afa6bcd7a 100644 --- a/tools/generator/InterfaceGen.cs +++ b/tools/generator/InterfaceGen.cs @@ -11,7 +11,7 @@ using Xamarin.Android.Tools; namespace MonoDroid.Generation { -#if USE_CECIL +#if HAVE_CECIL public class ManagedInterfaceGen : InterfaceGen { public ManagedInterfaceGen (TypeDefinition t) : base (new ManagedGenBaseSupport (t)) @@ -34,7 +34,7 @@ public override bool MayHaveManagedGenericArguments { get { return !this.IsAcw; } } } -#endif +#endif // HAVE_CECIL public class XmlInterfaceGen : InterfaceGen { diff --git a/tools/generator/Method.cs b/tools/generator/Method.cs index 08a1a4f25..a71db1d11 100644 --- a/tools/generator/Method.cs +++ b/tools/generator/Method.cs @@ -12,7 +12,7 @@ using System.Xml.Linq; namespace MonoDroid.Generation { -#if USE_CECIL +#if HAVE_CECIL public class ManagedMethod : Method { MethodDefinition m; string java_name; @@ -121,7 +121,7 @@ public override string CustomAttributes { get { return null; } } } -#endif +#endif // HAVE_CECIL public class XmlMethod : Method { diff --git a/tools/generator/MethodBase.cs b/tools/generator/MethodBase.cs index 251b91345..3563c8bc9 100644 --- a/tools/generator/MethodBase.cs +++ b/tools/generator/MethodBase.cs @@ -20,7 +20,7 @@ public interface IMethodBaseSupport { string Visibility { get; } } -#if USE_CECIL +#if HAVE_CECIL public class ManagedMethodBaseSupport : IMethodBaseSupport { MethodDefinition m; public ManagedMethodBaseSupport (MethodDefinition m) @@ -79,7 +79,7 @@ public IEnumerable GetParameters (CustomAttribute regatt) } } } -#endif +#endif // HAVE_CECIL public class XmlMethodBaseSupport : IMethodBaseSupport { diff --git a/tools/generator/Parameter.cs b/tools/generator/Parameter.cs index f113b9ef2..11cd34042 100644 --- a/tools/generator/Parameter.cs +++ b/tools/generator/Parameter.cs @@ -284,7 +284,7 @@ public static Parameter FromClassElement (XElement elem) return new Parameter (name, java_package + "." + java_type, null, false); } -#if USE_CECIL +#if HAVE_CECIL public static Parameter FromManagedParameter (ParameterDefinition p, string jnitype, string rawtype) { // FIXME: safe to use CLR type name? assuming yes as we often use it in metadatamap. @@ -297,6 +297,6 @@ public static Parameter FromManagedType (TypeDefinition t, string javaType) { return new Parameter ("__self", javaType ?? t.FullName, t.FullName, false); } -#endif +#endif // HAVE_CECIL } } diff --git a/tools/generator/generator.csproj b/tools/generator/generator.csproj index 3a201a9a6..957eb4009 100644 --- a/tools/generator/generator.csproj +++ b/tools/generator/generator.csproj @@ -23,10 +23,11 @@ full False $(UtilityOutputFullPath) - DEBUG;GENERATOR;USE_CECIL;JCW_ONLY_TYPE_NAMES + DEBUG;GENERATOR;HAVE_CECIL;JCW_ONLY_TYPE_NAMES prompt 4 false + anycpu full @@ -35,7 +36,7 @@ prompt 4 True - GENERATOR;USE_CECIL;JCW_ONLY_TYPE_NAMES + GENERATOR;HAVE_CECIL;JCW_ONLY_TYPE_NAMES