public static Ctor CreateCtor(GenBase declaringType, MethodDefinition m) { var reg_attr = GetRegisterAttribute(m.CustomAttributes); var ctor = new Ctor(declaringType) { AssemblyName = m.DeclaringType.Module.Assembly.FullName, Deprecated = m.Deprecated(), GenericArguments = m.GenericArguments(), IsAcw = reg_attr != null, // not a beautiful way to check static type, yes :| IsNonStaticNestedType = m.DeclaringType.IsNested && !(m.DeclaringType.IsAbstract && m.DeclaringType.IsSealed), Name = m.Name, Visibility = m.Visibility() }; // If 'elem' is a constructor for a non-static nested type, then // the type of the containing class must be inserted as the first // argument if (ctor.IsNonStaticNestedType) { ctor.Parameters.AddFirst(CreateParameter(m.DeclaringType.DeclaringType.FullName, ctor.DeclaringType.JavaName)); } foreach (var p in m.GetParameters(reg_attr)) { ctor.Parameters.Add(p); } return(ctor); }
internal override void WriteConstructorBody(Ctor ctor, TextWriter writer, string indent, CodeGenerationOptions opt, System.Collections.Specialized.StringCollection call_cleanup) { writer.WriteLine("{0}{1}string __id = \"{2}\";", indent, ctor.IsNonStaticNestedType ? "" : "const ", ctor.IsNonStaticNestedType ? "(" + ctor.Parameters.JniNestedDerivedSignature + ")V" : ctor.JniSignature); writer.WriteLine(); writer.WriteLine("{0}if ({1} != IntPtr.Zero)", indent, opt.ContextType.GetObjectHandleProperty("this")); writer.WriteLine("{0}\treturn;", indent); writer.WriteLine(); foreach (string prep in ctor.Parameters.GetCallPrep(opt)) { writer.WriteLine("{0}{1}", indent, prep); } writer.WriteLine("{0}try {{", indent); var oldindent = indent; indent += "\t"; ctor.Parameters.WriteCallArgs(writer, indent, opt, invoker: false); writer.WriteLine("{0}var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (){1});", indent, ctor.Parameters.GetCallArgs(opt, invoker: false)); writer.WriteLine("{0}SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef);", indent); writer.WriteLine("{0}_members.InstanceMethods.FinishCreateInstance (__id, this{1});", indent, ctor.Parameters.GetCallArgs(opt, invoker: false)); indent = oldindent; writer.WriteLine("{0}}} finally {{", indent); foreach (string cleanup in call_cleanup) { writer.WriteLine("{0}\t{1}", indent, cleanup); } writer.WriteLine("{0}}}", indent); }
internal override void WriteConstructorBody(Ctor ctor, string indent, System.Collections.Specialized.StringCollection call_cleanup) { writer.WriteLine("{0}{1}string __id = \"{2}\";", indent, ctor.IsNonStaticNestedType ? "" : "const ", ctor.IsNonStaticNestedType ? "(" + ctor.Parameters.GetJniNestedDerivedSignature(opt) + ")V" : ctor.JniSignature); writer.WriteLine(); writer.WriteLine("{0}if (PeerReference.IsValid)", indent); writer.WriteLine("{0}\treturn;", indent); writer.WriteLine(); foreach (string prep in ctor.Parameters.GetCallPrep(opt)) { writer.WriteLine("{0}{1}", indent, prep); } writer.WriteLine("{0}try {{", indent); var oldindent = indent; indent += "\t"; WriteParameterListCallArgs(ctor.Parameters, indent, invoker: false); writer.WriteLine("{0}var __r = _members.InstanceMethods.StartCreateInstance (__id, GetType (){1});", indent, ctor.Parameters.GetCallArgs(opt, invoker: false)); writer.WriteLine("{0}Construct (ref __r, JniObjectReferenceOptions.CopyAndDispose);", indent); writer.WriteLine("{0}_members.InstanceMethods.FinishCreateInstance (__id, this{1});", indent, ctor.Parameters.GetCallArgs(opt, invoker: false)); indent = oldindent; writer.WriteLine("{0}}} finally {{", indent); foreach (string cleanup in call_cleanup) { writer.WriteLine("{0}\t{1}", indent, cleanup); } writer.WriteLine("{0}}}", indent); }
public static Ctor CreateCtor(GenBase declaringType, XElement elem, CodeGenerationOptions options = null) { var ctor = new Ctor(declaringType) { ApiAvailableSince = declaringType.ApiAvailableSince, CustomAttributes = elem.XGetAttribute("customAttributes"), Deprecated = elem.Deprecated(), GenericArguments = elem.GenericArguments(), Name = elem.XGetAttribute("name"), Visibility = elem.Visibility() }; SetLineInfo(ctor, elem, options); var idx = ctor.Name.LastIndexOf('.'); if (idx > 0) { ctor.Name = ctor.Name.Substring(idx + 1); } // If 'elem' is a constructor for a non-static nested type, then // the type of the containing class must be inserted as the first argument ctor.IsNonStaticNestedType = idx > 0 && elem.Parent.Attribute("static").Value == "false"; if (ctor.IsNonStaticNestedType) { string declName = elem.Parent.XGetAttribute("name"); string expectedEnclosingName = declName.Substring(0, idx); XElement enclosingType = GetPreviousClass(elem.Parent.PreviousNode, expectedEnclosingName); if (enclosingType == null) { ctor.MissingEnclosingClass = true; Report.LogCodedWarning(0, Report.WarningMissingClassForConstructor, ctor, ctor.Name, expectedEnclosingName); } else { ctor.Parameters.AddFirst(CreateParameterFromClassElement(enclosingType, options)); } } foreach (var child in elem.Elements()) { if (child.Name == "parameter") { ctor.Parameters.Add(CreateParameter(child, options)); } } ctor.Name = EnsureValidIdentifer(ctor.Name); FillApiSince(ctor, elem); return(ctor); }
internal override void WriteConstructorBody(Ctor ctor, StreamWriter sw, string indent, CodeGenerationOptions opt, System.Collections.Specialized.StringCollection call_cleanup) { sw.WriteLine("{0}if ({1} != IntPtr.Zero)", indent, opt.ContextType.GetObjectHandleProperty("this")); sw.WriteLine("{0}\treturn;", indent); sw.WriteLine(); foreach (string prep in ctor.Parameters.GetCallPrep(opt)) { sw.WriteLine("{0}{1}", indent, prep); } sw.WriteLine("{0}try {{", indent); var oldindent = indent; indent += "\t"; ctor.Parameters.WriteCallArgs(sw, indent, opt, invoker: false); sw.WriteLine("{0}if (((object) this).GetType () != typeof ({1})) {{", indent, ctor.Name); sw.WriteLine("{0}\tSetHandle (", indent); sw.WriteLine("{0}\t\t\tglobal::Android.Runtime.JNIEnv.StartCreateInstance (((object) this).GetType (), \"{1}\"{2}),", indent, ctor.IsNonStaticNestedType ? "(" + ctor.Parameters.JniNestedDerivedSignature + ")V" : ctor.JniSignature, ctor.Parameters.GetCallArgs(opt, invoker: false)); sw.WriteLine("{0}\t\t\tJniHandleOwnership.TransferLocalRef);", indent); sw.WriteLine("{0}\tglobal::Android.Runtime.JNIEnv.FinishCreateInstance ({1}, \"{2}\"{3});", indent, opt.ContextType.GetObjectHandleProperty("this"), ctor.IsNonStaticNestedType ? "(" + ctor.Parameters.JniNestedDerivedSignature + ")V" : ctor.JniSignature, ctor.Parameters.GetCallArgs(opt, invoker: false)); sw.WriteLine("{0}\treturn;", indent); sw.WriteLine("{0}}}", indent); sw.WriteLine(); sw.WriteLine("{0}if ({1} == IntPtr.Zero)", indent, ctor.ID); sw.WriteLine("{0}\t{1} = JNIEnv.GetMethodID (class_ref, \"<init>\", \"{2}\");", indent, ctor.ID, ctor.JniSignature); sw.WriteLine("{0}SetHandle (", indent); sw.WriteLine("{0}\t\tglobal::Android.Runtime.JNIEnv.StartCreateInstance (class_ref, {1}{2}),", indent, ctor.ID, ctor.Parameters.GetCallArgs(opt, invoker: false)); sw.WriteLine("{0}\t\tJniHandleOwnership.TransferLocalRef);", indent); sw.WriteLine("{0}JNIEnv.FinishCreateInstance ({1}, class_ref, {2}{3});", indent, opt.ContextType.GetObjectHandleProperty("this"), ctor.ID, ctor.Parameters.GetCallArgs(opt, invoker: false)); indent = oldindent; sw.WriteLine("{0}}} finally {{", indent); foreach (string cleanup in call_cleanup) { sw.WriteLine("{0}\t{1}", indent, cleanup); } sw.WriteLine("{0}}}", indent); }
internal abstract void WriteConstructorBody(Ctor ctor, StreamWriter sw, string indent, CodeGenerationOptions opt, StringCollection call_cleanup);
internal abstract void WriteConstructorIdField(Ctor ctor, StreamWriter sw, string indent, CodeGenerationOptions opt);
internal override void WriteConstructorIdField(Ctor ctor, StreamWriter sw, string indent, CodeGenerationOptions opt) { sw.WriteLine("{0}static IntPtr {1};", indent, ctor.ID); }
internal override void WriteConstructorIdField(Ctor ctor, string indent) { writer.WriteLine("{0}static IntPtr {1};", indent, ctor.ID); }
internal override void WriteConstructorIdField(Ctor ctor, TextWriter writer, string indent, CodeGenerationOptions opt) { // No method id_ctor field required; it's now an `id` constant in the binding. }
internal override void WriteConstructorIdField(Ctor ctor, string indent) { // No method id_ctor field required; it's now an `id` constant in the binding. }
internal override void WriteConstructorIdField(Ctor ctor, TextWriter writer, string indent, CodeGenerationOptions opt) { writer.WriteLine("{0}static IntPtr {1};", indent, ctor.ID); }