diff --git a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers.csproj b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers.csproj index 5aa03e485..7496c3761 100644 --- a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers.csproj +++ b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers.csproj @@ -2,6 +2,8 @@ netstandard2.0 + false + 8.0 true @@ -23,6 +25,9 @@ JavaNativeTypeManager.cs + + NullableAttributes.cs + diff --git a/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs b/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs index cf1e00f73..71fa30309 100644 --- a/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs +++ b/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs @@ -1,5 +1,8 @@ +#nullable enable + using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Security.Cryptography; @@ -33,7 +36,7 @@ enum PackageNamingPolicy { #endif class JniTypeName { - public string Type { get; internal set; } + public string? Type { get; internal set; } public bool IsKeyword { get; internal set; } } @@ -45,7 +48,7 @@ static class JavaNativeTypeManager { public static PackageNamingPolicy PackageNamingPolicy { get; set; } = PackageNamingPolicy.LowercaseCrc64; - public static string ApplicationJavaClass { get; set; } + public static string? ApplicationJavaClass { get; set; } public static JniTypeName Parse (string jniType) { @@ -72,9 +75,10 @@ public static JniTypeName ReturnTypeFromSignature (string signature) } // as per: http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/types.html - static JniTypeName ExtractType (string signature, ref int index) + [return: NotNullIfNotNull ("signature")] + static JniTypeName? ExtractType (string? signature, ref int index) { - if (index >= signature.Length) + if (signature is null || index >= signature.Length) return null; var i = index++; switch (signature [i]) { @@ -82,7 +86,7 @@ static JniTypeName ExtractType (string signature, ref int index) ++i; if (i >= signature.Length) throw new InvalidOperationException ("Missing array type after '[' at index " + i + " in: " + signature); - JniTypeName r = ExtractType (signature, ref index); + var r = ExtractType (signature, ref index); return new JniTypeName { Type = r.Type + "[]", IsKeyword = r.IsKeyword }; } case 'B': @@ -155,7 +159,7 @@ public static string ToJniName (Type type) "java/lang/Object"; } - static string ToJniName (Type type, ExportParameterKind exportKind) + static string? ToJniName (Type type, ExportParameterKind exportKind) { if (type == null) throw new ArgumentNullException ("type"); @@ -168,9 +172,9 @@ static string ToJniName (Type type, ExportParameterKind exportKind) if (!type.GetInterfaces ().Any (t => t.FullName == "Android.Runtime.IJavaObject")) - return GetSpecialExportJniType (type.FullName, exportKind); + return GetSpecialExportJniType (type.FullName!, exportKind); - return ToJniName (type, t => t.DeclaringType, t => t.Name, GetPackageName, t => { + return ToJniName (type, t => t.DeclaringType!, t => t.Name, GetPackageName, t => { return ToJniNameFromAttributes (t); }, _ => false); } @@ -194,10 +198,10 @@ public static string GetPackageName (Type type) { string assemblyName = GetAssemblyName (type.Assembly); if (IsPackageNamePreservedForAssembly (assemblyName)) - return type.Namespace.ToLowerInvariant (); + return type.Namespace!.ToLowerInvariant (); switch (PackageNamingPolicy) { case PackageNamingPolicy.Lowercase: - return type.Namespace.ToLowerInvariant (); + return type.Namespace!.ToLowerInvariant (); case PackageNamingPolicy.LowercaseWithAssemblyName: return "assembly_" + (assemblyName.Replace ('.', '_') + "." + type.Namespace).ToLowerInvariant (); case PackageNamingPolicy.LowercaseCrc64: @@ -213,7 +217,7 @@ public static string GetPackageName (Type type) /// static string GetAssemblyName (Assembly assembly) { - var name = assembly.FullName; + var name = assembly.FullName!; int index = name.IndexOf (','); if (index != -1) { return name.Substring (0, index); @@ -227,12 +231,12 @@ public static int GetArrayInfo (Type type, out Type elementType) int rank = 0; while (type.IsArray) { rank++; - elementType = type = type.GetElementType (); + elementType = type = type.GetElementType ()!; } return rank; } - static string GetPrimitiveClass (Type type) + static string? GetPrimitiveClass (Type type) { if (type.IsEnum) return GetPrimitiveClass (Enum.GetUnderlyingType (type)); @@ -261,7 +265,7 @@ static string GetPrimitiveClass (Type type) return null; } - static string GetSpecialExportJniType (string typeName, ExportParameterKind exportKind) + static string? GetSpecialExportJniType (string typeName, ExportParameterKind exportKind) { switch (exportKind) { case ExportParameterKind.InputStream: @@ -287,7 +291,7 @@ static string GetSpecialExportJniType (string typeName, ExportParameterKind expo } // Keep in sync with ToJniNameFromAttributes(TypeDefinition) - public static string ToJniNameFromAttributes (Type type) + public static string? ToJniNameFromAttributes (Type type) { var aa = (IJniNameProviderAttribute []) type.GetCustomAttributes (typeof (IJniNameProviderAttribute), inherit: false); return aa.Length > 0 && !string.IsNullOrEmpty (aa [0].Name) ? aa [0].Name.Replace ('.', '/') : null; @@ -305,11 +309,11 @@ public static string ToJniNameFromAttributes (Type type) * Callers of GetJniSignature() MUST check for `null` and behave * appropriately. */ - static string GetJniSignature (IEnumerable

