public void AnnotateDeclarationRefactoringAction_AdjustAttributeSet_NoAttributeAnnotation_AsIfNotSet() { const string code = @" Public Sub Foo() End Sub "; const string expectedCode = @" '@Ignore ProcedureNotUsed Public Sub Foo() End Sub "; Func <RubberduckParserState, AnnotateDeclarationModel> modelBuilder = (state) => { var declaration = state.DeclarationFinder .UserDeclarations(DeclarationType.Procedure) .Single(); var annotation = new IgnoreAnnotation(); var arguments = new List <TypedAnnotationArgument> { new TypedAnnotationArgument(AnnotationArgumentType.Inspection, "ProcedureNotUsed") }; return(new AnnotateDeclarationModel(declaration, annotation, arguments, true)); }; var refactoredCode = RefactoredCode(code, modelBuilder); Assert.AreEqual(expectedCode, refactoredCode); }
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); }
public void ShowAdjustAttributeOption_NotAnAttributeAnnotation_False() { var viewModel = TestViewModel(DeclarationType.Procedure); var annotation = new IgnoreAnnotation(); viewModel.Annotation = annotation; Assert.IsFalse(viewModel.ShowAdjustAttributeOption); }
private void FixNonModule(IInspectionResult result, IRewriteSession rewriteSession) { var module = result.QualifiedSelection.QualifiedName; var lineToAnnotate = result.QualifiedSelection.Selection.StartLine; var existingIgnoreAnnotation = _state.DeclarationFinder.FindAnnotations(module, lineToAnnotate) .Where(pta => pta.Annotation is IgnoreAnnotation) .FirstOrDefault(); var annotationInfo = new IgnoreAnnotation(); if (existingIgnoreAnnotation != null) { var annotationValues = existingIgnoreAnnotation.AnnotationArguments.ToList(); annotationValues.Insert(0, result.Inspection.AnnotationName); _annotationUpdater.UpdateAnnotation(rewriteSession, existingIgnoreAnnotation, annotationInfo, annotationValues); } else { var annotationValues = new List <string> { result.Inspection.AnnotationName }; _annotationUpdater.AddAnnotation(rewriteSession, new QualifiedContext(module, result.Context), annotationInfo, annotationValues); } }
public void IgnoreAnnotation_TypeIsIgnore() { var annotation = new IgnoreAnnotation(new QualifiedSelection(), new[] { "param" }); Assert.AreEqual(AnnotationType.Ignore, annotation.AnnotationType); }
public void IgnoreAnnotation_CanBeAppliedMultipleTimes() { var annotation = new IgnoreAnnotation(new QualifiedSelection(), null, null); Assert.True(annotation.AllowMultiple); }
public void IgnoreAnnotation_TypeIsIgnore_NoParam() { var annotation = new IgnoreAnnotation(new QualifiedSelection(), new List <string>()); Assert.AreEqual(AnnotationType.Ignore, annotation.AnnotationType); }