public void AnnotateDeclarationRefactoringAction_InspectionNameArgument()
        {
            const string code         = @"
Public Sub Foo()
End Sub
";
            const string expectedCode = @"'@IgnoreModule AssignmentNotUsed, FunctionReturnValueNotUsed

Public Sub Foo()
End Sub
";
            Func <RubberduckParserState, AnnotateDeclarationModel> modelBuilder = (state) =>
            {
                var module = state.DeclarationFinder
                             .UserDeclarations(DeclarationType.ProceduralModule)
                             .Single();
                var annotation = new IgnoreModuleAnnotation();
                var arguments  = new List <TypedAnnotationArgument>
                {
                    new TypedAnnotationArgument(AnnotationArgumentType.Inspection, "AssignmentNotUsed"),
                    new TypedAnnotationArgument(AnnotationArgumentType.Inspection, "FunctionReturnValueNotUsed")
                };

                return(new AnnotateDeclarationModel(module, annotation, arguments));
            };

            var refactoredCode = RefactoredCode(code, modelBuilder);

            Assert.AreEqual(expectedCode, refactoredCode);
        }
コード例 #2
0
        public override void Fix(IInspectionResult result, IRewriteSession rewriteSession)
        {
            var module            = result.QualifiedSelection.QualifiedName;
            var moduleDeclaration = _state.DeclarationFinder.Members(module, DeclarationType.Module)
                                    .FirstOrDefault();

            if (moduleDeclaration == null)
            {
                return;
            }

            var existingIgnoreModuleAnnotation = moduleDeclaration.Annotations
                                                 .FirstOrDefault(pta => pta.Annotation is IgnoreModuleAnnotation);

            var annotationType = new IgnoreModuleAnnotation();

            if (existingIgnoreModuleAnnotation != null)
            {
                var annotationValues = existingIgnoreModuleAnnotation.AnnotationArguments.ToList();

                if (annotationValues.Contains(result.Inspection.AnnotationName))
                {
                    return;
                }

                annotationValues.Insert(0, result.Inspection.AnnotationName);
                _annotationUpdater.UpdateAnnotation(rewriteSession, existingIgnoreModuleAnnotation, annotationType, annotationValues);
            }
            else
            {
                var newModuleText    = rewriteSession.CheckOutModuleRewriter(module).GetText();
                var ignoreModuleText = $"'{ParseTreeAnnotation.ANNOTATION_MARKER}{annotationType.Name}";
                if (newModuleText.Contains(ignoreModuleText))
                {
                    //Most probably, we have added this already in another invocation on the same rewrite session.
                    return;
                }

                var annotationValues = new List <string> {
                    result.Inspection.AnnotationName
                };
                _annotationUpdater.AddAnnotation(rewriteSession, moduleDeclaration, annotationType, annotationValues);
            }
        }
コード例 #3
0
        private void FixModule(IInspectionResult result, IRewriteSession rewriteSession)
        {
            var moduleDeclaration = result.Target;
            var existingIgnoreModuleAnnotation = moduleDeclaration.Annotations
                                                 .FirstOrDefault(pta => pta.Annotation is IgnoreModuleAnnotation);

            var annotationType = new IgnoreModuleAnnotation();

            if (existingIgnoreModuleAnnotation != null)
            {
                var annotationValues = existingIgnoreModuleAnnotation.AnnotationArguments.ToList();
                annotationValues.Insert(0, result.Inspection.AnnotationName);
                _annotationUpdater.UpdateAnnotation(rewriteSession, existingIgnoreModuleAnnotation, annotationType, annotationValues);
            }
            else
            {
                var annotationValues = new List <string> {
                    result.Inspection.AnnotationName
                };
                _annotationUpdater.AddAnnotation(rewriteSession, moduleDeclaration, annotationType, annotationValues);
            }
        }
コード例 #4
0
        public void IgnoreModuleAnnotation_CanBeAppliedMultipleTimes()
        {
            var annotation = new IgnoreModuleAnnotation(new QualifiedSelection(), null, null);

            Assert.True(annotation.AllowMultiple);
        }
コード例 #5
0
        public void IgnoreModuleAnnotation_TypeIsIgnoreModule()
        {
            var annotation = new IgnoreModuleAnnotation(new QualifiedSelection(), null, null);

            Assert.AreEqual(AnnotationType.IgnoreModule, annotation.AnnotationType);
        }