Example #1
0
 protected ClassGen(GenBaseSupport support)
     : base(support)
 {
     inherits_object = true;
     if (Namespace == "Java.Lang" && (Name == "Object" || Name == "Throwable"))
     {
         inherits_object = false;
     }
 }
        public ClassGen(GenBaseSupport support) : base(support)
        {
            InheritsObject = true;

            if (Namespace == "Java.Lang" && (Name == "Object" || Name == "Throwable"))
            {
                InheritsObject = false;
            }

            DefaultValue = "IntPtr.Zero";
            NativeType   = "IntPtr";
        }
Example #3
0
        public static GenBaseSupport CreateGenBaseSupport(TypeDefinition t, CodeGenerationOptions opt)
        {
            var obs_attr = GetObsoleteAttribute(t.CustomAttributes);
            var reg_attr = GetRegisterAttribute(t.CustomAttributes);

            var jn  = reg_attr != null ? ((string)reg_attr.ConstructorArguments [0].Value).Replace('/', '.') : t.FullNameCorrected();
            var idx = jn.LastIndexOf('.');

            var support = new GenBaseSupport {
                IsAcw          = reg_attr != null,
                IsDeprecated   = obs_attr != null,
                IsGeneratable  = false,
                IsGeneric      = t.HasGenericParameters,
                IsObfuscated   = false,               // obfuscated types have no chance to be already bound in managed types.
                Name           = t.Name,
                Namespace      = t.Namespace,
                PackageName    = idx < 0 ? string.Empty : jn.Substring(0, idx),
                TypeParameters = GenericParameterDefinitionList.FromMetadata(t.GenericParameters),
                Visibility     = t.IsPublic || t.IsNestedPublic ? "public" : "protected internal"
            };

            support.JavaSimpleName = TypeNameUtilities.FilterPrimitiveFullName(t.FullNameCorrected());

            if (support.JavaSimpleName == null)
            {
                support.JavaSimpleName = idx < 0 ? jn : jn.Substring(idx + 1);
                support.FullName       = t.FullNameCorrected();
            }
            else
            {
                var sym = opt.SymbolTable.Lookup(support.JavaSimpleName);
                support.FullName = sym != null ? sym.FullName : t.FullNameCorrected();
            }

            support.JavaSimpleName = support.JavaSimpleName.Replace('$', '.');

            if (support.IsDeprecated)
            {
                support.DeprecatedComment = GetObsoleteComment(obs_attr) ?? "This class is obsoleted in this android platform";
            }

            return(support);
        }
Example #4
0
 protected GenBase(GenBaseSupport support)
 {
     this.support = support;
 }
Example #5
0
 protected InterfaceGen(GenBaseSupport support)
     : base(support)
 {
 }
Example #6
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);
        }
Example #7
0
 public InterfaceGen(GenBaseSupport support) : base(support)
 {
     DefaultValue = "IntPtr.Zero";
     NativeType   = "IntPtr";
 }