Skip to content

Commit 2a67236

Browse files
committed
Some extension methods and a QualifiedModuleName property on Declaration to remove clutter
1 parent c485e93 commit 2a67236

File tree

9 files changed

+48
-33
lines changed

9 files changed

+48
-33
lines changed

RetailCoder.VBE/UI/Command/AddTestMethodCommand.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Rubberduck.Parsing.VBA;
77
using Rubberduck.UnitTesting;
88
using Rubberduck.VBEditor;
9+
using Rubberduck.VBEditor.Extensions;
910
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
1011

1112
namespace Rubberduck.UI.Command
@@ -59,7 +60,7 @@ protected override bool EvaluateCanExecute(object parameter)
5960
{
6061
using( var activePaneCodeModule = activeCodePane.CodeModule)
6162
{
62-
return testModules.Any(a => HasEqualCodeModule(a.QualifiedName.QualifiedModuleName, activePaneCodeModule));
63+
return testModules.Any(a => _state.ProjectsProvider.Component(a.QualifiedModuleName).HasEqualCodeModule(activePaneCodeModule));
6364
}
6465
}
6566
}
@@ -81,7 +82,7 @@ protected override void OnExecute(object parameter)
8182
using (var module = pane.CodeModule)
8283
{
8384
var declaration = _state.GetTestModules()
84-
.FirstOrDefault(f => HasEqualCodeModule(f.QualifiedName.QualifiedModuleName, module));
85+
.FirstOrDefault(f => _state.ProjectsProvider.Component(f.QualifiedModuleName).HasEqualCodeModule(module));
8586

8687
if (declaration != null)
8788
{
@@ -98,14 +99,6 @@ protected override void OnExecute(object parameter)
9899
_state.OnParseRequested(this);
99100
}
100101

101-
private bool HasEqualCodeModule(QualifiedModuleName module, ICodeModule otherCodeModule)
102-
{
103-
using (var codeModule = _state.ProjectsProvider.Component(module).CodeModule)
104-
{
105-
return codeModule.Equals(otherCodeModule);
106-
}
107-
}
108-
109102
private string GetNextTestMethodName(IVBComponent component)
110103
{
111104
var names = component.GetTests(_vbe, _state).Select(test => test.Declaration.IdentifierName);

RetailCoder.VBE/UI/Command/AddTestMethodExpectedErrorCommand.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Rubberduck.Parsing.VBA;
77
using Rubberduck.UnitTesting;
88
using Rubberduck.VBEditor;
9+
using Rubberduck.VBEditor.Extensions;
910
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
1011

1112
namespace Rubberduck.UI.Command
@@ -69,7 +70,7 @@ protected override bool EvaluateCanExecute(object parameter)
6970
{
7071
using(var selectedModule = component.CodeModule)
7172
{
72-
return testModules.Any(a => HasEqualCodeModule(a.QualifiedName.QualifiedModuleName, selectedModule));
73+
return testModules.Any(a => _state.ProjectsProvider.Component(a.QualifiedModuleName).HasEqualCodeModule(selectedModule));
7374
}
7475
}
7576
}
@@ -80,14 +81,6 @@ protected override bool EvaluateCanExecute(object parameter)
8081
}
8182
}
8283

