Skip to content

Commit 163d1e5

Browse files
committed
Remove explicit casts areou extract interface commands
1 parent b59653f commit 163d1e5

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

Rubberduck.Core/UI/CodeExplorer/Commands/CodeExplorerExtractInterfaceCommand.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ public class CodeExplorerExtractInterfaceCommand : CodeExplorerCommandBase
1616
typeof(CodeExplorerComponentViewModel)
1717
};
1818

19-
private readonly IParserStatusProvider _state;
19+
private readonly RubberduckParserState _state;
2020
private readonly ExtractInterfaceRefactoring _refactoring;
2121
private readonly ExtractInterfaceFailedNotifier _failureNotifier;
2222

2323
public CodeExplorerExtractInterfaceCommand(
2424
ExtractInterfaceRefactoring refactoring,
25-
IParserStatusProvider state,
25+
RubberduckParserState state,
2626
ExtractInterfaceFailedNotifier failureNotifier,
2727
IVbeEvents vbeEvents)
2828
: base(vbeEvents)
@@ -38,16 +38,16 @@ public CodeExplorerExtractInterfaceCommand(
3838

3939
private bool SpecialEvaluateCanExecute(object parameter)
4040
{
41-
return _state.Status == ParserState.Ready &&
42-
parameter is CodeExplorerComponentViewModel node &&
43-
_refactoring.CanExecute((RubberduckParserState)_state, node.QualifiedSelection.Value.QualifiedName);
41+
return _state.Status == ParserState.Ready
42+
&& parameter is CodeExplorerComponentViewModel node
43+
&& _refactoring.CanExecute(_state, node.QualifiedSelection.Value.QualifiedName);
4444
}
4545

4646
private bool FurtherCanExecuteEvaluation(object parameter)
4747
{
48-
return _state.Status == ParserState.Ready &&
49-
parameter is CodeExplorerItemViewModel node &&
50-
node.Declaration != null;
48+
return _state.Status == ParserState.Ready
49+
&& parameter is CodeExplorerItemViewModel node
50+
&& node.Declaration != null;
5151
}
5252

5353
protected override void OnExecute(object parameter)

Rubberduck.Core/UI/Command/Refactorings/RefactorCodePaneCommandBase.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ public abstract class RefactorCodePaneCommandBase : RefactorCommandBase
1010
{
1111
protected readonly ISelectionProvider SelectionProvider;
1212

13-
protected RefactorCodePaneCommandBase(IRefactoring refactoring, IRefactoringFailureNotifier failureNotifier, ISelectionProvider selectionProvider, IParserStatusProvider parserStatusProvider)
13+
protected RefactorCodePaneCommandBase(
14+
IRefactoring refactoring,
15+
IRefactoringFailureNotifier failureNotifier,
16+
ISelectionProvider selectionProvider,
17+
IParserStatusProvider parserStatusProvider)
1418
: base (refactoring, failureNotifier, parserStatusProvider)
1519
{
1620
SelectionProvider = selectionProvider;

Rubberduck.Core/UI/Command/Refactorings/RefactorExtractInterfaceCommand.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
31
using System.Runtime.InteropServices;
4-
using Antlr4.Runtime;
5-
using Rubberduck.Parsing;
6-
using Rubberduck.Parsing.Grammar;
7-
using Rubberduck.Parsing.Symbols;
82
using Rubberduck.Parsing.VBA;
93
using Rubberduck.Refactorings.ExtractInterface;
104
using Rubberduck.UI.Command.Refactorings.Notifiers;
@@ -16,8 +10,8 @@ namespace Rubberduck.UI.Command.Refactorings
1610
public class RefactorExtractInterfaceCommand : RefactorCodePaneCommandBase
1711
{
1812
private readonly RubberduckParserState _state;
13+
private readonly ExtractInterfaceRefactoring _extractInterfaceRefactoring;
1914

20-
2115
public RefactorExtractInterfaceCommand(
2216
ExtractInterfaceRefactoring refactoring,
2317
ExtractInterfaceFailedNotifier extractInterfaceFailedNotifier,
@@ -26,6 +20,7 @@ public RefactorExtractInterfaceCommand(
2620
:base(refactoring, extractInterfaceFailedNotifier, selectionProvider, state)
2721
{
2822
_state = state;
23+
_extractInterfaceRefactoring = refactoring;
2924

3025
AddToCanExecuteEvaluation(SpecializedEvaluateCanExecute);
3126
}
@@ -37,7 +32,7 @@ private bool SpecializedEvaluateCanExecute(object parameter)
3732
{
3833
return false;
3934
}
40-
return ((ExtractInterfaceRefactoring)Refactoring).CanExecute(_state, activeSelection.Value.QualifiedName);
35+
return _extractInterfaceRefactoring.CanExecute(_state, activeSelection.Value.QualifiedName);
4136
}
4237
}
4338
}

Rubberduck.Refactorings/ExtractInterface/ExtractInterfaceRefactoring.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ private string GetInterfaceModuleBody(ExtractInterfaceModel model)
142142
DeclarationType.UserForm
143143
};
144144

145+
//TODO: Redesign how refactoring commands are wired up to make this a responsibility of the command again.
145146
public bool CanExecute(RubberduckParserState state, QualifiedModuleName qualifiedName)
146147
{
147148
var interfaceClass = state.AllUserDeclarations.SingleOrDefault(item =>

0 commit comments

Comments
 (0)