コード例 #1
0
        private string ApplyQuickFixToFirstInspectionResultForImplicitWorksheetInspection(string inputCode)
        {
            var inputModule = ("Sheet1", inputCode, ComponentType.Document);
            var vbe         = MockVbeBuilder.BuildFromModules(inputModule, ReferenceLibrary.Excel).Object;

            var(state, rewriteManager) = MockParser.CreateAndParseWithRewritingManager(vbe);
            using (state)
            {
                var documentModule = state.DeclarationFinder.UserDeclarations(DeclarationType.Document)
                                     .OfType <DocumentModuleDeclaration>()
                                     .Single();
                documentModule.AddSupertypeName("Worksheet");

                var inspection        = new ImplicitContainingWorksheetReferenceInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                var rewriteSession = rewriteManager.CheckOutCodePaneSession();

                var quickFix = QuickFix(state);

                var resultToFix = inspectionResults.First();
                quickFix.Fix(resultToFix, rewriteSession);

                var module = state.DeclarationFinder.AllModules.First(qmn => qmn.ComponentName == "Sheet1");

                return(rewriteSession.CheckOutModuleRewriter(module).GetText());
            }
        }
        public void Field_ConversionFunctions_OtherModule(string vbaFunc, string expectedType)
        {
            var targetName = "mTest";
            var inputCode  =
                $@"
Public mTest
";
            var assigningModuleName = "AssigningModule";
            var assigningModuleCode =
                $@"
Private Sub Test(arg As String)
    mTest = {vbaFunc}(arg)
End Sub
";
            var modules = new List <(string name, string content, ComponentType componentType)>()
            {
                (MockVbeBuilder.TestModuleName, inputCode, ComponentType.StandardModule),
                (assigningModuleName, assigningModuleCode, ComponentType.StandardModule)
            };

            var vbe            = MockVbeBuilder.BuildFromModules(modules, new ReferenceLibrary[] { ReferenceLibrary.VBA });
            var refactoredCode = RefactoredCode(vbe.Object,
                                                state => TestModel(state, NameAndDeclarationTypeTuple(targetName), (model) => model));

            StringAssert.Contains($"{targetName} As {expectedType}", refactoredCode[MockVbeBuilder.TestModuleName]);
        }
コード例 #3
0
        public void ImplicitActiveWorkbookReference_ReportsInWorksheetModules()
        {
            const string inputCode =
                @"
Sub foo()
    Dim sheet As Worksheet
    Set sheet = Worksheets(""Sheet1"")
End Sub";
            var module = ("Sheet1", inputCode, ComponentType.Document);
            var vbe    = MockVbeBuilder.BuildFromModules(module, ReferenceLibrary.Excel).Object;

            using (var state = MockParser.CreateAndParse(vbe))
            {
                var documentModule = state.DeclarationFinder.UserDeclarations(DeclarationType.Document)
                                     .OfType <DocumentModuleDeclaration>()
                                     .Single();
                documentModule.AddSupertypeName("Worksheet");

                var inspection        = InspectionUnderTest(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                Assert.AreEqual(1, inspectionResults.Count());
            }
        }