Exemplo n.º 1
0
        void AddConstructor(InterfaceGen iface, Method method, CodeGenerationOptions opt)
        {
            var ctor = new ConstructorWriter {
                Name     = iface.GetArgsName(method),
                IsPublic = true
            };

            if (method.IsEventHandlerWithHandledProperty)
            {
                ctor.Parameters.Add(new MethodParameterWriter("handled", TypeReferenceWriter.Bool));
                ctor.Body.Add("this.handled = handled;");
            }

            foreach (var p in method.Parameters)
            {
                if (p.IsSender)
                {
                    continue;
                }

                ctor.Parameters.Add(new MethodParameterWriter(p.Name, new TypeReferenceWriter(opt.GetTypeReferenceName(p))));
                ctor.Body.Add($"this.{opt.GetSafeIdentifier (p.Name)} = {opt.GetSafeIdentifier (p.Name)};");
            }

            Constructors.Add(ctor);
        }
Exemplo n.º 2
0
        void WriteType(FrameworkVersion version, TypeWrapper type)
        {
            var writer = new ClassWriter(this, version, type);

            writer.Write();

            foreach (var item in type.GetConstructors().Where(x => x.IsPublic))
            {
                var itemWriter = new ConstructorWriter(this, version, item);
                itemWriter.Write();
            }

            foreach (var item in type.GetMethodsToDocument())
            {
                // If a method is in another namespace, it is inherited and should not be overwritten
                if (item.DeclaringType.Namespace == type.Namespace)
                {
                    var itemWriter = new MethodWriter(this, version, item);
                    itemWriter.Write();
                }
            }

            foreach (var item in type.GetEvents())
            {
                // If an event is in another namespace, it is inherited and should not be overwritten
                if (item.DeclaringType.Namespace == type.Namespace)
                {
                    var itemWriter = new EventWriter(this, version, item);
                    itemWriter.Write();
                }
            }
        }
Exemplo n.º 3
0
        public void WriteConstructor(DataNode node)
        {
            var constructorWriter = new ConstructorWriter(this, node);

            Constructors.Add(constructorWriter);
            constructorWriter.Process();
        }
Exemplo n.º 4
0
        public void ConstructorWithThisCall()
        {
            ConstructorWriter writer        = new ConstructorWriter();
            ClassTemplate     classTemplate = new ClassTemplate((NamespaceTemplate)null, "Test");

            writer.Write(new ConstructorTemplate(classTemplate).WithThisConstructor(), this.output);
            Assert.AreEqual("public Test()\r\n    : this()\r\n{\r\n}", this.output.ToString());
        }
        public void Basics()
        {
            var ctor = new ConstructorWriter {
                Name = "MyClass", IsPublic = true, BaseCall = "base ()"
            };

            ctor.Parameters.Add(new MethodParameterWriter("test", TypeReferenceWriter.Bool));

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

            ctor.Write(writer);

            var expected =
                @"public MyClass (bool test) : base ()
{
}
";

            Assert.AreEqual(expected, sw.ToString());
        }
Exemplo n.º 6
0
        public ClassInvokerClass(ClassGen klass, CodeGenerationOptions opt)
        {
            Name = $"{klass.Name}Invoker";

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

            Inherits = klass.Name;

            foreach (var igen in klass.GetAllDerivedInterfaces().Where(i => i.IsGeneric))
            {
                Implements.Add(opt.GetOutputName(igen.FullName));
            }

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

            var ctor = new ConstructorWriter {
                Name     = Name,
                IsPublic = true,
                BaseCall = "base (handle, transfer)"
            };

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

            Constructors.Add(ctor);

            // ClassInvokerHandle
            Fields.Add(new PeerMembersField(opt, klass.RawJniName, $"{klass.Name}Invoker", false));
            Properties.Add(new JniPeerMembersGetter());
            Properties.Add(new ThresholdTypeGetter());

            AddMemberInvokers(klass, opt, new HashSet <string> ());
        }
        void AddConstructor(InterfaceGen iface, string jniClass, CodeGenerationOptions opt)
        {
            var ctor = new ConstructorWriter {
                Name     = iface.Name + "Implementor",
                IsPublic = true
            };

            if (iface.NeedsSender)
            {
                ctor.Parameters.Add(new MethodParameterWriter("sender", TypeReferenceWriter.Object));
            }

            ctor.BaseCall = $"base (global::Android.Runtime.JNIEnv.StartCreateInstance (\"{jniClass}\", \"()V\"), JniHandleOwnership.TransferLocalRef)";

            ctor.Body.Add($"global::Android.Runtime.JNIEnv.FinishCreateInstance ({iface.GetObjectHandleProperty ("this")}, \"()V\");");

            if (iface.NeedsSender)
            {
                ctor.Body.Add("this.sender = sender;");
            }

            Constructors.Add(ctor);
        }
Exemplo n.º 8
0
        void WriteType(FrameworkVersion version, TypeWrapper type)
        {
            var writer = new ClassWriter(this, version, type);

            writer.Write();

            foreach (var item in type.GetConstructors().Where(x => x.IsPublic))
            {
                var itemWriter = new ConstructorWriter(this, version, item);
                itemWriter.Write();
            }

            foreach (var item in type.GetMethodsToDocument())
            {
                var itemWriter = new MethodWriter(this, version, item);
                itemWriter.Write();
            }

            foreach (var item in type.GetEvents())
            {
                var itemWriter = new EventWriter(this, version, item);
                itemWriter.Write();
            }
        }
Exemplo n.º 9
0
        public ClassInvokerClass(ClassGen klass, CodeGenerationOptions opt)
        {
            Name = $"{klass.Name}Invoker";

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

            Inherits = klass.Name;

            foreach (var igen in klass.GetAllDerivedInterfaces().Where(i => i.IsGeneric))
            {
                Implements.Add(opt.GetOutputName(igen.FullName));
            }

            if (opt.CodeGenerationTarget == CodeGenerationTarget.JavaInterop1)
            {
                Attributes.Add(new JniTypeSignatureAttr(klass.RawJniName, false));
            }
            else
            {
                Attributes.Add(new RegisterAttr(klass.RawJniName, noAcw: true, additionalProperties: klass.AdditionalAttributeString())
                {
                    UseGlobal = true
                });
            }

            SourceWriterExtensions.AddSupportedOSPlatform(Attributes, klass, opt);

            ConstructorWriter ctor = opt.CodeGenerationTarget == CodeGenerationTarget.JavaInterop1
                                ? new ConstructorWriter {
                Name       = Name,
                IsPublic   = true,
                BaseCall   = "base (ref reference, options)",
                Parameters =
                {
                    new MethodParameterWriter("reference", new TypeReferenceWriter("ref JniObjectReference")),
                    new MethodParameterWriter("options",   new TypeReferenceWriter("JniObjectReferenceOptions")),
                },
            }
                                : new ConstructorWriter {
                Name       = Name,
                IsPublic   = true,
                BaseCall   = "base (handle, transfer)",
                Parameters =
                {
                    new MethodParameterWriter("handle",   TypeReferenceWriter.IntPtr),
                    new MethodParameterWriter("transfer", new TypeReferenceWriter("JniHandleOwnership")),
                },
            }
            ;

            Constructors.Add(ctor);

            // ClassInvokerHandle
            Fields.Add(new PeerMembersField(opt, klass.RawJniName, $"{klass.Name}Invoker", false));
            Properties.Add(new JniPeerMembersGetter());
            if (opt.CodeGenerationTarget != CodeGenerationTarget.JavaInterop1)
            {
                Properties.Add(new ThresholdTypeGetter());
            }

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