public void AnnotateDeclarationRefactoringAction_AdjustAttributeSet_DifferentiatesBetweenExtKeys_Adjust()
        {
            const string code         = @"Attribute VB_Ext_Key = ""MyFirstKey"", ""MyFirstValue""
Attribute VB_Ext_Key = ""MySecondKey"", ""MySecondValue""
Attribute VB_Ext_Key = ""MyThirdKey"", ""MyThirdValue""
Public Sub Foo()
End Sub
";
            const string expectedCode = @"Attribute VB_Ext_Key = ""MyFirstKey"", ""MyFirstValue""
Attribute VB_Ext_Key = ""MySecondKey"", ""MyNewValue""
Attribute VB_Ext_Key = ""MyThirdKey"", ""MyThirdValue""
'@ModuleAttribute VB_Ext_Key, ""MySecondKey"", ""MyNewValue""
Public Sub Foo()
End Sub
";
            Func <RubberduckParserState, AnnotateDeclarationModel> modelBuilder = (state) =>
            {
                var declaration = state.DeclarationFinder
                                  .UserDeclarations(DeclarationType.Module)
                                  .Single();
                var annotation = new ModuleAttributeAnnotation();
                var arguments  = new List <TypedAnnotationArgument>
                {
                    new TypedAnnotationArgument(AnnotationArgumentType.Attribute, "VB_Ext_Key"),
                    new TypedAnnotationArgument(AnnotationArgumentType.Text, "MySecondKey"),
                    new TypedAnnotationArgument(AnnotationArgumentType.Text, "MyNewValue")
                };

                return(new AnnotateDeclarationModel(declaration, annotation, arguments, true));
            };

            var refactoredCode = RefactoredCode(code, modelBuilder);

            Assert.AreEqual(expectedCode, refactoredCode);
        }
        public void AnnotateDeclarationRefactoringAction_BooleanArgument_Undefined()
        {
            const string code         = @"
Public Sub Foo()
End Sub
";
            const string expectedCode = @"'@ModuleAttribute VB_Exposed, NOT_A_BOOLEAN

Public Sub Foo()
End Sub
";
            Func <RubberduckParserState, AnnotateDeclarationModel> modelBuilder = (state) =>
            {
                var module = state.DeclarationFinder
                             .UserDeclarations(DeclarationType.ProceduralModule)
                             .Single();
                var annotation = new ModuleAttributeAnnotation();
                var arguments  = new List <TypedAnnotationArgument>
                {
                    new TypedAnnotationArgument(AnnotationArgumentType.Attribute, "VB_Exposed"),
                    new TypedAnnotationArgument(AnnotationArgumentType.Boolean, "aefefef")
                };

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

            var refactoredCode = RefactoredCode(code, modelBuilder);

            Assert.AreEqual(expectedCode, refactoredCode);
        }
        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 AddAnnotationDoesNotAddModuleAnnotationsToMembers()
        {
            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
    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 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);
        }
Example #5
0
        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);
        }
Example #6
0
        public void ModuleAttributeAnnotation_TypeIsModuleAttribute()
        {
            var annotation = new ModuleAttributeAnnotation(new QualifiedSelection(), null, new[] { "Attribute", "Value" });

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