public InterfaceEventHandlerImplClass(InterfaceGen iface, CodeGenerationOptions opt, CodeGeneratorContext context)
        {
            var jni_class = "mono/" + iface.RawJniName.Replace('$', '_') + "Implementor";

            Name     = iface.Name + "Implementor";
            Inherits = "global::Java.Lang.Object";
            Implements.Add(iface.Name);

            IsInternal = true;
            IsSealed   = true;
            IsPartial  = true;

            Attributes.Add(new RegisterAttr(jni_class, additionalProperties: iface.AdditionalAttributeString())
            {
                UseGlobal = true
            });

            if (iface.NeedsSender)
            {
                Fields.Add(new FieldWriter {
                    Name = "sender", Type = TypeReferenceWriter.Object
                });
            }

            AddConstructor(iface, jni_class, opt);
            AddMethods(iface, opt);
        }
        // Historically .NET has not allowed interface implemented fields or constants, so we
        // initially worked around that by moving them to an abstract class, generally
        // IMyInterface -> MyInterfaceConsts
        // This was later expanded to accomodate static interface methods, creating a more appropriately named class
        // IMyInterface -> MyInterface
        // In this case the XXXConsts class is [Obsolete]'d and simply inherits from the newer class
        // in order to maintain backward compatibility.
        // If we're creating a binding that supports DIM, we remove the XXXConsts class as they've been
        // [Obsolete:iserror] for a long time, and we add [Obsolete] to the interface "class".
        public InterfaceMemberAlternativeClass(InterfaceGen iface, CodeGenerationOptions opt, CodeGeneratorContext context)
        {
            var should_obsolete = opt.SupportInterfaceConstants && opt.SupportDefaultInterfaceMethods;

            Name = iface.HasManagedName
                                ? iface.Name.Substring(1) + "Consts"
                                : iface.Name.Substring(1);

            Inherits = "Java.Lang.Object";

            IsPublic   = true;
            IsAbstract = true;

            UsePriorityOrder = true;

            SourceWriterExtensions.AddSupportedOSPlatform(Attributes, iface, opt);

            Attributes.Add(new RegisterAttr(iface.RawJniName, noAcw: true, additionalProperties: iface.AdditionalAttributeString())
            {
                AcwLast = true
            });

            if (should_obsolete)
            {
                Attributes.Add(new ObsoleteAttr($"Use the '{iface.FullName}' type. This class will be removed in a future release.")
                {
                    WriteGlobal = true, NoAtSign = true
                });
            }

            Constructors.Add(new ConstructorWriter {
                Name = Name, IsInternal = true
            });

            var needs_class_ref = AddFields(iface, should_obsolete, opt, context);

            AddMethods(iface, should_obsolete, opt);

            if (needs_class_ref || iface.Methods.Where(m => m.IsStatic).Any())
            {
                Fields.Add(new PeerMembersField(opt, iface.RawJniName, Name, false));
            }

            if (!iface.HasManagedName && !opt.SupportInterfaceConstants)
            {
                sibling_classes.Add(new InterfaceConstsForwardClass(iface));
            }
        }
        public InterfaceConstsForwardClass(InterfaceGen iface)
        {
            Name     = iface.Name.Substring(1) + "Consts";
            Inherits = iface.Name.Substring(1);

            IsPublic   = true;
            IsAbstract = true;

            Attributes.Add(new RegisterAttr(iface.RawJniName, noAcw: true, additionalProperties: iface.AdditionalAttributeString()));
            Attributes.Add(new ObsoleteAttr($"Use the '{iface.Name.Substring (1)}' type. This type will be removed in a future release.", true)
            {
                NoAtSign = true, WriteGlobal = true
            });

            Constructors.Add(new ConstructorWriter {
                Name      = Name,
                IsPrivate = true
            });
        }
