Ejemplo n.º 1
0
        // Returns true if a type was removed.
        bool RemoveMethod(JavaMethodModel method, TypeResolutionOptions options)
        {
            // We cannot remove a non-static, non-default method on an interface without breaking the contract.
            // If we need to do that we have to remove the entire interface instead.
            if (method.DeclaringType is JavaInterfaceModel && !method.IsStatic && method.IsAbstract && options.RemoveInterfacesWithUnresolvableMembers)
            {
                return(RemoveResolvedType(method.DeclaringType));
            }

            if (method is JavaConstructorModel ctor && method.DeclaringType is JavaClassModel klass)
            {
                klass.Constructors.Remove(ctor);
            }
        public JavaParameterModel(JavaMethodModel declaringMethod, string javaName, string javaType, string jniType, bool isNotNull)
        {
            DeclaringMethod = declaringMethod;
            Name            = javaName;
            Type            = javaType;
            JniType         = jniType;
            IsNotNull       = isNotNull;
            GenericType     = javaType;

            if (Type.Contains('<'))
            {
                Type = Type.Substring(0, Type.IndexOf('<'));
            }
        }
        // It should detect implementation method for:
        //	- equivalent implementation
        //	- generic instantiation
        //	- TODO: variance
        //	- TODO?: array indicator fixup ("T..." should match "T[]")
        public static bool IsImplementing(JavaMethodModel derived, JavaMethodModel basis, IDictionary <JavaTypeReference, JavaTypeReference> genericInstantiation)
        {
            if (genericInstantiation == null)
            {
                throw new ArgumentNullException("genericInstantiation");
            }

            if (basis.Name != derived.Name)
            {
                return(false);
            }

            if (basis.Parameters.Count != derived.Parameters.Count)
            {
                return(false);
            }

            if (basis.Parameters.Zip(derived.Parameters, (bp, dp) => IsParameterAssignableTo(dp, bp, derived, basis, genericInstantiation)).All(v => v))
            {
                return(true);
            }
            return(false);
        }
        static bool IsParameterAssignableTo(JavaParameterModel dp, JavaParameterModel bp, JavaMethodModel derived, JavaMethodModel basis, IDictionary <JavaTypeReference, JavaTypeReference> genericInstantiation)
        {
            // If type names are equivalent, they simply match... except that the generic type parameter names match.
            // Generic type arguments need more check, so do not examine them just by name.
            //
            // FIXME: It is likely that this check should NOT result in "this method is not an override",
            // but rather like "this method is an override, but it should be still generated in the resulting XML".
            // For example, this results in that java.util.EnumMap#put() is NOT an override of
            // java.util.AbstractMap#put(), it is an override, not just that it is still generated in the XML.
            if (bp.TypeModel?.ReferencedTypeParameter != null && dp.TypeModel?.ReferencedTypeParameter != null &&
                bp.TypeModel.ReferencedTypeParameter.ToString() != dp.TypeModel.ReferencedTypeParameter.ToString())
            {
                return(false);
            }
            if (bp.GenericType == dp.GenericType)
            {
                return(true);
            }

            if (bp.TypeModel?.ArrayPart != bp.TypeModel?.ArrayPart)
            {
                return(false);
            }

            // if base is type with generic type parameters and derived is without any generic args, that's OK.
            // java.lang.Class should match java.lang.Class<T>.
            if (bp.TypeModel?.ReferencedType != null && dp.TypeModel?.ReferencedType != null &&
                bp.TypeModel?.ReferencedType.FullName == dp.TypeModel?.ReferencedType.FullName &&
                dp.TypeModel?.TypeParameters == null)
            {
                return(true);
            }

            // generic instantiation check.
            var baseGTP = bp.TypeModel?.ReferencedTypeParameter;

            if (baseGTP != null)
            {
                if (baseGTP.Parent?.DeclaringMethod != null && IsConformantType(baseGTP, dp.TypeModel))
                {
                    return(true);
                }
                var k = genericInstantiation.Keys.FirstOrDefault(tr => bp.TypeModel?.Equals(tr) ?? false);
                if (k == null)
                {
                    // the specified generic type parameter is not part of
                    // the mappings e.g. non-instantiated ones.
                    return(false);
                }
                if (genericInstantiation [k].Equals(dp.TypeModel))
                {
                    // the specified generic type parameter exactly matches
                    // whatever specified at the derived method.
                    return(true);
                }
            }

            // FIXME: implement variance check.

            return(false);
        }