internal CodeIssueFile(CodeIssue codeIssue, SourceFile file, string message)
        {
            this.codeIssue = codeIssue;
            this.file = file;
            this.message = message;

        }
Example #2
0
 protected void AddIssue(CodeIssue issue)
 {
     if (IsSuppressed(issue.Start))
     {
         return;
     }
     FoundIssues.Add(issue);
 }
Example #3
0
        public override IEnumerable <CodeIssue> GetIssues(Document document, CancellationToken cancellationToken)
        {
            var context = new MDRefactoringContext(document, document.Editor.Caret.Location, cancellationToken);

            if (context.IsInvalid || context.RootNode == null)
            {
                yield break;
            }
            int issueNum = 0;

            foreach (var action in issueProvider.GetIssues(context))
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    yield break;
                }
                if (action.Actions == null)
                {
                    LoggingService.LogError("NRefactory actions == null in :" + Title);
                    continue;
                }
                if (actionIdList.Count <= issueNum)
                {
                    actionIdList.Add(new List <string> ());
                }
                var actionId  = actionIdList [issueNum];
                int actionNum = 0;

                var actions = new List <MonoDevelop.CodeActions.CodeAction> ();
                foreach (var act in action.Actions)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        yield break;
                    }
                    if (act == null)
                    {
                        LoggingService.LogError("NRefactory issue action was null in :" + Title);
                        continue;
                    }
                    if (actionId.Count <= actionNum)
                    {
                        actionId.Add(issueProvider.GetType().FullName + "'" + issueNum + "'" + actionNum);
                    }
                    actions.Add(new NRefactoryCodeAction(actionId[actionNum], act.Description, act));
                    actionNum++;
                }
                var issue = new CodeIssue(
                    GettextCatalog.GetString(action.Description ?? ""),
                    action.Start,
                    action.End,
                    actions
                    );
                yield return(issue);

                issueNum++;
            }
        }
 public static IRefactoringWarningMessage CreateRefactoringWarningMessage(IDocument document, CodeIssue issue, ICodeIssueComputer computer)
 {
     var instance = new RefactoringWarningMessage
     {
         File = document.Name,
         Line = document.GetText().GetLineFromPosition(issue.TextSpan.Start).LineNumber,
         Description = issue.Description,
         CodeIssueComputer = computer
     };
     return instance;
 }
Example #5
0
 protected static void CheckFix(TestRefactoringContext ctx, CodeIssue issue, string expectedOutput, int fixIndex = 0)
 {
     using (var script = ctx.StartScript())
         issue.Actions[fixIndex].Run(script);
     if (expectedOutput != ctx.Text)
     {
         Console.WriteLine("expected:");
         Console.WriteLine(expectedOutput);
         Console.WriteLine("got:");
         Console.WriteLine(ctx.Text);
     }
     Assert.AreEqual(expectedOutput, ctx.Text);
 }
Example #6
0
        /// <summary>
        /// Gets all the code issues inside a document.
        /// </summary>
        public override IEnumerable <CodeIssue> GetIssues(object ctx, CancellationToken cancellationToken)
        {
            var context = ctx as MDRefactoringContext;

            if (context == null || context.IsInvalid || context.RootNode == null || context.ParsedDocument.HasErrors)
            {
                yield break;
            }
            foreach (var action in parentIssue.IssueProvider.GetIssues(context, subIssue.Title))
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    yield break;
                }
                if (action.Actions == null)
                {
                    LoggingService.LogError("NRefactory actions == null in :" + Title);
                    continue;
                }
                var actions = new List <MonoDevelop.CodeActions.CodeAction> ();
                foreach (var act in action.Actions)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        yield break;
                    }
                    if (act == null)
                    {
                        LoggingService.LogError("NRefactory issue action was null in :" + Title);
                        continue;
                    }
                    actions.Add(new NRefactoryCodeAction(parentIssue.ProviderIdString, act.Description, act));
                }
                var issue = new CodeIssue(
                    GettextCatalog.GetString(action.Description ?? ""),
                    context.TextEditor.FileName,
                    action.Start,
                    action.End,
                    IdString,
                    actions
                    );
                yield return(issue);
            }
        }
        public void TestSingleIssue <T, Node>(String code, String expectedCode, TextSpan textSpan)
            where T : ICodeIssueProvider, new()
            where Node : CommonSyntaxNode
        {
            CreateWorkspace(code);

            CommonSyntaxNode node = document.GetSyntaxRoot().FindToken(textSpan.Start).Parent.FirstAncestorOrSelf <Node>();

            ICodeIssueProvider codeIssueProvider = new T();

            IEnumerable <CodeIssue> codeIssues = codeIssueProvider.GetIssues(document, node, cancellationToken);

            Assert.AreEqual(1, codeIssues.Count());

            CodeIssue codeIssue = codeIssues.First();

            Assert.AreEqual(1, codeIssue.Actions.Count());

            ICodeAction codeAction = codeIssue.Actions.First();

            Assert.AreEqual(expectedCode, ExecuteAction(codeAction));
        }
