コード例 #1
0
        internal static TokenRenameInfo GetTokenRenameInfo(
            ISemanticFactsService semanticFacts,
            SemanticModel semanticModel,
            SyntaxToken token,
            CancellationToken cancellationToken)
        {
            var symbol = semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken);

            if (symbol != null)
            {
                return(TokenRenameInfo.CreateSingleSymbolTokenInfo(symbol));
            }

            var symbolInfo = semanticModel.GetSymbolInfo(token, cancellationToken);

            if (symbolInfo.Symbol != null)
            {
                if (symbolInfo.Symbol.IsTupleType())
                {
                    return(TokenRenameInfo.NoSymbolsTokenInfo);
                }

                return(TokenRenameInfo.CreateSingleSymbolTokenInfo(symbolInfo.Symbol));
            }

            if (symbolInfo.CandidateReason == CandidateReason.MemberGroup && symbolInfo.CandidateSymbols.Any())
            {
                // This is a reference from a nameof expression. Allow the rename but set the RenameOverloads option
                return(TokenRenameInfo.CreateMemberGroupTokenInfo(symbolInfo.CandidateSymbols));
            }

            return(TokenRenameInfo.NoSymbolsTokenInfo);
        }
コード例 #2
0
        internal static TokenRenameInfo GetTokenRenameInfo(
            ISemanticFactsService semanticFacts,
            SemanticModel semanticModel,
            SyntaxToken token,
            CancellationToken cancellationToken
            )
        {
            var symbol = semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken);

            if (symbol != null)
            {
                return(TokenRenameInfo.CreateSingleSymbolTokenInfo(symbol));
            }

            var symbolInfo = semanticModel.GetSymbolInfo(token, cancellationToken);

            if (symbolInfo.Symbol != null)
            {
                if (symbolInfo.Symbol.IsTupleType())
                {
                    return(TokenRenameInfo.NoSymbolsTokenInfo);
                }

                return(TokenRenameInfo.CreateSingleSymbolTokenInfo(symbolInfo.Symbol));
            }

            if (
                symbolInfo.CandidateReason == CandidateReason.MemberGroup &&
                symbolInfo.CandidateSymbols.Any()
                )
            {
                // This is a reference from a nameof expression. Allow the rename but set the RenameOverloads option
                return(TokenRenameInfo.CreateMemberGroupTokenInfo(symbolInfo.CandidateSymbols));
            }

            if (
                RenameLocation.ShouldRename(symbolInfo.CandidateReason) &&
                symbolInfo.CandidateSymbols.Length == 1
                )
            {
                // TODO(cyrusn): We're allowing rename here, but we likely should let the user
                // know that there is an error in the code and that rename results might be
                // inaccurate.
                return(TokenRenameInfo.CreateSingleSymbolTokenInfo(symbolInfo.CandidateSymbols[0]));
            }

            return(TokenRenameInfo.NoSymbolsTokenInfo);
        }
コード例 #3
0
        private static TokenSemanticInfo GetSemanticInfo(
            SemanticModel semanticModel,
            ISemanticFactsService semanticFacts,
            ISyntaxFactsService syntaxFacts,
            SyntaxToken token,
            CancellationToken cancellationToken)
        {
            var aliasSymbol = semanticModel.GetAliasInfo(token.Parent, cancellationToken);

            var bindableParent = syntaxFacts.GetBindableParent(token);
            var type           = semanticModel.GetTypeInfo(bindableParent, cancellationToken).Type;

            var declaredSymbol = MapSymbol(semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken), type);
            var allSymbols     = semanticModel.GetSymbolInfo(bindableParent, cancellationToken)
                                 .GetBestOrAllSymbols()
                                 .WhereAsArray(s => !s.Equals(declaredSymbol))
                                 .SelectAsArray(s => MapSymbol(s, type));

            // NOTE(cyrusn): This is a workaround to how the semantic model binds and returns
            // information for VB event handlers.  Namely, if you have:
            //
            // Event X]()
            // Sub Foo()
            //      Dim y = New $$XEventHandler(AddressOf bar)
            // End Sub
            //
            // Only GetTypeInfo will return any information for XEventHandler.  So, in this
            // case, we upgrade the type to be the symbol we return.
            if (type != null && allSymbols.Length == 0)
            {
                if (type.Kind == SymbolKind.NamedType)
                {
                    var namedType = (INamedTypeSymbol)type;
                    if (namedType.TypeKind == TypeKind.Delegate ||
                        namedType.AssociatedSymbol != null)
                    {
                        allSymbols = ImmutableArray.Create <ISymbol>(type);
                        type       = null;
                    }
                }
            }

            return(new TokenSemanticInfo(declaredSymbol, aliasSymbol, allSymbols, type));
        }
コード例 #4
0
        private static TokenSemanticInfo GetSemanticInfo(
            SemanticModelBase semanticModel,
            ISemanticFactsService semanticFacts,
            ISyntaxFactsService syntaxFacts,
            ISyntaxToken token,
            CancellationToken cancellationToken)
        {
            //var aliasSymbol = semanticModel.GetAliasInfo(token.Parent, cancellationToken);
            IAliasSymbol aliasSymbol = null;

            var bindableParent = syntaxFacts.GetBindableParent(token);
            var type           = semanticModel.GetTypeInfo(bindableParent).Type;

            var declaredSymbol = semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken);
            var allSymbols     = semanticModel.GetSymbolInfo(bindableParent)
                                 .GetBestOrAllSymbols()
                                 .WhereAsArray(s => !s.Equals(declaredSymbol))
                                 .SelectAsArray(s => s);

            return(new TokenSemanticInfo(declaredSymbol, aliasSymbol, allSymbols, type));
        }
