Exemple #1
0
        public BoundInterfaceMethodDeclaration(Method method, string adapter, CodeGenerationOptions opt)
        {
            this.method = method;
            this.opt    = opt;

            Name          = method.AdjustedName;
            ReturnType    = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal));
            IsDeclaration = true;

            if (method.DeclaringType.IsGeneratable)
            {
                Comments.Add($"// Metadata.xml XPath method reference: path=\"{method.GetMetadataXPathReference (method.DeclaringType)}\"");
            }
            if (method.Deprecated != null)
            {
                Attributes.Add(new ObsoleteAttr(method.Deprecated.Replace("\"", "\"\"")));
            }
            if (method.IsReturnEnumified)
            {
                Attributes.Add(new GeneratedEnumAttr(true));
            }
            if (method.IsInterfaceDefaultMethod)
            {
                Attributes.Add(new CustomAttr("[global::Java.Interop.JavaInterfaceDefaultMethod]"));
            }

            Attributes.Add(new RegisterAttr(method.JavaName, method.JniSignature, method.ConnectorName + ":" + method.GetAdapterName(opt, adapter), additionalProperties: method.AdditionalAttributeString()));

            SourceWriterExtensions.AddMethodCustomAttributes(Attributes, method);
            this.AddMethodParameters(method.Parameters, opt);
        }
Exemple #2
0
        public MethodExtensionAsyncWrapper(Method method, CodeGenerationOptions opt, string selfType)
        {
            Name     = method.AdjustedName + "Async";
            IsStatic = true;

            SetVisibility(method.Visibility);

            ReturnType = new TypeReferenceWriter("global::System.Threading.Tasks.Task");

            if (!method.IsVoid)
            {
                ReturnType.Name += "<" + opt.GetTypeReferenceName(method.RetVal) + ">";
            }

            SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt);

            Body.Add($"return global::System.Threading.Tasks.Task.Run (() => self.{method.AdjustedName} ({method.Parameters.GetCall (opt)}));");

            Parameters.Add(new MethodParameterWriter("self", new TypeReferenceWriter(selfType))
            {
                IsExtension = true
            });

            this.AddMethodParameters(method.Parameters, opt);
        }
Exemple #3
0
        public InterfaceListenerProperty(InterfaceGen iface, string name, string nameSpec, string methodName, string fullDelegateName, CodeGenerationOptions opt)
        {
            Name         = name;
            PropertyType = new TypeReferenceWriter(opt.GetOutputName(fullDelegateName))
            {
                Nullable = opt.SupportNullableReferenceTypes
            };

            IsPublic = true;

            HasGet = true;

            var handlerPrefix = iface.Methods.Count > 1 ? methodName : string.Empty;

            GetBody.Add($"{opt.GetOutputName (iface.FullName)}Implementor{opt.NullableOperator} impl = Impl{name};");
            GetBody.Add($"return impl == null ? null : impl.{handlerPrefix}Handler;");

            HasSet = true;

            SetBody.Add($"{opt.GetOutputName (iface.FullName)}Implementor{opt.NullableOperator} impl = Impl{name};");
            SetBody.Add($"if (impl == null) {{");
            SetBody.Add($"\timpl = new {opt.GetOutputName (iface.FullName)}Implementor ({(iface.NeedsSender ? "this" : string.Empty)});");
            SetBody.Add($"\tImpl{name} = impl;");
            SetBody.Add($"}} else");
            SetBody.Add($"impl.{nameSpec}Handler = value;");
        }
        // static sbyte n_ByteValueExact (IntPtr jnienv, IntPtr native__this)
        // {
        //  var __this = global::Java.Lang.Object.GetObject<Android.Icu.Math.BigDecimal> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
        //  return __this.ByteValueExact ();
        // }
        public MethodCallback(GenBase type, Method method, CodeGenerationOptions options, string propertyName, bool isFormatted)
        {
            this.type   = type;
            this.method = method;

            property_name = propertyName;
            is_formatted  = isFormatted;
            opt           = options;

            delegate_field  = new MethodCallbackDelegateField(method, options);
            delegate_getter = new GetDelegateHandlerMethod(method, options);

            Name       = "n_" + method.Name + method.IDSignature;
            ReturnType = new TypeReferenceWriter(method.RetVal.NativeType);

            IsStatic  = true;
            IsPrivate = method.IsInterfaceDefaultMethod;

            if (!string.IsNullOrWhiteSpace(method.Deprecated))
            {
                Attributes.Add(new ObsoleteAttr());
            }

            SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt);

            Parameters.Add(new MethodParameterWriter("jnienv", TypeReferenceWriter.IntPtr));
            Parameters.Add(new MethodParameterWriter("native__this", TypeReferenceWriter.IntPtr));

            foreach (var p in method.Parameters)
            {
                Parameters.Add(new MethodParameterWriter(options.GetSafeIdentifier(p.UnsafeNativeName), new TypeReferenceWriter(p.NativeType)));
            }
        }
        public InterfaceInvokerProperty(InterfaceGen iface, Property property, CodeGenerationOptions opt, CodeGeneratorContext context)
        {
            this.property = property;
            this.opt      = opt;

            Name         = property.AdjustedName;
            PropertyType = new TypeReferenceWriter(opt.GetTypeReferenceName(property));

            IsPublic = true;
            IsUnsafe = true;

            HasGet = property.Getter != null;

            if (property.Getter != null)
            {
                HasGet          = true;
                getter_callback = new MethodCallback(iface, property.Getter, opt, property.AdjustedName, false);
            }

            if (property.Setter != null)
            {
                HasSet          = true;
                setter_callback = new MethodCallback(iface, property.Setter, opt, property.AdjustedName, false);
            }

            context_this = context.ContextType.GetObjectHandleProperty("this");
        }
        // System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
        // {
        //  return GetEnumerator ();
        // }
        public CharSequenceEnumeratorMethod()
        {
            Name       = "System.Collections.IEnumerable.GetEnumerator";
            ReturnType = new TypeReferenceWriter("System.Collections.IEnumerator");

            Body.Add("return GetEnumerator ();");
        }
