Пример #1
0
        public override SyntaxNode VisitObjectCreationExpression(ObjectCreationExpressionSyntax node)
        {
            var symbol = SemanticHelper.GetSemanticSymbol(node, _semanticModel, _preportSemanticModel);
            ExpressionSyntax newNode      = node;
            bool             skipChildren = false; // This is here to skip actions on children node when the main identifier was changed. Just use new expression for the subsequent children actions.

            foreach (var action in _allActions.OfType <ObjectCreationExpressionAction>())
            {
                if (newNode.ToString() == action.Key || symbol?.OriginalDefinition.ToDisplayString() == action.Key)
                {
                    var actionExecution = new GenericActionExecution(action, _filePath)
                    {
                        TimesRun = 1
                    };
                    try
                    {
                        skipChildren = true;
                        newNode      = action.ObjectCreationExpressionGenericActionFunc(_syntaxGenerator, (ObjectCreationExpressionSyntax)newNode);
                        allExecutedActions.Add(actionExecution);
                        LogHelper.LogInformation(string.Format("{0}", action.Description));
                    }
                    catch (Exception ex)
                    {
                        var actionExecutionException = new ActionExecutionException(action.Name, action.Key, ex);
                        actionExecution.InvalidExecutions = 1;
                        LogHelper.LogError(actionExecutionException);
                    }
                }
            }
            if (!skipChildren)
            {
                newNode = (ObjectCreationExpressionSyntax)base.VisitObjectCreationExpression(node);
            }
            return(newNode);
        }
Пример #2
0
        public override SyntaxNode VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
        {
            var symbol  = SemanticHelper.GetSemanticSymbol(node, _semanticModel, _preportSemanticModel);
            var newNode = base.VisitMemberAccessExpression(node);

            if (symbol != null)
            {
                var nodeKey = $"{symbol.ContainingType}.{node.Name}";

                foreach (var action in _allActions.OfType <MemberAccessAction>())
                {
                    if (nodeKey == action.Key)
                    {
                        var actionExecution = new GenericActionExecution(action, _filePath)
                        {
                            TimesRun = 1
                        };
                        try
                        {
                            newNode = action.MemberAccessActionFunc(_syntaxGenerator, newNode);
                            LogHelper.LogInformation(string.Format("{0}: {1}", node.SpanStart, action.Description));
                        }
                        catch (Exception ex)
                        {
                            var actionExecutionException = new ActionExecutionException(action.Name, action.Key, ex);
                            actionExecution.InvalidExecutions = 1;
                            LogHelper.LogError(actionExecutionException);
                        }
                        allExecutedActions.Add(actionExecution);
                    }
                }
            }
            return(newNode);
        }
Пример #3
0
        public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node)
        {
            var symbol = SemanticHelper.GetSemanticSymbol(node, _semanticModel, _preportSemanticModel);

            var identifierNameSyntax = (IdentifierNameSyntax)base.VisitIdentifierName(node);

            if (symbol != null)
            {
                var nodeKey = symbol.OriginalDefinition != null?symbol.OriginalDefinition.ToString() : symbol.ToString();

                foreach (var action in _allActions.OfType <IdentifierNameAction>())
                {
                    if (nodeKey == action.Key && identifierNameTypes.Contains(identifierNameSyntax.Parent?.GetType()))
                    {
                        var actionExecution = new GenericActionExecution(action, _filePath)
                        {
                            TimesRun = 1
                        };
                        try
                        {
                            identifierNameSyntax = action.IdentifierNameActionFunc(_syntaxGenerator, identifierNameSyntax);
                            LogHelper.LogInformation(string.Format("{0}: {1}", node.SpanStart, action.Description));
                        }
                        catch (Exception ex)
                        {
                            var actionExecutionException = new ActionExecutionException(action.Name, action.Key, ex);
                            actionExecution.InvalidExecutions = 1;
                            LogHelper.LogError(actionExecutionException);
                        }
                        allExecutedActions.Add(actionExecution);
                    }
                }
            }
            return(identifierNameSyntax);
        }
Пример #4
0
        public override SyntaxNode VisitExpressionStatement(ExpressionStatementSyntax node)
        {
            var        newNode      = base.VisitExpressionStatement(node);
            SyntaxNode modifiedNode = newNode;

            var invocationExpressionNodes = node.DescendantNodes().OfType <InvocationExpressionSyntax>().ToList();

            if (invocationExpressionNodes.Count <= 0)
            {
                return(newNode);
            }
            var invocationExpressionNode = invocationExpressionNodes.First();

            var symbol = SemanticHelper.GetSemanticSymbol(invocationExpressionNode, _semanticModel, _preportSemanticModel);

            if (symbol == null)
            {
                return(newNode);
            }
            var nodeKey = symbol.OriginalDefinition.ToString();

            foreach (var action in _allActions.OfType <ExpressionAction>())
            {
                if (nodeKey == action.Key)
                {
                    var actionExecution = new GenericActionExecution(action, _filePath)
                    {
                        TimesRun = 1
                    };
                    try
                    {
                        modifiedNode = action.ExpressionActionFunc(_syntaxGenerator, newNode);
                        LogHelper.LogInformation(string.Format("{0}: {1}", node.SpanStart, action.Description));
                    }
                    catch (Exception ex)
                    {
                        var actionExecutionException = new ActionExecutionException(action.Name, action.Key, ex);
                        actionExecution.InvalidExecutions = 1;
                        LogHelper.LogError(actionExecutionException);
                    }
                    allExecutedActions.Add(actionExecution);
                }
            }
            return(modifiedNode);
        }