Beispiel #4
0
        public BoundInterface(InterfaceGen iface, CodeGenerationOptions opt, CodeGeneratorContext context, GenerationInfo genInfo)
        {
            context.ContextTypes.Push(iface);

            Name = iface.Name;

            AddNestedSiblingTypes(iface, opt, context, genInfo);
            AddAlternativesClass(iface, opt, context);

            // If this interface is just fields and we can't generate any of them
            // then we don't need to write the interface.  We still keep this type
            // because it may have nested types or need an InterfaceMemberAlternativeClass.
            if (iface.IsConstSugar(opt) && iface.GetGeneratableFields(opt).Count() == 0)
            {
                dont_generate = true;
                return;
            }

            IsPartial = true;

            UsePriorityOrder = true;

            SetVisibility(iface.Visibility);

            iface.JavadocInfo?.AddJavadocs(Comments);
            Comments.Add($"// Metadata.xml XPath interface reference: path=\"{iface.MetadataXPathReference}\"");

            if (iface.IsDeprecated)
            {
                Attributes.Add(new ObsoleteAttr(iface.DeprecatedComment)
                {
                    WriteAttributeSuffix = true, WriteEmptyString = true
                });
            }

            if (!iface.IsConstSugar(opt))
            {
                var signature = string.IsNullOrWhiteSpace(iface.Namespace)
                                        ? iface.FullName.Replace('.', '/')
                                        : iface.Namespace + "." + iface.FullName.Substring(iface.Namespace.Length + 1).Replace('.', '/');

                if (opt.CodeGenerationTarget == CodeGenerationTarget.JavaInterop1)
                {
                    Attributes.Add(new JniTypeSignatureAttr(iface.RawJniName, false));
                }
                else
                {
                    Attributes.Add(new RegisterAttr(iface.RawJniName, string.Empty, signature + "Invoker", additionalProperties: iface.AdditionalAttributeString()));
                }
            }

            if (iface.TypeParameters != null && iface.TypeParameters.Any())
            {
                Attributes.Add(new CustomAttr(iface.TypeParameters.ToGeneratedAttributeString()));
            }

            AddInheritedInterfaces(iface, opt);

            AddClassHandle(iface, opt);
            AddFields(iface, opt, context);
            AddProperties(iface, opt);
            AddMethods(iface, opt);
            AddNestedTypes(iface, opt, context, genInfo);

            // If this interface is just constant fields we don't need to add all the invoker bits
            if (iface.IsConstSugar(opt))
            {
                return;
            }

            if (!iface.AssemblyQualifiedName.Contains('/'))
            {
                if (iface.Methods.Any(m => m.CanHaveStringOverload) || iface.Methods.Any(m => m.Asyncify))
                {
                    post_sibling_types.Add(new InterfaceExtensionsClass(iface, null, opt));
                }
            }

            if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1)
            {
                // Worry about later; https://github.com/xamarin/java.interop/issues/910
                post_sibling_types.Add(new InterfaceInvokerClass(iface, opt, context));
            }

            AddInterfaceEventHandler(iface, opt, context);

            context.ContextTypes.Pop();
        }
Beispiel #5
0
        public InterfaceInvokerClass(InterfaceGen iface, CodeGenerationOptions opt, CodeGeneratorContext context)
        {
            Name = $"{iface.Name}Invoker";

            IsInternal       = true;
            IsPartial        = true;
            UsePriorityOrder = true;

            Inherits = "global::Java.Lang.Object";
            Implements.Add(iface.Name);

            Attributes.Add(new RegisterAttr(iface.RawJniName, noAcw: true, additionalProperties: iface.AdditionalAttributeString())
            {
                UseGlobal = true
            });

            Fields.Add(new PeerMembersField(opt, iface.RawJniName, $"{iface.Name}Invoker", false));

            Properties.Add(new InterfaceHandleGetter());
            Properties.Add(new JniPeerMembersGetter());
            Properties.Add(new InterfaceThresholdClassGetter());
            Properties.Add(new ThresholdTypeGetter());

            Fields.Add(new FieldWriter {
                Name = "class_ref", Type = TypeReferenceWriter.IntPtr, IsShadow = opt.BuildingCoreAssembly
            });

            Methods.Add(new GetObjectMethod(iface, opt));
            Methods.Add(new ValidateMethod(iface));
            Methods.Add(new DisposeMethod());

            Constructors.Add(new InterfaceInvokerConstructor(iface, context));

            AddMemberInvokers(iface, new HashSet <string> (), opt, context);
        }