Exemple #7
0
        // // Metadata.xml XPath field reference: path="/api/package[@name='android.os']/class[@name='Vibrator']/field[@name='VIBRATION_EFFECT_SUPPORT_UNKNOWN']"
        // [Register ("VIBRATION_EFFECT_SUPPORT_UNKNOWN", ApiSince = 30)]
        // [Obsolete ("This constant will be removed in the future version. Use Android.OS.VibrationEffectSupport enum directly instead of this field.", error: true)]
        // public const Android.OS.VibrationEffectSupport VibrationEffectSupportUnknown = (Android.OS.VibrationEffectSupport) 0;
        public BoundField(GenBase type, Field field, CodeGenerationOptions opt)
        {
            Name = field.Name;
            Type = new TypeReferenceWriter(opt.GetOutputName(field.Symbol.FullName));

            Comments.Add($"// Metadata.xml XPath field reference: path=\"{type.MetadataXPathReference}/field[@name='{field.JavaName}']\"");

            Attributes.Add(new RegisterAttr(field.JavaName, additionalProperties: field.AdditionalAttributeString()));

            if (field.IsEnumified)
            {
                Attributes.Add(new GeneratedEnumAttr());
            }
            if (field.IsDeprecated)
            {
                Attributes.Add(new ObsoleteAttr(field.DeprecatedComment, field.IsDeprecatedError)
                {
                    NoAtSign = true, WriteEmptyString = true
                });
            }
            if (field.Annotation.HasValue())
            {
                Attributes.Add(new CustomAttr(field.Annotation));
            }

            SetVisibility(field.Visibility);
            IsConst = true;

            // the Value complication is due to constant enum from negative integer value (C# compiler requires explicit parenthesis).
            Value = $"({opt.GetOutputName (field.Symbol.FullName)}) {(field.Value.Contains ('-') && field.Symbol.FullName.Contains ('.') ? '(' + field.Value + ')' : field.Value)}";
        }
        public BoundMethodExtensionStringOverload(Method method, CodeGenerationOptions opt, string selfType)
        {
            this.method = method;
            this.opt    = opt;
            self_type   = selfType;

            Name     = method.Name;
            IsStatic = true;

            SetVisibility(method.Visibility);
            ReturnType = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal).Replace("Java.Lang.ICharSequence", "string").Replace("global::string", "string"));

            if (method.Deprecated != null)
            {
                Attributes.Add(new ObsoleteAttr(method.Deprecated.Replace("\"", "\"\"").Trim()));
            }

            SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt);

            Parameters.Add(new MethodParameterWriter("self", new TypeReferenceWriter(selfType))
            {
                IsExtension = true
            });
            this.AddMethodParametersStringOverloads(method.Parameters, opt);
        }
