private void formatDocumentToolStripMenuItem_Click(object sender, EventArgs e) { var code = (from Line l in editor.Lines select l.Text).ToList(); var openedBlock = Refactoring.FormatLines(ref code, new String(editor.Indentation.UseTabs ? '\t' : ' ', editor.Indentation.UseTabs ? 1 : editor.Indentation.IndentWidth)); if (openedBlock != null) { MessageBox.Show("Can't format the code because missing closing statements after:\n" + (openedBlock.Line + 1) + ": '" + editor.Lines[openedBlock.Line].Text.Trim().Trim(new[] { '\n', '\r' }) + "'\n\nPlease check your code and retry.", "Format document", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); editor.Selection.Start = editor.Lines[openedBlock.Line].StartPosition; editor.Selection.End = editor.Lines[openedBlock.Line].EndPosition; editor.Scrolling.ScrollToCaret(); } else { int selectionStart = editor.Selection.Start, selectionEnd = editor.Selection.End; var first = editor.Lines.FirstVisibleIndex; editor.Text = String.Join(Environment.NewLine, code); editor.Lines.FirstVisibleIndex = first; editor.Selection.Start = Math.Min(selectionStart, editor.TextLength); editor.Selection.End = Math.Min(selectionEnd, editor.TextLength); editor.Refresh(); } }
private async Task TestFixOneAsync( string initial, string expected, Refactoring refactoring ) => await TestInRegularAndScript1Async( CreateTreeText("[||]" + initial), CreateTreeText(expected), (int)refactoring );
private void TestBlocksThatShouldNotChange(object[] args) { foreach (var l in _codeBlocks) { var tmp = String.Format(l, args); var original = new List <string>(tmp.Split(new[] { CRLF }, StringSplitOptions.None)); var test = new List <string>(tmp.Split(new[] { CRLF }, StringSplitOptions.None)); Refactoring.FormatLines(ref test, IndentationString); CollectionAssert.AreEqual(original, test); } }
public override Expression Simplify() { for (int i = 0; i < Body.Count; i++) { Body[i] = Body[i].Simplify(); } if (Refactoring.CanInline(this)) { return(Refactoring.InlineFunction(this).Simplify()); // Simplify call here may be redundant } return(this); }
protected override void OnExecute(object parameter) { var activeSelection = SelectionProvider.ActiveSelection(); if (!activeSelection.HasValue) { return; } try { Refactoring.Refactor(activeSelection.Value); } catch (RefactoringAbortedException) {} catch (RefactoringException exception) { FailureNotifier.Notify(exception); } }
protected override void OnExecute(object parameter) { var target = GetTarget(); if (target == null) { return; } try { Refactoring.Refactor(target); } catch (RefactoringAbortedException) { } catch (RefactoringException exception) { FailureNotifier.Notify(exception); } }
private static void FormatAndCheck(List <string> actual, List <string> expected) { Refactoring.FormatLines(ref actual, IndentationString); CollectionAssert.AreEqual(expected, actual); }
protected override void Refactor(IInspectionResult result) { Refactoring.Refactor(result.Target); }
private async Task TestFixOneAsync(string initial, string expected, Refactoring refactoring) { await TestAsync(CreateTreeText("[||]" + initial), CreateTreeText(expected), index : (int)refactoring); }