Exemplo n.º 1
0
        public JavaTypeReference ResolveTypeReference(JavaTypeName tn, params JavaTypeParameter [] contextTypeParameters)
        {
            var tp = contextTypeParameters.FirstOrDefault(xp => xp.Name == tn.DottedName);

            if (tp != null)
            {
                return(new JavaTypeReference(tp, tn.ArrayPart));
            }

            if (tn.DottedName == JavaTypeReference.GenericWildcard.SpecialName)
            {
                return(new JavaTypeReference(tn.BoundsType, tn.GenericConstraints?.Select(gc => ResolveTypeReference(gc, contextTypeParameters)), tn.ArrayPart));
            }

            var primitive = JavaTypeReference.GetSpecialType(tn.DottedName);

            if (primitive != null)
            {
                return(tn.ArrayPart == null && tn.GenericConstraints == null ? primitive : new JavaTypeReference(primitive, tn.ArrayPart, tn.BoundsType, tn.GenericConstraints?.Select(gc => ResolveTypeReference(gc, contextTypeParameters))));
            }

            var type = FindType(tn.FullNameNonGeneric);

            if (type is null)
            {
                throw new JavaTypeResolutionException(tn.FullNameNonGeneric);
            }

            return(new JavaTypeReference(type,
                                         tn.GenericArguments != null ? tn.GenericArguments.Select(_ => ResolveTypeReference(_, contextTypeParameters)).ToArray() : null,
                                         tn.ArrayPart));
        }
        public JavaTypeReference(JavaTypeReference referencedType, string?arrayPart, string?wildcardBoundsType, IEnumerable <JavaTypeReference>?wildcardConstraints)
        {
            if (referencedType == null)
            {
                throw new ArgumentNullException(nameof(referencedType));
            }

            SpecialName             = referencedType.SpecialName;
            WildcardBoundsType      = wildcardBoundsType;
            WildcardConstraints     = wildcardConstraints?.ToList();
            ReferencedType          = referencedType.ReferencedType;
            ReferencedTypeParameter = referencedType.ReferencedTypeParameter;
            TypeParameters          = referencedType.TypeParameters;
            ArrayPart = arrayPart;
        }