public static NavigateCodeEventArgs GetNavigateCodeEventArgs(this SyntaxErrorException exception, Declaration declaration) { if (declaration == null) return null; var selection = new Selection(exception.LineNumber, exception.Position, exception.LineNumber, exception.Position); return new NavigateCodeEventArgs(declaration.QualifiedName.QualifiedModuleName, selection); }
public void RemoveParamatersRefactoring_RemoveOnlyParam() { //Input const string inputCode = @"Private Sub Foo(ByVal arg1 As Integer) End Sub"; var selection = new Selection(1, 23, 1, 27); //startLine, startCol, endLine, endCol //Expectation const string expectedCode = @"Private Sub Foo() End Sub"; //Arrange SetupProject(inputCode); var parseResult = new RubberduckParser().Parse(_project.Object); var qualifiedSelection = GetQualifiedSelection(selection); //Specify Params to remove var model = new RemoveParametersModel(parseResult, qualifiedSelection); model.Parameters.ForEach(arg => arg.IsRemoved = true); //SetupFactory var factory = SetupFactory(model); //Act var refactoring = new RemoveParametersRefactoring(factory.Object); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode, _module.Object.Lines()); }
public ValuedDeclaration(QualifiedMemberName qualifiedName, string parentScope, string asTypeName, Accessibility accessibility, DeclarationType declarationType, string value, ParserRuleContext context, Selection selection, bool isBuiltIn = false) :base(qualifiedName, parentScope, asTypeName, true, false, accessibility, declarationType, context, selection, isBuiltIn) { _value = value; }
private void FixTypeHintUsage(string hint, CodeModule module, Selection selection, bool isDeclaration = false) { var line = module.Lines[selection.StartLine, 1]; var asTypeClause = ' ' + Tokens.As + ' ' + TypeHints[hint]; string fix; if (isDeclaration && (Context is VBAParser.FunctionStmtContext || Context is VBAParser.PropertyGetStmtContext)) { var typeHint = (ParserRuleContext)Context.children.First(c => c is VBAParser.TypeHintContext); var argList = (ParserRuleContext) Context.children.First(c => c is VBAParser.ArgListContext); var endLine = argList.Stop.Line; var endColumn = argList.Stop.Column; var oldLine = module.Lines[endLine, selection.LineCount]; fix = oldLine.Insert(endColumn + 1, asTypeClause).Remove(typeHint.Start.Column, 1); // adjust for VBA 0-based indexing module.ReplaceLine(endLine, fix); } else { var pattern = "\\b" + _declaration.IdentifierName + "\\" + hint; fix = Regex.Replace(line, pattern, _declaration.IdentifierName + (isDeclaration ? asTypeClause : string.Empty)); module.ReplaceLine(selection.StartLine, fix); } }
/// <summary>Common method for adding declaration with some default values</summary> private void AddDeclarationItem(IMock<ParserRuleContext> context, Selection selection, QualifiedMemberName? qualifiedName = null, DeclarationType declarationType = DeclarationType.Project, string identifierName = "identifierName") { Declaration declarationItem = null; var qualName = qualifiedName ?? new QualifiedMemberName(_module, "fakeModule"); declarationItem = new Declaration( qualifiedName: qualName, parentScope: "module.proc", asTypeName: "asTypeName", isSelfAssigned: false, isWithEvents: false, accessibility: Accessibility.Public, declarationType: declarationType, context: context.Object, selection: selection ); _declarations.Add(declarationItem); if (_listDeclarations == null) _listDeclarations = new List<Declaration>(); _listDeclarations.Add(declarationItem); }
protected QualifiedSelection GetQualifiedSelection(Selection selection) { if (_ide.Object.ActiveCodePane == null) { _ide.Object.ActiveVBProject = _ide.Object.VBProjects.Item(0); _ide.Object.ActiveCodePane = _ide.Object.ActiveVBProject.VBComponents.Item(0).CodeModule.CodePane; } return new QualifiedSelection(new QualifiedModuleName(_ide.Object.ActiveCodePane.CodeModule.Parent), selection); }
private Declaration AmbiguousId() { var values = _model.Declarations.Items.Where(item => (item.Scope.Contains(_model.Target.Scope) || _model.Target.ParentScope.Contains(item.ParentScope)) && _model.NewName == item.IdentifierName).ToList(); if (values.Any()) { return values.FirstOrDefault(); } foreach (var reference in _model.Target.References) { var targetReference = reference; var potentialDeclarations = _model.Declarations.Items.Where(item => !item.IsBuiltIn && item.Project.Equals(targetReference.Declaration.Project) && ((item.Context != null && item.Context.Start.Line <= targetReference.Selection.StartLine && item.Context.Stop.Line >= targetReference.Selection.EndLine) || (item.Selection.StartLine <= targetReference.Selection.StartLine && item.Selection.EndLine >= targetReference.Selection.EndLine)) && item.QualifiedName.QualifiedModuleName.ComponentName == targetReference.QualifiedModuleName.ComponentName); var currentSelection = new Selection(0, 0, int.MaxValue, int.MaxValue); Declaration target = null; foreach (var item in potentialDeclarations) { var startLine = item.Context == null ? item.Selection.StartLine : item.Context.Start.Line; var endLine = item.Context == null ? item.Selection.EndLine : item.Context.Stop.Column; var startColumn = item.Context == null ? item.Selection.StartColumn : item.Context.Start.Column; var endColumn = item.Context == null ? item.Selection.EndColumn : item.Context.Stop.Column; var selection = new Selection(startLine, startColumn, endLine, endColumn); if (currentSelection.Contains(selection)) { currentSelection = selection; target = item; } } if (target == null) { continue; } values = _model.Declarations.Items.Where(item => (item.Scope.Contains(target.Scope) || target.ParentScope.Contains(item.ParentScope)) && _model.NewName == item.IdentifierName).ToList(); if (values.Any()) { return values.FirstOrDefault(); } } return null; }
public void SetSelection(Selection selection) { if (Editor == null) { return; } var codePane = _wrapperFactory.Create(Editor.CodePane); codePane.Selection = selection; }
private void FixTypeHintUsage(string hint, CodeModule module, Selection selection, bool isDeclaration = false) { var line = module.get_Lines(selection.StartLine, 1); var asTypeClause = ' ' + Tokens.As + ' ' + TypeHints[hint]; var pattern = "\\b" + _declaration.IdentifierName + "\\" + hint; var fix = Regex.Replace(line, pattern, _declaration.IdentifierName + (isDeclaration ? asTypeClause : string.Empty)); module.ReplaceLine(selection.StartLine, fix); }
public IdentifierReference(QualifiedModuleName qualifiedName, string identifierName, Selection selection, ParserRuleContext context, Declaration declaration, bool isAssignmentTarget = false, bool hasExplicitLetStatement = false) { _qualifiedName = qualifiedName; _identifierName = identifierName; _selection = selection; _context = context; _declaration = declaration; _hasExplicitLetStatement = hasExplicitLetStatement; _isAssignmentTarget = isAssignmentTarget; }
public void EncapsulatePublicField_WithSetter() { //Input const string inputCode = @"Public fizz As Variant"; var selection = new Selection(1, 1, 1, 1); //Expectation const string expectedCode = @"Private fizz As Variant Public Property Get Name() As Variant Name = fizz End Property Public Property Set Name(ByVal value As Variant) fizz = value End Property "; //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var project = vbe.Object.VBProjects.Item(0); var module = project.VBComponents.Item(0).CodeModule; var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock<IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var model = new EncapsulateFieldModel(parser.State, qualifiedSelection) { ImplementLetSetterType = false, ImplementSetSetterType = true, ParameterName = "value", PropertyName = "Name" }; //SetupFactory var factory = SetupFactory(model); //Act var refactoring = new EncapsulateFieldRefactoring(factory.Object, new ActiveCodePaneEditor(vbe.Object, codePaneFactory)); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode, module.Lines()); }
/// <summary> /// Represents a context in the code tree. /// </summary> /// <param name="context">The parser rule context, obtained from an ANTLR-generated parser method.</param> /// <param name="parentScope">The scope this context belongs to. <c>null</c> for the root context.</param> /// <param name="localScope">The scope this context defines, if any. <c>null</c> if omitted.</param> /// <param name="childNodes">The child nodes.</param> /// <remarks> /// Specifying a <c>localScope</c> ensures child nodes can be added, regardless of /// </remarks> protected Node(ParserRuleContext context, string parentScope, string localScope = null, ICollection<Node> childNodes = null) { _context = context; _selection = context.GetSelection(); _parentScope = parentScope; _localScope = localScope; _childNodes = (localScope != null && childNodes == null) ? new List<Node>() : childNodes; }
public void ConstructorWorks_IsNotNull() { // arange var symbolSelection = new Selection(1, 1, 2, 2); var qualifiedSelection = new QualifiedSelection(_module, symbolSelection); //act //var presenter = new RenamePresenter(_vbe.Object, _view.Object, _declarations, qualifiedSelection); Assert.Inconclusive("This test is broken"); //assert //Assert.IsNotNull(presenter, "Successfully initialized"); }
public string GetSelectedProcedureScope(Selection selection) { var moduleName = Editor.Name; var projectName = Editor.Parent.Collection.Parent.Name; var parentScope = projectName + '.' + moduleName; vbext_ProcKind kind; var procStart = Editor.get_ProcOfLine(selection.StartLine, out kind); var procEnd = Editor.get_ProcOfLine(selection.EndLine, out kind); return procStart == procEnd ? parentScope + '.' + procStart : null; }
private IEnumerable<Declaration> GetParameters() { var targetSelection = new Selection(TargetDeclaration.Context.Start.Line, TargetDeclaration.Context.Start.Column, TargetDeclaration.Context.Stop.Line, TargetDeclaration.Context.Stop.Column); return Declarations.Where(d => d.DeclarationType == DeclarationType.Parameter && d.ComponentName == TargetDeclaration.ComponentName && d.ProjectId == TargetDeclaration.ProjectId && targetSelection.Contains(d.Selection)) .OrderBy(item => item.Selection.StartLine) .ThenBy(item => item.Selection.StartColumn); }
public Declaration(QualifiedMemberName qualifiedName, string parentScope, string asTypeName, bool isSelfAssigned, bool isWithEvents, Accessibility accessibility, DeclarationType declarationType, ParserRuleContext context, Selection selection, bool isBuiltIn = false) { _qualifiedName = qualifiedName; _parentScope = parentScope; _identifierName = qualifiedName.MemberName; _asTypeName = asTypeName; _isSelfAssigned = isSelfAssigned; _isWithEvents = isWithEvents; _accessibility = accessibility; _declarationType = declarationType; _selection = selection; _context = context; _isBuiltIn = isBuiltIn; }
/// <summary> /// Creates a new user declaration for a parameter. /// </summary> public ParameterDeclaration(QualifiedMemberName qualifiedName, Declaration parentDeclaration, ParserRuleContext context, Selection selection, string asTypeName, bool isOptional, bool isByRef, bool isArray = false, bool isParamArray = false) : base(qualifiedName, parentDeclaration, parentDeclaration, asTypeName, false, false, Accessibility.Implicit, DeclarationType.Parameter, context, selection, false) { _isOptional = isOptional; _isByRef = isByRef; _isArray = isArray; _isParamArray = isParamArray; }
private void RemoveField(Declaration target) { Selection selection; var declarationText = target.Context.GetText().Replace(" _" + Environment.NewLine, string.Empty); var multipleDeclarations = target.HasMultipleDeclarationsInStatement(); var variableStmtContext = target.GetVariableStmtContext(); if (!multipleDeclarations) { declarationText = variableStmtContext.GetText().Replace(" _" + Environment.NewLine, string.Empty); selection = target.GetVariableStmtContextSelection(); } else { selection = new Selection(target.Context.Start.Line, target.Context.Start.Column, target.Context.Stop.Line, target.Context.Stop.Column); } var pane = _vbe.ActiveCodePane; var module = pane.CodeModule; { var oldLines = module.GetLines(selection); var newLines = oldLines.Replace(" _" + Environment.NewLine, string.Empty) .Remove(selection.StartColumn, declarationText.Length); if (multipleDeclarations) { selection = target.GetVariableStmtContextSelection(); newLines = RemoveExtraComma(module.GetLines(selection).Replace(oldLines, newLines), target.CountOfDeclarationsInStatement(), target.IndexOfVariableDeclarationInStatement()); } newLines = newLines.Replace(" _" + Environment.NewLine, string.Empty); module.DeleteLines(selection); if (newLines.Trim() != string.Empty) { module.InsertLines(selection.StartLine, newLines); } } }
public void MoveCloserToUsageRefactoring_Variable() { //Input const string inputCode = @"Private Sub Foo() Dim bar As Boolean Dim bat As Integer bar = True End Sub"; var selection = new Selection(4, 6, 4, 8); //Expectation const string expectedCode = @"Private Sub Foo() Dim bat As Integer Dim bar As Boolean bar = True End Sub"; //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var project = vbe.Object.VBProjects.Item(0); var module = project.VBComponents.Item(0).CodeModule; var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock<IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); //Act var refactoring = new MoveCloserToUsageRefactoring(parser.State, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode, module.Lines()); }
public void RenameRefactoring_RenameVariable() { //Input const string inputCode = @"Private Sub Foo() Dim val1 As Integer End Sub"; var selection = new Selection(2, 12, 2, 12); //Expectation const string expectedCode = @"Private Sub Foo() Dim val2 As Integer End Sub"; //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var project = vbe.Object.VBProjects.Item(0); var module = project.VBComponents.Item(0).CodeModule; var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock<IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var model = new RenameModel(vbe.Object, parser.State, qualifiedSelection, null) { NewName = "val2" }; //SetupFactory var factory = SetupFactory(model); //Act var refactoring = new RenameRefactoring(factory.Object, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null, parser.State); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode, module.Lines()); }
public void ReorderParams_RefactorDeclaration() { //Input const string inputCode = @"Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String) End Sub"; var selection = new Selection(1, 23, 1, 27); //Expectation const string expectedCode = @"Private Sub Foo(ByVal arg2 As String, ByVal arg1 As Integer) End Sub"; //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var project = vbe.Object.VBProjects.Item(0); var module = project.VBComponents.Item(0).CodeModule; var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock<IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); //set up model var model = new ReorderParametersModel(parser.State, qualifiedSelection, null); model.Parameters.Reverse(); var factory = SetupFactory(model); //act var refactoring = new ReorderParametersRefactoring(factory.Object, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null); refactoring.Refactor(model.TargetDeclaration); //assert Assert.AreEqual(expectedCode, module.Lines()); }
public void IntroduceParameterRefactoring_NoParamsInList_Function() { //Input const string inputCode = @"Private Function Foo() As Boolean Dim bar As Boolean Foo = True End Function"; var selection = new Selection(2, 10, 2, 13); //Expectation const string expectedCode = @"Private Function Foo(ByVal bar As Boolean) As Boolean Foo = True End Function"; //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var project = vbe.Object.VBProjects.Item(0); var module = project.VBComponents.Item(0).CodeModule; var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock<IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); //Act var refactoring = new IntroduceParameterRefactoring(parser.State, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode, module.Lines()); }
public IdentifierReference( QualifiedModuleName qualifiedName, Declaration parentScopingDeclaration, Declaration parentNonScopingDeclaration, string identifierName, Selection selection, ParserRuleContext context, Declaration declaration, bool isAssignmentTarget = false, bool hasExplicitLetStatement = false, IEnumerable<IAnnotation> annotations = null) { _parentScopingDeclaration = parentScopingDeclaration; _parentNonScopingDeclaration = parentNonScopingDeclaration; _qualifiedName = qualifiedName; _identifierName = identifierName; _selection = selection; _context = context; _declaration = declaration; _hasExplicitLetStatement = hasExplicitLetStatement; _isAssignmentTarget = isAssignmentTarget; _annotations = annotations ?? new List<IAnnotation>(); }
private void ExtractMethod(ExtractMethodModel model) { var selection = model.Selection.Selection; _editor.DeleteLines(selection); _editor.InsertLines(selection.StartLine, GetMethodCall(model)); var insertionLine = model.SourceMember.Context.GetSelection().EndLine - selection.LineCount + 2; _editor.InsertLines(insertionLine, GetExtractedMethod(model)); // assumes these are declared *before* the selection... var offset = 0; foreach (var declaration in model.DeclarationsToMove.OrderBy(e => e.Selection.StartLine)) { var target = new Selection( declaration.Selection.StartLine - offset, declaration.Selection.StartColumn, declaration.Selection.EndLine - offset, declaration.Selection.EndColumn); _editor.DeleteLines(target); offset += declaration.Selection.LineCount; } }
public void DeleteLines(Selection selection) { Editor.DeleteLines(selection.StartLine, selection.LineCount); }
public CodeModuleSelection(CodeModule codeModule, Selection selection) { _codeModule = codeModule; _selection = selection; }
private IEnumerable<CommentNode> ParseComments(QualifiedModuleName qualifiedName) { var code = qualifiedName.Component.CodeModule.Code(); var commentBuilder = new StringBuilder(); var continuing = false; var startLine = 0; var startColumn = 0; for (var i = 0; i < code.Length; i++) { var line = code[i]; var index = 0; if (continuing || line.HasComment(out index)) { startLine = continuing ? startLine : i; startColumn = continuing ? startColumn : index; var commentLength = line.Length - index; continuing = line.EndsWith("_"); if (!continuing) { commentBuilder.Append(line.Substring(index, commentLength).TrimStart()); var selection = new Selection(startLine + 1, startColumn + 1, i + 1, line.Length + 1); var result = new CommentNode(commentBuilder.ToString(), new QualifiedSelection(qualifiedName, selection)); commentBuilder.Clear(); yield return result; } else { // ignore line continuations in comment text: commentBuilder.Append(line.Substring(index, commentLength).TrimStart()); } } } }
public void NoTargetFound() { // arange var symbolSelection = new Selection(1, 1, 2, 2); var qualifiedSelection = new QualifiedSelection(_module, symbolSelection); var context = new Mock<ParserRuleContext>(); AddDeclarationItem(context, symbolSelection); _view.Setup(form => form.ShowDialog()).Returns(DialogResult.Cancel); //act Assert.Inconclusive("This test is broken"); //var presenter = new RenamePresenter(_vbe.Object, _view.Object, _declarations, qualifiedSelection); //presenter.Show(); //assert Assert.IsNull(_view.Object.Target, "No Target was found"); }
public void AcquireTarget_MethodRenamingMoreComponents_CorrectTargetChosen() { // arange // initial selection var symbolSelection = new Selection(4, 5, 4, 8); var selectedComponent = new QualifiedModuleName("TestProject", "Module1"); var qualifiedSelection = new QualifiedSelection(selectedComponent, symbolSelection); // just for passing null reference exception var context = new Mock<ParserRuleContext>(); context.SetupGet(c => c.Start.Line).Returns(-1); context.SetupGet(c => c.Stop.Line).Returns(-1); context.SetupGet(c => c.Stop.Text).Returns("Fake"); // simulate all the components and symbols IdentifierReference reference; var differentComponent = new QualifiedModuleName("TestProject", "Module2"); var differentMember = new QualifiedMemberName(differentComponent, "Module2"); AddDeclarationItem(context, new Selection(4, 9, 4, 16), differentMember, DeclarationType.Variable, "FooTest"); // add references to the Foo declaration item to simulate prod usage AddDeclarationItem(context, new Selection(3, 5, 3, 8), differentMember, DeclarationType.Procedure, "Foo"); var declarationItem = _listDeclarations[_listDeclarations.Count - 1]; reference = new IdentifierReference(selectedComponent, "Foo", new Selection(7, 5, 7, 11), context.Object, declarationItem); AddReference(declarationItem, reference); reference = new IdentifierReference(selectedComponent, "Foo", symbolSelection, context.Object, declarationItem); AddReference(declarationItem, reference); AddDeclarationItem(context, new Selection(1, 1, 1, 1), differentMember, DeclarationType.Module, "Module2"); var member = new QualifiedMemberName(selectedComponent, "fakeModule"); AddDeclarationItem(context, new Selection(7, 5, 7, 11), member, DeclarationType.Procedure, "RunFoo"); AddDeclarationItem(context, new Selection(3, 5, 3, 9), member, DeclarationType.Procedure, "Main"); AddDeclarationItem(context, new Selection(1, 1, 1, 1), member, DeclarationType.Module, "Module1"); _view.Setup(view => view.ShowDialog()).Returns(DialogResult.Cancel); _view.SetupProperty(view => view.Target); //act //var presenter = new RenamePresenter(_vbe.Object, _view.Object, _declarations, qualifiedSelection); //presenter.Show(); Assert.Inconclusive("This test is broken"); //assert var retVal = _view.Object.Target; Assert.AreEqual("Foo", retVal.IdentifierName, "Selected the correct symbol name"); Assert.AreEqual(declarationItem.References.Count(), retVal.References.Count()); }
public void AcquireTarget_MethodRenamingAtSameComponent_CorrectTargetChosen() { // arange var symbolSelection = new Selection(8, 1, 8, 16); var selectedComponent = new QualifiedModuleName("TestProject", "TestModule"); var qualifiedSelection = new QualifiedSelection(selectedComponent, symbolSelection); // just for passing null reference exception var context = new Mock<ParserRuleContext>(); context.SetupGet(c => c.Start.Line).Returns(1); context.SetupGet(c => c.Stop.Line).Returns(2); context.SetupGet(c => c.Stop.Text).Returns("Four"); // simulate all the components and symbols var member = new QualifiedMemberName(selectedComponent, "fakeModule"); const string identifierName = "Foo"; AddDeclarationItem(context, symbolSelection, member, DeclarationType.Procedure, identifierName); AddDeclarationItem(context, new Selection(1, 1, 1, 16), member, DeclarationType.Procedure); AddDeclarationItem(context, new Selection(1, 1, 1, 1), member, DeclarationType.Module); // allow Moq to set the Target property _view.Setup(view => view.ShowDialog()).Returns(DialogResult.Cancel); _view.SetupProperty(view => view.Target); //act Assert.Inconclusive("This test is broken"); //var presenter = new RenamePresenter(_vbe.Object, _view.Object, _declarations, qualifiedSelection); //presenter.Show(); //assert var retVal = _view.Object.Target; Assert.AreEqual(symbolSelection, retVal.Selection, "Returns only the declaration on the desired selection"); Assert.AreEqual(identifierName, retVal.IdentifierName); }
public void AcquireTarget_ModuleRenaming_TargetIsNotNull() { // arange var symbolSelection = new Selection(1, 1, 2, 4); var qualifiedSelection = new QualifiedSelection(_module, symbolSelection); // just for passing null reference exception var context = new Mock<ParserRuleContext>(); context.SetupGet(c => c.Start.Line).Returns(1); context.SetupGet(c => c.Stop.Line).Returns(2); context.SetupGet(c => c.Stop.Text).Returns("Four"); // setting a declaration item as a module that will be renamed const string identifierName = "FakeModule"; AddDeclarationItem(context, symbolSelection, null, DeclarationType.Module, identifierName); // allow Moq to set the Target property _view.Setup(view => view.ShowDialog()).Returns(DialogResult.Cancel); _view.SetupProperty(view => view.Target); //act Assert.Inconclusive("This test is broken"); //var presenter = new RenamePresenter(_vbe.Object, _view.Object, _declarations, qualifiedSelection); //presenter.Show(); //assert Assert.IsNotNull(_view.Object.Target, "A target was found"); Assert.AreEqual(identifierName, _view.Object.Target.IdentifierName); }
private List<RegexSearchResult> SearchCurrentBlock(string searchPattern) { var declarationTypes = new[] { DeclarationType.Event, DeclarationType.Function, DeclarationType.Procedure, DeclarationType.PropertyGet, DeclarationType.PropertyLet, DeclarationType.PropertySet }; var parseResult = _parser.State; var results = GetResultsFromModule(_vbe.ActiveCodePane.CodeModule, searchPattern); var wrapper = _codePaneFactory.Create(_vbe.ActiveCodePane); var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(wrapper.CodeModule.Parent), wrapper.Selection); dynamic block = parseResult.AllDeclarations.FindTarget(qualifiedSelection, declarationTypes).Context.Parent; var selection = new Selection(block.Start.Line, block.Start.Column, block.Stop.Line, block.Stop.Column); return results.Where(r => selection.Contains(r.Selection)).ToList(); }
public string GetLines(Selection selection) { return(Editor.get_Lines(selection.StartLine, selection.LineCount)); }