Exemple #1
0
        private bool CheckMethod(IMethodSymbol methodSymbol)
        {
            Location   location   = methodSymbol.Locations[0];
            SyntaxNode syntaxNode = RolsynExtensions.GetSyntaxNodeFromLocation(solution, location);

            SemanticModel semanticModel = RolsynExtensions.GetSemanticModelFromLocation(solution, location);
            bool          result        = false;

            if (syntaxNode is MethodDeclarationSyntax)
            {
                MethodDeclarationSyntax             methodDeclarationSyntax = syntaxNode as MethodDeclarationSyntax;
                SyntaxList <StatementSyntax>        statements = methodDeclarationSyntax.Body.Statements;
                IEnumerable <ReturnStatementSyntax> returns    = statements.OfType <ReturnStatementSyntax>();
                foreach (ReturnStatementSyntax returnSyntax in returns)
                {
                    ISymbol returnSymbol = semanticModel.GetSymbolInfo(returnSyntax.Expression).Symbol;
                    if (returnSymbol is IFieldSymbol)
                    {
                        return(CheckFieldSymbol(returnSymbol as IFieldSymbol));
                    }
                }
            }
            ISymbol isymbol = semanticModel.GetDeclaredSymbol(syntaxNode);

            return(result);
        }
Exemple #2
0
        private bool CheckLocalSymbol(ILocalSymbol localSymbol)
        {
            Location      location      = localSymbol.Locations[0];
            SyntaxNode    syntaxNode    = RolsynExtensions.GetSyntaxNodeFromLocation(solution, location);
            SemanticModel semanticModel = RolsynExtensions.GetSemanticModelFromLocation(solution, location);
            ISymbol       isymbol       = semanticModel.GetDeclaredSymbol(syntaxNode);
            bool          result        = false;
            IEnumerable <ReferencedSymbol> referenceSymbols = SymbolFinder.FindReferencesAsync(isymbol, solution).Result;

            RolsynExtensions.IterateReferenceSymbols(referenceSymbols, (ISymbol symbol, ReferenceLocation referenceLocation) =>
            {
                SyntaxNode referenceNode = RolsynExtensions.GetSyntaxNodeFromLocation(solution, referenceLocation.Location);
                SyntaxNode parentNode    = referenceNode.Parent;
                if (parentNode is AssignmentExpressionSyntax)
                {
                    AssignmentExpressionSyntax assignmentExpressSyntax = parentNode as AssignmentExpressionSyntax;
                    SyntaxNode rightNode = assignmentExpressSyntax.Right;
                    ISymbol rightSymbol  = RolsynExtensions.GetISymbolFromSyntaxNode(solution, rightNode);
                    if (rightSymbol is IFieldSymbol)
                    {
                        result = this.CheckFieldSymbol(rightSymbol as IFieldSymbol);
                        return;
                    }
                }
            });
            return(result);
        }
Exemple #3
0
        private bool CheckParameterSymbol(IParameterSymbol parameterSymbol)
        {
            bool          result          = false;
            Location      location        = parameterSymbol.Locations[0];
            SyntaxNode    syntaxNode      = RolsynExtensions.GetSyntaxNodeFromLocation(solution, location);
            SemanticModel semanticModel   = RolsynExtensions.GetSemanticModelFromLocation(solution, location);
            ISymbol       workspaceSymbol = semanticModel.GetDeclaredSymbol(syntaxNode);

            ISymbol containerSymbol = workspaceSymbol.ContainingSymbol;
            IEnumerable <ReferencedSymbol> referenceSymbols = SymbolFinder.FindReferencesAsync(containerSymbol, solution).Result;

            RolsynExtensions.IterateReferenceSymbols(referenceSymbols, (ISymbol referenceSymbol, ReferenceLocation referenceLocation) =>
            {
                SyntaxNode referenceNode = RolsynExtensions.GetSyntaxNodeFromLocation(solution, referenceLocation.Location);
                InvocationExpressionSyntax invocationExpressionSyntax = referenceNode.Parent as InvocationExpressionSyntax;
                if (invocationExpressionSyntax != null)
                {
                    RolsynExtensions.IterateArgumentSyntax(invocationExpressionSyntax.ArgumentList, (ArgumentListSyntax argumentListSyntax, ArgumentSyntax argumentSyntax) =>
                    {
                        if (result)
                        {
                            return;
                        }
                        ISymbol isymbol = semanticModel.GetSymbolInfo(argumentSyntax.Expression).Symbol;
                        if (isymbol is IFieldSymbol)
                        {
                            result = CheckFieldSymbol(isymbol as IFieldSymbol);
                        }
                    });
                }
            });
            return(result);
        }