83-
private bool HasEqualCodeModule(QualifiedModuleName module, ICodeModule otherCodeModule)
84-
{
85-
using (var codeModule = _state.ProjectsProvider.Component(module).CodeModule)
86-
{
87-
return codeModule.Equals(otherCodeModule);
88-
}
89-
}
90-
9184
protected override void OnExecute(object parameter)
9285
{
9386
using (var pane = _vbe.ActiveCodePane)

RetailCoder.VBE/UnitTesting/UnitTestUtils.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using Rubberduck.Parsing;
34
using Rubberduck.Parsing.Annotations;
45
using Rubberduck.Parsing.Symbols;
56
using Rubberduck.Parsing.VBA;
67
using Rubberduck.VBEditor;
8+
using Rubberduck.VBEditor.Extensions;
79
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
810

911
namespace Rubberduck.UnitTesting
@@ -27,16 +29,7 @@ public static IEnumerable<TestMethod> GetTests(this IVBComponent component, IVBE
2729
// apparently, sometimes it thinks the components are different but knows the modules are the same
2830
// if the modules are the same, then the component is the same as far as we are concerned
2931
return GetAllTests(vbe, state)
30-
.Where(test => HaveEqualCodeModules(state.ProjectsProvider.Component(test.Declaration.QualifiedName.QualifiedModuleName), component));
31-
}
32-
33-
private static bool HaveEqualCodeModules(IVBComponent component, IVBComponent otherComponent)
34-
{
35-
using (var codeModule = component.CodeModule)
36-
using(var otherCodeModule = otherComponent.CodeModule)
37-
{
38-
return codeModule.Equals(otherCodeModule);
39-
}
32+
.Where(test => state.ProjectsProvider.Component(test.Declaration).HasEqualCodeModule(component));
4033
}
4134

4235
public static bool IsTestMethod(RubberduckParserState state, Declaration item)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Rubberduck.Parsing.Symbols;
2+
using Rubberduck.VBEditor.ComManagement;
3+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
4+
5+
namespace Rubberduck.Parsing
6+
{
7+
public static class ProjectsProviderExtensions
8+
{
9+
public static IVBComponent Component(this IProjectsProvider provider, Declaration declaration)
10+
{
11+
return provider.Component(declaration.QualifiedModuleName);
12+
}
13+
}
14+
}

Rubberduck.Parsing/Rubberduck.Parsing.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
<Compile Include="Binding\ParenthesizedDefaultBinding.cs" />
124124
<Compile Include="Binding\TypeBindingContext.cs" />
125125
<Compile Include="Binding\ExpressionClassification.cs" />
126+
<Compile Include="ProjectsProviderExtensions.cs" />
126127
<Compile Include="Common\ExperimentalAttribute.cs" />
127128
<Compile Include="ComReflection\ComAlias.cs" />
128129
<Compile Include="ComReflection\ComBase.cs" />

Rubberduck.Parsing/Symbols/Declaration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public static Declaration GetProjectParent(Declaration declaration)
279279
public Declaration ParentDeclaration { get; }
280280

281281
public QualifiedMemberName QualifiedName { get; }
282+
public QualifiedModuleName QualifiedModuleName => QualifiedName.QualifiedModuleName;
282283

283284
public ParserRuleContext Context { get; }
284285

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
2+
3+
namespace Rubberduck.VBEditor.Extensions
4+
{
5+
public static class VBComponentExtensions
6+
{
7+
public static bool HasEqualCodeModule(this IVBComponent component, IVBComponent otherComponent)
8+
{
9+
using (var otherCodeModule = otherComponent.CodeModule)
10+
{
11+
return component.HasEqualCodeModule(otherCodeModule);
12+
}
13+
}
14+
15+
public static bool HasEqualCodeModule(this IVBComponent component, ICodeModule otherCodeModule)
16+
{
17+
using (var codeModule = component.CodeModule)
18+
{
19+
return codeModule.Equals(otherCodeModule);
20+
}
21+
}
22+
}
23+
}

Rubberduck.VBEEditor/Extensions/VbProjectExtensions.cs

Lines changed: 0 additions & 3 deletions
This file was deleted.

Rubberduck.VBEEditor/Rubberduck.VBEditor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
<Compile Include="Events\SelectionChangedEventArgs.cs" />
142142
<Compile Include="Events\VBENativeServices.cs" />
143143
<Compile Include="Events\WindowChangedEventArgs.cs" />
144+
<Compile Include="Extensions\VBComponentExtensions.cs" />
144145
<Compile Include="Extensions\KeyValuePairExtensions.cs" />
145146
<Compile Include="Extensions\MSAccessComponentTypeExtensions.cs" />
146147
<Compile Include="SafeComWrappers\Office.Core\Abstract\IUserForm.cs" />
@@ -277,7 +278,6 @@
277278
<Compile Include="Application\Visio.cs" />
278279
<Compile Include="Application\WordApp.cs" />
279280
<Compile Include="Application\AutoCADApp.cs" />
280-
<Compile Include="Extensions\VBProjectExtensions.cs" />
281281
<Compile Include="Properties\AssemblyInfo.cs" />
282282
<Compile Include="WindowsApi\SubclassingWindow.cs" />
283283
<Compile Include="WindowsApi\User32.cs" />

0 commit comments

Comments
 (0)