Ejemplo n.º 1
0
        public override void Visit(SyntaxNode node)
        {
            _syntaxGraph.AddNode(node);
            if (!(node == _syntaxTree.GetRoot()))
            {
                _syntaxGraph.AddEdge(node.Parent, node);
            }

            base.Visit(node);
        }
        public override void VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            SyntaxNode parentNode = node.Parent;

            // TODO: deal with other cases (local functions, accessors, anonymous functions).
            // Move up the syntax tree until method declaration (parent) is found.
            while (!(parentNode is BaseMethodDeclarationSyntax))
            {
                parentNode = parentNode.Parent;
            }
            // TODO: deal with cases where we can't match back to original declaration (e.g. system calls).
            var originalMethodSymbol = _semanticModel.GetSymbolInfo(node).Symbol;
            var syntaxReference      = originalMethodSymbol.DeclaringSyntaxReferences.FirstOrDefault();

            if (syntaxReference != null)
            {
                // Will return true only if we can match back to original function declaration.
                var originalInvocationDeclaration = syntaxReference.GetSyntax();
                _callGraph.AddEdge(parentNode, originalInvocationDeclaration);
            }

            base.VisitInvocationExpression(node);
        }