예제 #1
0
        private RootUstNode AnalyzeFile(SourceFileBuildResult sourceFileBuildResult, string projectRootPath)
        {
            CodeContext codeContext = new CodeContext(sourceFileBuildResult.PrePortSemanticModel,
                                                      sourceFileBuildResult.SemanticModel,
                                                      sourceFileBuildResult.SyntaxTree,
                                                      projectRootPath,
                                                      sourceFileBuildResult.SourceFilePath,
                                                      AnalyzerConfiguration,
                                                      Logger);

            Logger.LogDebug("Analyzing: " + sourceFileBuildResult.SourceFileFullPath);

            using CSharpRoslynProcessor processor = new CSharpRoslynProcessor(codeContext);

            var result = processor.Visit(codeContext.SyntaxTree.GetRoot());

            return(result as RootUstNode);
        }
예제 #2
0
        private void RunCodeChanges(SyntaxNode root, SourceFileBuildResult sourceFileBuildResult, FileActions currentFileActions, ConcurrentDictionary <string, List <GenericActionExecution> > actionsPerProject)
        {
            ActionsRewriter oneRewriter = new ActionsRewriter(sourceFileBuildResult.SemanticModel, sourceFileBuildResult.PrePortSemanticModel, sourceFileBuildResult.SyntaxGenerator, currentFileActions.FilePath, currentFileActions.AllActions);

            root = oneRewriter.Visit(root);
            var result = root.NormalizeWhitespace().ToFullString();

            if (!_projectConfiguration.IsMockRun)
            {
                File.WriteAllText(sourceFileBuildResult.SourceFileFullPath, result);
            }

            var processedActions = ValidateActions(oneRewriter.allExecutedActions, root);

            processedActions = AddActionsWithoutExecutions(currentFileActions, oneRewriter.allExecutedActions);

            if (!actionsPerProject.TryAdd(sourceFileBuildResult.SourceFileFullPath, processedActions))
            {
                throw new FilePortingException(sourceFileBuildResult.SourceFilePath, new Exception("File already exists in collection"));
            }
        }
예제 #3
0
        private void GenerateCodeChanges(SyntaxNode root, SourceFileBuildResult sourceFileBuildResult, FileActions currentFileActions, int fileActionsCount, ConcurrentDictionary <string, List <GenericActionExecution> > actionsPerProject)
        {
            if (currentFileActions != null)
            {
                var normalizedRoot = root.NormalizeWhitespace().ToFullString();
                //If true, and we are doing a full analysis, line endings and spaces need to be normalized:
                //TODO change the condition to be a config value in ProjectConfiguration instead of file count
                if (normalizedRoot != root.ToFullString() && fileActionsCount > 1)
                {
                    File.WriteAllText(sourceFileBuildResult.SourceFileFullPath, normalizedRoot);
                }

                currentFileActions.NodeTokens.ForEach(nodetoken =>
                {
                    nodetoken.AllActions.ForEach(nodeAction => {
                        ActionsRewriter oneRewriter = new ActionsRewriter(sourceFileBuildResult.SemanticModel, sourceFileBuildResult.PrePortSemanticModel, sourceFileBuildResult.SyntaxGenerator, currentFileActions.FilePath, nodeAction);

                        var newRoot    = oneRewriter.Visit(root);
                        var allChanges = newRoot.SyntaxTree.GetChanges(root.SyntaxTree);

                        foreach (var textChange in allChanges)
                        {
                            var fileLinePositionSpan = root.SyntaxTree.GetMappedLineSpan(textChange.Span);
                            var newTextChange        = new TextChange()
                            {
                                FileLinePositionSpan = fileLinePositionSpan, NewText = textChange.NewText
                            };
                            if (!nodetoken.TextChanges.Contains(newTextChange))
                            {
                                nodetoken.TextChanges.Add(newTextChange);
                            }
                        }
                    });
                });
            }
        }