Exemple #9
0
        public InterfaceListenerEvent(InterfaceGen iface, Method method, string name, string nameSpec, string fullDelegateName, string wrefSuffix, string add, string remove, bool hasHandlerArgument, CodeGenerationOptions opt)
        {
            Name      = name;
            EventType = new TypeReferenceWriter(opt.GetOutputName(fullDelegateName));

            IsPublic = true;

            SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt);

            HasAdd = true;

            AddBody.Add($"global::Java.Interop.EventHelper.AddEventHandler<{opt.GetOutputName (iface.FullName)}, {opt.GetOutputName (iface.FullName)}Implementor>(");
            AddBody.Add($"ref weak_implementor_{wrefSuffix},");
            AddBody.Add($"__Create{iface.Name}Implementor,");
            AddBody.Add($"{add + (hasHandlerArgument ? "_Event_With_Handler_Helper" : null)},");
            AddBody.Add($"__h => __h.{nameSpec}Handler += value);");

            HasRemove = true;

            RemoveBody.Add($"global::Java.Interop.EventHelper.RemoveEventHandler<{opt.GetOutputName (iface.FullName)}, {opt.GetOutputName (iface.FullName)}Implementor>(");
            RemoveBody.Add($"ref weak_implementor_{wrefSuffix},");
            RemoveBody.Add($"{opt.GetOutputName (iface.FullName)}Implementor.__IsEmpty,");
            RemoveBody.Add($"{remove},");
            RemoveBody.Add($"__h => __h.{nameSpec}Handler -= value);");

            if (hasHandlerArgument)
            {
                helper_method = new InterfaceListenerEventHandlerHelper(iface, method, add, opt);
            }
        }
 public WeakImplementorField(string name, CodeGenerationOptions opt)
 {
     Name = "weak_implementor_" + name;
     Type = new TypeReferenceWriter(opt.GetOutputName("WeakReference"))
     {
         Nullable = opt.SupportNullableReferenceTypes
     };
 }
