void GenerateEventHandlerImplContent(Method m, StreamWriter sw, string indent, CodeGenerationOptions opt, bool needs_sender, string jniClass, List <string> handlers) { string methodSpec = Methods.Count > 1 ? m.AdjustedName : String.Empty; handlers.Add(methodSpec); string args_name = GetArgsName(m); if (m.EventName != string.Empty) { sw.WriteLine("#pragma warning disable 0649"); sw.WriteLine("{0}\tpublic {1} {2}Handler;", indent, GetEventDelegateName(m), methodSpec); sw.WriteLine("#pragma warning restore 0649"); } sw.WriteLine(); sw.WriteLine("{0}\tpublic {1} {2} ({3})", indent, m.RetVal.FullName, m.Name, GenBase.GetSignature(m, opt)); sw.WriteLine("{0}\t{{", indent); if (m.EventName == string.Empty) { // generate nothing } else if (m.IsVoid) { sw.WriteLine("{0}\t\tvar __h = {1}Handler;", indent, methodSpec); sw.WriteLine("{0}\t\tif (__h != null)", indent); sw.WriteLine("{0}\t\t\t__h ({1}, new {2} ({3}));", indent, needs_sender ? "sender" : m.Parameters.SenderName, args_name, m.Parameters.CallDropSender); } else if (m.IsEventHandlerWithHandledProperty) { sw.WriteLine("{0}\t\tvar __h = {1}Handler;", indent, methodSpec); sw.WriteLine("{0}\t\tif (__h == null)", indent); sw.WriteLine("{0}\t\t\treturn {1};", indent, m.RetVal.DefaultValue); var call = m.Parameters.CallDropSender; sw.WriteLine("{0}\t\tvar __e = new {1} (true{2}{3});", indent, args_name, call.Length != 0 ? ", " : "", call); sw.WriteLine("{0}\t\t__h ({1}, __e);", indent, needs_sender ? "sender" : m.Parameters.SenderName); sw.WriteLine("{0}\t\treturn __e.Handled;", indent); } else { sw.WriteLine("{0}\t\tvar __h = {1}Handler;", indent, methodSpec); sw.WriteLine("{0}\t\treturn __h != null ? __h ({1}) : default ({2});", indent, m.Parameters.Call, opt.GetOutputName(m.RetVal.FullName)); } sw.WriteLine("{0}\t}}", indent); }
public string GetMetadataXPathReference(GenBase declaringType) { return(string.Format("{0}/method[@name='{1}'{2}]", declaringType.MetadataXPathReference, JavaName, Parameters.GetMethodXPathPredicate())); }
void GenerateCallback(StreamWriter sw, string indent, CodeGenerationOptions opt, GenBase type, string property_name, bool as_formatted) { string delegate_type = GetDelegateType(); sw.WriteLine("{0}static Delegate {1};", indent, EscapedCallbackName); sw.WriteLine("#pragma warning disable 0169"); sw.WriteLine("{0}static Delegate {1} ()", indent, ConnectorName); sw.WriteLine("{0}{{", indent); sw.WriteLine("{0}\tif ({1} == null)", indent, EscapedCallbackName); sw.WriteLine("{0}\t\t{1} = JNINativeWrapper.CreateDelegate (({2}) n_{3});", indent, EscapedCallbackName, delegate_type, Name + IDSignature); sw.WriteLine("{0}\treturn {1};", indent, EscapedCallbackName); sw.WriteLine("{0}}}", indent); sw.WriteLine(); sw.WriteLine("{0}static {1} n_{2} (IntPtr jnienv, IntPtr native__this{3})", indent, RetVal.NativeType, Name + IDSignature, Parameters.GetCallbackSignature(opt)); sw.WriteLine("{0}{{", indent); sw.WriteLine("{0}\t{1} __this = global::Java.Lang.Object.GetObject<{1}> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);", indent, opt.GetOutputName(type.FullName)); foreach (string s in Parameters.GetCallbackPrep(opt)) { sw.WriteLine("{0}\t{1}", indent, s); } if (String.IsNullOrEmpty(property_name)) { string call = "__this." + Name + (as_formatted ? "Formatted" : String.Empty) + " (" + Parameters.GetCall(opt) + ")"; if (IsVoid) { sw.WriteLine("{0}\t{1};", indent, call); } else { sw.WriteLine("{0}\t{1} {2};", indent, Parameters.HasCleanup ? RetVal.NativeType + " __ret =" : "return", RetVal.ToNative(opt, call)); } } else { if (IsVoid) { sw.WriteLine("{0}\t__this.{1} = {2};", indent, property_name, Parameters.GetCall(opt)); } else { sw.WriteLine("{0}\t{1} {2};", indent, Parameters.HasCleanup ? RetVal.NativeType + " __ret =" : "return", RetVal.ToNative(opt, "__this." + property_name)); } } foreach (string cleanup in Parameters.GetCallbackCleanup(opt)) { sw.WriteLine("{0}\t{1}", indent, cleanup); } if (!IsVoid && Parameters.HasCleanup) { sw.WriteLine("{0}\treturn __ret;", indent); } sw.WriteLine("{0}}}", indent); sw.WriteLine("#pragma warning restore 0169"); sw.WriteLine(); }
internal override void WriteFieldSetBody(Field field, TextWriter writer, string indent, CodeGenerationOptions opt, GenBase type) { writer.WriteLine("{0}const string __id = \"{1}.{2}\";", indent, field.JavaName, field.Symbol.JniName); writer.WriteLine(); var invokeType = GetInvokeType(field.GetMethodPrefix); var indirect = field.IsStatic ? "StaticFields" : "InstanceFields"; string arg; bool have_prep = false; if (field.Symbol.IsArray) { arg = opt.GetSafeIdentifier(SymbolTable.GetNativeName("value")); writer.WriteLine("{0}IntPtr {1} = global::Android.Runtime.JavaArray<{2}>.ToLocalJniHandle (value);", indent, arg, opt.GetOutputName(field.Symbol.ElementType)); } else { foreach (string prep in field.SetParameters.GetCallPrep(opt)) { have_prep = true; writer.WriteLine("{0}{1}", indent, prep); } arg = field.SetParameters [0].ToNative(opt); if (field.SetParameters.HasCleanup && !have_prep) { arg = opt.GetSafeIdentifier(SymbolTable.GetNativeName("value")); writer.WriteLine("{0}IntPtr {1} = global::Android.Runtime.JNIEnv.ToLocalJniHandle (value);", indent, arg); } } writer.WriteLine("{0}try {{", indent); writer.WriteLine("{0}\t_members.{1}.SetValue (__id{2}, {3});", indent, indirect, field.IsStatic ? "" : ", this", invokeType != "Object" ? arg : "new JniObjectReference (" + arg + ")"); writer.WriteLine("{0}}} finally {{", indent); if (field.Symbol.IsArray) { writer.WriteLine("{0}\tglobal::Android.Runtime.JNIEnv.DeleteLocalRef ({1});", indent, arg); } else { foreach (string cleanup in field.SetParameters.GetCallCleanup(opt)) { writer.WriteLine("{0}\t{1}", indent, cleanup); } if (field.SetParameters.HasCleanup && !have_prep) { writer.WriteLine("{0}\tglobal::Android.Runtime.JNIEnv.DeleteLocalRef ({1});", indent, arg); } } writer.WriteLine("{0}}}", indent); }
public ManagedMethod(GenBase declaringType, MethodDefinition m) : this(declaringType, m, new ManagedMethodBaseSupport(m)) { }
public static Method CreateMethod(GenBase declaringType, XElement elem) { var method = new Method(declaringType) { ArgsType = elem.Attribute("argsType")?.Value, CustomAttributes = elem.XGetAttribute("customAttributes"), Deprecated = elem.Deprecated(), EventName = elem.Attribute("eventName")?.Value, GenerateAsyncWrapper = elem.Attribute("generateAsyncWrapper") != null, GenerateDispatchingSetter = elem.Attribute("generateDispatchingSetter") != null, GenericArguments = elem.GenericArguments(), IsAbstract = elem.XGetAttribute("abstract") == "true", IsAcw = true, IsFinal = elem.XGetAttribute("final") == "true", IsReturnEnumified = elem.Attribute("enumReturn") != null, IsStatic = elem.XGetAttribute("static") == "true", JavaName = elem.XGetAttribute("name"), ManagedReturn = elem.XGetAttribute("managedReturn"), PropertyNameOverride = elem.XGetAttribute("propertyName"), Return = elem.XGetAttribute("return"), ReturnNotNull = elem.XGetAttribute("return-not-null") == "true", SourceApiLevel = GetApiLevel(elem.XGetAttribute("merge.SourceFile")), Visibility = elem.Visibility() }; method.IsVirtual = !method.IsStatic && elem.XGetAttribute("final") == "false"; if (elem.Attribute("managedName") != null) { method.Name = elem.XGetAttribute("managedName"); } else { method.Name = StringRocks.MemberToPascalCase(method.JavaName); } if (method.IsReturnEnumified) { method.ManagedReturn = elem.XGetAttribute("enumReturn"); // FIXME: this should not require enumReturn. Somewhere in generator uses this property improperly. method.Return = method.ManagedReturn; } if (declaringType is InterfaceGen) { method.IsInterfaceDefaultMethod = !method.IsAbstract && !method.IsStatic; } foreach (var child in elem.Elements()) { if (child.Name == "parameter") { method.Parameters.Add(CreateParameter(child)); } } method.Name = EnsureValidIdentifer(method.Name); method.FillReturnType(); return(method); }
List <GenBase> ParsePackage(XElement ns, Predicate <XElement> p) { List <GenBase> result = new List <GenBase> (); Dictionary <string, GenBase> nested = new Dictionary <string, GenBase> (); Dictionary <string, GenBase> by_name = new Dictionary <string, GenBase> (); foreach (var elem in ns.Elements()) { string name = elem.XGetAttribute("name"); GenBase gen = null; switch (elem.Name.LocalName) { case "class": if (elem.XGetAttribute("obfuscated") == "true") { continue; } gen = XmlApiImporter.CreateClass(ns, elem, opt); break; case "interface": if (elem.XGetAttribute("obfuscated") == "true") { continue; } gen = XmlApiImporter.CreateInterface(ns, elem, opt); break; default: Report.Warning(0, Report.WarningParser + 3, "Unexpected node in package element: {0}.", elem.Name); break; } if (gen == null) { continue; } int idx = name.IndexOf('<'); if (idx > 0) { name = name.Substring(0, idx); } by_name [name] = gen; if (name.IndexOf('.') > 0) { nested [name] = gen; } else { result.Add(gen); } } foreach (string name in nested.Keys) { string top_ancestor = name.Substring(0, name.IndexOf('.')); if (by_name.ContainsKey(top_ancestor)) { by_name [top_ancestor].AddNestedType(nested [name]); } else { Report.Warning(0, Report.WarningParser + 4, "top ancestor {0} not found for nested type {1}.", top_ancestor, nested [name].FullName); nested [name].Invalidate(); } } return(result); }
public void GenerateInvoker(StreamWriter sw, string indent, CodeGenerationOptions opt, GenBase type) { GenerateCallback(sw, indent, opt, type, null, IsReturnCharSequence); GenerateIdField(sw, indent, opt, invoker: true); sw.WriteLine("{0}public unsafe {1}{2} {3} ({4})", indent, IsStatic ? "static " : string.Empty, opt.GetOutputName(RetVal.FullName), AdjustedName, GenBase.GetSignature(this, opt)); sw.WriteLine("{0}{{", indent); GenerateInvokerBody(sw, indent + "\t", opt); sw.WriteLine("{0}}}", indent); sw.WriteLine(); }
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 GenerateEventDelegate(StreamWriter sw, string indent, CodeGenerationOptions opt) { sw.WriteLine("{0}public delegate {1} {2}EventHandler ({3});", indent, opt.GetOutputName(RetVal.FullName), Name, GenBase.GetSignature(this, opt)); sw.WriteLine(); }
// This is supposed to generate instantiated generic method output, but I don't think it is done yet. public void GenerateExplicitIface(StreamWriter sw, string indent, CodeGenerationOptions opt, GenericSymbol gen) { sw.WriteLine("{0}// This method is explicitly implemented as a member of an instantiated {1}", indent, gen.FullName); GenerateCustomAttributes(sw, indent); sw.WriteLine("{0}{1} {2}.{3} ({4})", indent, opt.GetOutputName(RetVal.FullName), opt.GetOutputName(gen.Gen.FullName), Name, GenBase.GetSignature(this, opt)); sw.WriteLine("{0}{{", indent); Dictionary <string, string> mappings = new Dictionary <string, string> (); for (int i = 0; i < gen.TypeParams.Length; i++) { mappings [gen.Gen.TypeParameters[i].Name] = gen.TypeParams [i].FullName; } GenerateGenericBody(sw, indent + "\t", opt, null, String.Empty, mappings); sw.WriteLine("{0}}}", indent); sw.WriteLine(); }
public void GenerateDeclaration(StreamWriter sw, string indent, CodeGenerationOptions opt, GenBase type, string adapter) { if (DeclaringType.IsGeneratable) { 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(); }
public void GenerateAbstractDeclaration(StreamWriter sw, string indent, CodeGenerationOptions opt, InterfaceGen gen, GenBase impl) { if (RetVal.IsGeneric && gen != null) { GenerateCustomAttributes(sw, indent); sw.WriteLine("{0}{1} {2}.{3} ({4})", indent, opt.GetOutputName(RetVal.FullName), opt.GetOutputName(gen.FullName), Name, GenBase.GetSignature(this, opt)); sw.WriteLine("{0}{{", indent); sw.WriteLine("{0}\tthrow new NotImplementedException ();", indent); sw.WriteLine("{0}}}", indent); sw.WriteLine(); } else { bool gen_as_formatted = IsReturnCharSequence; string name = AdjustedName; GenerateCallback(sw, indent, opt, impl, null, gen_as_formatted); if (DeclaringType.IsGeneratable) { sw.WriteLine("{0}// Metadata.xml XPath method reference: path=\"{1}\"", indent, GetMetadataXPathReference(this.DeclaringType)); } sw.WriteLine("{0}[Register (\"{1}\", \"{2}\", \"{3}\"{4})]", indent, JavaName, JniSignature, ConnectorName, this.AdditionalAttributeString()); GenerateCustomAttributes(sw, indent); sw.WriteLine("{0}{1} abstract {2} {3} ({4});", indent, Visibility, opt.GetOutputName(RetVal.FullName), name, GenBase.GetSignature(this, opt)); sw.WriteLine(); if (gen_as_formatted || Parameters.HasCharSequence) { GenerateStringOverload(sw, indent, opt); } } GenerateAsyncWrapper(sw, indent, opt); }
public void GenerateExplicitInterfaceInvoker(StreamWriter sw, string indent, CodeGenerationOptions opt, GenBase iface) { //sw.WriteLine ("\t\t// explicitly implemented invoker method from " + iface.FullName); GenerateIdField(sw, indent, opt); sw.WriteLine("{0}unsafe {1} {2}.{3} ({4})", indent, opt.GetOutputName(RetVal.FullName), opt.GetOutputName(iface.FullName), Name, GenBase.GetSignature(this, opt)); sw.WriteLine("{0}{{", indent); GenerateBody(sw, indent + "\t", opt); sw.WriteLine("{0}}}", indent); sw.WriteLine(); }
public void Generate(StreamWriter sw, string indent, CodeGenerationOptions opt, GenBase type) { if (IsEnumified) { sw.WriteLine("[global::Android.Runtime.GeneratedEnum]"); } if (NeedsProperty) { GenerateProperty(sw, indent, opt, type); } else { sw.WriteLine("{0}// Metadata.xml XPath field reference: path=\"{1}/field[@name='{2}']\"", indent, type.MetadataXPathReference, JavaName); sw.WriteLine("{0}[Register (\"{1}\"{2})]", indent, JavaName, this.AdditionalAttributeString()); if (IsDeprecated) { sw.WriteLine("{0}[Obsolete (\"{1}\")]", indent, DeprecatedComment); } if (Annotation != null) { sw.WriteLine("{0}{1}", indent, Annotation); } // the Value complication is due to constant enum from negative integer value (C# compiler requires explicit parenthesis). sw.WriteLine("{0}{1} const {2} {3} = ({2}) {4};", indent, Visibility, opt.GetOutputName(Symbol.FullName), Name, Value.Contains('-') && Symbol.FullName.Contains('.') ? '(' + Value + ')' : Value); } }
public void GenerateAsyncWrapper(StreamWriter sw, string indent, CodeGenerationOptions opt) { if (!Asyncify) { return; } string static_arg = IsStatic ? " static" : String.Empty; string ret; if (IsVoid) { ret = "global::System.Threading.Tasks.Task"; } else { ret = "global::System.Threading.Tasks.Task<" + opt.GetOutputName(RetVal.FullName) + ">"; } sw.WriteLine("{0}{1}{2} {3} {4}Async ({5})", indent, Visibility, static_arg, ret, AdjustedName, GenBase.GetSignature(this, opt)); sw.WriteLine("{0}{{", indent); sw.WriteLine("{0}\treturn global::System.Threading.Tasks.Task.Run (() => {1} ({2}));", indent, AdjustedName, Parameters.GetCall(opt)); sw.WriteLine("{0}}}", indent); sw.WriteLine(); }
protected MethodBase(GenBase declaringType, IMethodBaseSupport support) { DeclaringType = declaringType; this.support = support; parms = new ParameterList(); }
public void GenerateExtensionAsyncWrapper(StreamWriter sw, string indent, CodeGenerationOptions opt, string selfType) { if (!Asyncify) { return; } string ret; if (IsVoid) { ret = "global::System.Threading.Tasks.Task"; } else { ret = "global::System.Threading.Tasks.Task<" + opt.GetOutputName(RetVal.FullName) + ">"; } sw.WriteLine("{0}public static {1} {2}Async (this {3} self{4}{5})", indent, ret, AdjustedName, selfType, Parameters.Count > 0 ? ", " : string.Empty, GenBase.GetSignature(this, opt)); sw.WriteLine("{0}{{", indent); sw.WriteLine("{0}\treturn global::System.Threading.Tasks.Task.Run (() => self.{1} ({2}));", indent, AdjustedName, Parameters.GetCall(opt)); sw.WriteLine("{0}}}", indent); sw.WriteLine(); }
protected Ctor(GenBase declaringType) : base(declaringType) { }
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(); if (gen_string_overload || gen_as_formatted) { GenerateStringOverload(sw, indent, opt); } GenerateAsyncWrapper(sw, indent, opt); }
internal override void WriteFieldGetBody(Field field, TextWriter writer, string indent, CodeGenerationOptions opt, GenBase type) { writer.WriteLine("{0}const string __id = \"{1}.{2}\";", indent, field.JavaName, field.Symbol.JniName); writer.WriteLine(); var invokeType = GetInvokeType(field.GetMethodPrefix); var indirect = field.IsStatic ? "StaticFields" : "InstanceFields"; var invoke = "Get{0}Value"; invoke = string.Format(invoke, invokeType); writer.WriteLine("{0}var __v = _members.{1}.{2} (__id{3});", indent, indirect, invoke, field.IsStatic ? "" : ", this"); if (field.Symbol.IsArray) { writer.WriteLine("{0}return global::Android.Runtime.JavaArray<{1}>.FromJniHandle (__v.Handle, JniHandleOwnership.TransferLocalRef);", indent, opt.GetOutputName(field.Symbol.ElementType)); } else if (field.Symbol.NativeType != field.Symbol.FullName) { writer.WriteLine("{0}return {1};", indent, field.Symbol.FromNative(opt, invokeType != "Object" ? "__v" : "__v.Handle", true)); } else { writer.WriteLine("{0}return __v;", indent); } }
protected MethodBase(GenBase declaringType) { DeclaringType = declaringType; }
public ISymbol Lookup(string java_type) { string type_params; int ar; bool he; string key = GetSymbolInfo(java_type, out type_params, out ar, out he); ISymbol sym; List <ISymbol> values; if (symbols.TryGetValue(key, out values)) { sym = values [values.Count - 1]; } else { // Note we're potentially searching shallow types, but this is only looking at the type name // Anything we find we will populate before returning to the user lock (cache_population_lock) { if (all_symbols_cache == null) { all_symbols_cache = new ConcurrentDictionary <string, ISymbol> (symbols.Values.SelectMany(v => v).GroupBy(s => s.FullName).ToDictionary(s => s.Key, s => s.FirstOrDefault())); } if (!all_symbols_cache.TryGetValue(key, out sym)) { // We may be looking for a type like: // - System.Collections.Generic.IList<Java.Util.Locale.LanguageRange> // Our key is "System.Collections.Generic.IList", but it's stored in // the symbol table with the arity so we need to look for // "System.Collections.Generic.IList`1" to find a match key = AddArity(key, type_params); all_symbols_cache.TryGetValue(key, out sym); } } } ISymbol result; if (sym != null) { if (type_params.Length > 0) { GenBase gen = sym as GenBase; EnsurePopulated(gen); if (gen != null && gen.IsGeneric) { result = new GenericSymbol(gen, type_params); } // In other case, it is still valid to derive from non-generic type. // Generics are likely removed but we should not invalidate such derived classes. else { result = gen; } } // disable this condition; consider that "java.lang.Class[]" can be specified as a parameter type //else if (sym is GenBase && (sym as GenBase).IsGeneric) // return null; else { result = sym; } } else { return(null); } if (result is GenBase gen_base) { EnsurePopulated(gen_base); } return(result); }
public Method(GenBase declaringType) : base(declaringType) { }
protected Method(GenBase declaringType, IMethodBaseSupport support) : base(declaringType, support) { }
public string GetMetadataXPathReference(GenBase declaringType) => $"{declaringType.MetadataXPathReference}/method[@name='{JavaName}'{Parameters.GetMethodXPathPredicate ()}]";
public void GenerateCallback(StreamWriter sw, string indent, CodeGenerationOptions opt, GenBase type, string property_name) { GenerateCallback(sw, indent, opt, type, property_name, false); }
void GenerateProperty(StreamWriter sw, string indent, CodeGenerationOptions opt, GenBase gen) { string type = Symbol.IsArray ? "IList<" + Symbol.ElementType + ">" : opt.GetOutputName(Symbol.FullName); opt.CodeGenerator.WriteFieldIdField(this, sw, indent, opt); sw.WriteLine(); sw.WriteLine("{0}// Metadata.xml XPath field reference: path=\"{1}/field[@name='{2}']\"", indent, gen.MetadataXPathReference, JavaName); sw.WriteLine("{0}[Register (\"{1}\"{2})]", indent, JavaName, this.AdditionalAttributeString()); sw.WriteLine("{0}{1} {2}{3} {4} {{", indent, Visibility, IsStatic ? "static " : String.Empty, type, Name); sw.WriteLine("{0}\tget {{", indent); opt.CodeGenerator.WriteFieldGetBody(this, sw, indent + "\t\t", opt); sw.WriteLine("{0}\t}}", indent); if (!IsConst) { sw.WriteLine("{0}\tset {{", indent); opt.CodeGenerator.WriteFieldSetBody(this, sw, indent + "\t\t", opt); sw.WriteLine("{0}\t}}", indent); } sw.WriteLine("{0}}}", indent); }
public void GenerateExplicitInterfaceImplementation(StreamWriter sw, string indent, CodeGenerationOptions opt, GenBase iface) { // sw.WriteLine ("// explicitly implemented method from " + iface.FullName); GenerateCustomAttributes(sw, indent); sw.WriteLine("{0}{1} {2}.{3} ({4})", indent, opt.GetOutputName(RetVal.FullName), opt.GetOutputName(iface.FullName), Name, GenBase.GetSignature(this, opt)); sw.WriteLine("{0}{{", indent); sw.WriteLine("{0}\treturn {1} ({2});", indent, Name, Parameters.GetCall(opt)); sw.WriteLine("{0}}}", indent); sw.WriteLine(); }
void GenerateEventArgs(Method m, StreamWriter sw, string indent, CodeGenerationOptions opt) { string args_name = GetArgsName(m); if (m.RetVal.IsVoid || m.IsEventHandlerWithHandledProperty) { if (!m.IsSimpleEventHandler || m.IsEventHandlerWithHandledProperty) { sw.WriteLine("{0}public partial class {1} : global::System.EventArgs {{", indent, args_name); sw.WriteLine(); var signature = m.Parameters.GetSignatureDropSender(opt); sw.WriteLine("{0}\tpublic {1} ({2}{3}{4})", indent, args_name, m.IsEventHandlerWithHandledProperty ? "bool handled" : "", (m.IsEventHandlerWithHandledProperty && signature.Length != 0) ? ", " : "", signature); sw.WriteLine("{0}\t{{", indent); if (m.IsEventHandlerWithHandledProperty) { sw.WriteLine("{0}\t\tthis.handled = handled;", indent); } foreach (Parameter p in m.Parameters) { if (!p.IsSender) { sw.WriteLine("{0}\t\tthis.{1} = {1};", indent, opt.GetSafeIdentifier(p.Name)); } } sw.WriteLine("{0}\t}}", indent); if (m.IsEventHandlerWithHandledProperty) { sw.WriteLine(); sw.WriteLine("{0}\tbool handled;", indent); sw.WriteLine("{0}\tpublic bool Handled {{", indent); sw.WriteLine("{0}\t\tget {{ return handled; }}", indent); sw.WriteLine("{0}\t\tset {{ handled = value; }}", indent); sw.WriteLine("{0}\t}}", indent); } foreach (Parameter p in m.Parameters) { if (p.IsSender) { continue; } sw.WriteLine(); sw.WriteLine("{0}\t{1} {2};", indent, opt.GetOutputName(p.Type), opt.GetSafeIdentifier(p.Name)); // AbsListView.IMultiChoiceModeListener.onItemCheckedStateChanged() hit this strict name check, at parameter "@checked". sw.WriteLine("{0}\tpublic {1} {2} {{", indent, opt.GetOutputName(p.Type), p.PropertyName); sw.WriteLine("{0}\t\tget {{ return {1}; }}", indent, opt.GetSafeIdentifier(p.Name)); sw.WriteLine("{0}\t}}", indent); } sw.WriteLine("{0}}}", indent); sw.WriteLine(); } } else { sw.WriteLine("{0}public delegate {1} {2} ({3});", indent, opt.GetOutputName(m.RetVal.FullName), GetEventDelegateName(m), GenBase.GetSignature(m, opt)); sw.WriteLine(); } }