예제 #1
0
        public static ITypeElement GetTypeElement([NotNull] this FSharpEntity entity, [NotNull] IPsiModule psiModule)
        {
            if (((FSharpSymbol)entity).DeclarationLocation == null || entity.IsByRef || entity.IsProvidedAndErased)
            {
                return(null);
            }

            if (!entity.IsFSharpAbbreviation)
            {
                var clrTypeName = entity.GetClrName();
                if (clrTypeName == null)
                {
                    return(null);
                }

                var typeElements = psiModule.GetSymbolScope().GetTypeElementsByCLRName(clrTypeName);
                if (typeElements.IsEmpty())
                {
                    return(null);
                }

                if (typeElements.Length == 1)
                {
                    return(typeElements[0]);
                }

                var assemblySimpleName = entity.Assembly?.SimpleName;
                return(assemblySimpleName != null
          ? typeElements.FirstOrDefault(typeElement => typeElement.Module.DisplayName == assemblySimpleName)
          : null);
            }

            var symbolScope = psiModule.GetSymbolScope();

            while (entity.IsFSharpAbbreviation)
            {
                // FCS returns Clr names for non-abbreviated types only, using fullname
                var typeElement = TryFindByNames(GetPossibleNames(entity), symbolScope);
                if (typeElement != null)
                {
                    return(typeElement);
                }

                var abbreviatedType = entity.AbbreviatedType;
                if (!abbreviatedType.HasTypeDefinition)
                {
                    return(null);
                }

                entity = entity.AbbreviatedType.TypeDefinition;
            }

            return(entity.GetTypeElement(psiModule));
        }
        private static INamespace GetDeclaredNamespace([NotNull] FSharpEntity entity, IPsiModule psiModule)
        {
            var name = entity.LogicalName;
            var containingNamespace = entity.Namespace?.Value;
            var fullName            = containingNamespace != null ? containingNamespace + "." + name : name;
            var elements            = psiModule.GetSymbolScope().GetElementsByQualifiedName(fullName);

            return(elements.FirstOrDefault() as INamespace);
        }
        internal static ITypeElement GetTypeElement([NotNull] FSharpEntity entity, [NotNull] IPsiModule psiModule)
        {
            if (((FSharpSymbol)entity).DeclarationLocation == null || entity.IsByRef || entity.IsProvidedAndErased)
            {
                return(null);
            }

            if (!entity.IsFSharpAbbreviation)
            {
                var clrName = FSharpTypesUtil.GetClrName(entity);
                return(clrName != null
          ? TypeFactory.CreateTypeByCLRName(clrName, psiModule).GetTypeElement()
          : null);
            }

            var symbolScope = psiModule.GetSymbolScope();

            while (entity.IsFSharpAbbreviation)
            {
                // FCS returns Clr names for non-abbreviated types only, using fullname
                var typeElement = TryFindByNames(GetPossibleNames(entity), symbolScope);
                if (typeElement != null)
                {
                    return(typeElement);
                }

                var abbreviatedType = entity.AbbreviatedType;
                if (!abbreviatedType.HasTypeDefinition)
                {
                    return(null);
                }

                entity = entity.AbbreviatedType.TypeDefinition;
            }

            var name = FSharpTypesUtil.GetClrName(entity);

            return(name != null?TypeFactory.CreateTypeByCLRName(name, psiModule).GetTypeElement() : null);
        }
        public static ITypeElement GetTypeElement([NotNull] this FSharpEntity entity, [NotNull] IPsiModule psiModule)
        {
            if (((FSharpSymbol)entity).DeclarationLocation == null || entity.IsByRef || entity.IsProvidedAndErased)
            {
                return(null);
            }

            if (!entity.IsFSharpAbbreviation)
            {
                var clrTypeName = entity.GetClrName();
                if (clrTypeName == null)
                {
                    return(null);
                }

                var typeElements = psiModule.GetSymbolScope().GetTypeElementsByCLRName(clrTypeName);
                if (typeElements.IsEmpty())
                {
                    return(null);
                }

                if (typeElements.Length == 1)
                {
                    return(typeElements[0]);
                }

                // If there are multiple entities with given FQN, try to choose one based on assembly name or entity kind.
                var fcsAssemblySimpleName = entity.Assembly?.SimpleName;
                if (fcsAssemblySimpleName == null)
                {
                    return(null);
                }

                var isModule = entity.IsFSharpModule;
                return(typeElements.FirstOrDefault(typeElement =>
                {
                    if (typeElement.Module.DisplayName != fcsAssemblySimpleName)
                    {
                        return false;
                    }

                    // Happens when there are an exception and a module with the same name.
                    // It's now allowed, but we want keep resolve working where possible.
                    if (typeElement is IFSharpDeclaredElement)
                    {
                        return isModule == typeElement is IFSharpModule;
                    }

                    return true;
                }));
            }

            var symbolScope = psiModule.GetSymbolScope();

            while (entity.IsFSharpAbbreviation)
            {
                // FCS returns Clr names for non-abbreviated types only, using fullname
                var typeElement = TryFindByNames(GetPossibleNames(entity), symbolScope);
                if (typeElement != null)
                {
                    return(typeElement);
                }

                var abbreviatedType = entity.AbbreviatedType;
                if (!abbreviatedType.HasTypeDefinition)
                {
                    return(null);
                }

                entity = entity.AbbreviatedType.TypeDefinition;
            }

            return(entity.GetTypeElement(psiModule));
        }
예제 #5
0
 public INamespace GetContainingNamespace() =>
 Method.GetContainingType()?.GetContainingNamespace() ??
 Module.GetSymbolScope().GlobalNamespace;