Exemple #11
0
        public CreateImplementorMethod(InterfaceGen iface, CodeGenerationOptions opt)
        {
            Name = $"__Create{iface.Name}Implementor";

            ReturnType = new TypeReferenceWriter($"{opt.GetOutputName (iface.FullName)}Implementor");

            Body.Add($"return new {opt.GetOutputName (iface.FullName)}Implementor ({(iface.NeedsSender ? "this" : "")});");
        }
        public BoundAbstractProperty(GenBase gen, Property property, CodeGenerationOptions opt)
        {
            Name         = property.AdjustedName;
            PropertyType = new TypeReferenceWriter(opt.GetTypeReferenceName(property.Getter.RetVal));

            SetVisibility(property.Getter.RetVal.IsGeneric ? "protected" : property.Getter.Visibility);

            IsAbstract = true;
            HasGet     = true;

            var baseProp = gen.BaseSymbol != null?gen.BaseSymbol.GetPropertyByName(property.Name, true) : null;

            if (baseProp != null)
            {
                IsOverride = true;
            }
            else
            {
                IsShadow = gen.RequiresNew(property);

                getter_callback = new MethodCallback(gen, property.Getter, opt, property.AdjustedName, false);

                if (property.Setter != null)
                {
                    setter_callback = new MethodCallback(gen, property.Setter, opt, property.AdjustedName, false);
                }
            }

            if (gen.IsGeneratable)
            {
                GetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.MetadataXPathReference}/method[@name='{property.Getter.JavaName}'{property.Getter.Parameters.GetMethodXPathPredicate ()}]\"");
            }
            if (property.Getter.IsReturnEnumified)
            {
                GetterAttributes.Add(new GeneratedEnumAttr(true));
            }

            SourceWriterExtensions.AddSupportedOSPlatform(GetterAttributes, property.Getter, opt);

            GetterAttributes.Add(new RegisterAttr(property.Getter.JavaName, property.Getter.JniSignature, property.Getter.GetConnectorNameFull(opt), additionalProperties: property.Getter.AdditionalAttributeString()));

            SourceWriterExtensions.AddMethodCustomAttributes(GetterAttributes, property.Getter);

            if (property.Setter != null)
            {
                HasSet = true;

                if (gen.IsGeneratable)
                {
                    SetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.MetadataXPathReference}/method[@name='{property.Setter.JavaName}'{property.Setter.Parameters.GetMethodXPathPredicate ()}]\"");
                }

                SourceWriterExtensions.AddSupportedOSPlatform(SetterAttributes, property.Setter, opt);

                SourceWriterExtensions.AddMethodCustomAttributes(SetterAttributes, property.Setter);
                SetterAttributes.Add(new RegisterAttr(property.Setter.JavaName, property.Setter.JniSignature, property.Setter.GetConnectorNameFull(opt), additionalProperties: property.Setter.AdditionalAttributeString()));
            }
        }
        // public System.Collections.Generic.IEnumerator<char> GetEnumerator ()
        // {
        //  for (int i = 0; i < Length(); i++)
        //      yield return CharAt (i);
        // }
        public CharSequenceGenericEnumeratorMethod()
        {
            Name       = "GetEnumerator";
            ReturnType = new TypeReferenceWriter("System.Collections.Generic.IEnumerator<char>");

            IsPublic = true;

            Body.Add("for (int i = 0; i < Length (); i++)");
            Body.Add("\tyield return CharAt (i);");
        }
        public void NotNull()
        {
            var t = new TypeReferenceWriter("string");

            var sw = new StringWriter();
            var cw = new CodeWriter(sw);

            t.WriteTypeReference(cw);

            Assert.AreEqual("string ", sw.ToString());
        }
        public GenericExplicitInterfaceImplementationProperty(Property property, GenericSymbol gen, string adapter, Dictionary <string, string> mappings, CodeGenerationOptions opt)
        {
            Name = property.AdjustedName;

            PropertyType = new TypeReferenceWriter(opt.GetTypeReferenceName(property));
            ExplicitInterfaceImplementation = opt.GetOutputName(gen.Gen.FullName);

            Comments.Add($"// This method is explicitly implemented as a member of an instantiated {gen.FullName}");

            if (property.Getter != null)
            {
                HasGet = true;

                if (gen.Gen.IsGeneratable)
                {
                    GetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.Gen.MetadataXPathReference}/method[@name='{property.Getter.JavaName}'{property.Getter.Parameters.GetMethodXPathPredicate ()}]\"");
                }
                if (property.Getter.GenericArguments != null && property.Getter.GenericArguments.Any())
                {
                    GetterAttributes.Add(new CustomAttr(property.Getter.GenericArguments.ToGeneratedAttributeString()));
                }

                SourceWriterExtensions.AddSupportedOSPlatform(GetterAttributes, property.Getter, opt);

                GetterAttributes.Add(new RegisterAttr(property.Getter.JavaName, property.Getter.JniSignature, property.Getter.ConnectorName + ":" + property.Getter.GetAdapterName(opt, adapter), additionalProperties: property.Getter.AdditionalAttributeString()));

                GetBody.Add($"return {property.Name};");
            }

            if (property.Setter != null)
            {
                HasSet = true;

                if (gen.Gen.IsGeneratable)
                {
                    SetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.Gen.MetadataXPathReference}/method[@name='{property.Setter.JavaName}'{property.Setter.Parameters.GetMethodXPathPredicate ()}]\"");
                }
                if (property.Setter.GenericArguments != null && property.Setter.GenericArguments.Any())
                {
                    SetterAttributes.Add(new CustomAttr(property.Setter.GenericArguments.ToGeneratedAttributeString()));
                }

                SourceWriterExtensions.AddSupportedOSPlatform(SetterAttributes, property.Setter, opt);

                SetterAttributes.Add(new RegisterAttr(property.Setter.JavaName, property.Setter.JniSignature, property.Setter.ConnectorName + ":" + property.Setter.GetAdapterName(opt, adapter), additionalProperties: property.Setter.AdditionalAttributeString()));

                // Temporarily rename the parameter to "value"
                var pname = property.Setter.Parameters [0].Name;
                property.Setter.Parameters [0].Name = "value";
                SetBody.Add($"{property.Name} = {property.Setter.Parameters.GetGenericCall (opt, mappings)};");
                property.Setter.Parameters [0].Name = pname;
            }
        }
        // static readonly JniPeerMembers _members = new XAPeerMembers ("android/provider/ContactsContract$AggregationExceptions", typeof (AggregationExceptions));
        public PeerMembersField(CodeGenerationOptions opt, string rawJniType, string declaringType, bool isInterface)
        {
            Name = "_members";
            Type = new TypeReferenceWriter("JniPeerMembers");

            IsPrivate  = isInterface;
            IsStatic   = true;
            IsReadonly = true;

            var peer = opt.CodeGenerationTarget == Xamarin.Android.Binder.CodeGenerationTarget.XAJavaInterop1 ? "XAPeerMembers" : "JniPeerMembers";

            Value = $"new {peer} (\"{rawJniType}\", typeof ({declaringType}){(isInterface ? ", isInterface: true" : string.Empty)})";
        }
        public void Nullable()
        {
            var t = new TypeReferenceWriter("string")
            {
                Nullable = true
            };

            var sw = new StringWriter();
            var cw = new CodeWriter(sw);

            t.WriteTypeReference(cw);

            Assert.AreEqual("string? ", sw.ToString());
        }
        // [DebuggerBrowsable (DebuggerBrowsableState.Never)]
        // [EditorBrowsable (EditorBrowsableState.Never)]
        // public override global::Java.Interop.JniPeerMembers JniPeerMembers {
        //   get { return _members; }
        // }
        public JniPeerMembersGetter()
        {
            Name         = "JniPeerMembers";
            PropertyType = new TypeReferenceWriter("global::Java.Interop.JniPeerMembers");

            IsPublic   = true;
            IsOverride = true;

            Attributes.Add(new DebuggerBrowsableAttr());
            Attributes.Add(new EditorBrowsableAttr());

            HasGet = true;
            GetBody.Add("return _members;");
        }
        public MethodExplicitInterfaceImplementation(GenBase iface, Method method, CodeGenerationOptions opt)
        {
            this.method = method;
            this.opt    = opt;

            Name = method.Name;

            ReturnType = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal));
            ExplicitInterfaceImplementation = opt.GetOutputName(iface.FullName);

            SourceWriterExtensions.AddMethodCustomAttributes(Attributes, method);

            this.AddMethodParameters(method.Parameters, opt);
        }
        // [DebuggerBrowsable (DebuggerBrowsableState.Never)]
        // [EditorBrowsable (EditorBrowsableState.Never)]
        // protected override global::System.Type ThresholdType {
        //  get { return _members.ManagedPeerType; }
        // }
        public ThresholdTypeGetter()
        {
            Name         = "ThresholdType";
            PropertyType = new TypeReferenceWriter("global::System.Type");

            IsProtected = true;
            IsOverride  = true;

            Attributes.Add(new DebuggerBrowsableAttr());
            Attributes.Add(new EditorBrowsableAttr());

            HasGet = true;
            GetBody.Add("return _members.ManagedPeerType;");
        }
        public BoundMethodAbstractDeclaration(GenBase gen, Method method, CodeGenerationOptions opt, GenBase impl)
        {
            this.method = method;
            this.opt    = opt;

            ReturnType = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal));
            this.AddMethodParameters(method.Parameters, opt);

            if (method.RetVal.IsGeneric && gen != null)
            {
                Name = method.Name;
                ExplicitInterfaceImplementation = opt.GetOutputName(gen.FullName);

                SourceWriterExtensions.AddMethodCustomAttributes(Attributes, method);

                Body.Add("throw new NotImplementedException ();");

                return;
            }

            Name = method.AdjustedName;

            IsAbstract = true;
            IsShadow   = impl.RequiresNew(method.Name, method);
            SetVisibility(method.Visibility);

            NewFirst = true;

            if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1)
            {
                method_callback = new MethodCallback(impl, method, opt, null, method.IsReturnCharSequence);
            }

            method.JavadocInfo?.AddJavadocs(Comments);

            if (method.DeclaringType.IsGeneratable)
            {
                Comments.Add($"// Metadata.xml XPath method reference: path=\"{method.GetMetadataXPathReference (method.DeclaringType)}\"");
            }

            SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt);

            if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1)
            {
                Attributes.Add(new RegisterAttr(method.JavaName, method.JniSignature, method.ConnectorName, additionalProperties: method.AdditionalAttributeString()));
            }

            SourceWriterExtensions.AddMethodCustomAttributes(Attributes, method);
        }
