예제 #1
0
 /// <nodoc />
 public static SymbolLocation GetLocationFromNode(INode node, ISymbol symbol)
 {
     return(SymbolLocation.LocalLocation(
                node.GetSourceFile().Path.AbsolutePath,
                TextRange.FromLength(
                    node.GetNodeStartPositionWithoutTrivia(),
                    node.GetNodeWidth()),
                symbol));
 }
예제 #2
0
        /// <inheritdoc/>
        public bool IsNamespaceType(ISymbol thisSymbol)
        {
            Contract.Requires(thisSymbol != null, "symbol != null");
            if ((thisSymbol.Flags & SymbolFlags.ValueModule) == SymbolFlags.ValueModule)
            {
                return(true);
            }

            var typeOfNode = TypeChecker.GetTypeOfSymbolAtLocation(thisSymbol, thisSymbol.DeclarationList.First());

            return(IsNamespaceType(typeOfNode));
        }
예제 #3
0
        private Possible <IReadOnlyList <SymbolLocation> > GetDefinitionFromSymbol([NotNull] ISymbol symbol, INode node)
        {
            var result          = new List <SymbolLocation>();
            var declarations    = symbol.GetDeclarations();
            var symbolName      = TypeChecker.SymbolToString(symbol);
            var symbolKind      = Utilities.GetSymbolKind(symbol, node);
            var containerSymbol = symbol.Parent;
            var containerName   = containerSymbol != null?TypeChecker.SymbolToString(containerSymbol, node) : string.Empty;

            if (!TryAddConstructSignature(symbol, node, symbolKind, symbolName, containerName, result) &&
                !TryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result))
            {
                // Just add all the declarations
                foreach (var declaration in declarations)
                {
                    result.Add(GetLocationFromNode(declaration, symbol));
                }
            }

            return(result.Count != 0 ? Success(result.ToArray()) : SilentError());
        }
예제 #4
0
        private static bool TryAddSignature(
            ISymbol symbol,
            IEnumerable <IDeclaration> signatureDeclarations,
            bool selectConstructors,
            string symbolKind,
            string symbolName,
            string containerName,
            List <SymbolLocation> result)
        {
            var          declarations = new List <IDeclaration>();
            IDeclaration definition   = null;

            foreach (var declaration in signatureDeclarations ?? Enumerable.Empty <IDeclaration>())
            {
                if ((selectConstructors && declaration.Kind == SyntaxKind.Constructor) ||
                    (!selectConstructors && (declaration.Kind == SyntaxKind.FunctionDeclaration || declaration.Kind == SyntaxKind.MethodSignature)))
                {
                    declarations.Add(declaration);
                    if (declaration.As <IFunctionLikeDeclaration>()?.Body != null)
                    {
                        definition = declaration;
                    }
                }
            }

            if (definition != null)
            {
                result.Add(GetLocationFromNode(definition, symbol));
                return(true);
            }

            if (declarations.Count > 0)
            {
                result.Add(GetLocationFromNode(declarations.LastOrUndefined(), symbol));
                return(true);
            }

            return(false);
        }
예제 #5
0
        private static bool TryAddCallSignature(
            ISymbol symbol,
            INode location,
            string symbolKind,
            string symbolName,
            string containerName,
            List <Location> result)
        {
            if (DScriptUtilities.IsCallExpressionTarget(location) ||
                DScriptUtilities.IsNewExpressionTarget(location) ||
                DScriptUtilities.IsNameOfFunctionDeclaration(location))
            {
                return(TryAddSignature(
                           symbol.Declarations,
                           /*selectConstructors*/ false,
                           symbolKind,
                           symbolName,
                           containerName,
                           result));
            }

            return(false);
        }
