public void Generate(StreamWriter sw, string indent, CodeGenerationOptions opt, bool use_base, ClassGen type) { string jni_sig = JniSignature; bool gen_string_overload = Parameters.HasCharSequence && !type.ContainsCtor(jni_sig.Replace("java/lang/CharSequence", "java/lang/String")); System.Collections.Specialized.StringCollection call_cleanup = Parameters.GetCallCleanup(opt); opt.CodeGenerator.WriteConstructorIdField(this, sw, indent, opt); sw.WriteLine("{0}// Metadata.xml XPath constructor reference: path=\"{1}/constructor[@name='{2}'{3}]\"", indent, type.MetadataXPathReference, type.JavaSimpleName, Parameters.GetMethodXPathPredicate()); sw.WriteLine("{0}[Register (\"{1}\", \"{2}\", \"{3}\"{4})]", indent, ".ctor", jni_sig, String.Empty, this.AdditionalAttributeString()); if (Deprecated != null) { sw.WriteLine("{0}[Obsolete (@\"{1}\")]", indent, Deprecated.Replace("\"", "\"\"")); } GenerateCustomAttributes(sw, indent); sw.WriteLine("{0}{1} unsafe {2} ({3})\n{0}\t: {4} (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)", indent, Visibility, Name, GenBase.GetSignature(this, opt), use_base ? "base" : "this"); sw.WriteLine("{0}{{", indent); opt.CodeGenerator.WriteConstructorBody(this, sw, indent + "\t", opt, call_cleanup); sw.WriteLine("{0}}}", indent); sw.WriteLine(); if (gen_string_overload) { sw.WriteLine("{0}[Register (\"{1}\", \"{2}\", \"{3}\"{4})]", indent, ".ctor", jni_sig, String.Empty, this.AdditionalAttributeString()); sw.WriteLine("{0}{1} unsafe {2} ({3})\n{0}\t: {4} (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)", indent, Visibility, Name, GenBase.GetSignature(this, opt).Replace("Java.Lang.ICharSequence", "string").Replace("global::string", "string"), use_base ? "base" : "this"); sw.WriteLine("{0}{{", indent); opt.CodeGenerator.WriteConstructorBody(this, sw, indent + "\t", opt, call_cleanup); sw.WriteLine("{0}}}", indent); sw.WriteLine(); } }
public void Generate(StreamWriter sw, string indent, CodeGenerationOptions opt, GenBase type, bool generate_callbacks) { if (!IsValid) { return; } bool gen_as_formatted = IsReturnCharSequence; if (generate_callbacks && IsVirtual) { GenerateCallback(sw, indent, opt, type, null, gen_as_formatted); } string name_and_jnisig = JavaName + JniSignature.Replace("java/lang/CharSequence", "java/lang/String"); bool gen_string_overload = !IsOverride && Parameters.HasCharSequence && !type.ContainsMethod(name_and_jnisig); string static_arg = IsStatic ? " static" : String.Empty; string virt_ov = IsOverride ? " override" : IsVirtual ? " virtual" : String.Empty; if ((string.IsNullOrEmpty(virt_ov) || virt_ov == " virtual") && type.RequiresNew(AdjustedName)) { virt_ov = " new" + virt_ov; } string seal = IsOverride && IsFinal ? " sealed" : null; string ret = opt.GetOutputName(RetVal.FullName); GenerateIdField(sw, indent, opt); if (DeclaringType.IsGeneratable) { sw.WriteLine("{0}// Metadata.xml XPath method reference: path=\"{1}\"", indent, GetMetadataXPathReference(this.DeclaringType)); } if (Deprecated != null) { sw.WriteLine("{0}[Obsolete (@\"{1}\")]", indent, Deprecated.Replace("\"", "\"\"")); } if (IsReturnEnumified) { sw.WriteLine("{0}[return:global::Android.Runtime.GeneratedEnum]", indent); } sw.WriteLine("{0}[Register (\"{1}\", \"{2}\", \"{3}\"{4})]", indent, JavaName, JniSignature, IsVirtual ? ConnectorName : String.Empty, this.AdditionalAttributeString()); GenerateCustomAttributes(sw, indent); sw.WriteLine("{0}{1}{2}{3}{4} unsafe {5} {6} ({7})", indent, Visibility, static_arg, virt_ov, seal, ret, AdjustedName, GenBase.GetSignature(this, opt)); sw.WriteLine("{0}{{", indent); GenerateBody(sw, indent + "\t", opt); sw.WriteLine("{0}}}", indent); sw.WriteLine(); //NOTE: Invokers are the only place false is passed for generate_callbacks, they do not need string overloads if (generate_callbacks && (gen_string_overload || gen_as_formatted)) { GenerateStringOverload(sw, indent, opt); } GenerateAsyncWrapper(sw, indent, opt); }
void GenerateStringOverload(StreamWriter sw, string indent, CodeGenerationOptions opt) { string static_arg = IsStatic ? " static" : String.Empty; string ret = opt.GetOutputName(RetVal.FullName.Replace("Java.Lang.ICharSequence", "string")); if (Deprecated != null) { sw.WriteLine("{0}[Obsolete (@\"{1}\")]", indent, Deprecated.Replace("\"", "\"\"").Trim()); } sw.WriteLine("{0}{1}{2} {3} {4} ({5})", indent, Visibility, static_arg, ret, Name, GenBase.GetSignature(this, opt).Replace("Java.Lang.ICharSequence", "string").Replace("global::string", "string")); sw.WriteLine("{0}{{", indent); GenerateStringOverloadBody(sw, indent + "\t", opt, false); sw.WriteLine("{0}}}", indent); sw.WriteLine(); }
public void GenerateDeclaration(StreamWriter sw, string indent, CodeGenerationOptions opt, GenBase type, string adapter) { sw.WriteLine("{0}// Metadata.xml XPath method reference: path=\"{1}\"", indent, GetMetadataXPathReference(this.DeclaringType)); if (Deprecated != null) { sw.WriteLine("[Obsolete (@\"{0}\")]", Deprecated.Replace("\"", "\"\"")); } if (IsReturnEnumified) { sw.WriteLine("{0}[return:global::Android.Runtime.GeneratedEnum]", indent); } if (IsInterfaceDefaultMethod) { sw.WriteLine("{0}[global::Java.Interop.JavaInterfaceDefaultMethod]", indent); } sw.WriteLine("{0}[Register (\"{1}\", \"{2}\", \"{3}:{4}\"{5})]", indent, JavaName, JniSignature, ConnectorName, GetAdapterName(opt, adapter), this.AdditionalAttributeString()); GenerateCustomAttributes(sw, indent); sw.WriteLine("{0}{1} {2} ({3});", indent, opt.GetOutputName(RetVal.FullName), AdjustedName, GenBase.GetSignature(this, opt)); sw.WriteLine(); }