Esempio n. 1
0
        void AddFields(InterfaceGen iface, CodeGenerationOptions opt, CodeGeneratorContext context)
        {
            // Interface fields are only supported with DIM
            if (!opt.SupportInterfaceConstants && !opt.SupportDefaultInterfaceMethods)
            {
                return;
            }

            var seen   = new HashSet <string> ();
            var fields = iface.GetGeneratableFields(opt).ToList();

            SourceWriterExtensions.AddFields(this, iface, fields, seen, opt, context);
        }
        public InterfaceConstsClass(ClassGen klass, HashSet <string> seen, CodeGenerationOptions opt, CodeGeneratorContext context)
        {
            Name = "InterfaceConsts";

            IsPublic = true;
            IsStatic = true;

            UsePriorityOrder = true;

            foreach (var iface in klass.GetAllImplementedInterfaces()
                     .Except(klass.BaseGen?.GetAllImplementedInterfaces() ?? new InterfaceGen [0])
                     .Where(i => i.Fields.Count > 0))
            {
                AddInlineComment($"// The following are fields from: {iface.JavaName}");

                SourceWriterExtensions.AddFields(this, iface, iface.Fields, seen, opt, context);
            }
        }
Esempio n. 3
0
        public BoundClass(ClassGen klass, CodeGenerationOptions opt, CodeGeneratorContext context, GenerationInfo generationInfo)
        {
            context.ContextTypes.Push(klass);
            context.ContextGeneratedMethods = new List <Method> ();

            generationInfo.TypeRegistrations.Add(new KeyValuePair <string, string> (klass.RawJniName, klass.AssemblyQualifiedName));

            var is_enum = klass.base_symbol != null && klass.base_symbol.FullName == "Java.Lang.Enum";

            if (is_enum)
            {
                generationInfo.Enums.Add(klass.RawJniName.Replace('/', '.') + ":" + klass.Namespace + ":" + klass.JavaSimpleName);
            }

            this.opt = opt;

            Name = klass.Name;

            SetVisibility(klass.Visibility);
            IsShadow   = klass.NeedsNew;
            IsAbstract = klass.IsAbstract;
            IsSealed   = klass.IsFinal;
            IsPartial  = true;

            UsePriorityOrder = true;

            AddImplementedInterfaces(klass);

            Comments.Add($"// Metadata.xml XPath class reference: path=\"{klass.MetadataXPathReference}\"");

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

            Attributes.Add(new RegisterAttr(klass.RawJniName, null, null, true, klass.AdditionalAttributeString())
            {
                UseGlobal = true, UseShortForm = true
            });

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

            // Figure out our base class
            string obj_type = null;

            if (klass.base_symbol != null)
            {
                obj_type = klass.base_symbol is GenericSymbol gs &&
                           gs.IsConcrete ? gs.GetGenericType(null) : opt.GetOutputName(klass.base_symbol.FullName);
            }

            if (klass.InheritsObject && obj_type != null)
            {
                Inherits = obj_type;
            }

            // Handle fields
            var seen = new HashSet <string> ();

            SourceWriterExtensions.AddFields(this, klass, klass.Fields, seen, opt, context);

            var ic = new InterfaceConstsClass(klass, seen, opt, context);

            if (ic.ShouldGenerate)
            {
                NestedTypes.Add(ic);
            }

            // Sibling classes
            if (!klass.AssemblyQualifiedName.Contains('/'))
            {
                foreach (InterfaceExtensionInfo nestedIface in klass.GetNestedInterfaceTypes())
                {
                    if (nestedIface.Type.Methods.Any(m => m.CanHaveStringOverload) || nestedIface.Type.Methods.Any(m => m.Asyncify))
                    {
                        sibling_types.Add(new InterfaceExtensionsClass(nestedIface.Type, nestedIface.DeclaringType, opt));
                    }
                }
            }

            if (klass.IsAbstract)
            {
                sibling_types.Add(new ClassInvokerClass(klass, opt));
            }

            AddNestedTypes(klass, opt, context, generationInfo);
            AddBindingInfrastructure(klass);
            AddConstructors(klass, opt, context);
            AddProperties(klass, opt);
            AddMethods(klass, opt, context);
            AddAbstractMembers(klass, opt, context);
            AddExplicitGenericInterfaceMembers(klass, opt);
            AddCharSequenceEnumerator(klass);

            context.ContextGeneratedMethods.Clear();
            context.ContextTypes.Pop();
        }