예제 #6
0
        private static bool TryAddConstructSignature(
            ISymbol symbol,
            INode location,
            string symbolKind,
            string symbolName,
            string containerName,
            List <SymbolLocation> result)
        {
            // Applicable only if we are in a new expression, or we are on a constructor declaration
            // and in either case the symbol has a construct signature definition, i.e. class
            if (Utilities.IsNewExpressionTarget(location) || location.Kind == SyntaxKind.ConstructorKeyword)
            {
                if ((symbol.Flags & SymbolFlags.Class) != SymbolFlags.None)
                {
                    // Find the first class-like declaration and try to get the construct signature.
                    foreach (var declaration in symbol.GetDeclarations())
                    {
                        var classLikeDeclaration = NodeUtilities.IsClassLike(declaration);
                        if (classLikeDeclaration != null)
                        {
                            return(TryAddSignature(
                                       symbol,
                                       classLikeDeclaration.Members.Elements,
                                       /*selectConstructors*/ true,
                                       symbolKind,
                                       symbolName,
                                       containerName,
                                       result));
                        }
                    }

                    Debug.Fail("Expected declaration to have at least one class-like declaration");
                }
            }

            return(false);
        }
예제 #7
0
        /// <inheritdoc />
        public IDeclaration GetFirstNotFilteredDeclarationOrDefault(ISymbol resolvedSymbol)
        {
            if (resolvedSymbol == null)
            {
                return(null);
            }

            // Not using LINQ intentionally to avoid allocations.
            // This is a hot path.
            if (m_filteredOutSpecs == null)
            {
                return(resolvedSymbol.GetFirstDeclarationOrDefault());
            }

            foreach (var declaration in resolvedSymbol.DeclarationList)
            {
                if (declaration != null && !m_filteredOutSpecs.Contains(declaration.GetSourceFile()))
                {
                    return(declaration);
                }
            }

            return(null);
        }
예제 #8
0
 public IDeclaration GetFirstNotFilteredDeclarationOrDefault(ISymbol resolvedSymbol)
 {
     return(null);
 }
예제 #9
0
 public bool IsNamespaceType(ISymbol symbol)
 {
     Contract.Requires(symbol != null, "symbol != null");
     throw new NotImplementedException();
 }
예제 #10
0
 public ISymbol GetAliasedSymbol(ISymbol symbol, bool resolveAliasRecursively = true)
 {
     Contract.Requires(symbol != null, "symbol != null");
     throw new NotImplementedException();
 }
예제 #11
0
 public string GetFullyQualifiedName(ISymbol symbol)
 {
     Contract.Requires(symbol != null, "symbol != null");
     throw new NotImplementedException();
 }
예제 #12
0
        private Result <ArrayOrObject <Location, Location>, ResponseError> GetDefinitionFromSymbol([NotNull] ISymbol symbol, INode node)
        {
            var result          = new List <Location>();
            var declarations    = symbol.GetDeclarations();
            var symbolName      = TypeChecker.SymbolToString(symbol);
            var symbolKind      = DScriptUtilities.GetSymbolKind(symbol, node);
            var containerSymbol = symbol.Parent;
            var containerName   = containerSymbol != null?TypeChecker.SymbolToString(containerSymbol, node) : string.Empty;

            if (!TryAddConstructSignature(symbol, node, symbolKind, symbolName, containerName, result) &&
                !TryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result))
            {
                // Just add all the declarations
                foreach (var declaration in declarations)
                {
                    result.Add(GetLocationFromNode(declaration));
                }
            }

            return(Success(result.ToArray()));
        }
예제 #13
0
 /// <inheritdoc/>
 public ISymbol GetAliasedSymbol(ISymbol symbol, bool resolveAliasRecursively = true)
 {
     Contract.Requires(symbol != null, "symbol != null");
     return(TypeChecker.GetAliasedSymbol(symbol, resolveAliasRecursively));
 }
예제 #14
0
 /// <inheritdoc/>
 public string GetFullyQualifiedName(ISymbol symbol)
 {
     Contract.Requires(symbol != null, "symbol != null");
     return(TypeChecker.GetFullyQualifiedName(symbol));
 }