parameters, Func getParameterType, Func getExportKind, T returnType, ExportParameterKind returnExportKind, Func getJniTypeName, bool isConstructor) + static string? GetJniSignature (IEnumerable

parameters, Func getParameterType, Func getExportKind, T returnType, ExportParameterKind returnExportKind, Func getJniTypeName, bool isConstructor) { StringBuilder sb = new StringBuilder ().Append ("("); foreach (P p in parameters) { - string jniType = getJniTypeName (getParameterType (p), getExportKind (p)); + var jniType = getJniTypeName (getParameterType (p), getExportKind (p)); if (jniType == null) return null; sb.Append (jniType); @@ -318,7 +322,7 @@ public static string ToJniNameFromAttributes (Type type) if (isConstructor) sb.Append ("V"); else { - string jniType = getJniTypeName (returnType, returnExportKind); + var jniType = getJniTypeName (returnType, returnExportKind); if (jniType == null) return null; sb.Append (jniType); @@ -326,7 +330,7 @@ public static string ToJniNameFromAttributes (Type type) return sb.ToString (); } - static string GetJniTypeName (TR typeRef, ExportParameterKind exportKind, Func resolve, Func> getArrayInfo, Func getFullName, Func toJniName) + static string? GetJniTypeName (TR typeRef, ExportParameterKind exportKind, Func resolve, Func> getArrayInfo, Func getFullName, Func toJniName) { TD ptype = resolve (typeRef); var p = getArrayInfo (typeRef); @@ -343,7 +347,7 @@ public static string ToJniNameFromAttributes (Type type) // Probably a (IntPtr, JniHandleOwnership) parameter; skip return null; - string pJniName = toJniName (ptype, exportKind); + var pJniName = toJniName (ptype, exportKind); if (pJniName == null) { return null; } @@ -357,7 +361,7 @@ static ExportParameterKind GetExportKind (System.Reflection.ICustomAttributeProv return ExportParameterKind.Unspecified; } - public static string GetJniSignature (MethodInfo method) + public static string? GetJniSignature (MethodInfo method) { return GetJniSignature (method.GetParameters (), p => p.ParameterType, @@ -368,21 +372,21 @@ public static string GetJniSignature (MethodInfo method) method.IsConstructor); } - public static string GetJniTypeName (Type typeRef) + public static string? GetJniTypeName (Type typeRef) { return GetJniTypeName (typeRef, ExportParameterKind.Unspecified); } - internal static string GetJniTypeName (Type typeRef, ExportParameterKind exportKind) + internal static string? GetJniTypeName (Type typeRef, ExportParameterKind exportKind) { return GetJniTypeName (typeRef, exportKind, t => t, t => { Type etype; int rank = GetArrayInfo (t, out etype); return new KeyValuePair (rank, etype); - }, t => t.FullName, (t, k) => ToJniNameWhichShouldReplaceExistingToJniName (t, k)); + }, t => t.FullName!, (t, k) => ToJniNameWhichShouldReplaceExistingToJniName (t, k)); } - static string ToJniNameWhichShouldReplaceExistingToJniName (Type type, ExportParameterKind exportKind) + static string? ToJniNameWhichShouldReplaceExistingToJniName (Type type, ExportParameterKind exportKind) { // we need some method that exactly does the same as ToJniName(TypeDefinition) var ret = ToJniNameFromAttributes (type); @@ -407,7 +411,7 @@ internal static ExportParameterAttribute ToExportParameterAttribute (CustomAttri public static bool IsApplication (TypeDefinition type) => IsApplication (type, cache: null); - public static bool IsApplication (TypeDefinition type, TypeDefinitionCache cache) + public static bool IsApplication (TypeDefinition type, TypeDefinitionCache? cache) { return type.GetBaseTypes (cache).Any (b => b.FullName == "Android.App.Application"); } @@ -416,17 +420,17 @@ public static bool IsApplication (TypeDefinition type, TypeDefinitionCache cache public static bool IsInstrumentation (TypeDefinition type) => IsInstrumentation (type, cache: null); - public static bool IsInstrumentation (TypeDefinition type, TypeDefinitionCache cache) + public static bool IsInstrumentation (TypeDefinition type, TypeDefinitionCache? cache) { return type.GetBaseTypes (cache).Any (b => b.FullName == "Android.App.Instrumentation"); } // moved from JavaTypeInfo [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] - public static string GetJniSignature (MethodDefinition method) => + public static string? GetJniSignature (MethodDefinition method) => GetJniSignature (method, cache: null); - public static string GetJniSignature (MethodDefinition method, TypeDefinitionCache cache) + public static string? GetJniSignature (MethodDefinition method, TypeDefinitionCache? cache) { return GetJniSignature ( method.Parameters, @@ -440,15 +444,15 @@ public static string GetJniSignature (MethodDefinition method, TypeDefinitionCac // moved from JavaTypeInfo [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] - public static string GetJniTypeName (TypeReference typeRef) => + public static string? GetJniTypeName (TypeReference typeRef) => GetJniTypeName (typeRef, cache: null); - public static string GetJniTypeName (TypeReference typeRef, TypeDefinitionCache cache) + public static string? GetJniTypeName (TypeReference typeRef, TypeDefinitionCache? cache) { return GetJniTypeName (typeRef, ExportParameterKind.Unspecified, cache); } - internal static string GetJniTypeName (TypeReference typeRef, ExportParameterKind exportKind, TypeDefinitionCache cache) + internal static string? GetJniTypeName (TypeReference typeRef, ExportParameterKind exportKind, TypeDefinitionCache? cache) { return GetJniTypeName (typeRef, exportKind, t => t.Resolve (), t => { TypeReference etype; @@ -461,7 +465,7 @@ internal static string GetJniTypeName (TypeReference typeRef, ExportParameterKin public static string ToCompatJniName (TypeDefinition type) => ToCompatJniName (type, cache: null); - public static string ToCompatJniName (TypeDefinition type, TypeDefinitionCache cache) + public static string ToCompatJniName (TypeDefinition type, TypeDefinitionCache? cache) { return ToJniName (type, t => t.DeclaringType, t => t.Name, ToCompatPackageName, ToJniNameFromAttributes, t => IsNonStaticInnerClass (t as TypeDefinition, cache)); } @@ -475,13 +479,13 @@ static string ToCompatPackageName (TypeDefinition type) public static string ToJniName (TypeDefinition type) => ToJniName (type, cache: null); - public static string ToJniName (TypeDefinition type, TypeDefinitionCache cache) + public static string ToJniName (TypeDefinition type, TypeDefinitionCache? cache) { return ToJniName (type, ExportParameterKind.Unspecified, cache) ?? "java/lang/Object"; } - static string ToJniName (TypeDefinition type, ExportParameterKind exportKind, TypeDefinitionCache cache) + static string? ToJniName (TypeDefinition type, ExportParameterKind exportKind, TypeDefinitionCache? cache) { if (type == null) throw new ArgumentNullException ("type"); @@ -499,13 +503,13 @@ static string ToJniName (TypeDefinition type, ExportParameterKind exportKind, Ty return ToJniName (type, t => t.DeclaringType, t => t.Name, t => GetPackageName (t, cache), ToJniNameFromAttributes, t => IsNonStaticInnerClass (t as TypeDefinition, cache)); } - static string ToJniNameFromAttributes (TypeDefinition type) + static string? ToJniNameFromAttributes (TypeDefinition type) { #region CustomAttribute alternate name support var attrs = type.CustomAttributes.Where (a => a.AttributeType.Resolve ().Interfaces.Any (it => it.InterfaceType.FullName == typeof (IJniNameProviderAttribute).FullName)); return attrs.Select (attr => { var ap = attr.Properties.FirstOrDefault (p => p.Name == "Name"); - string name = null; + string? name = null; if (ap.Name == null) { var ca = attr.ConstructorArguments.FirstOrDefault (); if (ca.Type == null || ca.Type.FullName != "System.String") @@ -533,7 +537,7 @@ public static int GetArrayInfo (Mono.Cecil.TypeReference type, out Mono.Cecil.Ty return rank; } - static string GetPrimitiveClass (Mono.Cecil.TypeDefinition type) + static string? GetPrimitiveClass (Mono.Cecil.TypeDefinition type) { if (type.IsEnum) return GetPrimitiveClass (type.Fields.First (f => f.IsSpecialName).FieldType.Resolve ()); @@ -560,7 +564,7 @@ static string GetPrimitiveClass (Mono.Cecil.TypeDefinition type) public static string GetPackageName (TypeDefinition type) => GetPackageName (type, cache: null); - public static string GetPackageName (TypeDefinition type, TypeDefinitionCache cache) + public static string GetPackageName (TypeDefinition type, TypeDefinitionCache? cache) { if (IsPackageNamePreservedForAssembly (type.GetPartialAssemblyName (cache))) return type.Namespace.ToLowerInvariant (); @@ -578,11 +582,11 @@ public static string GetPackageName (TypeDefinition type, TypeDefinitionCache ca } #endif - static string ToJniName (T type, Func decl, Func name, Func ns, Func overrideName, Func shouldUpdateName) + static string ToJniName (T type, Func decl, Func name, Func ns, Func overrideName, Func shouldUpdateName) where T : class { var nameParts = new List (); - var typeName = (string) null; + var typeName = (string?) null; var nsType = type; for (var declType = type ; declType != null; declType = decl (declType)) { @@ -617,7 +621,7 @@ static string ToJniName (T type, Func decl, Func name, Func< } #if HAVE_CECIL - internal static bool IsNonStaticInnerClass (TypeDefinition type, TypeDefinitionCache cache) + internal static bool IsNonStaticInnerClass (TypeDefinition? type, TypeDefinitionCache? cache) { if (type == null) return false; @@ -631,7 +635,7 @@ internal static bool IsNonStaticInnerClass (TypeDefinition type, TypeDefinitionC .Any (ctor => ctor.Parameters.Any (p => p.Name == "__self")); } - static IEnumerable GetBaseConstructors (TypeDefinition type, TypeDefinitionCache cache) + static IEnumerable GetBaseConstructors (TypeDefinition type, TypeDefinitionCache? cache) { var baseType = type.GetBaseTypes (cache).FirstOrDefault (t => t.GetCustomAttributes (typeof (RegisterAttribute)).Any ()); if (baseType != null) diff --git a/src/Java.Interop/Java.Interop.csproj b/src/Java.Interop/Java.Interop.csproj index 825c512a3..d085be3f4 100644 --- a/src/Java.Interop/Java.Interop.csproj +++ b/src/Java.Interop/Java.Interop.csproj @@ -19,6 +19,7 @@ DEBUG;$(DefineConstants) + diff --git a/src/Java.Interop/Java.Interop/JavaObjectArray.cs b/src/Java.Interop/Java.Interop/JavaObjectArray.cs index 34735e0db..7a41a6274 100644 --- a/src/Java.Interop/Java.Interop/JavaObjectArray.cs +++ b/src/Java.Interop/Java.Interop/JavaObjectArray.cs @@ -158,7 +158,7 @@ public override IList CreateGenericValue (ref JniObjectReference reference, J }); } - public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList value, ParameterAttributes synchronize) + public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IList value, ParameterAttributes synchronize) { return JavaArray.CreateArgumentState (value, synchronize, (list, copy) => { var a = copy @@ -169,7 +169,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState }); } - public override void DestroyGenericArgumentState (IList value, ref JniValueMarshalerState state, ParameterAttributes synchronize) + public override void DestroyGenericArgumentState ([AllowNull]IList value, ref JniValueMarshalerState state, ParameterAttributes synchronize) { JavaArray.DestroyArgumentState> (value, ref state, synchronize); } diff --git a/src/Java.Interop/Java.Interop/JniRuntime.JniMarshalMemberBuilder.cs b/src/Java.Interop/Java.Interop/JniRuntime.JniMarshalMemberBuilder.cs index cb167a8a9..909184bb0 100644 --- a/src/Java.Interop/Java.Interop/JniRuntime.JniMarshalMemberBuilder.cs +++ b/src/Java.Interop/Java.Interop/JniRuntime.JniMarshalMemberBuilder.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; using System.Reflection; @@ -203,7 +204,7 @@ public override JniValueMarshalerState CreateArgumentState (object? value, Param throw new NotSupportedException (); } - public override JniValueMarshalerState CreateGenericArgumentState (IntPtr value, ParameterAttributes synchronize) + public override JniValueMarshalerState CreateGenericArgumentState ([MaybeNull]IntPtr value, ParameterAttributes synchronize) { throw new NotSupportedException (); } @@ -213,7 +214,7 @@ public override JniValueMarshalerState CreateObjectReferenceArgumentState (objec throw new NotSupportedException (); } - public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IntPtr value, ParameterAttributes synchronize) + public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IntPtr value, ParameterAttributes synchronize) { throw new NotSupportedException (); } diff --git a/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs b/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs index c4de63a81..41d8ba07e 100644 --- a/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs +++ b/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs @@ -155,7 +155,7 @@ static Type GetUnderlyingType (Type type, out int rank) } // `type` will NOT be an array type. - protected virtual string GetSimpleReference (Type type) + protected virtual string? GetSimpleReference (Type type) { return GetSimpleReferences (type).FirstOrDefault (); } diff --git a/src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs b/src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs index 347e8f1e8..b344c0b2b 100644 --- a/src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs +++ b/src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs @@ -199,7 +199,7 @@ public virtual void DisposePeerUnlessReferenced (IJavaPeerable value) DisposePeer (h, value); } - public abstract IJavaPeerable PeekPeer (JniObjectReference reference); + public abstract IJavaPeerable? PeekPeer (JniObjectReference reference); public object? PeekValue (JniObjectReference reference) { @@ -261,7 +261,7 @@ static Type GetPeerType (Type type) return type; } - public virtual IJavaPeerable CreatePeer (ref JniObjectReference reference, JniObjectReferenceOptions transfer, Type? targetType) + public virtual IJavaPeerable? CreatePeer (ref JniObjectReference reference, JniObjectReferenceOptions transfer, Type? targetType) { if (disposed) throw new ObjectDisposedException (GetType ().Name); @@ -396,7 +396,9 @@ public T CreateValue (ref JniObjectReference reference, JniObjectReferenceOpt targetType = targetType ?? typeof (T); if (typeof (IJavaPeerable).IsAssignableFrom (targetType)) { +#pragma warning disable CS8601 // Possible null reference assignment. return (T) JavaPeerableValueMarshaler.Instance.CreateGenericValue (ref reference, options, targetType); +#pragma warning restore CS8601 // Possible null reference assignment. } var marshaler = GetValueMarshaler (); @@ -473,7 +475,9 @@ public T GetValue (ref JniObjectReference reference, JniObjectReferenceOption } if (typeof (IJavaPeerable).IsAssignableFrom (targetType)) { +#pragma warning disable CS8601 // Possible null reference assignment. return (T) JavaPeerableValueMarshaler.Instance.CreateGenericValue (ref reference, options, targetType); +#pragma warning restore CS8601 // Possible null reference assignment. } var marshaler = GetValueMarshaler (); @@ -607,12 +611,12 @@ public override void DestroyArgumentState (object? value, ref JniValueMarshalerS } } - sealed class JavaPeerableValueMarshaler : JniValueMarshaler { + sealed class JavaPeerableValueMarshaler : JniValueMarshaler { internal static JavaPeerableValueMarshaler Instance = new JavaPeerableValueMarshaler (); [return: MaybeNull] - public override IJavaPeerable CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type? targetType) + public override IJavaPeerable? CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type? targetType) { var jvm = JniEnvironment.Runtime; var marshaler = jvm.ValueManager.GetValueMarshaler (targetType ?? typeof(IJavaPeerable)); @@ -621,7 +625,7 @@ public override IJavaPeerable CreateGenericValue (ref JniObjectReference referen return jvm.ValueManager.CreatePeer (ref reference, options, targetType); } - public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IJavaPeerable value, ParameterAttributes synchronize) + public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IJavaPeerable? value, ParameterAttributes synchronize) { if (value == null || !value.PeerReference.IsValid) return new JniValueMarshalerState (); @@ -629,7 +633,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState return new JniValueMarshalerState (r); } - public override void DestroyGenericArgumentState (IJavaPeerable value, ref JniValueMarshalerState state, ParameterAttributes synchronize) + public override void DestroyGenericArgumentState ([MaybeNull]IJavaPeerable? value, ref JniValueMarshalerState state, ParameterAttributes synchronize) { var r = state.ReferenceValue; JniObjectReference.Dispose (ref r); @@ -694,12 +698,12 @@ public override T CreateGenericValue (ref JniObjectReference reference, JniObjec return (T) ValueMarshaler.CreateValue (ref reference, options, targetType ?? typeof (T))!; } - public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (T value, ParameterAttributes synchronize) + public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]T value, ParameterAttributes synchronize) { return ValueMarshaler.CreateObjectReferenceArgumentState (value, synchronize); } - public override void DestroyGenericArgumentState (T value, ref JniValueMarshalerState state, ParameterAttributes synchronize) + public override void DestroyGenericArgumentState ([AllowNull]T value, ref JniValueMarshalerState state, ParameterAttributes synchronize) { ValueMarshaler.DestroyArgumentState (value, ref state, synchronize); } @@ -720,12 +724,12 @@ public override Expression CreateReturnValueFromManagedExpression (JniValueMarsh } } - sealed class ProxyValueMarshaler : JniValueMarshaler { + sealed class ProxyValueMarshaler : JniValueMarshaler { internal static ProxyValueMarshaler Instance = new ProxyValueMarshaler (); [return: MaybeNull] - public override object CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type? targetType) + public override object? CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type? targetType) { var jvm = JniEnvironment.Runtime; @@ -748,7 +752,7 @@ public override object CreateGenericValue (ref JniObjectReference reference, Jni return jvm.ValueManager.CreatePeer (ref reference, options, targetType); } - public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (object value, ParameterAttributes synchronize) + public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]object? value, ParameterAttributes synchronize) { if (value == null) return new JniValueMarshalerState (); @@ -765,7 +769,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState return new JniValueMarshalerState (p!.PeerReference.NewLocalRef ()); } - public override void DestroyGenericArgumentState (object value, ref JniValueMarshalerState state, ParameterAttributes synchronize) + public override void DestroyGenericArgumentState (object? value, ref JniValueMarshalerState state, ParameterAttributes synchronize) { var vm = state.Extra as JniValueMarshaler; if (vm != null) { diff --git a/src/Java.Interop/Java.Interop/JniStringValueMarshaler.cs b/src/Java.Interop/Java.Interop/JniStringValueMarshaler.cs index 1fb3c59eb..8692639b7 100644 --- a/src/Java.Interop/Java.Interop/JniStringValueMarshaler.cs +++ b/src/Java.Interop/Java.Interop/JniStringValueMarshaler.cs @@ -1,6 +1,7 @@ #nullable enable using System; +using System.Diagnostics.CodeAnalysis; using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices; @@ -18,7 +19,7 @@ sealed class JniStringValueMarshaler : JniValueMarshaler { return JniEnvironment.Strings.ToString (ref reference, options, targetType ?? typeof (string)); } - public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (string? value, ParameterAttributes synchronize) + public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]string? value, ParameterAttributes synchronize) { var r = JniEnvironment.Strings.NewString (value); return new JniValueMarshalerState (r); diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteInterfaceProperties.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteInterfaceProperties.txt index f25490fa5..4c99ec981 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteInterfaceProperties.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteInterfaceProperties.txt @@ -5,7 +5,7 @@ int Count { [Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")] set; } -java.lang.String Key { +string Key { // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Key' and count(parameter)=0]" [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")] get; // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterface.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterface.txt index 10a3c8536..45a770fb1 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterface.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterface.txt @@ -39,7 +39,7 @@ public partial interface IMyInterface : IJavaObject, IJavaPeerable { [Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")] set; } - java.lang.String Key { + string Key { // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Key' and count(parameter)=0]" [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")] get; // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterfaceDeclaration.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterfaceDeclaration.txt index 15447c62b..73ed59b91 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterfaceDeclaration.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterfaceDeclaration.txt @@ -9,7 +9,7 @@ public partial interface IMyInterface : IJavaObject, IJavaPeerable { [Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")] set; } - java.lang.String Key { + string Key { // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Key' and count(parameter)=0]" [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")] get; // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCharSequenceEnumerator.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCharSequenceEnumerator.txt new file mode 100644 index 000000000..0a27a4a22 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCharSequenceEnumerator.txt @@ -0,0 +1,11 @@ +System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator () +{ + return GetEnumerator (); +} + +public System.Collections.Generic.IEnumerator GetEnumerator () +{ + for (int i = 0; i < Length(); i++) + yield return CharAt (i); +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClass.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClass.txt new file mode 100644 index 000000000..01ea5c4e6 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClass.txt @@ -0,0 +1,325 @@ +// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']" +[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] +public partial class MyClass { + + static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/MyClass", typeof (MyClass)); + internal static new IntPtr class_ref { + get { + return _members.JniPeerType.PeerReference.Handle; + } + } + + protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} + + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" + [Register (".ctor", "()V", "")] + unsafe MyClass () + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + const string __id = "()V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + try { + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), null); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, null); + } finally { + } + } + + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register (".ctor", "(Ljava/lang/String;)V", "")] + unsafe MyClass (string? p0) + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + const string __id = "(Ljava/lang/String;)V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + IntPtr native_p0 = JNIEnv.NewString (p0); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_p0); + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_p0); + } + } + + static Delegate? cb_get_Count; +#pragma warning disable 0169 + static Delegate Getget_CountHandler () + { + if (cb_get_Count == null) + cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); + return cb_get_Count; + } + + static int n_get_Count (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.Count; + } +#pragma warning restore 0169 + + static Delegate? cb_set_Count_I; +#pragma warning disable 0169 + static Delegate Getset_Count_IHandler () + { + if (cb_set_Count_I == null) + cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); + return cb_set_Count_I; + } + + static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.Count = value; + } +#pragma warning restore 0169 + + public virtual unsafe int Count { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" + [Register ("get_Count", "()I", "Getget_CountHandler")] + get { + const string __id = "get_Count.()I"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] + set { + const string __id = "set_Count.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); + } finally { + } + } + } + + static Delegate? cb_get_Key; +#pragma warning disable 0169 + static Delegate Getget_KeyHandler () + { + if (cb_get_Key == null) + cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); + return cb_get_Key; + } + + static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return JNIEnv.NewString (__this.Key); + } +#pragma warning restore 0169 + + static Delegate? cb_set_Key_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate Getset_Key_Ljava_lang_String_Handler () + { + if (cb_set_Key_Ljava_lang_String_ == null) + cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); + return cb_set_Key_Ljava_lang_String_; + } + + static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); + __this.Key = value; + } +#pragma warning restore 0169 + + public virtual unsafe string? Key { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" + [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] + get { + const string __id = "get_Key.()Ljava/lang/String;"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); + return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler")] + set { + const string __id = "set_Key.(Ljava/lang/String;)V"; + IntPtr native_value = JNIEnv.NewString (value); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_value); + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_value); + } + } + } + + public static unsafe int StaticCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" + [Register ("get_StaticCount", "()I", "")] + get { + const string __id = "get_StaticCount.()I"; + try { + var __rm = _members.StaticMethods.InvokeInt32Method (__id, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_StaticCount", "(I)V", "")] + set { + const string __id = "set_StaticCount.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.StaticMethods.InvokeVoidMethod (__id, __args); + } finally { + } + } + } + + static Delegate? cb_get_AbstractCount; +#pragma warning disable 0169 + static Delegate Getget_AbstractCountHandler () + { + if (cb_get_AbstractCount == null) + cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); + return cb_get_AbstractCount; + } + + static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.AbstractCount; + } +#pragma warning restore 0169 + + static Delegate? cb_set_AbstractCount_I; +#pragma warning disable 0169 + static Delegate Getset_AbstractCount_IHandler () + { + if (cb_set_AbstractCount_I == null) + cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); + return cb_set_AbstractCount_I; + } + + static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.AbstractCount = value; + } +#pragma warning restore 0169 + + public abstract int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; + } + + static Delegate? cb_GetCountForKey_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate GetGetCountForKey_Ljava_lang_String_Handler () + { + if (cb_GetCountForKey_Ljava_lang_String_ == null) + cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); + return cb_GetCountForKey_Ljava_lang_String_; + } + + static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); + int __ret = __this.GetCountForKey (key); + return __ret; + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] + public virtual unsafe int GetCountForKey (string? key) + { + const string __id = "GetCountForKey.(Ljava/lang/String;)I"; + IntPtr native_key = JNIEnv.NewString (key); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_key); + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, __args); + return __rm; + } finally { + JNIEnv.DeleteLocalRef (native_key); + } + } + + static Delegate? cb_Key; +#pragma warning disable 0169 + static Delegate GetKeyHandler () + { + if (cb_Key == null) + cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); + return cb_Key; + } + + static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return JNIEnv.NewString (__this.Key ()); + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" + [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] + public virtual unsafe string? Key () + { + const string __id = "Key.()Ljava/lang/String;"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); + return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); + } finally { + } + } + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" + [Register ("StaticMethod", "()V", "")] + public static unsafe void StaticMethod () + { + const string __id = "StaticMethod.()V"; + try { + _members.StaticMethods.InvokeVoidMethod (__id, null); + } finally { + } + } + + static Delegate? cb_AbstractMethod; +#pragma warning disable 0169 + static Delegate GetAbstractMethodHandler () + { + if (cb_AbstractMethod == null) + cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); + return cb_AbstractMethod; + } + + static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.AbstractMethod (); + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" + [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] + public abstract void AbstractMethod (); + +} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassAbstractMembers.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassAbstractMembers.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassConstructors.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassConstructors.txt new file mode 100644 index 000000000..8a45f35e3 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassConstructors.txt @@ -0,0 +1,42 @@ +protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} + +// Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" +[Register (".ctor", "()V", "")] + unsafe MyClass () + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) +{ + const string __id = "()V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + try { + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), null); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, null); + } finally { + } +} + +// Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" +[Register (".ctor", "(Ljava/lang/String;)V", "")] + unsafe MyClass (string? p0) + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) +{ + const string __id = "(Ljava/lang/String;)V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + IntPtr native_p0 = JNIEnv.NewString (p0); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_p0); + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_p0); + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassHandle.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassHandle.txt new file mode 100644 index 000000000..9cb131cea --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassHandle.txt @@ -0,0 +1,7 @@ + static readonly JniPeerMembers _members = new XAPeerMembers ("com/mypackage/foo", typeof (foo)); + internal static IntPtr class_ref { + get { + return _members.JniPeerType.PeerReference.Handle; + } + } + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassInvoker.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassInvoker.txt new file mode 100644 index 000000000..9cd0169c0 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassInvoker.txt @@ -0,0 +1,52 @@ +[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] +internal partial class MyClassInvoker : MyClass { + + public MyClassInvoker (IntPtr handle, JniHandleOwnership transfer) : base (handle, transfer) {} + + static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/MyClass", typeof (MyClassInvoker)); + + public override global::Java.Interop.JniPeerMembers JniPeerMembers { + get { return _members; } + } + + protected override global::System.Type ThresholdType { + get { return _members.ManagedPeerType; } + } + + public override unsafe int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] + get { + const string __id = "get_AbstractCount.()I"; + try { + var __rm = _members.InstanceMethods.InvokeAbstractInt32Method (__id, this, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] + set { + const string __id = "set_AbstractCount.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, __args); + } finally { + } + } + } + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" + [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] + public override unsafe void AbstractMethod () + { + const string __id = "AbstractMethod.()V"; + try { + _members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, null); + } finally { + } + } + +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassInvokerHandle.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassInvokerHandle.txt new file mode 100644 index 000000000..f19ad766e --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassInvokerHandle.txt @@ -0,0 +1,10 @@ +static readonly JniPeerMembers _members = new XAPeerMembers ("com/mypackage/foo", typeof (Com.MyPackage.Foo)); + +public override global::Java.Interop.JniPeerMembers JniPeerMembers { + get { return _members; } +} + +protected override global::System.Type ThresholdType { + get { return _members.ManagedPeerType; } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassInvokerMembers.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassInvokerMembers.txt new file mode 100644 index 000000000..98bc27c15 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassInvokerMembers.txt @@ -0,0 +1,35 @@ +public override unsafe int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] + get { + const string __id = "get_AbstractCount.()I"; + try { + var __rm = _members.InstanceMethods.InvokeAbstractInt32Method (__id, this, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] + set { + const string __id = "set_AbstractCount.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, __args); + } finally { + } + } +} + +// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" +[Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] +public override unsafe void AbstractMethod () +{ + const string __id = "AbstractMethod.()V"; + try { + _members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, null); + } finally { + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassMethodInvokers.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassMethodInvokers.txt new file mode 100644 index 000000000..7fec37680 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassMethodInvokers.txt @@ -0,0 +1,11 @@ +// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" +[Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] +public override unsafe void AbstractMethod () +{ + const string __id = "AbstractMethod.()V"; + try { + _members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, null); + } finally { + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassMethodInvokersWithSkips.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassMethodInvokersWithSkips.txt new file mode 100644 index 000000000..7fec37680 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassMethodInvokersWithSkips.txt @@ -0,0 +1,11 @@ +// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" +[Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] +public override unsafe void AbstractMethod () +{ + const string __id = "AbstractMethod.()V"; + try { + _members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, null); + } finally { + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassMethods.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassMethods.txt new file mode 100644 index 000000000..97d97f813 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassMethods.txt @@ -0,0 +1,93 @@ +static Delegate? cb_GetCountForKey_Ljava_lang_String_; +#pragma warning disable 0169 +static Delegate GetGetCountForKey_Ljava_lang_String_Handler () +{ + if (cb_GetCountForKey_Ljava_lang_String_ == null) + cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); + return cb_GetCountForKey_Ljava_lang_String_; +} + +static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); + int __ret = __this.GetCountForKey (key); + return __ret; +} +#pragma warning restore 0169 + +// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" +[Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] +public virtual unsafe int GetCountForKey (string? key) +{ + const string __id = "GetCountForKey.(Ljava/lang/String;)I"; + IntPtr native_key = JNIEnv.NewString (key); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_key); + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, __args); + return __rm; + } finally { + JNIEnv.DeleteLocalRef (native_key); + } +} + +static Delegate? cb_Key; +#pragma warning disable 0169 +static Delegate GetKeyHandler () +{ + if (cb_Key == null) + cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); + return cb_Key; +} + +static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return JNIEnv.NewString (__this.Key ()); +} +#pragma warning restore 0169 + +// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" +[Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] +public virtual unsafe string? Key () +{ + const string __id = "Key.()Ljava/lang/String;"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); + return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); + } finally { + } +} + +// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" +[Register ("StaticMethod", "()V", "")] +public static unsafe void StaticMethod () +{ + const string __id = "StaticMethod.()V"; + try { + _members.StaticMethods.InvokeVoidMethod (__id, null); + } finally { + } +} + +static Delegate? cb_AbstractMethod; +#pragma warning disable 0169 +static Delegate GetAbstractMethodHandler () +{ + if (cb_AbstractMethod == null) + cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); + return cb_AbstractMethod; +} + +static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.AbstractMethod (); +} +#pragma warning restore 0169 + +// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" +[Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] +public abstract void AbstractMethod (); + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassProperties.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassProperties.txt new file mode 100644 index 000000000..8b1868591 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassProperties.txt @@ -0,0 +1,178 @@ +static Delegate? cb_get_Count; +#pragma warning disable 0169 +static Delegate Getget_CountHandler () +{ + if (cb_get_Count == null) + cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); + return cb_get_Count; +} + +static int n_get_Count (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.Count; +} +#pragma warning restore 0169 + +static Delegate? cb_set_Count_I; +#pragma warning disable 0169 +static Delegate Getset_Count_IHandler () +{ + if (cb_set_Count_I == null) + cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); + return cb_set_Count_I; +} + +static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.Count = value; +} +#pragma warning restore 0169 + +public virtual unsafe int Count { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" + [Register ("get_Count", "()I", "Getget_CountHandler")] + get { + const string __id = "get_Count.()I"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] + set { + const string __id = "set_Count.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); + } finally { + } + } +} + +static Delegate? cb_get_Key; +#pragma warning disable 0169 +static Delegate Getget_KeyHandler () +{ + if (cb_get_Key == null) + cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); + return cb_get_Key; +} + +static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return JNIEnv.NewString (__this.Key); +} +#pragma warning restore 0169 + +static Delegate? cb_set_Key_Ljava_lang_String_; +#pragma warning disable 0169 +static Delegate Getset_Key_Ljava_lang_String_Handler () +{ + if (cb_set_Key_Ljava_lang_String_ == null) + cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); + return cb_set_Key_Ljava_lang_String_; +} + +static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); + __this.Key = value; +} +#pragma warning restore 0169 + +public virtual unsafe string? Key { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" + [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] + get { + const string __id = "get_Key.()Ljava/lang/String;"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); + return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler")] + set { + const string __id = "set_Key.(Ljava/lang/String;)V"; + IntPtr native_value = JNIEnv.NewString (value); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_value); + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_value); + } + } +} + +public static unsafe int StaticCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" + [Register ("get_StaticCount", "()I", "")] + get { + const string __id = "get_StaticCount.()I"; + try { + var __rm = _members.StaticMethods.InvokeInt32Method (__id, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_StaticCount", "(I)V", "")] + set { + const string __id = "set_StaticCount.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.StaticMethods.InvokeVoidMethod (__id, __args); + } finally { + } + } +} + +static Delegate? cb_get_AbstractCount; +#pragma warning disable 0169 +static Delegate Getget_AbstractCountHandler () +{ + if (cb_get_AbstractCount == null) + cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); + return cb_get_AbstractCount; +} + +static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.AbstractCount; +} +#pragma warning restore 0169 + +static Delegate? cb_set_AbstractCount_I; +#pragma warning disable 0169 +static Delegate Getset_AbstractCount_IHandler () +{ + if (cb_set_AbstractCount_I == null) + cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); + return cb_set_AbstractCount_I; +} + +static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.AbstractCount = value; +} +#pragma warning restore 0169 + +public abstract int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassPropertyInvokers.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassPropertyInvokers.txt new file mode 100644 index 000000000..55d7c1ca1 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassPropertyInvokers.txt @@ -0,0 +1,24 @@ +public override unsafe int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] + get { + const string __id = "get_AbstractCount.()I"; + try { + var __rm = _members.InstanceMethods.InvokeAbstractInt32Method (__id, this, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] + set { + const string __id = "set_AbstractCount.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, __args); + } finally { + } + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassPropertyInvokersWithSkips.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassPropertyInvokersWithSkips.txt new file mode 100644 index 000000000..55d7c1ca1 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClassPropertyInvokersWithSkips.txt @@ -0,0 +1,24 @@ +public override unsafe int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] + get { + const string __id = "get_AbstractCount.()I"; + try { + var __rm = _members.InstanceMethods.InvokeAbstractInt32Method (__id, this, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] + set { + const string __id = "set_AbstractCount.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, __args); + } finally { + } + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCtor.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCtor.txt new file mode 100644 index 000000000..238012f4d --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCtor.txt @@ -0,0 +1,18 @@ +// Metadata.xml XPath constructor reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/constructor[@name='foo' and count(parameter)=0]" +[Register (".ctor", "", "")] + unsafe Object () + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) +{ + const string __id = ""; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + try { + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), null); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, null); + } finally { + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCtorDeprecated.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCtorDeprecated.txt new file mode 100644 index 000000000..159077c9b --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCtorDeprecated.txt @@ -0,0 +1,21 @@ +// Metadata.xml XPath constructor reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/constructor[@name='foo' and count(parameter)=0]" +[Register (".ctor", "", "")] +[Obsolete (@"This constructor is obsolete")] +[MyAttribute] +[global::Android.Runtime.IntDefinition (null, JniField = "xamarin/test/SomeObject.SOME_VALUE")] + unsafe Object () + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) +{ + const string __id = ""; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + try { + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), null); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, null); + } finally { + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCtorWithStringOverload.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCtorWithStringOverload.txt new file mode 100644 index 000000000..342763a13 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteCtorWithStringOverload.txt @@ -0,0 +1,43 @@ +// Metadata.xml XPath constructor reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/constructor[@name='foo' and count(parameter)=1 and parameter[1][@type='java.lang.CharSequence']]" +[Register (".ctor", "(Ljava/lang/CharSequence;)V", "")] + unsafe Object (Java.Lang.ICharSequence? mystring) + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) +{ + const string __id = "(Ljava/lang/CharSequence;)V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + IntPtr native_mystring = CharSequence.ToLocalJniHandle (mystring); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_mystring); + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_mystring); + } +} + +[Register (".ctor", "(Ljava/lang/CharSequence;)V", "")] + unsafe Object (string? mystring) + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) +{ + const string __id = "(Ljava/lang/CharSequence;)V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + IntPtr native_mystring = CharSequence.ToLocalJniHandle (mystring); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_mystring); + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_mystring); + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldConstant.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldConstant.txt new file mode 100644 index 000000000..ad70609e6 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldConstant.txt @@ -0,0 +1,11 @@ + +// Metadata.xml XPath field reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/field[@name='bar']" +[Register ("bar")] +public static string? bar { + get { + const string __id = "bar.Ljava/lang/String;"; + + var __v = _members.StaticFields.GetObjectValue (__id); + return JNIEnv.GetString (__v.Handle, JniHandleOwnership.TransferLocalRef); + } +} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldConstantWithIntValue.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldConstantWithIntValue.txt new file mode 100644 index 000000000..a1f3257f0 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldConstantWithIntValue.txt @@ -0,0 +1,3 @@ +// Metadata.xml XPath field reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/field[@name='bar']" +[Register ("bar")] +public const int bar = (int) 1234; diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldConstantWithStringValue.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldConstantWithStringValue.txt new file mode 100644 index 000000000..1e7186b00 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldConstantWithStringValue.txt @@ -0,0 +1,3 @@ +// Metadata.xml XPath field reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/field[@name='bar']" +[Register ("bar")] +public const string bar = (string) "hello"; diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldGetBody.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldGetBody.txt new file mode 100644 index 000000000..44cde23dc --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldGetBody.txt @@ -0,0 +1,4 @@ +const string __id = "bar.Ljava/lang/String;"; + +var __v = _members.InstanceFields.GetObjectValue (__id, this); +return JNIEnv.GetString (__v.Handle, JniHandleOwnership.TransferLocalRef); diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldIdField.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldIdField.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldInt.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldInt.txt new file mode 100644 index 000000000..d1a71f54e --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldInt.txt @@ -0,0 +1,19 @@ + +// Metadata.xml XPath field reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/field[@name='bar']" +[Register ("bar")] +public int bar { + get { + const string __id = "bar.I"; + + var __v = _members.InstanceFields.GetInt32Value (__id, this); + return __v; + } + set { + const string __id = "bar.I"; + + try { + _members.InstanceFields.SetValue (__id, this, value); + } finally { + } + } +} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldSetBody.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldSetBody.txt new file mode 100644 index 000000000..77008f500 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldSetBody.txt @@ -0,0 +1,8 @@ +const string __id = "bar.Ljava/lang/String;"; + +IntPtr native_value = JNIEnv.NewString (value); +try { + _members.InstanceFields.SetValue (__id, this, new JniObjectReference (native_value)); +} finally { + JNIEnv.DeleteLocalRef (native_value); +} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldString.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldString.txt new file mode 100644 index 000000000..f4d689919 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteFieldString.txt @@ -0,0 +1,21 @@ + +// Metadata.xml XPath field reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/field[@name='bar']" +[Register ("bar")] +public string? bar { + get { + const string __id = "bar.Ljava/lang/String;"; + + var __v = _members.InstanceFields.GetObjectValue (__id, this); + return JNIEnv.GetString (__v.Handle, JniHandleOwnership.TransferLocalRef); + } + set { + const string __id = "bar.Ljava/lang/String;"; + + IntPtr native_value = JNIEnv.NewString (value); + try { + _members.InstanceFields.SetValue (__id, this, new JniObjectReference (native_value)); + } finally { + JNIEnv.DeleteLocalRef (native_value); + } + } +} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterface.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterface.txt new file mode 100644 index 000000000..4e9e88940 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterface.txt @@ -0,0 +1,351 @@ +[Register ("java/code/IMyInterface", DoNotGenerateAcw=true)] +public abstract class MyInterface : Java.Lang.Object { + + internal MyInterface () + { + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='StaticMethod' and count(parameter)=0]" + [Register ("StaticMethod", "()V", "")] + public static unsafe void StaticMethod () + { + const string __id = "StaticMethod.()V"; + try { + _members.StaticMethods.InvokeVoidMethod (__id, null); + } finally { + } + } + + + static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (MyInterface)); +} + +[Register ("java/code/IMyInterface", DoNotGenerateAcw=true)] +[global::System.Obsolete ("Use the 'MyInterface' type. This type will be removed in a future release.", error: true)] +public abstract class MyInterfaceConsts : MyInterface { + + private MyInterfaceConsts () + { + } +} + +// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']" +[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")] +public partial interface IMyInterface : IJavaObject, IJavaPeerable { + + int Count { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Count' and count(parameter)=0]" + [Register ("get_Count", "()I", "Getget_CountHandler:java.code.IMyInterfaceInvoker, ")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")] set; + } + + string? Key { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Key' and count(parameter)=0]" + [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler:java.code.IMyInterfaceInvoker, ")] set; + } + + int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler:java.code.IMyInterfaceInvoker, ")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler:java.code.IMyInterfaceInvoker, ")] set; + } + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler:java.code.IMyInterfaceInvoker, ")] + int GetCountForKey (string? key); + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='Key' and count(parameter)=0]" + [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler:java.code.IMyInterfaceInvoker, ")] + string? Key (); + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='AbstractMethod' and count(parameter)=0]" + [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler:java.code.IMyInterfaceInvoker, ")] + void AbstractMethod (); + +} + +[global::Android.Runtime.Register ("java/code/IMyInterface", DoNotGenerateAcw=true)] +internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterface { + + static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterfaceInvoker)); + + static IntPtr java_class_ref { + get { return _members.JniPeerType.PeerReference.Handle; } + } + + public override global::Java.Interop.JniPeerMembers JniPeerMembers { + get { return _members; } + } + + protected override IntPtr ThresholdClass { + get { return class_ref; } + } + + protected override global::System.Type ThresholdType { + get { return _members.ManagedPeerType; } + } + + IntPtr class_ref; + + public static IMyInterface? GetObject (IntPtr handle, JniHandleOwnership transfer) + { + return global::Java.Lang.Object.GetObject (handle, transfer); + } + + static IntPtr Validate (IntPtr handle) + { + if (!JNIEnv.IsInstanceOf (handle, java_class_ref)) + throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.", + JNIEnv.GetClassNameFromInstance (handle), "java.code.IMyInterface")); + return handle; + } + + protected override void Dispose (bool disposing) + { + if (this.class_ref != IntPtr.Zero) + JNIEnv.DeleteGlobalRef (this.class_ref); + this.class_ref = IntPtr.Zero; + base.Dispose (disposing); + } + + public IMyInterfaceInvoker (IntPtr handle, JniHandleOwnership transfer) : base (Validate (handle), transfer) + { + IntPtr local_ref = JNIEnv.GetObjectClass (((global::Java.Lang.Object) this).Handle); + this.class_ref = JNIEnv.NewGlobalRef (local_ref); + JNIEnv.DeleteLocalRef (local_ref); + } + + static Delegate? cb_get_Count; +#pragma warning disable 0169 + static Delegate Getget_CountHandler () + { + if (cb_get_Count == null) + cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); + return cb_get_Count; + } + + static int n_get_Count (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.Count; + } +#pragma warning restore 0169 + + static Delegate? cb_set_Count_I; +#pragma warning disable 0169 + static Delegate Getset_Count_IHandler () + { + if (cb_set_Count_I == null) + cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); + return cb_set_Count_I; + } + + static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.Count = value; + } +#pragma warning restore 0169 + + IntPtr id_get_Count; + IntPtr id_set_Count_I; + public unsafe int Count { + get { + if (id_get_Count == IntPtr.Zero) + id_get_Count = JNIEnv.GetMethodID (class_ref, "get_Count", "()I"); + return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_Count); + } + set { + if (id_set_Count_I == IntPtr.Zero) + id_set_Count_I = JNIEnv.GetMethodID (class_ref, "set_Count", "(I)V"); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Count_I, __args); + } + } + + static Delegate? cb_get_Key; +#pragma warning disable 0169 + static Delegate Getget_KeyHandler () + { + if (cb_get_Key == null) + cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); + return cb_get_Key; + } + + static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return JNIEnv.NewString (__this.Key); + } +#pragma warning restore 0169 + + static Delegate? cb_set_Key_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate Getset_Key_Ljava_lang_String_Handler () + { + if (cb_set_Key_Ljava_lang_String_ == null) + cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); + return cb_set_Key_Ljava_lang_String_; + } + + static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); + __this.Key = value; + } +#pragma warning restore 0169 + + IntPtr id_get_Key; + IntPtr id_set_Key_Ljava_lang_String_; + public unsafe string? Key { + get { + if (id_get_Key == IntPtr.Zero) + id_get_Key = JNIEnv.GetMethodID (class_ref, "get_Key", "()Ljava/lang/String;"); + return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_get_Key), JniHandleOwnership.TransferLocalRef); + } + set { + if (id_set_Key_Ljava_lang_String_ == IntPtr.Zero) + id_set_Key_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "set_Key", "(Ljava/lang/String;)V"); + IntPtr native_value = JNIEnv.NewString (value); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args); + JNIEnv.DeleteLocalRef (native_value); + } + } + + static Delegate? cb_get_AbstractCount; +#pragma warning disable 0169 + static Delegate Getget_AbstractCountHandler () + { + if (cb_get_AbstractCount == null) + cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); + return cb_get_AbstractCount; + } + + static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.AbstractCount; + } +#pragma warning restore 0169 + + static Delegate? cb_set_AbstractCount_I; +#pragma warning disable 0169 + static Delegate Getset_AbstractCount_IHandler () + { + if (cb_set_AbstractCount_I == null) + cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); + return cb_set_AbstractCount_I; + } + + static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.AbstractCount = value; + } +#pragma warning restore 0169 + + IntPtr id_get_AbstractCount; + IntPtr id_set_AbstractCount_I; + public unsafe int AbstractCount { + get { + if (id_get_AbstractCount == IntPtr.Zero) + id_get_AbstractCount = JNIEnv.GetMethodID (class_ref, "get_AbstractCount", "()I"); + return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_AbstractCount); + } + set { + if (id_set_AbstractCount_I == IntPtr.Zero) + id_set_AbstractCount_I = JNIEnv.GetMethodID (class_ref, "set_AbstractCount", "(I)V"); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_AbstractCount_I, __args); + } + } + + static Delegate? cb_GetCountForKey_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate GetGetCountForKey_Ljava_lang_String_Handler () + { + if (cb_GetCountForKey_Ljava_lang_String_ == null) + cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); + return cb_GetCountForKey_Ljava_lang_String_; + } + + static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); + int __ret = __this.GetCountForKey (key); + return __ret; + } +#pragma warning restore 0169 + + IntPtr id_GetCountForKey_Ljava_lang_String_; + public unsafe int GetCountForKey (string? key) + { + if (id_GetCountForKey_Ljava_lang_String_ == IntPtr.Zero) + id_GetCountForKey_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "GetCountForKey", "(Ljava/lang/String;)I"); + IntPtr native_key = JNIEnv.NewString (key); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_key); + var __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args); + JNIEnv.DeleteLocalRef (native_key); + return __ret; + } + + static Delegate? cb_Key; +#pragma warning disable 0169 + static Delegate GetKeyHandler () + { + if (cb_Key == null) + cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); + return cb_Key; + } + + static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return JNIEnv.NewString (__this.Key ()); + } +#pragma warning restore 0169 + + IntPtr id_Key; + public unsafe string? Key () + { + if (id_Key == IntPtr.Zero) + id_Key = JNIEnv.GetMethodID (class_ref, "Key", "()Ljava/lang/String;"); + return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_Key), JniHandleOwnership.TransferLocalRef); + } + + static Delegate? cb_AbstractMethod; +#pragma warning disable 0169 + static Delegate GetAbstractMethodHandler () + { + if (cb_AbstractMethod == null) + cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); + return cb_AbstractMethod; + } + + static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.AbstractMethod (); + } +#pragma warning restore 0169 + + IntPtr id_AbstractMethod; + public unsafe void AbstractMethod () + { + if (id_AbstractMethod == IntPtr.Zero) + id_AbstractMethod = JNIEnv.GetMethodID (class_ref, "AbstractMethod", "()V"); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_AbstractMethod); + } + +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceDeclaration.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceDeclaration.txt new file mode 100644 index 000000000..10e8a134b --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceDeclaration.txt @@ -0,0 +1,39 @@ +// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']" +[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")] +public partial interface IMyInterface : IJavaObject, IJavaPeerable { + + int Count { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Count' and count(parameter)=0]" + [Register ("get_Count", "()I", "Getget_CountHandler:java.code.IMyInterfaceInvoker, ")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")] set; + } + + string? Key { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Key' and count(parameter)=0]" + [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler:java.code.IMyInterfaceInvoker, ")] set; + } + + int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler:java.code.IMyInterfaceInvoker, ")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler:java.code.IMyInterfaceInvoker, ")] set; + } + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler:java.code.IMyInterfaceInvoker, ")] + int GetCountForKey (string? key); + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='Key' and count(parameter)=0]" + [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler:java.code.IMyInterfaceInvoker, ")] + string? Key (); + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='AbstractMethod' and count(parameter)=0]" + [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler:java.code.IMyInterfaceInvoker, ")] + void AbstractMethod (); + +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceEventArgs.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceEventArgs.txt new file mode 100644 index 000000000..b184c765c --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceEventArgs.txt @@ -0,0 +1,2 @@ +public delegate int MyIGetCountForKeyHandler (string? key); + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceEventHandler.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceEventHandler.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceEventHandlerImpl.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceEventHandlerImpl.txt new file mode 100644 index 000000000..7b680517d --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceEventHandlerImpl.txt @@ -0,0 +1,59 @@ +[global::Android.Runtime.Register ("mono/java/code/IMyInterfaceImplementor")] +internal sealed partial class IMyInterfaceImplementor : global::Java.Lang.Object, IMyInterface { + + object sender; + + public IMyInterfaceImplementor (object sender) + : base ( + global::Android.Runtime.JNIEnv.StartCreateInstance ("mono/java/code/IMyInterfaceImplementor", "()V"), + JniHandleOwnership.TransferLocalRef) + { + global::Android.Runtime.JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, "()V"); + this.sender = sender; + } + +#pragma warning disable 0649 + public MyIGetCountForKeyHandler? GetCountForKeyHandler; +#pragma warning restore 0649 + + public int GetCountForKey (string? key) + { + var __h = GetCountForKeyHandler; + return __h != null ? __h (key) : default (int); + } +#pragma warning disable 0649 + public MyIKeyHandler? KeyHandler; +#pragma warning restore 0649 + + public string? Key () + { + var __h = KeyHandler; + return __h != null ? __h () : default (string?); + } +#pragma warning disable 0649 + public EventHandler? StaticMethodHandler; +#pragma warning restore 0649 + + public void StaticMethod () + { + var __h = StaticMethodHandler; + if (__h != null) + __h (sender, new EventArgs ()); + } +#pragma warning disable 0649 + public EventHandler? AbstractMethodHandler; +#pragma warning restore 0649 + + public void AbstractMethod () + { + var __h = AbstractMethodHandler; + if (__h != null) + __h (sender, new EventArgs ()); + } + + internal static bool __IsEmpty (IMyInterfaceImplementor value) + { + return value.GetCountForKeyHandler == null && value.KeyHandler == null && value.StaticMethodHandler == null && value.AbstractMethodHandler == null; + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceEventHandlerImplContent.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceEventHandlerImplContent.txt new file mode 100644 index 000000000..e6011b413 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceEventHandlerImplContent.txt @@ -0,0 +1,9 @@ +#pragma warning disable 0649 + public MyIGetCountForKeyHandler? GetCountForKeyHandler; +#pragma warning restore 0649 + + public int GetCountForKey (string? key) + { + var __h = GetCountForKeyHandler; + return __h != null ? __h (key) : default (int); + } diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceExtensionMethods.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceExtensionMethods.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceExtensionsDeclaration.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceExtensionsDeclaration.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceInvoker.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceInvoker.txt new file mode 100644 index 000000000..eea98acb4 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceInvoker.txt @@ -0,0 +1,282 @@ +[global::Android.Runtime.Register ("java/code/IMyInterface", DoNotGenerateAcw=true)] +internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterface { + + static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterfaceInvoker)); + + static IntPtr java_class_ref { + get { return _members.JniPeerType.PeerReference.Handle; } + } + + public override global::Java.Interop.JniPeerMembers JniPeerMembers { + get { return _members; } + } + + protected override IntPtr ThresholdClass { + get { return class_ref; } + } + + protected override global::System.Type ThresholdType { + get { return _members.ManagedPeerType; } + } + + IntPtr class_ref; + + public static IMyInterface? GetObject (IntPtr handle, JniHandleOwnership transfer) + { + return global::Java.Lang.Object.GetObject (handle, transfer); + } + + static IntPtr Validate (IntPtr handle) + { + if (!JNIEnv.IsInstanceOf (handle, java_class_ref)) + throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.", + JNIEnv.GetClassNameFromInstance (handle), "java.code.IMyInterface")); + return handle; + } + + protected override void Dispose (bool disposing) + { + if (this.class_ref != IntPtr.Zero) + JNIEnv.DeleteGlobalRef (this.class_ref); + this.class_ref = IntPtr.Zero; + base.Dispose (disposing); + } + + public IMyInterfaceInvoker (IntPtr handle, JniHandleOwnership transfer) : base (Validate (handle), transfer) + { + IntPtr local_ref = JNIEnv.GetObjectClass (((global::Java.Lang.Object) this).Handle); + this.class_ref = JNIEnv.NewGlobalRef (local_ref); + JNIEnv.DeleteLocalRef (local_ref); + } + + static Delegate? cb_get_Count; +#pragma warning disable 0169 + static Delegate Getget_CountHandler () + { + if (cb_get_Count == null) + cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); + return cb_get_Count; + } + + static int n_get_Count (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.Count; + } +#pragma warning restore 0169 + + static Delegate? cb_set_Count_I; +#pragma warning disable 0169 + static Delegate Getset_Count_IHandler () + { + if (cb_set_Count_I == null) + cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); + return cb_set_Count_I; + } + + static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.Count = value; + } +#pragma warning restore 0169 + + IntPtr id_get_Count; + IntPtr id_set_Count_I; + public unsafe int Count { + get { + if (id_get_Count == IntPtr.Zero) + id_get_Count = JNIEnv.GetMethodID (class_ref, "get_Count", "()I"); + return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_Count); + } + set { + if (id_set_Count_I == IntPtr.Zero) + id_set_Count_I = JNIEnv.GetMethodID (class_ref, "set_Count", "(I)V"); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Count_I, __args); + } + } + + static Delegate? cb_get_Key; +#pragma warning disable 0169 + static Delegate Getget_KeyHandler () + { + if (cb_get_Key == null) + cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); + return cb_get_Key; + } + + static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return JNIEnv.NewString (__this.Key); + } +#pragma warning restore 0169 + + static Delegate? cb_set_Key_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate Getset_Key_Ljava_lang_String_Handler () + { + if (cb_set_Key_Ljava_lang_String_ == null) + cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); + return cb_set_Key_Ljava_lang_String_; + } + + static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); + __this.Key = value; + } +#pragma warning restore 0169 + + IntPtr id_get_Key; + IntPtr id_set_Key_Ljava_lang_String_; + public unsafe string? Key { + get { + if (id_get_Key == IntPtr.Zero) + id_get_Key = JNIEnv.GetMethodID (class_ref, "get_Key", "()Ljava/lang/String;"); + return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_get_Key), JniHandleOwnership.TransferLocalRef); + } + set { + if (id_set_Key_Ljava_lang_String_ == IntPtr.Zero) + id_set_Key_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "set_Key", "(Ljava/lang/String;)V"); + IntPtr native_value = JNIEnv.NewString (value); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args); + JNIEnv.DeleteLocalRef (native_value); + } + } + + static Delegate? cb_get_AbstractCount; +#pragma warning disable 0169 + static Delegate Getget_AbstractCountHandler () + { + if (cb_get_AbstractCount == null) + cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); + return cb_get_AbstractCount; + } + + static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.AbstractCount; + } +#pragma warning restore 0169 + + static Delegate? cb_set_AbstractCount_I; +#pragma warning disable 0169 + static Delegate Getset_AbstractCount_IHandler () + { + if (cb_set_AbstractCount_I == null) + cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); + return cb_set_AbstractCount_I; + } + + static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.AbstractCount = value; + } +#pragma warning restore 0169 + + IntPtr id_get_AbstractCount; + IntPtr id_set_AbstractCount_I; + public unsafe int AbstractCount { + get { + if (id_get_AbstractCount == IntPtr.Zero) + id_get_AbstractCount = JNIEnv.GetMethodID (class_ref, "get_AbstractCount", "()I"); + return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_AbstractCount); + } + set { + if (id_set_AbstractCount_I == IntPtr.Zero) + id_set_AbstractCount_I = JNIEnv.GetMethodID (class_ref, "set_AbstractCount", "(I)V"); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_AbstractCount_I, __args); + } + } + + static Delegate? cb_GetCountForKey_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate GetGetCountForKey_Ljava_lang_String_Handler () + { + if (cb_GetCountForKey_Ljava_lang_String_ == null) + cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); + return cb_GetCountForKey_Ljava_lang_String_; + } + + static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); + int __ret = __this.GetCountForKey (key); + return __ret; + } +#pragma warning restore 0169 + + IntPtr id_GetCountForKey_Ljava_lang_String_; + public unsafe int GetCountForKey (string? key) + { + if (id_GetCountForKey_Ljava_lang_String_ == IntPtr.Zero) + id_GetCountForKey_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "GetCountForKey", "(Ljava/lang/String;)I"); + IntPtr native_key = JNIEnv.NewString (key); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_key); + var __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args); + JNIEnv.DeleteLocalRef (native_key); + return __ret; + } + + static Delegate? cb_Key; +#pragma warning disable 0169 + static Delegate GetKeyHandler () + { + if (cb_Key == null) + cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); + return cb_Key; + } + + static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return JNIEnv.NewString (__this.Key ()); + } +#pragma warning restore 0169 + + IntPtr id_Key; + public unsafe string? Key () + { + if (id_Key == IntPtr.Zero) + id_Key = JNIEnv.GetMethodID (class_ref, "Key", "()Ljava/lang/String;"); + return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_Key), JniHandleOwnership.TransferLocalRef); + } + + static Delegate? cb_AbstractMethod; +#pragma warning disable 0169 + static Delegate GetAbstractMethodHandler () + { + if (cb_AbstractMethod == null) + cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); + return cb_AbstractMethod; + } + + static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.AbstractMethod (); + } +#pragma warning restore 0169 + + IntPtr id_AbstractMethod; + public unsafe void AbstractMethod () + { + if (id_AbstractMethod == IntPtr.Zero) + id_AbstractMethod = JNIEnv.GetMethodID (class_ref, "AbstractMethod", "()V"); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_AbstractMethod); + } + +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceListenerEvent.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceListenerEvent.txt new file mode 100644 index 000000000..381b7754e --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceListenerEvent.txt @@ -0,0 +1,17 @@ +public event MyFullDelegateName MyName { + add { + global::Java.Interop.EventHelper.AddEventHandler( + ref weak_implementor_MyWrefSuffix, + __CreateIMyInterfaceImplementor, + Add, + __h => __h.MyNameSpecHandler += value); + } + remove { + global::Java.Interop.EventHelper.RemoveEventHandler( + ref weak_implementor_MyWrefSuffix, + java.code.IMyInterfaceImplementor.__IsEmpty, + Remove, + __h => __h.MyNameSpecHandler -= value); + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceListenerEventWithHandlerArgument.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceListenerEventWithHandlerArgument.txt new file mode 100644 index 000000000..7f1b240c0 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceListenerEventWithHandlerArgument.txt @@ -0,0 +1,22 @@ +public event MyFullDelegateName MyName { + add { + global::Java.Interop.EventHelper.AddEventHandler( + ref weak_implementor_MyWrefSuffix, + __CreateIMyInterfaceImplementor, + AddMyName_Event_With_Handler_Helper, + __h => __h.MyNameSpecHandler += value); + } + remove { + global::Java.Interop.EventHelper.RemoveEventHandler( + ref weak_implementor_MyWrefSuffix, + java.code.IMyInterfaceImplementor.__IsEmpty, + RemoveMyName, + __h => __h.MyNameSpecHandler -= value); + } +} + +void AddMyName_Event_With_Handler_Helper (java.code.IMyInterface value) +{ + AddMyName (value, null); +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceListenerProperty.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceListenerProperty.txt new file mode 100644 index 000000000..dbb6cfeab --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceListenerProperty.txt @@ -0,0 +1,15 @@ +public MyFullDelegateName? MyName { + get { + java.code.IMyInterfaceImplementor? impl = ImplMyName; + return impl == null ? null : impl.MyMethodNameHandler; + } + set { + java.code.IMyInterfaceImplementor? impl = ImplMyName; + if (impl == null) { + impl = new java.code.IMyInterfaceImplementor (this); + ImplMyName = impl; + } else + impl.MyNameSpecHandler = value; + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceMethodInvokers.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceMethodInvokers.txt new file mode 100644 index 000000000..bd1a8b1a8 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceMethodInvokers.txt @@ -0,0 +1,79 @@ +static Delegate? cb_GetCountForKey_Ljava_lang_String_; +#pragma warning disable 0169 +static Delegate GetGetCountForKey_Ljava_lang_String_Handler () +{ + if (cb_GetCountForKey_Ljava_lang_String_ == null) + cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); + return cb_GetCountForKey_Ljava_lang_String_; +} + +static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); + int __ret = __this.GetCountForKey (key); + return __ret; +} +#pragma warning restore 0169 + +IntPtr id_GetCountForKey_Ljava_lang_String_; +public unsafe int GetCountForKey (string? key) +{ + if (id_GetCountForKey_Ljava_lang_String_ == IntPtr.Zero) + id_GetCountForKey_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "GetCountForKey", "(Ljava/lang/String;)I"); + IntPtr native_key = JNIEnv.NewString (key); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_key); + var __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args); + JNIEnv.DeleteLocalRef (native_key); + return __ret; +} + +static Delegate? cb_Key; +#pragma warning disable 0169 +static Delegate GetKeyHandler () +{ + if (cb_Key == null) + cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); + return cb_Key; +} + +static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return JNIEnv.NewString (__this.Key ()); +} +#pragma warning restore 0169 + +IntPtr id_Key; +public unsafe string? Key () +{ + if (id_Key == IntPtr.Zero) + id_Key = JNIEnv.GetMethodID (class_ref, "Key", "()Ljava/lang/String;"); + return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_Key), JniHandleOwnership.TransferLocalRef); +} + +static Delegate? cb_AbstractMethod; +#pragma warning disable 0169 +static Delegate GetAbstractMethodHandler () +{ + if (cb_AbstractMethod == null) + cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); + return cb_AbstractMethod; +} + +static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.AbstractMethod (); +} +#pragma warning restore 0169 + +IntPtr id_AbstractMethod; +public unsafe void AbstractMethod () +{ + if (id_AbstractMethod == IntPtr.Zero) + id_AbstractMethod = JNIEnv.GetMethodID (class_ref, "AbstractMethod", "()V"); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_AbstractMethod); +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceMethodInvokersWithSkips.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceMethodInvokersWithSkips.txt new file mode 100644 index 000000000..bd1a8b1a8 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceMethodInvokersWithSkips.txt @@ -0,0 +1,79 @@ +static Delegate? cb_GetCountForKey_Ljava_lang_String_; +#pragma warning disable 0169 +static Delegate GetGetCountForKey_Ljava_lang_String_Handler () +{ + if (cb_GetCountForKey_Ljava_lang_String_ == null) + cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); + return cb_GetCountForKey_Ljava_lang_String_; +} + +static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); + int __ret = __this.GetCountForKey (key); + return __ret; +} +#pragma warning restore 0169 + +IntPtr id_GetCountForKey_Ljava_lang_String_; +public unsafe int GetCountForKey (string? key) +{ + if (id_GetCountForKey_Ljava_lang_String_ == IntPtr.Zero) + id_GetCountForKey_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "GetCountForKey", "(Ljava/lang/String;)I"); + IntPtr native_key = JNIEnv.NewString (key); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_key); + var __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args); + JNIEnv.DeleteLocalRef (native_key); + return __ret; +} + +static Delegate? cb_Key; +#pragma warning disable 0169 +static Delegate GetKeyHandler () +{ + if (cb_Key == null) + cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); + return cb_Key; +} + +static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return JNIEnv.NewString (__this.Key ()); +} +#pragma warning restore 0169 + +IntPtr id_Key; +public unsafe string? Key () +{ + if (id_Key == IntPtr.Zero) + id_Key = JNIEnv.GetMethodID (class_ref, "Key", "()Ljava/lang/String;"); + return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_Key), JniHandleOwnership.TransferLocalRef); +} + +static Delegate? cb_AbstractMethod; +#pragma warning disable 0169 +static Delegate GetAbstractMethodHandler () +{ + if (cb_AbstractMethod == null) + cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); + return cb_AbstractMethod; +} + +static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.AbstractMethod (); +} +#pragma warning restore 0169 + +IntPtr id_AbstractMethod; +public unsafe void AbstractMethod () +{ + if (id_AbstractMethod == IntPtr.Zero) + id_AbstractMethod = JNIEnv.GetMethodID (class_ref, "AbstractMethod", "()V"); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_AbstractMethod); +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceMethods.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceMethods.txt new file mode 100644 index 000000000..8972f95d9 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceMethods.txt @@ -0,0 +1,12 @@ +// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" +[Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler:java.code.IMyInterfaceInvoker, ")] +int GetCountForKey (string? key); + +// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='Key' and count(parameter)=0]" +[Register ("Key", "()Ljava/lang/String;", "GetKeyHandler:java.code.IMyInterfaceInvoker, ")] +string? Key (); + +// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='AbstractMethod' and count(parameter)=0]" +[Register ("AbstractMethod", "()V", "GetAbstractMethodHandler:java.code.IMyInterfaceInvoker, ")] +void AbstractMethod (); + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceProperties.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceProperties.txt new file mode 100644 index 000000000..e519f8dd9 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfaceProperties.txt @@ -0,0 +1,21 @@ +int Count { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Count' and count(parameter)=0]" + [Register ("get_Count", "()I", "Getget_CountHandler:java.code.IMyInterfaceInvoker, ")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")] set; +} + +string? Key { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Key' and count(parameter)=0]" + [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler:java.code.IMyInterfaceInvoker, ")] set; +} + +int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler:java.code.IMyInterfaceInvoker, ")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler:java.code.IMyInterfaceInvoker, ")] set; +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfacePropertyInvokers.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfacePropertyInvokers.txt new file mode 100644 index 000000000..9acf4f6f0 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfacePropertyInvokers.txt @@ -0,0 +1,199 @@ +static Delegate? cb_get_Count; +#pragma warning disable 0169 +static Delegate Getget_CountHandler () +{ + if (cb_get_Count == null) + cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); + return cb_get_Count; +} + +static int n_get_Count (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.Count; +} +#pragma warning restore 0169 + +static Delegate? cb_set_Count_I; +#pragma warning disable 0169 +static Delegate Getset_Count_IHandler () +{ + if (cb_set_Count_I == null) + cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); + return cb_set_Count_I; +} + +static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.Count = value; +} +#pragma warning restore 0169 + +IntPtr id_get_Count; +IntPtr id_set_Count_I; +public unsafe int Count { + get { + if (id_get_Count == IntPtr.Zero) + id_get_Count = JNIEnv.GetMethodID (class_ref, "get_Count", "()I"); + return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_Count); + } + set { + if (id_set_Count_I == IntPtr.Zero) + id_set_Count_I = JNIEnv.GetMethodID (class_ref, "set_Count", "(I)V"); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Count_I, __args); + } +} + +static Delegate? cb_get_Key; +#pragma warning disable 0169 +static Delegate Getget_KeyHandler () +{ + if (cb_get_Key == null) + cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); + return cb_get_Key; +} + +static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return JNIEnv.NewString (__this.Key); +} +#pragma warning restore 0169 + +static Delegate? cb_set_Key_Ljava_lang_String_; +#pragma warning disable 0169 +static Delegate Getset_Key_Ljava_lang_String_Handler () +{ + if (cb_set_Key_Ljava_lang_String_ == null) + cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); + return cb_set_Key_Ljava_lang_String_; +} + +static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); + __this.Key = value; +} +#pragma warning restore 0169 + +IntPtr id_get_Key; +IntPtr id_set_Key_Ljava_lang_String_; +public unsafe string? Key { + get { + if (id_get_Key == IntPtr.Zero) + id_get_Key = JNIEnv.GetMethodID (class_ref, "get_Key", "()Ljava/lang/String;"); + return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_get_Key), JniHandleOwnership.TransferLocalRef); + } + set { + if (id_set_Key_Ljava_lang_String_ == IntPtr.Zero) + id_set_Key_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "set_Key", "(Ljava/lang/String;)V"); + IntPtr native_value = JNIEnv.NewString (value); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args); + JNIEnv.DeleteLocalRef (native_value); + } +} + +static Delegate? cb_get_StaticCount; +#pragma warning disable 0169 +static Delegate Getget_StaticCountHandler () +{ + if (cb_get_StaticCount == null) + cb_get_StaticCount = JNINativeWrapper.CreateDelegate ((Func) n_get_StaticCount); + return cb_get_StaticCount; +} + +static int n_get_StaticCount (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.StaticCount; +} +#pragma warning restore 0169 + +static Delegate? cb_set_StaticCount_I; +#pragma warning disable 0169 +static Delegate Getset_StaticCount_IHandler () +{ + if (cb_set_StaticCount_I == null) + cb_set_StaticCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_StaticCount_I); + return cb_set_StaticCount_I; +} + +static void n_set_StaticCount_I (IntPtr jnienv, IntPtr native__this, int value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.StaticCount = value; +} +#pragma warning restore 0169 + +IntPtr id_get_StaticCount; +IntPtr id_set_StaticCount_I; +public unsafe int StaticCount { + get { + if (id_get_StaticCount == IntPtr.Zero) + id_get_StaticCount = JNIEnv.GetMethodID (class_ref, "get_StaticCount", "()I"); + return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_StaticCount); + } + set { + if (id_set_StaticCount_I == IntPtr.Zero) + id_set_StaticCount_I = JNIEnv.GetMethodID (class_ref, "set_StaticCount", "(I)V"); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_StaticCount_I, __args); + } +} + +static Delegate? cb_get_AbstractCount; +#pragma warning disable 0169 +static Delegate Getget_AbstractCountHandler () +{ + if (cb_get_AbstractCount == null) + cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); + return cb_get_AbstractCount; +} + +static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.AbstractCount; +} +#pragma warning restore 0169 + +static Delegate? cb_set_AbstractCount_I; +#pragma warning disable 0169 +static Delegate Getset_AbstractCount_IHandler () +{ + if (cb_set_AbstractCount_I == null) + cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); + return cb_set_AbstractCount_I; +} + +static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.AbstractCount = value; +} +#pragma warning restore 0169 + +IntPtr id_get_AbstractCount; +IntPtr id_set_AbstractCount_I; +public unsafe int AbstractCount { + get { + if (id_get_AbstractCount == IntPtr.Zero) + id_get_AbstractCount = JNIEnv.GetMethodID (class_ref, "get_AbstractCount", "()I"); + return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_AbstractCount); + } + set { + if (id_set_AbstractCount_I == IntPtr.Zero) + id_set_AbstractCount_I = JNIEnv.GetMethodID (class_ref, "set_AbstractCount", "(I)V"); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_AbstractCount_I, __args); + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfacePropertyInvokersWithSkips.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfacePropertyInvokersWithSkips.txt new file mode 100644 index 000000000..b310fffd9 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteInterfacePropertyInvokersWithSkips.txt @@ -0,0 +1,150 @@ +static Delegate? cb_get_Key; +#pragma warning disable 0169 +static Delegate Getget_KeyHandler () +{ + if (cb_get_Key == null) + cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); + return cb_get_Key; +} + +static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return JNIEnv.NewString (__this.Key); +} +#pragma warning restore 0169 + +static Delegate? cb_set_Key_Ljava_lang_String_; +#pragma warning disable 0169 +static Delegate Getset_Key_Ljava_lang_String_Handler () +{ + if (cb_set_Key_Ljava_lang_String_ == null) + cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); + return cb_set_Key_Ljava_lang_String_; +} + +static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); + __this.Key = value; +} +#pragma warning restore 0169 + +IntPtr id_get_Key; +IntPtr id_set_Key_Ljava_lang_String_; +public unsafe string? Key { + get { + if (id_get_Key == IntPtr.Zero) + id_get_Key = JNIEnv.GetMethodID (class_ref, "get_Key", "()Ljava/lang/String;"); + return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_get_Key), JniHandleOwnership.TransferLocalRef); + } + set { + if (id_set_Key_Ljava_lang_String_ == IntPtr.Zero) + id_set_Key_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "set_Key", "(Ljava/lang/String;)V"); + IntPtr native_value = JNIEnv.NewString (value); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args); + JNIEnv.DeleteLocalRef (native_value); + } +} + +static Delegate? cb_get_StaticCount; +#pragma warning disable 0169 +static Delegate Getget_StaticCountHandler () +{ + if (cb_get_StaticCount == null) + cb_get_StaticCount = JNINativeWrapper.CreateDelegate ((Func) n_get_StaticCount); + return cb_get_StaticCount; +} + +static int n_get_StaticCount (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.StaticCount; +} +#pragma warning restore 0169 + +static Delegate? cb_set_StaticCount_I; +#pragma warning disable 0169 +static Delegate Getset_StaticCount_IHandler () +{ + if (cb_set_StaticCount_I == null) + cb_set_StaticCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_StaticCount_I); + return cb_set_StaticCount_I; +} + +static void n_set_StaticCount_I (IntPtr jnienv, IntPtr native__this, int value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.StaticCount = value; +} +#pragma warning restore 0169 + +IntPtr id_get_StaticCount; +IntPtr id_set_StaticCount_I; +public unsafe int StaticCount { + get { + if (id_get_StaticCount == IntPtr.Zero) + id_get_StaticCount = JNIEnv.GetMethodID (class_ref, "get_StaticCount", "()I"); + return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_StaticCount); + } + set { + if (id_set_StaticCount_I == IntPtr.Zero) + id_set_StaticCount_I = JNIEnv.GetMethodID (class_ref, "set_StaticCount", "(I)V"); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_StaticCount_I, __args); + } +} + +static Delegate? cb_get_AbstractCount; +#pragma warning disable 0169 +static Delegate Getget_AbstractCountHandler () +{ + if (cb_get_AbstractCount == null) + cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); + return cb_get_AbstractCount; +} + +static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.AbstractCount; +} +#pragma warning restore 0169 + +static Delegate? cb_set_AbstractCount_I; +#pragma warning disable 0169 +static Delegate Getset_AbstractCount_IHandler () +{ + if (cb_set_AbstractCount_I == null) + cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); + return cb_set_AbstractCount_I; +} + +static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.AbstractCount = value; +} +#pragma warning restore 0169 + +IntPtr id_get_AbstractCount; +IntPtr id_set_AbstractCount_I; +public unsafe int AbstractCount { + get { + if (id_get_AbstractCount == IntPtr.Zero) + id_get_AbstractCount = JNIEnv.GetMethodID (class_ref, "get_AbstractCount", "()I"); + return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_AbstractCount); + } + set { + if (id_set_AbstractCount_I == IntPtr.Zero) + id_set_AbstractCount_I = JNIEnv.GetMethodID (class_ref, "set_AbstractCount", "(I)V"); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_AbstractCount_I, __args); + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodAbstractWithVoidReturn.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodAbstractWithVoidReturn.txt new file mode 100644 index 000000000..3db5f7776 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodAbstractWithVoidReturn.txt @@ -0,0 +1,27 @@ +static Delegate? cb_bar; +#pragma warning disable 0169 +static Delegate GetbarHandler () +{ + if (cb_bar == null) + cb_bar = JNINativeWrapper.CreateDelegate ((Action) n_bar); + return cb_bar; +} + +static void n_bar (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.bar (); +} +#pragma warning restore 0169 + +// Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='bar' and count(parameter)=0]" +[Register ("bar", "()V", "GetbarHandler")] +public virtual unsafe void bar () +{ + const string __id = "bar.()V"; + try { + _members.InstanceMethods.InvokeAbstractVoidMethod (__id, this, null); + } finally { + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodAsyncifiedWithIntReturn.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodAsyncifiedWithIntReturn.txt new file mode 100644 index 000000000..9bfecaea4 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodAsyncifiedWithIntReturn.txt @@ -0,0 +1,33 @@ +static Delegate? cb_bar; +#pragma warning disable 0169 +static Delegate GetbarHandler () +{ + if (cb_bar == null) + cb_bar = JNINativeWrapper.CreateDelegate ((Func) n_bar); + return cb_bar; +} + +static int n_bar (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.bar (); +} +#pragma warning restore 0169 + +// Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='bar' and count(parameter)=0]" +[Register ("bar", "()I", "GetbarHandler")] +public virtual unsafe int bar () +{ + const string __id = "bar.()I"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null); + return __rm; + } finally { + } +} + +public global::System.Threading.Tasks.Task barAsync () +{ + return global::System.Threading.Tasks.Task.Run (() => bar ()); +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodAsyncifiedWithVoidReturn.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodAsyncifiedWithVoidReturn.txt new file mode 100644 index 000000000..46d511e7a --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodAsyncifiedWithVoidReturn.txt @@ -0,0 +1,32 @@ +static Delegate? cb_bar; +#pragma warning disable 0169 +static Delegate GetbarHandler () +{ + if (cb_bar == null) + cb_bar = JNINativeWrapper.CreateDelegate ((Action) n_bar); + return cb_bar; +} + +static void n_bar (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.bar (); +} +#pragma warning restore 0169 + +// Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='bar' and count(parameter)=0]" +[Register ("bar", "()V", "GetbarHandler")] +public virtual unsafe void bar () +{ + const string __id = "bar.()V"; + try { + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, null); + } finally { + } +} + +public global::System.Threading.Tasks.Task barAsync () +{ + return global::System.Threading.Tasks.Task.Run (() => bar ()); +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodBody.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodBody.txt new file mode 100644 index 000000000..49e16b488 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodBody.txt @@ -0,0 +1,5 @@ +const string __id = "bar.()V"; +try { + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, null); +} finally { +} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodFinalWithVoidReturn.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodFinalWithVoidReturn.txt new file mode 100644 index 000000000..28abf4fe7 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodFinalWithVoidReturn.txt @@ -0,0 +1,11 @@ +// Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='bar' and count(parameter)=0]" +[Register ("bar", "()V", "")] +public unsafe void bar () +{ + const string __id = "bar.()V"; + try { + _members.InstanceMethods.InvokeNonvirtualVoidMethod (__id, this, null); + } finally { + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodIdField.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodIdField.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodProtected.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodProtected.txt new file mode 100644 index 000000000..73dcfc51b --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodProtected.txt @@ -0,0 +1,27 @@ +static Delegate? cb_bar; +#pragma warning disable 0169 +static Delegate GetbarHandler () +{ + if (cb_bar == null) + cb_bar = JNINativeWrapper.CreateDelegate ((Action) n_bar); + return cb_bar; +} + +static void n_bar (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.bar (); +} +#pragma warning restore 0169 + +// Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='bar' and count(parameter)=0]" +[Register ("bar", "()V", "GetbarHandler")] +protected virtual unsafe void bar () +{ + const string __id = "bar.()V"; + try { + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, null); + } finally { + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodStaticWithVoidReturn.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodStaticWithVoidReturn.txt new file mode 100644 index 000000000..05fb6bf0b --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodStaticWithVoidReturn.txt @@ -0,0 +1,11 @@ +// Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='bar' and count(parameter)=0]" +[Register ("bar", "()V", "")] +public static unsafe void bar () +{ + const string __id = "bar.()V"; + try { + _members.StaticMethods.InvokeVoidMethod (__id, null); + } finally { + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodWithIntReturn.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodWithIntReturn.txt new file mode 100644 index 000000000..df6cbf4ab --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodWithIntReturn.txt @@ -0,0 +1,28 @@ +static Delegate? cb_bar; +#pragma warning disable 0169 +static Delegate GetbarHandler () +{ + if (cb_bar == null) + cb_bar = JNINativeWrapper.CreateDelegate ((Func) n_bar); + return cb_bar; +} + +static int n_bar (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.bar (); +} +#pragma warning restore 0169 + +// Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='bar' and count(parameter)=0]" +[Register ("bar", "()I", "GetbarHandler")] +public virtual unsafe int bar () +{ + const string __id = "bar.()I"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null); + return __rm; + } finally { + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodWithStringReturn.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodWithStringReturn.txt new file mode 100644 index 000000000..81279c403 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodWithStringReturn.txt @@ -0,0 +1,28 @@ +static Delegate? cb_bar; +#pragma warning disable 0169 +static Delegate GetbarHandler () +{ + if (cb_bar == null) + cb_bar = JNINativeWrapper.CreateDelegate ((Func) n_bar); + return cb_bar; +} + +static IntPtr n_bar (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return JNIEnv.NewString (__this.bar ()); +} +#pragma warning restore 0169 + +// Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='bar' and count(parameter)=0]" +[Register ("bar", "()Ljava/lang/String;", "GetbarHandler")] +public virtual unsafe string? bar () +{ + const string __id = "bar.()Ljava/lang/String;"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); + return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); + } finally { + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodWithVoidReturn.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodWithVoidReturn.txt new file mode 100644 index 000000000..adaf55a1a --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteMethodWithVoidReturn.txt @@ -0,0 +1,27 @@ +static Delegate? cb_bar; +#pragma warning disable 0169 +static Delegate GetbarHandler () +{ + if (cb_bar == null) + cb_bar = JNINativeWrapper.CreateDelegate ((Action) n_bar); + return cb_bar; +} + +static void n_bar (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.bar (); +} +#pragma warning restore 0169 + +// Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='bar' and count(parameter)=0]" +[Register ("bar", "()V", "GetbarHandler")] +public virtual unsafe void bar () +{ + const string __id = "bar.()V"; + try { + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, null); + } finally { + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteParameterListCallArgs.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteParameterListCallArgs.txt new file mode 100644 index 000000000..a0d1315f3 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteParameterListCallArgs.txt @@ -0,0 +1,4 @@ +JniArgumentValue* __args = stackalloc JniArgumentValue [3]; +__args [0] = new JniArgumentValue (value); +__args [1] = new JniArgumentValue (native_str); +__args [2] = new JniArgumentValue (flag); diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteParameterListCallArgsForInvoker.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteParameterListCallArgsForInvoker.txt new file mode 100644 index 000000000..1506c62aa --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteParameterListCallArgsForInvoker.txt @@ -0,0 +1,4 @@ +JValue* __args = stackalloc JValue [3]; +__args [0] = new JValue (value); +__args [1] = new JValue (native_str); +__args [2] = new JValue (flag); diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteProperty.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteProperty.txt new file mode 100644 index 000000000..3471e7696 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteProperty.txt @@ -0,0 +1,56 @@ +static Delegate? cb_get_MyProperty; +#pragma warning disable 0169 +static Delegate Getget_MyPropertyHandler () +{ + if (cb_get_MyProperty == null) + cb_get_MyProperty = JNINativeWrapper.CreateDelegate ((Func) n_get_MyProperty); + return cb_get_MyProperty; +} + +static int n_get_MyProperty (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.MyProperty; +} +#pragma warning restore 0169 + +static Delegate? cb_set_MyProperty_I; +#pragma warning disable 0169 +static Delegate Getset_MyProperty_IHandler () +{ + if (cb_set_MyProperty_I == null) + cb_set_MyProperty_I = JNINativeWrapper.CreateDelegate ((Action) n_set_MyProperty_I); + return cb_set_MyProperty_I; +} + +static void n_set_MyProperty_I (IntPtr jnienv, IntPtr native__this, int value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.MyProperty = value; +} +#pragma warning restore 0169 + +public virtual unsafe int MyProperty { + // Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='get_MyProperty' and count(parameter)=0]" + [Register ("get_MyProperty", "()I", "Getget_MyPropertyHandler")] + get { + const string __id = "get_MyProperty.()I"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='set_MyProperty' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_MyProperty", "(I)V", "Getset_MyProperty_IHandler")] + set { + const string __id = "set_MyProperty.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); + } finally { + } + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyAbstractDeclaration.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyAbstractDeclaration.txt new file mode 100644 index 000000000..4b3c054db --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyAbstractDeclaration.txt @@ -0,0 +1,39 @@ +static Delegate? cb_get_MyProperty; +#pragma warning disable 0169 +static Delegate Getget_MyPropertyHandler () +{ + if (cb_get_MyProperty == null) + cb_get_MyProperty = JNINativeWrapper.CreateDelegate ((Func) n_get_MyProperty); + return cb_get_MyProperty; +} + +static int n_get_MyProperty (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.MyProperty; +} +#pragma warning restore 0169 + +static Delegate? cb_set_MyProperty_I; +#pragma warning disable 0169 +static Delegate Getset_MyProperty_IHandler () +{ + if (cb_set_MyProperty_I == null) + cb_set_MyProperty_I = JNINativeWrapper.CreateDelegate ((Action) n_set_MyProperty_I); + return cb_set_MyProperty_I; +} + +static void n_set_MyProperty_I (IntPtr jnienv, IntPtr native__this, int value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.MyProperty = value; +} +#pragma warning restore 0169 + +public abstract int MyProperty { + // Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='get_MyProperty' and count(parameter)=0]" + [Register ("get_MyProperty", "()I", "Getget_MyPropertyHandler")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='set_MyProperty' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_MyProperty", "(I)V", "Getset_MyProperty_IHandler")] set; +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyCallbacks.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyCallbacks.txt new file mode 100644 index 000000000..7b980b89f --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyCallbacks.txt @@ -0,0 +1,32 @@ +static Delegate? cb_get_MyProperty; +#pragma warning disable 0169 +static Delegate Getget_MyPropertyHandler () +{ + if (cb_get_MyProperty == null) + cb_get_MyProperty = JNINativeWrapper.CreateDelegate ((Func) n_get_MyProperty); + return cb_get_MyProperty; +} + +static int n_get_MyProperty (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.MyProperty; +} +#pragma warning restore 0169 + +static Delegate? cb_set_MyProperty_I; +#pragma warning disable 0169 +static Delegate Getset_MyProperty_IHandler () +{ + if (cb_set_MyProperty_I == null) + cb_set_MyProperty_I = JNINativeWrapper.CreateDelegate ((Action) n_set_MyProperty_I); + return cb_set_MyProperty_I; +} + +static void n_set_MyProperty_I (IntPtr jnienv, IntPtr native__this, int value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.MyProperty = value; +} +#pragma warning restore 0169 + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyDeclaration.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyDeclaration.txt new file mode 100644 index 000000000..d23bc113c --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyDeclaration.txt @@ -0,0 +1,7 @@ +int MyProperty { + // Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='get_MyProperty' and count(parameter)=0]" + [Register ("get_MyProperty", "()I", "Getget_MyPropertyHandler:ObjectAdapter, ")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='com.mypackage']/class[@name='foo']/method[@name='set_MyProperty' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_MyProperty", "(I)V", "Getset_MyProperty_IHandler:ObjectAdapter, ")] set; +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyInvoker.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyInvoker.txt new file mode 100644 index 000000000..5b1f0b725 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyInvoker.txt @@ -0,0 +1,49 @@ +static Delegate? cb_get_MyProperty; +#pragma warning disable 0169 +static Delegate Getget_MyPropertyHandler () +{ + if (cb_get_MyProperty == null) + cb_get_MyProperty = JNINativeWrapper.CreateDelegate ((Func) n_get_MyProperty); + return cb_get_MyProperty; +} + +static int n_get_MyProperty (IntPtr jnienv, IntPtr native__this) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + return __this.MyProperty; +} +#pragma warning restore 0169 + +static Delegate? cb_set_MyProperty_I; +#pragma warning disable 0169 +static Delegate Getset_MyProperty_IHandler () +{ + if (cb_set_MyProperty_I == null) + cb_set_MyProperty_I = JNINativeWrapper.CreateDelegate ((Action) n_set_MyProperty_I); + return cb_set_MyProperty_I; +} + +static void n_set_MyProperty_I (IntPtr jnienv, IntPtr native__this, int value) +{ + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!; + __this.MyProperty = value; +} +#pragma warning restore 0169 + +IntPtr id_get_MyProperty; +IntPtr id_set_MyProperty_I; +public unsafe int MyProperty { + get { + if (id_get_MyProperty == IntPtr.Zero) + id_get_MyProperty = JNIEnv.GetMethodID (class_ref, "get_MyProperty", "()I"); + return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_MyProperty); + } + set { + if (id_set_MyProperty_I == IntPtr.Zero) + id_set_MyProperty_I = JNIEnv.GetMethodID (class_ref, "set_MyProperty", "(I)V"); + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_MyProperty_I, __args); + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyStringVariant.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyStringVariant.txt new file mode 100644 index 000000000..72025a88f --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WritePropertyStringVariant.txt @@ -0,0 +1,9 @@ +public string? MyProperty { + get { return MyProperty == null ? null : MyProperty.ToString (); } + set { + var jls = value == null ? null : new global::Java.Lang.String (value); + MyProperty = jls; + if (jls != null) jls.Dispose (); + } +} + diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteInterface.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteInterface.txt index f0e2bdc7c..a87fcc6ac 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteInterface.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteInterface.txt @@ -39,7 +39,7 @@ public partial interface IMyInterface : IJavaObject, IJavaPeerable { [Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")] set; } - java.lang.String Key { + string Key { // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Key' and count(parameter)=0]" [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")] get; // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteInterfaceDeclaration.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteInterfaceDeclaration.txt index 15447c62b..73ed59b91 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteInterfaceDeclaration.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteInterfaceDeclaration.txt @@ -9,7 +9,7 @@ public partial interface IMyInterface : IJavaObject, IJavaPeerable { [Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")] set; } - java.lang.String Key { + string Key { // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Key' and count(parameter)=0]" [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")] get; // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteInterface.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteInterface.txt index ac85a3976..24dbc1929 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteInterface.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteInterface.txt @@ -41,7 +41,7 @@ public partial interface IMyInterface : IJavaObject { [Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")] set; } - java.lang.String Key { + string Key { // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Key' and count(parameter)=0]" [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")] get; // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteInterfaceDeclaration.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteInterfaceDeclaration.txt index 991f1b45a..fb079e879 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteInterfaceDeclaration.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteInterfaceDeclaration.txt @@ -9,7 +9,7 @@ public partial interface IMyInterface : IJavaObject { [Register ("set_Count", "(I)V", "Getset_Count_IHandler:java.code.IMyInterfaceInvoker, ")] set; } - java.lang.String Key { + string Key { // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Key' and count(parameter)=0]" [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler:java.code.IMyInterfaceInvoker, ")] get; // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorTestBase.cs b/tests/generator-Tests/Unit-Tests/CodeGeneratorTestBase.cs index 2b2cb4b01..f3435d3f7 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorTestBase.cs +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorTestBase.cs @@ -42,20 +42,20 @@ protected virtual CodeGenerationOptions CreateOptions () protected abstract Xamarin.Android.Binder.CodeGenerationTarget Target { get; } + // Optionally override the directory where the expected test results are located. + // For example, we duplicate the "XAJavaInterop1" tests with NRT as "XAJavaInterop1-NRT". + protected virtual string TargetedDirectoryOverride => null; + protected virtual string CommonDirectoryOverride => null; + // Get the test results from "Common" for tests with the same results regardless of Target - protected string GetExpected (string testName) - { - var root = Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location); + protected string GetExpected (string testName) => GetExpectedResults (testName, CommonDirectoryOverride ?? "Common"); - return File.ReadAllText (Path.Combine (root, "Unit-Tests", "CodeGeneratorExpectedResults", "Common", $"{testName}.txt")).NormalizeLineEndings (); - } + // Get the test results from "JavaInterop1" or "XamarinAndroid" for tests with different results per Target + protected string GetTargetedExpected (string testName) => GetExpectedResults (testName, TargetedDirectoryOverride ?? Target.ToString ()); - // Get the test results from "JavaInterop1" or "XamarinAndroid" for tests with the different results per Target - protected string GetTargetedExpected (string testName) + string GetExpectedResults (string testName, string target) { - var target = Target.ToString (); var root = Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location); - return File.ReadAllText (Path.Combine (root, "Unit-Tests", "CodeGeneratorExpectedResults", target, $"{testName}.txt")).NormalizeLineEndings (); } diff --git a/tests/generator-Tests/Unit-Tests/NRTJavaInteropCodeGeneratorTests.cs b/tests/generator-Tests/Unit-Tests/NRTJavaInteropCodeGeneratorTests.cs new file mode 100644 index 000000000..d86486258 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/NRTJavaInteropCodeGeneratorTests.cs @@ -0,0 +1,24 @@ +using MonoDroid.Generation; +using NUnit.Framework; +using Xamarin.Android.Binder; + +namespace generatortests +{ + [TestFixture] + class NRTJavaInteropCodeGeneratorTests : CodeGeneratorTests + { + protected override CodeGenerationTarget Target => CodeGenerationTarget.XAJavaInterop1; + + protected override CodeGenerationOptions CreateOptions () + { + var options = base.CreateOptions (); + + options.SupportNullableReferenceTypes = true; + + return options; + } + + protected override string CommonDirectoryOverride => "XAJavaInterop1-NRT"; + protected override string TargetedDirectoryOverride => "XAJavaInterop1-NRT"; + } +} diff --git a/tests/generator-Tests/Unit-Tests/XmlApiImporterTests.cs b/tests/generator-Tests/Unit-Tests/XmlApiImporterTests.cs index 079d2653d..c30cbae94 100644 --- a/tests/generator-Tests/Unit-Tests/XmlApiImporterTests.cs +++ b/tests/generator-Tests/Unit-Tests/XmlApiImporterTests.cs @@ -99,5 +99,14 @@ public void CreateParameter_EnsureValidName () Assert.AreEqual ("_3", p.Name); } + + [Test] + public void CreateParameter_NotNull () + { + var xml = XDocument.Parse (""); + var p = XmlApiImporter.CreateParameter (xml.Root); + + Assert.True (p.NotNull); + } } } diff --git a/tools/generator/CodeGenerationOptions.cs b/tools/generator/CodeGenerationOptions.cs index b4aff1c43..d5085ff74 100644 --- a/tools/generator/CodeGenerationOptions.cs +++ b/tools/generator/CodeGenerationOptions.cs @@ -52,6 +52,7 @@ internal CodeGenerator CreateCodeGenerator (TextWriter writer) public bool SupportInterfaceConstants { get; set; } public bool SupportDefaultInterfaceMethods { get; set; } public bool SupportNestedInterfaceTypes { get; set; } + public bool SupportNullableReferenceTypes { get; set; } public bool UseShallowReferencedTypes { get; set; } bool? buildingCoreAssembly; @@ -61,6 +62,100 @@ internal CodeGenerator CreateCodeGenerator (TextWriter writer) } } + public string NullableOperator => SupportNullableReferenceTypes ? "?" : string.Empty; + + public string NullForgivingOperator => SupportNullableReferenceTypes ? "!" : string.Empty; + + public string GetTypeReferenceName (Field field) + { + var name = GetOutputName (field.Symbol.FullName); + + if (field.NotNull || field.Symbol.IsEnum) + return name; + + return name + GetNullable (field.Symbol.FullName); + } + + public string GetTypeReferenceName (Parameter symbol) + { + var name = GetOutputName (symbol.Type); + + if (symbol.NotNull || symbol.Symbol.IsEnum) + return name; + + return name + GetNullable (symbol.Type); + } + + public string GetTypeReferenceName (ReturnValue symbol) + { + var name = GetOutputName (symbol.FullName); + + if (symbol.NotNull || symbol.Symbol.IsEnum) + return name; + + return name + GetNullable (symbol.FullName); + } + + public string GetTypeReferenceName (Property symbol) + { + if (symbol.Getter != null) + return GetTypeReferenceName (symbol.Getter.RetVal); + + return GetTypeReferenceName (symbol.Setter.Parameters [0]); + } + + + public string GetNullForgiveness (Field field) + { + if (field.NotNull || field.Symbol.IsEnum) + return NullForgivingOperator; + + return string.Empty; + } + + public string GetNullForgiveness (ReturnValue symbol) + { + if (symbol.NotNull || symbol.Symbol.IsEnum) + return NullForgivingOperator; + + return string.Empty; + } + + public string GetNullForgiveness (Parameter symbol) + { + if (symbol.NotNull || symbol.Symbol.IsEnum) + return NullForgivingOperator; + + return string.Empty; + } + + string GetNullable (string s) + { + switch (s) { + case "void": + case "int": + //case "int[]": + case "bool": + //case "bool[]": + case "float": + //case "float[]": + case "sbyte": + //case "sbyte[]": + case "long": + //case "long[]": + case "char": + //case "char[]": + case "double": + //case "double[]": + case "short": + //case "short[]": + case "Android.Graphics.Color": + return string.Empty; + } + + return NullableOperator; + } + public string GetOutputName (string s) { if (s == "System.Void") diff --git a/tools/generator/CodeGenerator.cs b/tools/generator/CodeGenerator.cs index 20027a66e..cb7160f1f 100644 --- a/tools/generator/CodeGenerator.cs +++ b/tools/generator/CodeGenerator.cs @@ -68,6 +68,7 @@ static void Run (CodeGeneratorOptions options, DirectoryAssemblyResolver resolve SupportInterfaceConstants = options.SupportInterfaceConstants, SupportDefaultInterfaceMethods = options.SupportDefaultInterfaceMethods, SupportNestedInterfaceTypes = options.SupportNestedInterfaceTypes, + SupportNullableReferenceTypes = options.SupportNullableReferenceTypes, }; var resolverCache = new TypeDefinitionCache (); diff --git a/tools/generator/CodeGeneratorOptions.cs b/tools/generator/CodeGeneratorOptions.cs index 2df51b0b8..d4973c20d 100644 --- a/tools/generator/CodeGeneratorOptions.cs +++ b/tools/generator/CodeGeneratorOptions.cs @@ -45,6 +45,7 @@ public CodeGeneratorOptions () public bool SupportInterfaceConstants { get; set; } public bool SupportDefaultInterfaceMethods { get; set; } public bool SupportNestedInterfaceTypes { get; set; } + public bool SupportNullableReferenceTypes { get; set; } public static CodeGeneratorOptions Parse (string[] args) { @@ -92,11 +93,12 @@ public static CodeGeneratorOptions Parse (string[] args) "SDK Platform {VERSION}/API level.", v => opts.ApiLevel = v }, { "lang-features=", - "For internal use. (Flags: interface-constants,default-interface-methods)", + "For internal use. (Flags: interface-constants,default-interface-methods,nullable-reference-types)", v => { opts.SupportInterfaceConstants = v?.Contains ("interface-constants") == true; opts.SupportDefaultInterfaceMethods = v?.Contains ("default-interface-methods") == true; opts.SupportNestedInterfaceTypes = v?.Contains ("nested-interface-types") == true; + opts.SupportNullableReferenceTypes = v?.Contains ("nullable-reference-types") == true; }}, { "preserve-enums", "For internal use.", diff --git a/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs b/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs index e63116627..66d469ac0 100644 --- a/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs +++ b/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs @@ -418,7 +418,7 @@ internal virtual void WriteField (Field field, string indent, GenBase type) if (field.IsEnumified) writer.WriteLine ("[global::Android.Runtime.GeneratedEnum]"); if (field.NeedsProperty) { - string fieldType = field.Symbol.IsArray ? "IList<" + field.Symbol.ElementType + ">" : opt.GetOutputName (field.Symbol.FullName); + string fieldType = field.Symbol.IsArray ? "IList<" + field.Symbol.ElementType + ">" + opt.NullableOperator : opt.GetTypeReferenceName (field); WriteFieldIdField (field, indent); writer.WriteLine (); writer.WriteLine ("{0}// Metadata.xml XPath field reference: path=\"{1}/field[@name='{2}']\"", indent, type.MetadataXPathReference, field.JavaName); @@ -599,10 +599,10 @@ public void WriteInterfaceEventArgs (InterfaceGen @interface, Method m, string i if (p.IsSender) continue; writer.WriteLine (); - var safeTypeName = p.Type.StartsWith ("params ", StringComparison.Ordinal) ? p.Type.Substring ("params ".Length) : p.Type; - writer.WriteLine ("{0}\t{1} {2};", indent, opt.GetOutputName (safeTypeName), opt.GetSafeIdentifier (p.Name)); + //var safeTypeName = p.Type.StartsWith ("params ", StringComparison.Ordinal) ? p.Type.Substring ("params ".Length) : p.Type; + writer.WriteLine ("{0}\t{1} {2};", indent, opt.GetTypeReferenceName (p), opt.GetSafeIdentifier (p.Name)); // AbsListView.IMultiChoiceModeListener.onItemCheckedStateChanged() hit this strict name check, at parameter "@checked". - writer.WriteLine ("{0}\tpublic {1} {2} {{", indent, opt.GetOutputName (safeTypeName), p.PropertyName); + writer.WriteLine ("{0}\tpublic {1} {2} {{", indent, opt.GetTypeReferenceName (p), p.PropertyName); writer.WriteLine ("{0}\t\tget {{ return {1}; }}", indent, opt.GetSafeIdentifier (p.Name)); writer.WriteLine ("{0}\t}}", indent); } @@ -610,7 +610,7 @@ public void WriteInterfaceEventArgs (InterfaceGen @interface, Method m, string i writer.WriteLine (); } } else { - writer.WriteLine ("{0}public delegate {1} {2} ({3});", indent, opt.GetOutputName (m.RetVal.FullName), @interface.GetEventDelegateName (m), m.GetSignature (opt)); + writer.WriteLine ("{0}public delegate {1} {2} ({3});", indent, opt.GetTypeReferenceName (m.RetVal), @interface.GetEventDelegateName (m), m.GetSignature (opt)); writer.WriteLine (); } } @@ -669,11 +669,11 @@ public void WriteInterfaceEventHandlerImplContent (InterfaceGen @interface, Meth string args_name = @interface.GetArgsName (m); if (m.EventName != string.Empty) { writer.WriteLine ("#pragma warning disable 0649"); - writer.WriteLine ("{0}\tpublic {1} {2}Handler;", indent, @interface.GetEventDelegateName (m), methodSpec); + writer.WriteLine ("{0}\tpublic {1}{3} {2}Handler;", indent, @interface.GetEventDelegateName (m), methodSpec, opt.NullableOperator); writer.WriteLine ("#pragma warning restore 0649"); } writer.WriteLine (); - writer.WriteLine ("{0}\tpublic {1} {2} ({3})", indent, m.RetVal.FullName, m.Name, m.GetSignature (opt)); + writer.WriteLine ("{0}\tpublic {1} {2} ({3})", indent, opt.GetTypeReferenceName (m.RetVal), m.Name, m.GetSignature (opt)); writer.WriteLine ("{0}\t{{", indent); if (m.EventName == string.Empty) { // generate nothing @@ -693,7 +693,7 @@ public void WriteInterfaceEventHandlerImplContent (InterfaceGen @interface, Meth writer.WriteLine ("{0}\t\treturn __e.Handled;", indent); } else { writer.WriteLine ("{0}\t\tvar __h = {1}Handler;", indent, methodSpec); - writer.WriteLine ("{0}\t\treturn __h != null ? __h ({1}) : default ({2});", indent, m.Parameters.GetCall (opt), opt.GetOutputName (m.RetVal.FullName)); + writer.WriteLine ("{0}\t\treturn __h != null ? __h ({1}) : default ({2});", indent, m.Parameters.GetCall (opt), opt.GetTypeReferenceName (m.RetVal)); } writer.WriteLine ("{0}\t}}", indent); } @@ -837,7 +837,7 @@ public void WriteInterfaceInvoker (InterfaceGen @interface, string indent) WriteInterfaceInvokerHandle (@interface, indent + "\t", @interface.Name + "Invoker"); writer.WriteLine ("{0}\t{1}IntPtr class_ref;", indent, opt.BuildingCoreAssembly ? "new " : ""); writer.WriteLine (); - writer.WriteLine ("{0}\tpublic static {1} GetObject (IntPtr handle, JniHandleOwnership transfer)", indent, @interface.Name); + writer.WriteLine ("{0}\tpublic static {1}{2} GetObject (IntPtr handle, JniHandleOwnership transfer)", indent, @interface.Name, opt.NullableOperator); writer.WriteLine ("{0}\t{{", indent); writer.WriteLine ("{0}\t\treturn global::Java.Lang.Object.GetObject<{1}> (handle, transfer);", indent, @interface.Name); writer.WriteLine ("{0}\t}}", indent); @@ -972,7 +972,7 @@ public void WriteInterfaceListenerEventsAndProperties (InterfaceGen @interface, } foreach (var r in refs) { - writer.WriteLine ("{0}WeakReference weak_implementor_{1};", indent, r); + writer.WriteLine ("{0}WeakReference{2} weak_implementor_{1};", indent, r, opt.NullableOperator); } writer.WriteLine (); writer.WriteLine ("{0}{1}Implementor __Create{2}Implementor ()", indent, opt.GetOutputName (@interface.FullName), @interface.Name); @@ -1010,8 +1010,8 @@ public void WriteInterfaceListenerEventOrProperty (InterfaceGen @interface, Meth Report.Warning (0, Report.WarningInterfaceGen + 6, "event property name for {0}.{1} is invalid. `eventName' or `argsType` can be used to assign a valid member name.", @interface.FullName, name); return; } - writer.WriteLine ("{0}WeakReference weak_implementor_{1};", indent, name); - writer.WriteLine ("{0}{1}Implementor Impl{2} {{", indent, opt.GetOutputName (@interface.FullName), name); + writer.WriteLine ("{0}WeakReference{2} weak_implementor_{1};", indent, name, opt.NullableOperator); + writer.WriteLine ("{0}{1}Implementor{3} Impl{2} {{", indent, opt.GetOutputName (@interface.FullName), name, opt.NullableOperator); writer.WriteLine ("{0}\tget {{", indent); writer.WriteLine ("{0}\t\tif (weak_implementor_{1} == null || !weak_implementor_{1}.IsAlive)", indent, name); writer.WriteLine ("{0}\t\t\treturn null;", indent); @@ -1027,13 +1027,13 @@ public void WriteInterfaceListenerEventOrProperty (InterfaceGen @interface, Meth public void WriteInterfaceListenerProperty (InterfaceGen @interface, string indent, string name, string nameSpec, string methodName, string connector_fmt, string full_delegate_name) { string handlerPrefix = @interface.Methods.Count > 1 ? methodName : string.Empty; - writer.WriteLine ("{0}public {1} {2} {{", indent, opt.GetOutputName (full_delegate_name), name); + writer.WriteLine ("{0}public {1}{3} {2} {{", indent, opt.GetOutputName (full_delegate_name), name, opt.NullableOperator); writer.WriteLine ("{0}\tget {{", indent); - writer.WriteLine ("{0}\t\t{1}Implementor impl = Impl{2};", indent, opt.GetOutputName (@interface.FullName), name); + writer.WriteLine ("{0}\t\t{1}Implementor{3} impl = Impl{2};", indent, opt.GetOutputName (@interface.FullName), name, opt.NullableOperator); writer.WriteLine ("{0}\t\treturn impl == null ? null : impl.{1}Handler;", indent, handlerPrefix); writer.WriteLine ("{0}\t}}", indent); writer.WriteLine ("{0}\tset {{", indent); - writer.WriteLine ("{0}\t\t{1}Implementor impl = Impl{2};", indent, opt.GetOutputName (@interface.FullName), name); + writer.WriteLine ("{0}\t\t{1}Implementor{3} impl = Impl{2};", indent, opt.GetOutputName (@interface.FullName), name, opt.NullableOperator); writer.WriteLine ("{0}\t\tif (impl == null) {{", indent); writer.WriteLine ("{0}\t\t\timpl = new {1}Implementor ({2});", indent, opt.GetOutputName (@interface.FullName), @interface.NeedsSender ? "this" : string.Empty); writer.WriteLine ("{0}\t\t\tImpl{1} = impl;", indent, name); @@ -1094,7 +1094,7 @@ public virtual void WriteMethodCallback (Method method, string indent, GenBase t var is_private = method.IsInterfaceDefaultMethod ? "private " : string.Empty; string delegate_type = method.GetDelegateType (); - writer.WriteLine ("{0}{2}static Delegate {1};", indent, method.EscapedCallbackName, is_private); + writer.WriteLine ("{0}{2}static Delegate{3} {1};", indent, method.EscapedCallbackName, is_private, opt.NullableOperator); writer.WriteLine ("#pragma warning disable 0169"); if (method.Deprecated != null) writer.WriteLine ($"{indent}[Obsolete]"); @@ -1109,7 +1109,7 @@ public virtual void WriteMethodCallback (Method method, string indent, GenBase t writer.WriteLine ($"{indent}[Obsolete]"); writer.WriteLine ("{0}{4}static {1} n_{2} (IntPtr jnienv, IntPtr native__this{3})", indent, method.RetVal.NativeType, method.Name + method.IDSignature, method.Parameters.GetCallbackSignature (opt), is_private); writer.WriteLine ("{0}{{", indent); - writer.WriteLine ("{0}\tvar __this = global::Java.Lang.Object.GetObject<{1}> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);", indent, opt.GetOutputName (type.FullName)); + writer.WriteLine ("{0}\tvar __this = global::Java.Lang.Object.GetObject<{1}> (jnienv, native__this, JniHandleOwnership.DoNotTransfer){2};", indent, opt.GetOutputName (type.FullName), opt.NullForgivingOperator); foreach (string s in method.Parameters.GetCallbackPrep (opt)) writer.WriteLine ("{0}\t{1}", indent, s); if (String.IsNullOrEmpty (property_name)) { @@ -1148,7 +1148,7 @@ public void WriteMethodExplicitInterfaceImplementation (Method method, string in { //writer.WriteLine ("// explicitly implemented method from " + iface.FullName); WriteMethodCustomAttributes (method, indent); - writer.WriteLine ("{0}{1} {2}.{3} ({4})", indent, opt.GetOutputName (method.RetVal.FullName), opt.GetOutputName (iface.FullName), method.Name, method.GetSignature (opt)); + writer.WriteLine ("{0}{1} {2}.{3} ({4})", indent, opt.GetTypeReferenceName (method.RetVal), opt.GetOutputName (iface.FullName), method.Name, method.GetSignature (opt)); writer.WriteLine ("{0}{{", indent); writer.WriteLine ("{0}\treturn {1} ({2});", indent, method.Name, method.Parameters.GetCall (opt)); writer.WriteLine ("{0}}}", indent); @@ -1160,7 +1160,7 @@ public void WriteMethodExplicitInterfaceInvoker (Method method, string indent, G //writer.WriteLine ("\t\t// explicitly implemented invoker method from " + iface.FullName); WriteMethodIdField (method, indent); writer.WriteLine ("{0}unsafe {1} {2}.{3} ({4})", - indent, opt.GetOutputName (method.RetVal.FullName), opt.GetOutputName (iface.FullName), method.Name, method.GetSignature (opt)); + indent, opt.GetTypeReferenceName (method.RetVal), opt.GetOutputName (iface.FullName), method.Name, method.GetSignature (opt)); writer.WriteLine ("{0}{{", indent); WriteMethodBody (method, indent + "\t", iface); writer.WriteLine ("{0}}}", indent); @@ -1171,7 +1171,7 @@ public void WriteMethodAbstractDeclaration (Method method, string indent, Interf { if (method.RetVal.IsGeneric && gen != null) { WriteMethodCustomAttributes (method, indent); - writer.WriteLine ("{0}{1} {2}.{3} ({4})", indent, opt.GetOutputName (method.RetVal.FullName), opt.GetOutputName (gen.FullName), method.Name, method.GetSignature (opt)); + writer.WriteLine ("{0}{1} {2}.{3} ({4})", indent, opt.GetTypeReferenceName (method.RetVal), opt.GetOutputName (gen.FullName), method.Name, method.GetSignature (opt)); writer.WriteLine ("{0}{{", indent); writer.WriteLine ("{0}\tthrow new NotImplementedException ();", indent); writer.WriteLine ("{0}}}", indent); @@ -1188,7 +1188,7 @@ public void WriteMethodAbstractDeclaration (Method method, string indent, Interf indent, impl.RequiresNew (method.Name, method) ? "new " : "", method.Visibility, - opt.GetOutputName (method.RetVal.FullName), + opt.GetTypeReferenceName (method.RetVal), name, method.GetSignature (opt)); writer.WriteLine (); @@ -1212,13 +1212,13 @@ public void WriteMethodDeclaration (Method method, string indent, GenBase type, writer.WriteLine ("{0}[global::Java.Interop.JavaInterfaceDefaultMethod]", indent); writer.WriteLine ("{0}[Register (\"{1}\", \"{2}\", \"{3}:{4}\"{5})]", indent, method.JavaName, method.JniSignature, method.ConnectorName, method.GetAdapterName (opt, adapter), method.AdditionalAttributeString ()); WriteMethodCustomAttributes (method, indent); - writer.WriteLine ("{0}{1} {2} ({3});", indent, opt.GetOutputName (method.RetVal.FullName), method.AdjustedName, method.GetSignature (opt)); + writer.WriteLine ("{0}{1} {2} ({3});", indent, opt.GetTypeReferenceName (method.RetVal), method.AdjustedName, method.GetSignature (opt)); writer.WriteLine (); } public void WriteMethodEventDelegate (Method method, string indent) { - writer.WriteLine ("{0}public delegate {1} {2}EventHandler ({3});", indent, opt.GetOutputName (method.RetVal.FullName), method.Name, method.GetSignature (opt)); + writer.WriteLine ("{0}public delegate {1} {2}EventHandler ({3});", indent, opt.GetTypeReferenceName (method.RetVal), method.Name, method.GetSignature (opt)); writer.WriteLine (); } @@ -1227,7 +1227,7 @@ public void WriteMethodExplicitIface (Method method, string indent, GenericSymbo { writer.WriteLine ("{0}// This method is explicitly implemented as a member of an instantiated {1}", indent, gen.FullName); WriteMethodCustomAttributes (method, indent); - writer.WriteLine ("{0}{1} {2}.{3} ({4})", indent, opt.GetOutputName (method.RetVal.FullName), opt.GetOutputName (gen.Gen.FullName), method.Name, method.GetSignature (opt)); + writer.WriteLine ("{0}{1} {2}.{3} ({4})", indent, opt.GetTypeReferenceName (method.RetVal), opt.GetOutputName (gen.Gen.FullName), method.Name, method.GetSignature (opt)); writer.WriteLine ("{0}{{", indent); Dictionary mappings = new Dictionary (); for (int i = 0; i < gen.TypeParams.Length; i++) @@ -1264,7 +1264,7 @@ public void WriteMethodInvoker (Method method, string indent, GenBase type) WriteMethodCallback (method, indent, type, null, method.IsReturnCharSequence); WriteMethodIdField (method, indent, invoker: true); writer.WriteLine ("{0}public unsafe {1}{2} {3} ({4})", - indent, method.IsStatic ? "static " : string.Empty, opt.GetOutputName (method.RetVal.FullName), method.AdjustedName, method.GetSignature (opt)); + indent, method.IsStatic ? "static " : string.Empty, opt.GetTypeReferenceName (method.RetVal), method.AdjustedName, method.GetSignature (opt)); writer.WriteLine ("{0}{{", indent); WriteMethodInvokerBody (method, indent + "\t"); writer.WriteLine ("{0}}}", indent); @@ -1284,7 +1284,7 @@ public void WriteMethodInvokerBody (Method method, string indent) if (method.IsVoid) writer.WriteLine ("{0}{1};", indent, call); else - writer.WriteLine ("{0}{1}{2};", indent, method.Parameters.HasCleanup ? "var __ret = " : "return ", method.RetVal.FromNative (opt, call, true)); + writer.WriteLine ("{0}{1}{2};", indent, method.Parameters.HasCleanup ? "var __ret = " : "return ", method.RetVal.FromNative (opt, call, true) + opt.GetNullForgiveness (method.RetVal)); foreach (string cleanup in method.Parameters.GetCallCleanup (opt)) writer.WriteLine ("{0}{1}", indent, cleanup); @@ -1307,9 +1307,9 @@ void WriteMethodStringOverloadBody (Method method, string indent, bool haveSelf) } if (call.Length > 0) call.Append (", "); - call.Append (pname); + call.Append (pname + (p.Type == "Java.Lang.ICharSequence" ? opt.GetNullForgiveness (p) : string.Empty)); } - writer.WriteLine ("{0}{1}{2}{3} ({4});", indent, method.RetVal.IsVoid ? String.Empty : opt.GetOutputName (method.RetVal.FullName) + " __result = ", haveSelf ? "self." : "", method.AdjustedName, call.ToString ()); + writer.WriteLine ("{0}{1}{2}{3} ({4});", indent, method.RetVal.IsVoid ? String.Empty : opt.GetTypeReferenceName (method.RetVal) + " __result = ", haveSelf ? "self." : "", method.AdjustedName, call.ToString ()); switch (method.RetVal.FullName) { case "void": break; @@ -1330,14 +1330,14 @@ void WriteMethodStringOverloadBody (Method method, string indent, bool haveSelf) writer.WriteLine ("{0}if ({1} != null) foreach (var s in {1}) s?.Dispose ();", indent, p.GetName ("jlca_")); } if (!method.RetVal.IsVoid) { - writer.WriteLine ($"{indent}return __rsval;"); + writer.WriteLine ($"{indent}return __rsval{opt.GetNullForgiveness (method.RetVal)};"); } } void WriteMethodStringOverload (Method method, string indent) { string static_arg = method.IsStatic ? " static" : String.Empty; - string ret = opt.GetOutputName (method.RetVal.FullName.Replace ("Java.Lang.ICharSequence", "string")); + string ret = opt.GetTypeReferenceName (method.RetVal).Replace ("Java.Lang.ICharSequence", "string").Replace ("global::string", "string"); if (method.Deprecated != null) writer.WriteLine ("{0}[Obsolete (@\"{1}\")]", indent, method.Deprecated.Replace ("\"", "\"\"").Trim ()); writer.WriteLine ("{0}{1}{2} {3} {4} ({5})", indent, method.Visibility, static_arg, ret, method.Name, method.GetSignature (opt).Replace ("Java.Lang.ICharSequence", "string").Replace ("global::string", "string")); @@ -1352,7 +1352,7 @@ public void WriteMethodExtensionOverload (Method method, string indent, string s if (!method.CanHaveStringOverload) return; - string ret = opt.GetOutputName (method.RetVal.FullName.Replace ("Java.Lang.ICharSequence", "string")); + string ret = opt.GetTypeReferenceName (method.RetVal).Replace ("Java.Lang.ICharSequence", "string").Replace ("global::string", "string"); writer.WriteLine (); var parameters = method.GetSignature (opt).Replace ("Java.Lang.ICharSequence", "string").Replace ("global::string", "string"); @@ -1382,7 +1382,7 @@ public void WriteMethodAsyncWrapper (Method method, string indent) if (method.IsVoid) ret = "global::System.Threading.Tasks.Task"; else - ret = "global::System.Threading.Tasks.Task<" + opt.GetOutputName (method.RetVal.FullName) + ">"; + ret = "global::System.Threading.Tasks.Task<" + opt.GetTypeReferenceName (method.RetVal) + ">"; writer.WriteLine ("{0}{1}{2} {3} {4}Async ({5})", indent, method.Visibility, static_arg, ret, method.AdjustedName, method.GetSignature (opt)); writer.WriteLine ("{0}{{", indent); @@ -1401,7 +1401,7 @@ public void WriteMethodExtensionAsyncWrapper (Method method, string indent, stri if (method.IsVoid) ret = "global::System.Threading.Tasks.Task"; else - ret = "global::System.Threading.Tasks.Task<" + opt.GetOutputName (method.RetVal.FullName) + ">"; + ret = "global::System.Threading.Tasks.Task<" + opt.GetTypeReferenceName (method.RetVal) + ">"; writer.WriteLine ("{0}public static {1} {2}Async (this {3} self{4}{5})", indent, ret, method.AdjustedName, selfType, method.Parameters.Count > 0 ? ", " : string.Empty, method.GetSignature (opt)); writer.WriteLine ("{0}{{", indent); @@ -1437,7 +1437,7 @@ public void WriteMethod (Method method, string indent, GenBase type, bool genera if ((string.IsNullOrEmpty (virt_ov) || virt_ov == " virtual") && type.RequiresNew (method.AdjustedName, method)) { virt_ov = " new" + virt_ov; } - string ret = opt.GetOutputName (method.RetVal.FullName); + string ret = opt.GetTypeReferenceName (method.RetVal); WriteMethodIdField (method, indent); if (method.DeclaringType.IsGeneratable) writer.WriteLine ("{0}// Metadata.xml XPath method reference: path=\"{1}\"", indent, method.GetMetadataXPathReference (method.DeclaringType)); @@ -1558,7 +1558,7 @@ public void WriteProperty (Property property, GenBase gen, string indent, bool w if (property.Getter.Deprecated != null && (property.Setter == null || property.Setter.Deprecated != null)) writer.WriteLine ("{0}[Obsolete (@\"{1}\")]", indent, property.Getter.Deprecated.Replace ("\"", "\"\"").Trim () + (property.Setter != null && property.Setter.Deprecated != property.Getter.Deprecated ? " " + property.Setter.Deprecated.Replace ("\"", "\"\"").Trim () : null)); WriteMethodCustomAttributes (property.Getter, indent); - writer.WriteLine ("{0}{1}{2} unsafe {3} {4} {{", indent, visibility, virtual_override, opt.GetOutputName (property.Getter.ReturnType), decl_name); + writer.WriteLine ("{0}{1}{2} unsafe {3} {4} {{", indent, visibility, virtual_override, opt.GetTypeReferenceName (property.Getter.RetVal), decl_name); if (gen.IsGeneratable) writer.WriteLine ("{0}\t// Metadata.xml XPath method reference: path=\"{1}/method[@name='{2}'{3}]\"", indent, gen.MetadataXPathReference, property.Getter.JavaName, property.Getter.Parameters.GetMethodXPathPredicate ()); writer.WriteLine ("{0}\t[Register (\"{1}\", \"{2}\", \"{3}\"{4})]", indent, property.Getter.JavaName, property.Getter.JniSignature, property.Getter.IsVirtual ? property.Getter.GetConnectorNameFull (opt) : string.Empty, property.Getter.AdditionalAttributeString ()); @@ -1612,7 +1612,7 @@ public void WritePropertyAbstractDeclaration (Property property, string indent, visibility, requiresNew ? " new" : "", overrides ? " override" : "", - opt.GetOutputName (property.Getter.ReturnType), + opt.GetTypeReferenceName (property.Getter.RetVal), abstract_name); if (gen.IsGeneratable) writer.WriteLine ("{0}\t// Metadata.xml XPath method reference: path=\"{1}/method[@name='{2}'{3}]\"", indent, gen.MetadataXPathReference, property.Getter.JavaName, property.Getter.Parameters.GetMethodXPathPredicate ()); @@ -1656,7 +1656,7 @@ public void WritePropertyExplicitInterface (Property property, string indent, Ge return; writer.WriteLine ("{0}// This method is explicitly implemented as a member of an instantiated {1}", indent, gen.FullName); - writer.WriteLine ("{0}{1} {2}.{3} {{", indent, opt.GetOutputName (property.Type), opt.GetOutputName (gen.Gen.FullName), property.AdjustedName); + writer.WriteLine ("{0}{1} {2}.{3} {{", indent, opt.GetTypeReferenceName (property), opt.GetOutputName (gen.Gen.FullName), property.AdjustedName); if (property.Getter != null) { if (gen.Gen.IsGeneratable) writer.WriteLine ("{0}\t// Metadata.xml XPath method reference: path=\"{1}/method[@name='{2}'{3}]\"", indent, gen.Gen.MetadataXPathReference, property.Getter.JavaName, property.Getter.Parameters.GetMethodXPathPredicate ()); @@ -1687,7 +1687,7 @@ public void WritePropertyExplicitInterface (Property property, string indent, Ge public void WritePropertyDeclaration (Property property, string indent, GenBase gen, string adapter) { - writer.WriteLine ("{0}{1} {2} {{", indent, opt.GetOutputName (property.Type), property.AdjustedName); + writer.WriteLine ("{0}{1} {2} {{", indent, opt.GetTypeReferenceName (property), property.AdjustedName); if (property.Getter != null) { if (gen.IsGeneratable) writer.WriteLine ("{0}\t// Metadata.xml XPath method reference: path=\"{1}/method[@name='{2}'{3}]\"", indent, gen.MetadataXPathReference, property.Getter.JavaName, property.Getter.Parameters.GetMethodXPathPredicate ()); @@ -1712,7 +1712,7 @@ public void WritePropertyInvoker (Property property, string indent, GenBase cont WriteMethodIdField (property.Getter, indent, invoker: true); if (property.Setter != null) WriteMethodIdField (property.Setter, indent, invoker: true); - writer.WriteLine ("{0}public unsafe {1} {2} {{", indent, opt.GetOutputName (property.Getter.ReturnType), property.AdjustedName); + writer.WriteLine ("{0}public unsafe {1} {2} {{", indent, opt.GetTypeReferenceName (property), property.AdjustedName); writer.WriteLine ("{0}\tget {{", indent); WriteMethodInvokerBody (property.Getter, indent + "\t\t"); writer.WriteLine ("{0}\t}}", indent); @@ -1731,7 +1731,7 @@ public void WritePropertyInvoker (Property property, string indent, GenBase cont public void WritePropertyStringVariant (Property property, string indent) { bool is_array = property.Getter.RetVal.IsArray; - writer.WriteLine ("{0}{1} string{2} {3} {{", indent, (property.Setter ?? property.Getter).Visibility, is_array ? "[]" : String.Empty, property.Name); + writer.WriteLine ("{0}{1} string{2}{4} {3} {{", indent, (property.Setter ?? property.Getter).Visibility, is_array ? "[]" : String.Empty, property.Name, opt.NullableOperator); if (is_array) writer.WriteLine ("{0}\tget {{ return CharSequence.ArrayToStringArray ({1}); }}", indent, property.AdjustedName); else diff --git a/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/JavaInteropCodeGenerator.cs b/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/JavaInteropCodeGenerator.cs index 87fa8aa7c..52d2788ae 100644 --- a/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/JavaInteropCodeGenerator.cs +++ b/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/JavaInteropCodeGenerator.cs @@ -111,7 +111,7 @@ internal override void WriteConstructorBody (Ctor ctor, string indent, System.Co indent, ctor.IsNonStaticNestedType ? "" : "const ", ctor.IsNonStaticNestedType - ? "(" + ctor.Parameters.JniNestedDerivedSignature + ")V" + ? "(" + ctor.Parameters.GetJniNestedDerivedSignature (opt) + ")V" : ctor.JniSignature); writer.WriteLine (); writer.WriteLine ("{0}if ({1} != IntPtr.Zero)", indent, Context.ContextType.GetObjectHandleProperty ("this")); @@ -175,7 +175,7 @@ internal override void WriteMethodBody (Method method, string indent, GenBase ty if (!method.IsVoid) { var r = invokeType == "Object" ? "__rm.Handle" : "__rm"; - writer.WriteLine ("{0}return {2}{1};", indent, method.RetVal.FromNative (opt, r, true), method.RetVal.ReturnCast); + writer.WriteLine ("{0}return {2}{1};", indent, method.RetVal.FromNative (opt, r, true) + opt.GetNullForgiveness (method.RetVal), method.RetVal.ReturnCast); } indent = oldindent; @@ -213,7 +213,7 @@ internal override void WriteFieldGetBody (Field field, string indent, GenBase ty else if (field.Symbol.NativeType != field.Symbol.FullName) { writer.WriteLine ("{0}return {2}{1};", indent, - field.Symbol.FromNative (opt, invokeType != "Object" ? "__v" : "__v.Handle", true), + field.Symbol.FromNative (opt, invokeType != "Object" ? "__v" : "__v.Handle", true) + opt.GetNullForgiveness (field), field.Symbol.ReturnCast); } else { writer.WriteLine ("{0}return __v;", indent); diff --git a/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/XamarinAndroidCodeGenerator.cs b/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/XamarinAndroidCodeGenerator.cs index 1de68e0c4..8bc7868f4 100644 --- a/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/XamarinAndroidCodeGenerator.cs +++ b/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/XamarinAndroidCodeGenerator.cs @@ -79,13 +79,13 @@ internal override void WriteConstructorBody (Ctor ctor, string indent, System.Co writer.WriteLine ("{0}\tSetHandle (", indent); writer.WriteLine ("{0}\t\t\tglobal::Android.Runtime.JNIEnv.StartCreateInstance (((object) this).GetType (), \"{1}\"{2}),", indent, - ctor.IsNonStaticNestedType ? "(" + ctor.Parameters.JniNestedDerivedSignature + ")V" : ctor.JniSignature, + ctor.IsNonStaticNestedType ? "(" + ctor.Parameters.GetJniNestedDerivedSignature (opt) + ")V" : ctor.JniSignature, ctor.Parameters.GetCallArgs (opt, invoker:false)); writer.WriteLine ("{0}\t\t\tJniHandleOwnership.TransferLocalRef);", indent); writer.WriteLine ("{0}\tglobal::Android.Runtime.JNIEnv.FinishCreateInstance ({1}, \"{2}\"{3});", indent, Context.ContextType.GetObjectHandleProperty ("this"), - ctor.IsNonStaticNestedType ? "(" + ctor.Parameters.JniNestedDerivedSignature + ")V" : ctor.JniSignature, + ctor.IsNonStaticNestedType ? "(" + ctor.Parameters.GetJniNestedDerivedSignature (opt) + ")V" : ctor.JniSignature, ctor.Parameters.GetCallArgs (opt, invoker:false)); writer.WriteLine ("{0}\treturn;", indent); writer.WriteLine ("{0}}}", indent); @@ -118,7 +118,7 @@ void GenerateJNICall (Method method, string indent, string call, bool declare_re if (method.IsVoid) writer.WriteLine ("{0}{1};", indent, call); else if (method.Parameters.HasCleanup) - writer.WriteLine ("{0}{1}__ret = {2};", indent, declare_ret ? opt.GetOutputName (method.RetVal.FullName) + " " : String.Empty, method.RetVal.FromNative (opt, call, true)); + writer.WriteLine ("{0}{1}__ret = {2};", indent, declare_ret ? opt.GetTypeReferenceName (method.RetVal) + " " : String.Empty, method.RetVal.FromNative (opt, call, true)); else writer.WriteLine ("{0}return {1};", indent, method.RetVal.FromNative (opt, call, true)); } @@ -139,7 +139,7 @@ internal override void WriteMethodBody (Method method, string indent, GenBase ty } else if (use_non_virtual) { writer.WriteLine (); if (!method.IsVoid && method.Parameters.HasCleanup) - writer.WriteLine ("{0}{1} __ret;", indent, opt.GetOutputName (method.RetVal.FullName)); + writer.WriteLine ("{0}{1} __ret;", indent, opt.GetTypeReferenceName (method.RetVal)); writer.WriteLine ("{0}if (((object) this).GetType () == ThresholdType)", indent); GenerateJNICall (method, indent + "\t", "JNIEnv.Call" + method.RetVal.CallMethodPrefix + "Method (" + diff --git a/tools/generator/Java.Interop.Tools.Generator.Importers/XmlApiImporter.cs b/tools/generator/Java.Interop.Tools.Generator.Importers/XmlApiImporter.cs index 0732f53af..fbbc562b2 100644 --- a/tools/generator/Java.Interop.Tools.Generator.Importers/XmlApiImporter.cs +++ b/tools/generator/Java.Interop.Tools.Generator.Importers/XmlApiImporter.cs @@ -103,6 +103,7 @@ public static Field CreateField (XElement elem) IsFinal = elem.XGetAttribute ("final") == "true", IsStatic = elem.XGetAttribute ("static") == "true", JavaName = elem.XGetAttribute ("name"), + NotNull = elem.XGetAttribute ("not-null") == "true", SetterParameter = CreateParameter (elem), TypeName = elem.XGetAttribute ("type"), Value = elem.XGetAttribute ("value"), // do not trim @@ -247,6 +248,7 @@ public static Method CreateMethod (GenBase declaringType, XElement elem) ManagedReturn = elem.XGetAttribute ("managedReturn"), PropertyNameOverride = elem.XGetAttribute ("propertyName"), Return = elem.XGetAttribute ("return"), + ReturnNotNull = elem.XGetAttribute ("return-not-null") == "true", SourceApiLevel = GetApiLevel (elem.XGetAttribute ("merge.SourceFile")), Visibility = elem.Visibility () }; @@ -287,8 +289,9 @@ public static Parameter CreateParameter (XElement elem) string java_type = elem.XGetAttribute ("type"); string enum_type = elem.Attribute ("enumType") != null ? elem.XGetAttribute ("enumType") : null; string managed_type = elem.Attribute ("managedType") != null ? elem.XGetAttribute ("managedType") : null; + var not_null = elem.XGetAttribute ("not-null") == "true"; // FIXME: "enum_type ?? java_type" should be extraneous. Somewhere in generator uses it improperly. - var result = new Parameter (name, enum_type ?? java_type, enum_type ?? managed_type, enum_type != null, java_type); + var result = new Parameter (name, enum_type ?? java_type, enum_type ?? managed_type, enum_type != null, java_type, not_null); if (elem.Attribute ("sender") != null) result.IsSender = true; return result; diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ClassGen.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ClassGen.cs index 78be073c5..f43183ed8 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ClassGen.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ClassGen.cs @@ -196,7 +196,7 @@ public static void GenerateTypeRegistrations (CodeGenerationOptions opt, Generat sw.WriteLine ("\t\t\t\t\t\t\"{0}\",", e.Key); } sw.WriteLine ("\t\t\t\t\t},"); - sw.WriteLine ("\t\t\t\t\tnew Converter[]{"); + sw.WriteLine ("\t\t\t\t\tnew Converter[]{{", opt.NullableOperator); foreach (KeyValuePair>> e in mapping) { sw.WriteLine ("\t\t\t\t\t\tlookup_{0}_package,", e.Key.Replace ('/', '_')); } @@ -207,7 +207,7 @@ public static void GenerateTypeRegistrations (CodeGenerationOptions opt, Generat sw.WriteLine ("#endif // def MONODROID_TIMING"); sw.WriteLine ("\t\t}"); sw.WriteLine (); - sw.WriteLine ("\t\tstatic Type Lookup (string[] mappings, string javaType)"); + sw.WriteLine ("\t\tstatic Type{0} Lookup (string[] mappings, string javaType)", opt.NullableOperator); sw.WriteLine ("\t\t{"); sw.WriteLine ("\t\t\tvar managedType = Java.Interop.TypeManager.LookupTypeMapping (mappings, javaType);"); sw.WriteLine ("\t\t\tif (managedType == null)"); @@ -217,8 +217,8 @@ public static void GenerateTypeRegistrations (CodeGenerationOptions opt, Generat foreach (KeyValuePair>> map in mapping) { sw.WriteLine (); string package = map.Key.Replace ('/', '_'); - sw.WriteLine ("\t\tstatic string[] package_{0}_mappings;", package); - sw.WriteLine ("\t\tstatic Type lookup_{0}_package (string klass)", package); + sw.WriteLine ("\t\tstatic string[]{1} package_{0}_mappings;", package, opt.NullableOperator); + sw.WriteLine ("\t\tstatic Type{1} lookup_{0}_package (string klass)", package, opt.NullableOperator); sw.WriteLine ("\t\t{"); sw.WriteLine ("\t\t\tif (package_{0}_mappings == null) {{", package); sw.WriteLine ("\t\t\t\tpackage_{0}_mappings = new string[]{{", package); diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs index 86b165fb6..4d599f4f5 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs @@ -19,6 +19,7 @@ public class Field : ApiVersionsSupport.IApiAvailability public ISymbol Symbol { get; private set; } public string JavaName { get; set; } public string Name { get; set; } + public bool NotNull { get; set; } public Parameter SetterParameter { get; set; } public string TypeName { get; set; } public string Value { get; set; } diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBase.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBase.cs index 24fa892fa..95ce07828 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBase.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBase.cs @@ -366,7 +366,7 @@ protected void GenerateAnnotationAttribute (CodeGenerationOptions opt, Generatio foreach (var method in Methods.Where (m => m.Parameters.Count == 0 && IsTypeCommensurate (opt, opt.SymbolTable.Lookup (m.RetVal.JavaName)))) { sw.WriteLine ("\t\t[global::Android.Runtime.Register (\"{0}\"{1})]", method.JavaName, method.AdditionalAttributeString ()); - sw.WriteLine ("\t\tpublic {0} {1} {{ get; set; }}", opt.GetOutputName (method.RetVal.FullName), method.Name); + sw.WriteLine ("\t\tpublic {0} {1} {{ get; set; }}", opt.GetTypeReferenceName (method.RetVal), method.Name); sw.WriteLine (); } sw.WriteLine ("\t}"); @@ -715,7 +715,7 @@ protected virtual bool OnValidate (CodeGenerationOptions opt, GenericParameterDe opt.GetSafeIdentifier (TypeNameUtilities.GetNativeName (var_name)), owned ? "JniHandleOwnership.TransferLocalRef" : "JniHandleOwnership.DoNotTransfer", opt.GetOutputName (rgm != null ? (rgm.GetGenericJavaObjectTypeOverride () ?? FullName) : FullName), - rgm != null ? "(" + opt.GetOutputName (FullName) + ")" : string.Empty) + rgm != null ? "(" + opt.GetOutputName (FullName) + opt.NullableOperator + ")" : string.Empty) }; } diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Method.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Method.cs index 60c84c6aa..3632a9b01 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Method.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Method.cs @@ -29,6 +29,7 @@ public Method (GenBase declaringType) : base (declaringType) public string ManagedReturn { get; set; } public string PropertyNameOverride { get; set; } public string Return { get; set; } + public bool ReturnNotNull { get; set; } public ReturnValue RetVal { get; set; } public int SourceApiLevel { get; set; } @@ -112,7 +113,7 @@ internal string CalculateEventName (Func checkNameDuplicate) internal void FillReturnType () { - RetVal = new ReturnValue (this, Return, ManagedReturn, IsReturnEnumified); + RetVal = new ReturnValue (this, Return, ManagedReturn, IsReturnEnumified, ReturnNotNull); } internal string GetAdapterName (CodeGenerationOptions opt, string adapter) diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/MethodBase.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/MethodBase.cs index be0869f3a..3c259f1d9 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/MethodBase.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/MethodBase.cs @@ -68,7 +68,7 @@ public string GetSignature (CodeGenerationOptions opt) sb.Append ("[global::Android.Runtime.GeneratedEnum] "); if (p.Annotation != null) sb.Append (p.Annotation); - sb.Append (opt.GetOutputName (p.Type)); + sb.Append (opt.GetTypeReferenceName (p)); sb.Append (" "); sb.Append (opt.GetSafeIdentifier (p.Name)); } diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs index de42eb9fa..dc3c11bce 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs @@ -18,13 +18,14 @@ public class Parameter { ISymbol sym; bool is_enumified; - internal Parameter (string name, string type, string managedType, bool isEnumified, string rawtype = null) + internal Parameter (string name, string type, string managedType, bool isEnumified, string rawtype = null, bool notNull = false) { this.name = name; this.type = type; this.rawtype = rawtype ?? type; this.managed_type = managedType; this.is_enumified = isEnumified; + NotNull = notNull; } public string GetCall (CodeGenerationOptions opt) @@ -97,6 +98,8 @@ public string GetGenericType (Dictionary mappings) set { name = value; } } + public bool NotNull { get; set; } + public string PropertyName { get { if (Name == "e") @@ -247,9 +250,10 @@ public string GetGenericCall (CodeGenerationOptions opt, Dictionary ()", name, targetType.Replace ("[]","")); } var rgm = opt.SymbolTable.Lookup (targetType) as IRequireGenericMarshal; - return string.Format ("global::Java.Interop.JavaObjectExtensions.JavaCast<{0}>({1})", + return string.Format ("global::Java.Interop.JavaObjectExtensions.JavaCast<{0}>({1}){2}", opt.GetOutputName (rgm != null ? (rgm.GetGenericJavaObjectTypeOverride () ?? targetType) : targetType), - name); + name, + opt.NullForgivingOperator); } public bool Validate (CodeGenerationOptions opt, GenericParameterDefinitionList type_params, CodeGeneratorContext context) @@ -265,5 +269,7 @@ public bool Validate (CodeGenerationOptions opt, GenericParameterDefinitionList } return true; } + + public ISymbol Symbol => sym; } } diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ParameterList.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ParameterList.cs index 49650e686..711932e52 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ParameterList.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ParameterList.cs @@ -43,7 +43,7 @@ public string GetCall (CodeGenerationOptions opt) foreach (Parameter p in items) { if (sb.Length > 0) sb.Append (", "); - sb.Append (opt.GetSafeIdentifier (p.Name)); + sb.Append (opt.GetSafeIdentifier (p.Name) + opt.GetNullForgiveness (p)); } return sb.ToString (); } @@ -205,18 +205,17 @@ public string GetCallbackSignature (CodeGenerationOptions opt) } } - public string JniNestedDerivedSignature { - get { - StringBuilder sb = new StringBuilder (); - foreach (Parameter p in items) { - if (p.Name == "__self") { - sb.Append ("L\" + global::Android.Runtime.JNIEnv.GetJniName (GetType ().DeclaringType) + \";"); - continue; - } - sb.Append (p.JniType); + public string GetJniNestedDerivedSignature (CodeGenerationOptions opt) + { + StringBuilder sb = new StringBuilder (); + foreach (Parameter p in items) { + if (p.Name == "__self") { + sb.AppendFormat ("L\" + global::Android.Runtime.JNIEnv.GetJniName (GetType ().DeclaringType{0}) + \";", opt.NullForgivingOperator); + continue; } - return sb.ToString (); + sb.Append (p.JniType); } + return sb.ToString (); } public string SenderName { @@ -236,7 +235,7 @@ public string GetSignatureDropSender (CodeGenerationOptions opt) continue; else if (sb.Length > 0) sb.Append (", "); - sb.Append (opt.GetOutputName (p.Type)); + sb.Append (opt.GetTypeReferenceName (p)); sb.Append (" "); sb.Append (p.Name); } diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Property.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Property.cs index ae0f560e0..391199e3e 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Property.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Property.cs @@ -10,13 +10,24 @@ namespace MonoDroid.Generation { public class Property { + private Method setter; + public Property (string name) { Name = name; } public Method Getter {get; set;} - public Method Setter {get; set;} + + public Method Setter { + get => setter; + set { + setter = value; + + if (Getter?.RetVal?.NotNull == true) + Setter.Parameters.First ().NotNull = true; + } + } public bool IsGeneric => Getter.IsGeneric; diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs index bcdacec12..4ec5368a5 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs @@ -15,11 +15,12 @@ public class ReturnValue { string raw_type; bool is_enumified; - public ReturnValue (Method owner, string java_type, string managed_type, bool isEnumified) + public ReturnValue (Method owner, string java_type, string managed_type, bool isEnumified, bool notNull) { this.raw_type = this.java_type = java_type; this.managed_type = managed_type; this.is_enumified = isEnumified; + NotNull = notNull; } public string CallMethodPrefix => TypeNameUtilities.GetCallPrefix (sym); @@ -78,12 +79,16 @@ public string GetGenericType (Dictionary mappings) get { return sym.NativeType; } } + public bool NotNull { get; set; } + public string RawJavaType { get { return raw_type; } } public string ReturnCast => sym?.ReturnCast ?? string.Empty; + public ISymbol Symbol => sym; + public string FromNative (CodeGenerationOptions opt, string var_name, bool owned) { if (!string.IsNullOrEmpty (managed_type) && (sym is ClassGen || sym is InterfaceGen)) { @@ -104,11 +109,12 @@ public string GetGenericReturn (CodeGenerationOptions opt, string name, Dictiona if (string.IsNullOrEmpty (targetType)) return name; if (targetType == "string") - return string.Format ("{0}.ToString ()", name); + return string.Format ("{0}?.ToString ()", name); var rgm = opt.SymbolTable.Lookup (targetType) as IRequireGenericMarshal; - return string.Format ("global::Java.Interop.JavaObjectExtensions.JavaCast<{0}>({1})", + return string.Format ("global::Java.Interop.JavaObjectExtensions.JavaCast<{0}>({1}){2}", rgm != null ? (rgm.GetGenericJavaObjectTypeOverride () ?? sym.FullName) : sym.FullName, - opt.GetSafeIdentifier (rgm != null ? rgm.ToInteroperableJavaObject (name) : name)); + opt.GetSafeIdentifier (rgm != null ? rgm.ToInteroperableJavaObject (name) : name), + opt.NullForgivingOperator); } public bool Validate (CodeGenerationOptions opt, GenericParameterDefinitionList type_params, CodeGeneratorContext context) diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/ArraySymbol.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/ArraySymbol.cs index 18365006c..55bd29895 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/ArraySymbol.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/ArraySymbol.cs @@ -78,7 +78,7 @@ public string GetGenericType (Dictionary mappings) public string FromNative (CodeGenerationOptions opt, string var_name, bool owned) { - return String.Format ("({0}[]) JNIEnv.GetArray ({1}, {2}, typeof ({3}))", opt.GetOutputName (ElementType), var_name, owned ? "JniHandleOwnership.TransferLocalRef" : "JniHandleOwnership.DoNotTransfer", opt.GetOutputName (sym.FullName)); + return String.Format ("({0}[]{4}) JNIEnv.GetArray ({1}, {2}, typeof ({3}))", opt.GetOutputName (ElementType), var_name, owned ? "JniHandleOwnership.TransferLocalRef" : "JniHandleOwnership.DoNotTransfer", opt.GetOutputName (sym.FullName), opt.NullableOperator); } public string ToNative (CodeGenerationOptions opt, string var_name, Dictionary mappings = null) @@ -117,7 +117,7 @@ public string[] PostCall (CodeGenerationOptions opt, string var_name) public string[] PreCallback (CodeGenerationOptions opt, string var_name, bool owned) { - return new string[] { String.Format ("var {1} = ({0}[]) JNIEnv.GetArray ({2}, JniHandleOwnership.DoNotTransfer, typeof ({3}));", opt.GetOutputName (ElementType), opt.GetSafeIdentifier (var_name), opt.GetSafeIdentifier (TypeNameUtilities.GetNativeName (var_name)), opt.GetOutputName (sym.FullName)) }; + return new string[] { String.Format ("var {1} = ({0}[]{4}) JNIEnv.GetArray ({2}, JniHandleOwnership.DoNotTransfer, typeof ({3}));", opt.GetOutputName (ElementType), opt.GetSafeIdentifier (var_name), opt.GetSafeIdentifier (TypeNameUtilities.GetNativeName (var_name)), opt.GetOutputName (sym.FullName), opt.NullableOperator) }; } public string[] PreCall (CodeGenerationOptions opt, string var_name) diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/GeneratedEnumSymbol.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/GeneratedEnumSymbol.cs index 55638ddd0..3f8a1fddc 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/GeneratedEnumSymbol.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/GeneratedEnumSymbol.cs @@ -27,7 +27,7 @@ public string GetGenericType (Dictionary mappings) public string FromNative (CodeGenerationOptions opt, string var_name, bool owned) { if (IsArray) - return String.Format ("({0}[]) JNIEnv.GetArray ({1}, {2}, typeof ({0}))", opt.GetOutputName (enum_type), var_name, owned ? "JniHandleOwnership.TransferLocalRef" : "JniHandleOwnership.DoNotTransfer"); + return String.Format ("({0}[]{3}) JNIEnv.GetArray ({1}, {2}, typeof ({0}))", opt.GetOutputName (enum_type), var_name, owned ? "JniHandleOwnership.TransferLocalRef" : "JniHandleOwnership.DoNotTransfer", opt.NullableOperator); else return String.Format ("({0}) {1}", opt.GetOutputName (enum_type), var_name); } diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/GenericTypeParameter.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/GenericTypeParameter.cs index 8fd2c794f..f144c4d10 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/GenericTypeParameter.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/GenericTypeParameter.cs @@ -72,7 +72,7 @@ public string GetObjectHandleProperty (string variable) public string FromNative (CodeGenerationOptions opt, string varname, bool owned) { - return String.Format ("({0}) global::Java.Lang.Object.GetObject<{3}> ({1}, {2})", type, varname, owned ? "JniHandleOwnership.TransferLocalRef" : "JniHandleOwnership.DoNotTransfer", opt.GetOutputName (FullName)); + return String.Format ("({0}{4}) global::Java.Lang.Object.GetObject<{3}> ({1}, {2})", type, varname, owned ? "JniHandleOwnership.TransferLocalRef" : "JniHandleOwnership.DoNotTransfer", opt.GetOutputName (FullName), opt.NullableOperator); } public string GetGenericType (Dictionary mappings)