public void RemoveAnnotationsWorks() { const string inputCode = @"'@ModuleAttribute SomeAttribute Option Explicit '@ModuleAttribute SomeOtherAttribute @ModuleAttribute YetAnotherAttribute 'Strange indent comment '@ModuleAttribute YetYetAnotherAttribute @Exposed '@Folder ""Folder"" '@PredeclaredId @ModuleDescription ""Desc"""; const string expectedCode = @"Option Explicit 'Strange indent comment '@Exposed "; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var moduleDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.ProceduralModule) .First(); var annotationsToRemove = moduleDeclaration.Annotations.Where(pta => !(pta.Annotation is ExposedModuleAnnotation)); var annotationUpdater = new AnnotationUpdater(); annotationUpdater.RemoveAnnotations(rewriteSession, annotationsToRemove); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
protected override IRefactoringAction <AnnotateDeclarationModel> TestBaseRefactoring(RubberduckParserState state, IRewritingManager rewritingManager) { var annotationUpdater = new AnnotationUpdater(state); var attributesUpdater = new AttributesUpdater(state); return(new AnnotateDeclarationRefactoringAction(rewritingManager, annotationUpdater, attributesUpdater)); }
//The only relevant test is in the base class. protected override CommandBase TestCommand( IVBE vbe, RubberduckParserState state, IRewritingManager rewritingManager, ISelectionService selectionService) { var factory = new Mock <IRefactoringPresenterFactory>().Object; var msgBox = new Mock <IMessageBox>().Object; var uiDispatcherMock = new Mock <IUiDispatcher>(); uiDispatcherMock .Setup(m => m.Invoke(It.IsAny <Action>())) .Callback((Action action) => action.Invoke()); var userInteraction = new RefactoringUserInteraction <IMoveMultipleFoldersPresenter, MoveMultipleFoldersModel>(factory, uiDispatcherMock.Object); var annotationUpdater = new AnnotationUpdater(state); var moveToFolderAction = new MoveToFolderRefactoringAction(rewritingManager, annotationUpdater); var changeFolderAction = new ChangeFolderRefactoringAction(rewritingManager, moveToFolderAction); var moveFolderAction = new MoveFolderRefactoringAction(rewritingManager, changeFolderAction); var moveMultipleFoldersAction = new MoveMultipleFoldersRefactoringAction(rewritingManager, moveFolderAction); var selectedDeclarationProvider = new SelectedDeclarationProvider(selectionService, state); var refactoring = new MoveContainingFolderRefactoring(moveMultipleFoldersAction, selectedDeclarationProvider, selectionService, userInteraction, state, state); var notifier = new MoveContainingFolderRefactoringFailedNotifier(msgBox); return(new CodePaneRefactorMoveContainingFolderCommand(refactoring, notifier, selectionService, state, selectedDeclarationProvider)); }
public Result OnStartup(UIControlledApplication app) { // (Konrad) Initiate Nlog logger. NLogUtils.CreateConfiguration(); _logger = LogManager.GetCurrentClassLogger(); // (Konrad) Setup Document events. app.ControlledApplication.DocumentOpened += OnDocumentOpened; app.ControlledApplication.DocumentCreated += OnDocumentCreated; app.ControlledApplication.DocumentSaving += OnDocumentSaving; app.ControlledApplication.DocumentSynchronizingWithCentral += OnDocumentSynchronizingWithCentral; app.ControlledApplication.DocumentSynchronizedWithCentral += OnDocumentSynchronizedWithCentral; app.ControlledApplication.FailuresProcessing += FailureProcessor.CheckFailure; app.ViewActivated += OnViewActivated; app.CreateRibbonTab("Honeybee"); var panel = app.CreateRibbonPanel("Honeybee", "Honeybee"); SettingsCommand.CreateButton(panel); var hbButton = CreateHbModelCommand.CreateButton(); var dfButton = CreateDfModelCommand.CreateButton(); var splitButton = new SplitButtonData("CreateModelCommand", "Split"); var sb = (SplitButton)panel.AddItem(splitButton); sb.AddPushButton(hbButton); sb.AddPushButton(dfButton); CreateModelHandler = new CreateModelRequestHandler(); CreateModelEvent = ExternalEvent.Create(CreateModelHandler); // (Konrad) Register an updater that will watch annotations for changes. AnnotationUpdater = new AnnotationUpdater(app.ActiveAddInId); return(Result.Succeeded); }
protected override CommandBase TestCommand( IVBE vbe, RubberduckParserState state, IRewritingManager rewritingManager, ISelectionService selectionService) { var factory = new Mock <IRefactoringPresenterFactory>().Object; var msgBox = new Mock <IMessageBox>().Object; var uiDispatcherMock = new Mock <IUiDispatcher>(); uiDispatcherMock .Setup(m => m.Invoke(It.IsAny <Action>())) .Callback((Action action) => action.Invoke()); var userInteraction = new RefactoringUserInteraction <IAnnotateDeclarationPresenter, AnnotateDeclarationModel>(factory, uiDispatcherMock.Object); var annotationUpdater = new AnnotationUpdater(state); var attributesUpdater = new AttributesUpdater(state); var annotateDeclarationAction = new AnnotateDeclarationRefactoringAction(rewritingManager, annotationUpdater, attributesUpdater); var selectedDeclarationProvider = new SelectedDeclarationProvider(selectionService, state); var refactoring = new AnnotateDeclarationRefactoring(annotateDeclarationAction, selectedDeclarationProvider, selectionService, userInteraction); var notifier = new AnnotateDeclarationFailedNotifier(msgBox); return(new AnnotateSelectedMemberCommand(refactoring, notifier, selectionService, state, state, selectedDeclarationProvider)); }
protected override IRefactoringAction <ChangeFolderModel> TestBaseRefactoring(RubberduckParserState state, IRewritingManager rewritingManager) { var annotationUpdater = new AnnotationUpdater(state); var moveToFolderAction = new MoveToFolderRefactoringAction(rewritingManager, annotationUpdater); return(new ChangeFolderRefactoringAction(rewritingManager, moveToFolderAction)); }
public void RemoveAnnotationForStandaloneAnnotationRemovesEntireLineOnLastLine() { const string inputCode = @" Option Explicit 'Strange indent comment '@PredeclaredId"; const string expectedCode = @" Option Explicit 'Strange indent comment"; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var moduleDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.ProceduralModule) .First(); var annotationToRemove = moduleDeclaration.Annotations.First(); var annotationUpdater = new AnnotationUpdater(); annotationUpdater.RemoveAnnotation(rewriteSession, annotationToRemove); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
public void AddAnnotationAddsIdentifierReferenceAnnotationsRightAboveTheReference() { const string inputCode = @"'@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() Dim bar As Variant bar = Foo(""x"") End Sub '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; const string expectedCode = @"'@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() Dim bar As Variant '@Ignore ObsoleteMemberUsage bar = Foo(""x"") End Sub '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; var annotationToAdd = new IgnoreAnnotation(); var annotationValues = new List <string> { "ObsoleteMemberUsage" }; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var fooReference = state.DeclarationFinder .UserDeclarations(DeclarationType.Procedure) .First(decl => decl.IdentifierName == "Foo") .References.First(); var annotationUpdater = new AnnotationUpdater(); annotationUpdater.AddAnnotation(rewriteSession, fooReference, annotationToAdd, annotationValues); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
protected override IQuickFix QuickFix(RubberduckParserState state) { var annotationUpdater = new AnnotationUpdater(state); var inspections = new List <IInspection> { new VariableNotUsedInspection(state) }; return(new IgnoreInModuleQuickFix(annotationUpdater, state, inspections)); }
public void AddAnnotationAddsModuleAnnotationAboveTheFirstLine() { const string inputCode = @"'@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() End Sub '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; const string expectedCode = @"'@ModuleAttribute VB_Ext_Key, ""Key"", ""Value"" '@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() End Sub '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; var annotationToAdd = new ModuleAttributeAnnotation(); var annotationValues = new List <string> { "VB_Ext_Key", "\"Key\"", "\"Value\"" }; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var moduleDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.ProceduralModule) .First(); var annotationUpdater = new AnnotationUpdater(); annotationUpdater.AddAnnotation(rewriteSession, moduleDeclaration, annotationToAdd, annotationValues); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
public void UpdateAnnotationReplacesEntireAnnotation() { const string inputCode = @"'@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() End Sub '@Obsolete @Description ""Desc"" @DefaultMember Public Sub Foo(bar As String) bar = vbNullString End Sub "; const string expectedCode = @"'@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() End Sub '@Obsolete @MemberAttribute VB_ExtKey, ""Key"", ""Value"" @DefaultMember Public Sub Foo(bar As String) bar = vbNullString End Sub "; var newAnnotation = new MemberAttributeAnnotation(); var newAnnotationValues = new List <string> { "VB_ExtKey", "\"Key\"", "\"Value\"" }; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var fooDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.Procedure) .First(decl => decl.IdentifierName == "Foo"); var annotationToUpdate = fooDeclaration.Annotations.First(pta => pta.Annotation is DescriptionAnnotation); var annotationUpdater = new AnnotationUpdater(); annotationUpdater.UpdateAnnotation(rewriteSession, annotationToUpdate, newAnnotation, newAnnotationValues); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
protected override IRefactoring TestRefactoring( IRewritingManager rewritingManager, RubberduckParserState state, RefactoringUserInteraction <IMoveMultipleToFolderPresenter, MoveMultipleToFolderModel> userInteraction, ISelectionService selectionService) { var annotationUpdater = new AnnotationUpdater(state); var moveToFolderAction = new MoveToFolderRefactoringAction(rewritingManager, annotationUpdater); var moveMultipleToFolderAction = new MoveMultipleToFolderRefactoringAction(rewritingManager, moveToFolderAction); var selectedDeclarationProvider = new SelectedDeclarationProvider(selectionService, state); return(new MoveToFolderRefactoring(moveMultipleToFolderAction, selectedDeclarationProvider, selectionService, userInteraction, state)); }
protected override IRefactoring TestRefactoring( IRewritingManager rewritingManager, RubberduckParserState state, RefactoringUserInteraction <IAnnotateDeclarationPresenter, AnnotateDeclarationModel> userInteraction, ISelectionService selectionService) { var annotationUpdater = new AnnotationUpdater(state); var attributesUpdater = new AttributesUpdater(state); var annotateDeclarationAction = new AnnotateDeclarationRefactoringAction(rewritingManager, annotationUpdater, attributesUpdater); var selectedDeclarationProvider = new SelectedDeclarationProvider(selectionService, state); return(new AnnotateDeclarationRefactoring(annotateDeclarationAction, selectedDeclarationProvider, selectionService, userInteraction)); }
public DocumentAnnotationUpdater(SrmDocument document, IProgressMonitor progressMonitor) { SkylineDataSchema = SkylineDataSchema.MemoryDataSchema(document, DataSchemaLocalizer.INVARIANT); _annotationUpdaters = new Dictionary <AnnotationDef.AnnotationTarget, AnnotationUpdater>(); var calculatedAnnotations = document.Settings.DataSettings.AnnotationDefs .Where(def => null != def.Expression).ToArray(); foreach (AnnotationDef.AnnotationTarget target in Enum.GetValues(typeof(AnnotationDef.AnnotationTarget))) { var annotations = ImmutableList.ValueOf(calculatedAnnotations.Where(def => def.AnnotationTargets.Contains(target))); if (annotations.Count == 0) { continue; } _annotationUpdaters[target] = new AnnotationUpdater(annotations); } AnnotationUpdater transitionResultAnnotationUpdater; if (_annotationUpdaters.TryGetValue(AnnotationDef.AnnotationTarget.transition_result, out transitionResultAnnotationUpdater)) { _transitionResultUpdater = new TransitionResultUpdater { AnnotationUpdater = transitionResultAnnotationUpdater, SkylineDataSchema = SkylineDataSchema }; } AnnotationUpdater precursorResultAnnotationUpdater; if (_annotationUpdaters.TryGetValue(AnnotationDef.AnnotationTarget.precursor_result, out precursorResultAnnotationUpdater)) { _precursorResultUpdater = new PrecursorResultUpdater { AnnotationUpdater = precursorResultAnnotationUpdater, SkylineDataSchema = SkylineDataSchema }; } RecurseTransitions = _annotationUpdaters.ContainsKey(AnnotationDef.AnnotationTarget.transition) || transitionResultAnnotationUpdater != null; RecursePrecursors = RecurseTransitions || _annotationUpdaters.ContainsKey(AnnotationDef.AnnotationTarget.precursor) || precursorResultAnnotationUpdater != null; RecurseMolecules = RecursePrecursors || _annotationUpdaters.ContainsKey(AnnotationDef.AnnotationTarget.peptide); }
public void RemoveAnnotationWorksForLastAnnotation() { const string inputCode = @"'@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() End Sub '@Obsolete @Description ""Desc"" @DefaultMember Public Sub Foo(bar As String) bar = vbNullString End Sub "; const string expectedCode = @"'@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() End Sub '@Obsolete @Description ""Desc"" Public Sub Foo(bar As String) bar = vbNullString End Sub "; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var fooDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.Procedure) .First(decl => decl.IdentifierName == "Foo"); var annotationToRemove = fooDeclaration.Annotations.Last(); var annotationUpdater = new AnnotationUpdater(); annotationUpdater.RemoveAnnotation(rewriteSession, annotationToRemove); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
public void AddAnnotationAddsMemberAnnotationRightAboveMember() { const string inputCode = @" Private Sub FooBar() End Sub '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; const string expectedCode = @" Private Sub FooBar() End Sub '@Obsolete '@MemberAttribute VB_Ext_Key, ""Key"", ""Value"" Public Sub Foo(bar As String) bar = vbNullString End Sub "; var annotationToAdd = new MemberAttributeAnnotation(); var annotationValues = new List <string> { "VB_Ext_Key", "\"Key\"", "\"Value\"" }; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var fooDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.Procedure) .First(decl => decl.IdentifierName == "Foo"); var annotationUpdater = new AnnotationUpdater(); annotationUpdater.AddAnnotation(rewriteSession, fooDeclaration, annotationToAdd, annotationValues); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
public void AddAnnotationNotOnFirstPhysicalLineOfALogicalLineDoesNothing() { const string inputCode = @" Private fooBar As Long, _ baz As Variant '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; const string expectedCode = @" Private fooBar As Long, _ baz As Variant '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; var annotationToAdd = new ObsoleteAnnotation(); string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var bazDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.Variable) .First(decl => decl.IdentifierName == "baz"); var annotationUpdater = new AnnotationUpdater(); annotationUpdater.AddAnnotation(rewriteSession, bazDeclaration, annotationToAdd); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
public void AddAnnotationOnTheFirstLineIgnoresIndentation() { const string inputCode = @" Private Sub FooBar() End Sub '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; const string expectedCode = @"'@Obsolete Private Sub FooBar() End Sub '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; var annotationToAdd = new ObsoleteAnnotation(); string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var fooBarDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.Procedure) .First(decl => decl.IdentifierName == "FooBar"); var annotationUpdater = new AnnotationUpdater(); annotationUpdater.AddAnnotation(rewriteSession, fooBarDeclaration, annotationToAdd); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
public void AddAnnotationAddsModuleAnnotationBelowTheLastAttributeForAttributeRewriteSession() { const string inputCode = @"VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = ""ClassKeys"" Attribute VB_GlobalNameSpace = False '@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() End Sub '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; const string expectedCode = @"VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = ""ClassKeys"" Attribute VB_GlobalNameSpace = False '@ModuleAttribute VB_Ext_Key, ""Key"", ""Value"" '@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() End Sub '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; var annotationToAdd = new ModuleAttributeAnnotation(); var annotationValues = new List <string> { "VB_Ext_Key", "\"Key\"", "\"Value\"" }; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode, ComponentType.ClassModule, CodeKind.AttributesCode); using (state) { var moduleDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.ClassModule) .First(); var annotationUpdater = new AnnotationUpdater(state); annotationUpdater.AddAnnotation(rewriteSession, moduleDeclaration, annotationToAdd, annotationValues); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }