/// <summary>
        /// Is our <see cref="instanceOfCondition"/> an interface implemented by the given type (or one of it's base types)?
        /// </summary>
        private bool Implements(ReachableContext context, ClassFile javaClass)
        {
            while (javaClass != null)
            {
                if (javaClass.ClassName == className)
                {
                    return(true);
                }

                if (javaClass.Interfaces != null)
                {
                    foreach (var intfRef in javaClass.Interfaces)
                    {
                        ClassFile intf;
                        if (context.TryLoadClass(intfRef.ClassName, out intf))
                        {
                            if (Implements(context, intf))
                            {
                                return(true);
                            }
                        }
                    }
                }

                ClassFile superClass;
                if (!javaClass.TryGetSuperClass(out superClass))
                {
                    return(false);
                }
                javaClass = superClass;
            }
            return(false);
        }
        /// <summary>
        /// Gets all classes that the given classes extends or implements
        /// </summary>
        private IEnumerable <ClassFile> SelfBaseAndImplementedClasses(ClassFile original)
        {
            // Return self
            yield return(original);

            // Base classes
            var currentClass = original;

            while (currentClass != null)
            {
                if (currentClass.TryGetSuperClass(out currentClass))
                {
                    yield return(currentClass);
                }
                else
                {
                    break;
                }
            }

            // Implemented interfaces
            currentClass = original;
            while (currentClass != null)
            {
                if (currentClass.Interfaces != null)
                {
                    foreach (var intfRef in currentClass.Interfaces)
                    {
                        ClassFile intfClass;
                        if (Loader.TryLoadClass(intfRef.ClassName, out intfClass))
                        {
                            foreach (var x in SelfBaseAndImplementedClasses(intfClass))
                            {
                                yield return(x);
                            }
                        }
                    }
                }
                if (currentClass.TryGetSuperClass(out currentClass))
                {
                    yield return(currentClass);
                }
                else
                {
                    break;
                }
            }
        }
 /// <summary>
 /// Is our <see cref="instanceOfCondition"/> a base class of the given type?
 /// </summary>
 private bool Extends(ClassFile javaClass)
 {
     while (javaClass != null)
     {
         if (javaClass.ClassName == className)
         {
             return(true);
         }
         ClassFile superClass;
         if (!javaClass.TryGetSuperClass(out superClass))
         {
             return(false);
         }
         javaClass = superClass;
     }
     return(false);
 }
        /// <summary>
        /// Add this type to the layout.xml file if needed.
        /// </summary>
        public override void FillLayoutXml(JarFile jf, XElement parent)
        {
            var baseName = GetLayoutBaseClassName(cf);

            if (baseName == null)
            {
                return;
            }
            string elementName;

            switch (baseName)
            {
            case SdkConstants.ViewClass:
                elementName = "view";
                break;

            case SdkConstants.ViewGroupClass:
                elementName = "viewgroup";
                break;

            default:
                return;
            }
            var shortName = GetShortName(cf.ClassName);
            var element   = new XElement(elementName,
                                         new XAttribute("name", shortName));

            if (cf.IsAbstract)
            {
                element.Add(new XAttribute("abstract", "true"));
            }
            ClassFile superClass;

            if (cf.TryGetSuperClass(out superClass))
            {
                if ((superClass != null) && (GetLayoutBaseClassName(superClass) != null))
                {
                    element.Add(new XAttribute("super", GetShortName(superClass.ClassName)));
                }
            }
            parent.Add(element);
        }
Example #5
0
        /// <summary>
        /// Try to resolve a type parameter in a base class.
        /// </summary>
        private NetTypeReference ResolveTypeParameterInBaseClass(ClassFile @class, string name, TargetFramework target)
        {
            ClassFile baseClass;

            while (@class.TryGetSuperClass(out baseClass))
            {
                var signature = baseClass.Signature;
                if (signature != null)
                {
                    var typeParam = signature.TypeParameters.FirstOrDefault(x => x.Name == name);
                    if (typeParam != null)
                    {
                        var index    = signature.TypeParameters.IndexOf(typeParam);
                        var javaType = @class.Signature.SuperClass.Arguments.ElementAt(index).Signature;
                        return(javaType.Resolve(target, this, method.IsSignConverted));
                    }
                }
                @class = baseClass;
            }
            return(null);
        }
        /// <summary>
        /// Gets the class name of the base class relevant for layout.xml.
        /// </summary>
        private static string GetLayoutBaseClassName(ClassFile classFile)
        {
            while (true)
            {
                var className = classFile.ClassName;
                switch (className)
                {
                case SdkConstants.ViewClass:
                case SdkConstants.ViewGroupClass:
                    return(className);

                case SdkConstants.ObjectClass:
                    return(null);
                }

                // Go to the base class
                if (!classFile.TryGetSuperClass(out classFile))
                {
                    return(null);
                }
            }
        }
        /// <summary>
        /// Gets all classes that the given classes extends or implements
        /// </summary>
        private IEnumerable<ClassFile> SelfBaseAndImplementedClasses(ClassFile original)
        {
            // Return self
            yield return original;

            // Base classes
            var currentClass = original;
            while (currentClass != null)
            {
                if (currentClass.TryGetSuperClass(out currentClass))
                {
                    yield return currentClass;
                }
                else
                {
                    break;
                }
            }

            // Implemented interfaces
            currentClass = original;
            while (currentClass != null)
            {
                if (currentClass.Interfaces != null)
                {
                    foreach (var intfRef in currentClass.Interfaces)
                    {
                        ClassFile intfClass;
                        if (Loader.TryLoadClass(intfRef.ClassName, out intfClass))
                        {
                            foreach (var x in SelfBaseAndImplementedClasses(intfClass))
                            {
                                yield return x;
                            }
                        }
                    }
                }
                if (currentClass.TryGetSuperClass(out currentClass))
                {
                    yield return currentClass;
                }
                else
                {
                    break;
                }
            }
        }