コード例 #5
0
ファイル: RenameUtilities.cs プロジェクト: Rickinio/roslyn
        internal static TokenRenameInfo GetTokenRenameInfo(
            ISemanticFactsService semanticFacts,
            SemanticModel semanticModel,
            SyntaxToken token,
            CancellationToken cancellationToken)
        {
            var symbol = semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken);
            if (symbol != null)
            {
                return TokenRenameInfo.CreateSingleSymbolTokenInfo(symbol);
            }

            var symbolInfo = semanticModel.GetSymbolInfo(token, cancellationToken);
            if (symbolInfo.Symbol != null)
            {
                return TokenRenameInfo.CreateSingleSymbolTokenInfo(symbolInfo.Symbol);
            }

            if (symbolInfo.CandidateReason == CandidateReason.MemberGroup && symbolInfo.CandidateSymbols.Any())
            {
                // This is a reference from a nameof expression. Allow the rename but set the RenameOverloads option
                return TokenRenameInfo.CreateMemberGroupTokenInfo(symbolInfo.CandidateSymbols);
            }

            return TokenRenameInfo.NoSymbolsTokenInfo;
        }
コード例 #6
0
        private static IEnumerable <ISymbol> GetSymbolsEnumerable(
            SemanticModel semanticModel,
            ISemanticFactsService semanticFacts,
            ISyntaxFactsService syntaxFacts,
            SyntaxToken token,
            bool bindLiteralsToUnderlyingType,
            CancellationToken cancellationToken)
        {
            var declaredSymbol = semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken);

            if (declaredSymbol != null)
            {
                yield return(declaredSymbol);

                yield break;
            }

            var aliasInfo = semanticModel.GetAliasInfo(token.Parent, cancellationToken);

            if (aliasInfo != null)
            {
                yield return(aliasInfo);
            }

            var bindableParent = syntaxFacts.GetBindableParent(token);
            var allSymbols     = semanticModel.GetSymbolInfo(bindableParent, cancellationToken).GetBestOrAllSymbols().ToList();
            var type           = semanticModel.GetTypeInfo(bindableParent, cancellationToken).Type;

            if (type != null && allSymbols.Count == 0)
            {
                if ((bindLiteralsToUnderlyingType && syntaxFacts.IsLiteral(token)) ||
                    syntaxFacts.IsAwaitKeyword(token))
                {
                    yield return(type);
                }

                if (type.Kind == SymbolKind.NamedType)
                {
                    var namedType = (INamedTypeSymbol)type;
                    if (namedType.TypeKind == TypeKind.Delegate ||
                        namedType.AssociatedSymbol != null)
                    {
                        yield return(type);
                    }
                }
            }

            foreach (var symbol in allSymbols)
            {
                if (symbol.IsThisParameter() && type != null)
                {
                    yield return(type);
                }
                else if (symbol.IsFunctionValue())
                {
                    var method = symbol.ContainingSymbol as IMethodSymbol;

                    if (method != null)
                    {
                        if (method.AssociatedSymbol != null)
                        {
                            yield return(method.AssociatedSymbol);
                        }
                        else
                        {
                            yield return(method);
                        }
                    }
                    else
                    {
                        yield return(symbol);
                    }
                }
                else
                {
                    yield return(symbol);
                }
            }
        }
コード例 #7
0
ファイル: RenameUtilities.cs プロジェクト: XieShuquan/roslyn
        internal static TokenRenameInfo GetTokenRenameInfo(
            ISemanticFactsService semanticFacts,
            SemanticModel semanticModel,
            SyntaxToken token,
            CancellationToken cancellationToken)
        {
            var symbol = semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken);
            if (symbol != null)
            {
                return TokenRenameInfo.CreateSingleSymbolTokenInfo(symbol);
            }

            var symbolInfo = semanticModel.GetSymbolInfo(token, cancellationToken);
            if (symbolInfo.Symbol != null)
            {
                if (symbolInfo.Symbol.IsTupleType())
                {
                    return TokenRenameInfo.NoSymbolsTokenInfo;
                }

                return TokenRenameInfo.CreateSingleSymbolTokenInfo(symbolInfo.Symbol);
            }

            if (symbolInfo.CandidateReason == CandidateReason.MemberGroup && symbolInfo.CandidateSymbols.Any())
            {
                // This is a reference from a nameof expression. Allow the rename but set the RenameOverloads option
                return TokenRenameInfo.CreateMemberGroupTokenInfo(symbolInfo.CandidateSymbols);
            }

            if (RenameLocation.ShouldRename(symbolInfo.CandidateReason) &&
                symbolInfo.CandidateSymbols.Length == 1)
            {
                // TODO(cyrusn): We're allowing rename here, but we likely should let the user
                // know that there is an error in the code and that rename results might be
                // inaccurate.
                return TokenRenameInfo.CreateSingleSymbolTokenInfo(symbolInfo.CandidateSymbols[0]);
            }

            return TokenRenameInfo.NoSymbolsTokenInfo;
        }