Ejemplo 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();
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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");
            }
        }
Ejemplo n.º 4
0
        string CreateNamespaceCref(string jniTypeName)
        {
            string package = jniTypeName.Substring(0, jniTypeName.LastIndexOf('/'));

            package = package.Replace('/', '.');
            if (Application.PackageRenames.ContainsKey(package))
            {
                package = Application.PackageRenames [package];
            }
            return("N:" + StringRocks.PackageToPascalCase(package));
        }
Ejemplo n.º 5
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);
                }
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public static GenBaseSupport CreateGenBaseSupport(XElement pkg, XElement elem, bool isInterface)
        {
            var support = new GenBaseSupport {
                IsAcw          = true,
                IsDeprecated   = elem.XGetAttribute("deprecated") != "not deprecated",
                IsGeneratable  = true,
                JavaSimpleName = elem.XGetAttribute("name"),
                PackageName    = pkg.XGetAttribute("name"),
                Visibility     = elem.XGetAttribute("visibility")
            };

            if (support.IsDeprecated)
            {
                support.DeprecatedComment = elem.XGetAttribute("deprecated");

                if (support.DeprecatedComment == "deprecated")
                {
                    support.DeprecatedComment = "This class is obsoleted in this android platform";
                }
            }

            if (support.Visibility == "protected")
            {
                support.Visibility = "protected internal";
            }

            if (pkg.Attribute("managedName") != null)
            {
                support.Namespace = pkg.XGetAttribute("managedName");
            }
            else
            {
                support.Namespace = StringRocks.PackageToPascalCase(support.PackageName);
            }

            var tpn = elem.Element("typeParameters");

            if (tpn != null)
            {
                support.TypeParameters = GenericParameterDefinitionList.FromXml(tpn);
                support.IsGeneric      = true;
                int idx = support.JavaSimpleName.IndexOf('<');
                if (idx > 0)
                {
                    support.JavaSimpleName = support.JavaSimpleName.Substring(0, idx);
                }
            }
            else
            {
                int idx = support.JavaSimpleName.IndexOf('<');
                if (idx > 0)
                {
                    throw new NotSupportedException("Looks like old API XML is used, which we don't support anymore.");
                }
            }

            string raw_name;

            if (elem.Attribute("managedName") != null)
            {
                support.Name     = elem.XGetAttribute("managedName");
                support.FullName = string.Format("{0}.{1}", support.Namespace, support.Name);
                int idx = support.Name.LastIndexOf('.');
                support.Name = idx > 0 ? support.Name.Substring(idx + 1) : support.Name;
                raw_name     = support.Name;
            }
            else
            {
                int idx = support.JavaSimpleName.LastIndexOf('.');
                support.Name = idx > 0 ? support.JavaSimpleName.Substring(idx + 1) : support.JavaSimpleName;
                if (char.IsLower(support.Name [0]))
                {
                    support.Name = StringRocks.TypeToPascalCase(support.Name);
                }
                raw_name = support.Name;
                support.TypeNamePrefix = isInterface ? IsPrefixableName(raw_name) ? "I" : string.Empty : string.Empty;
                support.Name           = EnsureValidIdentifer(support.TypeNamePrefix + raw_name);
                support.FullName       = string.Format("{0}.{1}{2}", support.Namespace, idx > 0 ? StringRocks.TypeToPascalCase(support.JavaSimpleName.Substring(0, idx + 1)) : string.Empty, support.Name);
            }

            support.IsObfuscated = IsObfuscatedName(pkg.Elements().Count(), support.JavaSimpleName) && elem.XGetAttribute("obfuscated") != "false";

            return(support);
        }
        public XmlGenBaseSupport(XElement pkg, XElement elem)
        {
            deprecated = elem.XGetAttribute("deprecated") != "not deprecated";
            if (deprecated)
            {
                deprecatedComment = elem.XGetAttribute("deprecated");
                if (deprecatedComment == "deprecated")
                {
                    deprecatedComment = "This class is obsoleted in this android platform";
                }
            }
            visibility = elem.XGetAttribute("visibility");
            if (visibility == "protected")
            {
                visibility = "protected internal";
            }

            pkg_name  = pkg.XGetAttribute("name");
            java_name = elem.XGetAttribute("name");
            if (pkg.Attribute("managedName") != null)
            {
                ns = pkg.XGetAttribute("managedName");
            }
            else
            {
                ns = StringRocks.PackageToPascalCase(PackageName);
            }

            var tpn = elem.Element("typeParameters");

            if (tpn != null)
            {
                type_params = GenericParameterDefinitionList.FromXml(tpn);
                is_generic  = true;
                int idx = java_name.IndexOf('<');
                if (idx > 0)
                {
                    java_name = java_name.Substring(0, idx);
                }
            }
            else
            {
                int idx = java_name.IndexOf('<');
                if (idx > 0)
                {
                    throw new NotSupportedException("Looks like old API XML is used, which we don't support anymore.");
                }
            }

            if (elem.Attribute("managedName") != null)
            {
                name      = elem.XGetAttribute("managedName");
                full_name = String.Format("{0}.{1}", ns, name);
                int idx = name.LastIndexOf('.');
                name     = idx > 0 ? name.Substring(idx + 1) : name;
                raw_name = name;
            }
            else
            {
                int idx = java_name.LastIndexOf('.');
                name = idx > 0 ? java_name.Substring(idx + 1) : java_name;
                if (Char.IsLower(name[0]))
                {
                    name = StringRocks.TypeToPascalCase(name);
                }
                raw_name  = name;
                name      = TypeNamePrefix + raw_name;
                full_name = String.Format("{0}.{1}{2}", ns, idx > 0 ? StringRocks.TypeToPascalCase(java_name.Substring(0, idx + 1)) : String.Empty, name);
            }

            obfuscated = IsObfuscatedName(pkg.Elements().Count(), java_name) && elem.XGetAttribute("obfuscated") != "false";
        }