Exemple #22
0
        public BoundInterfacePropertyDeclaration(GenBase gen, Property property, string adapter, CodeGenerationOptions opt)
        {
            Name = property.AdjustedName;

            PropertyType   = new TypeReferenceWriter(opt.GetTypeReferenceName(property));
            IsAutoProperty = true;

            if (property.Getter != null)
            {
                HasGet = true;

                if (gen.IsGeneratable)
                {
                    GetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.MetadataXPathReference}/method[@name='{property.Getter.JavaName}'{property.Getter.Parameters.GetMethodXPathPredicate ()}]\"");
                }
                if (property.Getter.GenericArguments?.Any() == true)
                {
                    GetterAttributes.Add(new CustomAttr(property.Getter.GenericArguments.ToGeneratedAttributeString()));
                }

                SourceWriterExtensions.AddSupportedOSPlatform(GetterAttributes, property.Getter, opt);

                if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1)
                {
                    GetterAttributes.Add(new RegisterAttr(property.Getter.JavaName, property.Getter.JniSignature, property.Getter.ConnectorName + ":" + property.Getter.GetAdapterName(opt, adapter), additionalProperties: property.Getter.AdditionalAttributeString()));
                }
            }

            if (property.Setter != null)
            {
                HasSet = true;

                if (gen.IsGeneratable)
                {
                    SetterComments.Add($"// Metadata.xml XPath method reference: path=\"{gen.MetadataXPathReference}/method[@name='{property.Setter.JavaName}'{property.Setter.Parameters.GetMethodXPathPredicate ()}]\"");
                }
                if (property.Setter.GenericArguments?.Any() == true)
                {
                    SetterAttributes.Add(new CustomAttr(property.Setter.GenericArguments.ToGeneratedAttributeString()));
                }

                SourceWriterExtensions.AddSupportedOSPlatform(SetterAttributes, property.Setter, opt);

                if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1)
                {
                    SetterAttributes.Add(new RegisterAttr(property.Setter.JavaName, property.Setter.JniSignature, property.Setter.ConnectorName + ":" + property.Setter.GetAdapterName(opt, adapter), additionalProperties: property.Setter.AdditionalAttributeString()));
                }
            }
        }
        public ExplicitInterfaceInvokerMethod(GenBase iface, Method method, CodeGenerationOptions opt)
        {
            this.method = method;
            this.opt    = opt;

            Name = method.Name;

            IsUnsafe = true;

            ReturnType = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal));
            ExplicitInterfaceImplementation = opt.GetOutputName(iface.FullName);

            this.AddMethodParameters(method.Parameters, opt);
            SourceWriterExtensions.AddMethodBody(Body, method, opt);
        }