Example #8
0
 internal CodeIssueFile(CodeIssue codeIssue, SourceFile file, string message)
 {
     this.codeIssue = codeIssue;
     this.file      = file;
     this.message   = message;
 }
 private bool IsIssuedTo(CodeIssue issue, SyntaxNode node)
 {
     return issue.TextSpan.Equals(node.Span);
 }
Example #10
0
 private bool ShouldIncludeIssue(CodeIssue issue)
 {
     return(!_ignoredCodeIssues.Any(ignore => Regex.IsMatch(issue.Description, ignore)));
 }
 protected static void CheckFix(TestRefactoringContext ctx, CodeIssue issue, string expectedOutput, int fixIndex = 0)
 {
     using (var script = ctx.StartScript())
         issue.Actions[fixIndex].Run(script);
     Assert.AreEqual(expectedOutput, ctx.Text);
 }
 internal void AddCodeIssue(CodeIssue issue, SourceFile file, string message)
 {
     CodeIssues.Add(new CodeIssueFile(issue, file, message));
 }
Example #13
0
        public override IEnumerable <CodeIssue> GetIssues(object ctx, CancellationToken cancellationToken)
        {
            var context = ctx as MDRefactoringContext;

            if (context == null || context.IsInvalid || context.RootNode == null || context.ParsedDocument.HasErrors)
            {
                yield break;
            }

            // Holds all the actions in a particular sibling group.
            var actionGroups = new Dictionary <object, IList <ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction> > ();

            foreach (var action in issueProvider.GetIssues(context))
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    yield break;
                }
                if (action.Actions == null)
                {
                    LoggingService.LogError("NRefactory actions == null in :" + Title);
                    continue;
                }
                var actions = new List <NRefactoryCodeAction> ();
                foreach (var act in action.Actions)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        yield break;
                    }
                    if (act == null)
                    {
                        LoggingService.LogError("NRefactory issue action was null in :" + Title);
                        continue;
                    }
                    var nrefactoryCodeAction = new NRefactoryCodeAction(IdString, act.Description, act, act.SiblingKey);
                    if (act.SiblingKey != null)
                    {
                        // make sure the action has a list of its siblings
                        IList <ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction> siblingGroup;
                        if (!actionGroups.TryGetValue(act.SiblingKey, out siblingGroup))
                        {
                            siblingGroup = new List <ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction> ();
                            actionGroups.Add(act.SiblingKey, siblingGroup);
                        }
                        siblingGroup.Add(act);
                        nrefactoryCodeAction.SiblingActions = siblingGroup;
                    }
                    actions.Add(nrefactoryCodeAction);
                }
                var issue = new CodeIssue(
                    GettextCatalog.GetString(action.Description ?? ""),
                    context.TextEditor.FileName,
                    action.Start,
                    action.End,
                    IdString,
                    actions
                    );
                yield return(issue);
            }
        }
 internal void AddCodeIssue(CodeIssue issue, SourceFile file, string message)
 {
     CodeIssues.Add(new CodeIssueFile(issue, file, message));
 }