Exemplo n.º 1
0
        public XmlMethod(GenBase declaringType, XmlElement elem)
            : base(declaringType, new XmlMethodBaseSupport(elem))
        {
            this.elem  = elem;
            is_static  = elem.XGetAttribute("static") == "true";
            is_virtual = !is_static && elem.XGetAttribute("final") == "false";
            if (elem.HasAttribute("managedName"))
            {
                name = elem.XGetAttribute("managedName");
            }
            else
            {
                name = StringRocks.MemberToPascalCase(JavaName);
            }

            is_abstract = elem.XGetAttribute("abstract") == "true";
            if (declaringType is InterfaceGen)
            {
                is_interface_default_method = !is_abstract && !is_static;
            }

            GenerateDispatchingSetter = elem.HasAttribute("generateDispatchingSetter");

            foreach (XmlNode child in elem.ChildNodes)
            {
                if (child.Name == "parameter")
                {
                    Parameters.Add(Parameter.FromElement(child as XmlElement));
                }
            }
            FillReturnType();
        }
Exemplo n.º 2
0
        public static string GetCallPrefix(ISymbol symbol)
        {
            if (symbol is SimpleSymbol || symbol.IsEnum)
            {
                var ret = StringRocks.MemberToPascalCase(symbol.JavaName);

                // We do not have unsigned versions of GetIntValue, etc.
                // We use the signed versions and cast the result
                if (ret == "Uint")
                {
                    return("Int");
                }
                if (ret == "Ushort")
                {
                    return("Short");
                }
                if (ret == "Ulong")
                {
                    return("Long");
                }
                if (ret == "Ubyte")
                {
                    return("Byte");
                }

                return(ret);
            }
            else
            {
                return("Object");
            }
        }
Exemplo n.º 3
0
        public XmlMethod(GenBase declaringType, XElement elem)
            : base(declaringType)
        {
            this.elem        = elem;
            GenericArguments = elem.GenericArguments();
            is_static        = elem.XGetAttribute("static") == "true";
            is_virtual       = !is_static && elem.XGetAttribute("final") == "false";
            if (elem.Attribute("managedName") != null)
            {
                name = elem.XGetAttribute("managedName");
            }
            else
            {
                name = StringRocks.MemberToPascalCase(JavaName);
            }

            is_abstract = elem.XGetAttribute("abstract") == "true";
            if (declaringType is InterfaceGen)
            {
                is_interface_default_method = !is_abstract && !is_static;
            }

            GenerateDispatchingSetter = elem.Attribute("generateDispatchingSetter") != null;

            foreach (var child in elem.Elements())
            {
                if (child.Name == "parameter")
                {
                    Parameters.Add(Parameter.FromElement(child));
                }
            }
            FillReturnType();
        }
Exemplo n.º 4
0
        private static void FixMethodName(Method method)
        {
            // Only run this if it's the default name (ie: not a user's "managedName")
            if (method.Name == StringRocks.MemberToPascalCase(method.JavaName).Replace('-', '_'))
            {
                // We want to remove the hyphen and anything afterwards to fix mangled names,
                // but a previous step converted it to an underscore. Remove the final
                // underscore and anything after it.
                var index = method.Name.IndexOf("_impl");

                if (index >= 0)
                {
                    method.Name = method.Name.Substring(0, index);
                }
                else
                {
                    method.Name = method.Name.Substring(0, method.Name.Length - 8);
                }
            }
        }
Exemplo n.º 5
0
        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);
        }