Exemple #24
0
        public GenericExplicitInterfaceImplementationMethod(Method method, GenericSymbol gen, CodeGenerationOptions opt)
        {
            this.method = method;
            this.opt    = opt;
            this.gen    = gen;

            Name = method.Name;

            ReturnType = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal));
            ExplicitInterfaceImplementation = opt.GetOutputName(gen.Gen.FullName);

            Comments.Add($"// This method is explicitly implemented as a member of an instantiated {gen.FullName}");

            SourceWriterExtensions.AddMethodCustomAttributes(Attributes, method);
            this.AddMethodParameters(method.Parameters, opt);
        }
Exemple #25
0
        public InterfaceInvokerMethod(InterfaceGen iface, Method method, CodeGenerationOptions opt, CodeGeneratorContext context)
        {
            this.method = method;
            this.opt    = opt;

            Name       = method.AdjustedName;
            ReturnType = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal));

            IsPublic = true;
            IsUnsafe = true;
            IsStatic = method.IsStatic;

            method_callback = new MethodCallback(iface, method, opt, null, method.IsReturnCharSequence);
            context_this    = context.ContextType.GetObjectHandleProperty("this");

            this.AddMethodParameters(method.Parameters, opt);
        }
Exemple #26
0
        // public static IInterface? GetObject (IntPtr handle, JniHandleOwnership transfer)
        // {
        //     return global::Java.Lang.Object.GetObject<IInterface> (handle, transfer);
        // }
        public GetObjectMethod(InterfaceGen iface, CodeGenerationOptions opt)
        {
            Name = "GetObject";

            ReturnType = new TypeReferenceWriter(iface.Name)
            {
                Nullable = opt.SupportNullableReferenceTypes
            };

            IsPublic = true;
            IsStatic = true;

            Parameters.Add(new MethodParameterWriter("handle", TypeReferenceWriter.IntPtr));
            Parameters.Add(new MethodParameterWriter("transfer", new TypeReferenceWriter("JniHandleOwnership")));

            Body.Add($"return global::Java.Lang.Object.GetObject<{iface.Name}> (handle, transfer);");
        }
        public void Constructor()
        {
            var t = new TypeReferenceWriter("String");

            Assert.AreEqual(null, t.Namespace);
            Assert.AreEqual("String", t.Name);

            t = new TypeReferenceWriter("System.String");

            Assert.AreEqual("System", t.Namespace);
            Assert.AreEqual("String", t.Name);

            t = new TypeReferenceWriter("System.Internal.String");

            Assert.AreEqual("System.Internal", t.Namespace);
            Assert.AreEqual("String", t.Name);
        }
