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 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;
            }
        }
Esempio n. 3
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()));
                }
            }
        }
Esempio n. 4
0
        public BoundProperty(GenBase gen, Property property, CodeGenerationOptions opt, bool withCallbacks = true, bool forceOverride = false)
        {
            Name         = property.AdjustedName;
            PropertyType = new TypeReferenceWriter(opt.GetTypeReferenceName(property.Getter.RetVal));

            SetVisibility(gen is InterfaceGen ? string.Empty : property.Getter.IsAbstract && property.Getter.RetVal.IsGeneric ? "protected" : (property.Setter ?? property.Getter).Visibility);

            IsUnsafe = true;
            HasGet   = true;

            var is_virtual = property.Getter.IsVirtual && (property.Setter == null || property.Setter.IsVirtual);

            if (is_virtual && withCallbacks)
            {
                IsVirtual = true;
                IsShadow  = gen.RequiresNew(property);

                if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1)
                {
                    getter_callback = new MethodCallback(gen, property.Getter, opt, property.AdjustedName, false);
                }

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

            if (forceOverride || ShouldForceOverride(property))
            {
                IsVirtual  = false;
                IsOverride = true;
            }

            if ((property.Getter ?? property.Setter).IsStatic)
            {
                IsStatic   = true;
                IsVirtual  = false;
                IsOverride = false;
            }
            else if (gen.BaseSymbol != null)
            {
                // It should be using AdjustedName instead of Name, but ICharSequence ("Formatted") properties are not caught by this...
                var base_prop = gen.BaseSymbol.GetPropertyByName(property.Name, true);

                // If the matching base getter we found is a DIM, we do not override it, it should stay virtual
                if (base_prop != null && !base_prop.Getter.IsInterfaceDefaultMethod)
                {
                    IsVirtual  = false;
                    IsOverride = true;
                }
            }

            // Allow user to override our virtual/override logic
            if (!forceOverride && (property.Getter ?? property.Setter).ManagedOverride?.ToLowerInvariant() == "virtual")
            {
                IsVirtual  = true;
                IsOverride = false;
            }
            else if (!forceOverride && (property.Getter ?? property.Setter).ManagedOverride?.ToLowerInvariant() == "override")
            {
                IsVirtual  = false;
                IsOverride = true;
            }

            // Unlike [Register], [Obsolete] cannot be put on property accessors, so we can apply them only under limited condition...
            if (property.Getter.Deprecated != null && (property.Setter == null || property.Setter.Deprecated != null))
            {
                Attributes.Add(new ObsoleteAttr(property.Getter.Deprecated.Replace("\"", "\"\"").Trim() + (property.Setter != null && property.Setter.Deprecated != property.Getter.Deprecated ? " " + property.Setter.Deprecated.Replace("\"", "\"\"").Trim() : null)));
            }

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

            SourceWriterExtensions.AddMethodCustomAttributes(GetterAttributes, property.Getter);

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

            if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1)
            {
                GetterAttributes.Add(new RegisterAttr(property.Getter.JavaName, property.Getter.JniSignature, property.Getter.IsVirtual ? property.Getter.GetConnectorNameFull(opt) : string.Empty, additionalProperties: property.Getter.AdditionalAttributeString()));
            }

            SourceWriterExtensions.AddMethodBody(GetBody, property.Getter, opt);

            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);
                if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1)
                {
                    SetterAttributes.Add(new RegisterAttr(property.Setter.JavaName, property.Setter.JniSignature, property.Setter.IsVirtual ? property.Setter.GetConnectorNameFull(opt) : string.Empty, additionalProperties: property.Setter.AdditionalAttributeString()));
                }

                var pname = property.Setter.Parameters [0].Name;
                property.Setter.Parameters [0].Name = "value";
                SourceWriterExtensions.AddMethodBody(SetBody, property.Setter, opt);
                property.Setter.Parameters [0].Name = pname;
            }
            else if (property.GenerateDispatchingSetter)
            {
                HasSet = true;
                SetterComments.Add("// This is a dispatching setter");
                SetBody.Add($"Set{property.Name} (value);");
            }

            AddJavadocs(property);
        }