public static Method CreateMethod(GenBase declaringType, MethodDefinition m) { var reg_attr = GetRegisterAttribute(m.CustomAttributes); var method = new Method(declaringType) { AssemblyName = m.DeclaringType.Module.Assembly.FullName, Deprecated = m.Deprecated(), GenerateAsyncWrapper = false, GenericArguments = m.GenericArguments(), IsAbstract = m.IsAbstract, IsAcw = reg_attr != null, IsFinal = m.IsFinal, IsInterfaceDefaultMethod = IsDefaultInterfaceMethod(declaringType, m), IsReturnEnumified = GetGeneratedEnumAttribute(m.MethodReturnType.CustomAttributes) != null, IsStatic = m.IsStatic, IsVirtual = m.IsVirtual, JavaName = reg_attr != null ? ((string)reg_attr.ConstructorArguments [0].Value) : m.Name, ManagedReturn = m.ReturnType.FullNameCorrected().StripArity().FilterPrimitive(), Return = m.ReturnType.FullNameCorrected().StripArity().FilterPrimitive(), ReturnNotNull = m.GetReturnTypeNullability() == Nullability.NotNull, Visibility = m.Visibility() }; foreach (var p in m.GetParameters(reg_attr)) { method.Parameters.Add(p); } if (reg_attr != null) { var jnisig = (string)(reg_attr.ConstructorArguments.Count > 1 ? reg_attr.ConstructorArguments [1].Value : reg_attr.Properties.First(p => p.Name == "JniSignature").Argument.Value); var rt = JavaNativeTypeManager.ReturnTypeFromSignature(jnisig); if (rt?.Type != null) { method.Return = rt.Type; } } method.FillReturnType(); // Strip "Formatted" from ICharSequence-based method. var name_base = method.IsReturnCharSequence ? m.Name.Substring(0, m.Name.Length - "Formatted".Length) : m.Name; method.Name = m.IsGetter ? (m.Name.StartsWith("get_Is", StringComparison.Ordinal) && m.Name.Length > 6 && char.IsUpper(m.Name [6]) ? string.Empty : "Get") + name_base.Substring(4) : m.IsSetter ? (m.Name.StartsWith("set_Is", StringComparison.Ordinal) && m.Name.Length > 6 && char.IsUpper(m.Name [6]) ? string.Empty : "Set") + name_base.Substring(4) : name_base; return(method); }
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"), 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); }