Exemple #28
0
        public BoundPropertyStringVariant(Property property, CodeGenerationOptions opt)
        {
            var is_array = property.Getter.RetVal.IsArray;

            Name = property.Name;

            PropertyType = new TypeReferenceWriter("string" + (is_array ? "[]" : string.Empty))
            {
                Nullable = opt.SupportNullableReferenceTypes
            };

            SetVisibility((property.Setter ?? property.Getter).Visibility);

            SourceWriterExtensions.AddSupportedOSPlatform(Attributes, property.Getter, opt);

            HasGet = true;

            if (is_array)
            {
                GetBody.Add($"return CharSequence.ArrayToStringArray ({property.AdjustedName});");
            }
            else
            {
                GetBody.Add($"return {property.AdjustedName} == null ? null : {property.AdjustedName}.ToString ();");
            }

            if (property.Setter is null)
            {
                return;
            }

            HasSet = true;

            if (is_array)
            {
                SetBody.Add($"global::Java.Lang.ICharSequence[] jlsa = CharSequence.ArrayFromStringArray (value);");
                SetBody.Add($"{property.AdjustedName} = jlsa;");
                SetBody.Add($"foreach (var jls in jlsa) if (jls != null) jls.Dispose ();");
            }
            else
            {
                SetBody.Add($"var jls = value == null ? null : new global::Java.Lang.String (value);");
                SetBody.Add($"{property.AdjustedName} = jls;");
                SetBody.Add($"if (jls != null) jls.Dispose ();");
            }
        }
        public BoundFieldAsProperty(GenBase type, Field field, CodeGenerationOptions opt)
        {
            this.field = field;
            this.opt   = opt;

            Name = field.Name;

            var fieldType = field.Symbol.IsArray ? "IList<" + field.Symbol.ElementType + ">" + opt.NullableOperator : opt.GetTypeReferenceName(field);

            PropertyType = new TypeReferenceWriter(fieldType);

            field.JavadocInfo?.AddJavadocs(Comments);
            Comments.Add($"// Metadata.xml XPath field reference: path=\"{type.MetadataXPathReference}/field[@name='{field.JavaName}']\"");

            if (field.IsEnumified)
            {
                Attributes.Add(new GeneratedEnumAttr());
            }

            SourceWriterExtensions.AddSupportedOSPlatform(Attributes, field, opt);

            if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1)
            {
                Attributes.Add(new RegisterAttr(field.JavaName, additionalProperties: field.AdditionalAttributeString()));
            }

            if (field.IsDeprecated)
            {
                Attributes.Add(new ObsoleteAttr(field.DeprecatedComment, field.IsDeprecatedError)
                {
                    NoAtSign = true
                });
            }

            SetVisibility(field.Visibility);
            UseExplicitPrivateKeyword = true;

            IsStatic = field.IsStatic;

            HasGet = true;

            if (!field.IsConst)
            {
                HasSet = true;
            }
        }
        public BoundMethodStringOverload(Method method, CodeGenerationOptions opt)
        {
            this.method = method;
            this.opt    = opt;

            Name     = method.Name;
            IsStatic = method.IsStatic;

            SetVisibility(method.Visibility);
            ReturnType = new TypeReferenceWriter(opt.GetTypeReferenceName(method.RetVal).Replace("Java.Lang.ICharSequence", "string").Replace("global::string", "string"));

            if (method.Deprecated != null)
            {
                Attributes.Add(new ObsoleteAttr(method.Deprecated.Replace("\"", "\"\"").Trim()));
            }

            this.AddMethodParametersStringOverloads(method.Parameters, opt);
        }