Skip to content

Commit 58d413f

Browse files
authored
Merge pull request #3643 from Hosch250/Issue2182
Extract Interface refactoring edge casr fix
2 parents 088ce6b + 09cd17f commit 58d413f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

RetailCoder.VBE/UI/Command/Refactorings/RefactorExtractInterfaceCommand.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using System.Runtime.InteropServices;
4+
using Antlr4.Runtime;
5+
using Rubberduck.Parsing;
6+
using Rubberduck.Parsing.Grammar;
47
using Rubberduck.Parsing.Symbols;
58
using Rubberduck.Parsing.VBA;
69
using Rubberduck.Refactorings.ExtractInterface;
@@ -41,14 +44,27 @@ protected override bool EvaluateCanExecute(object parameter)
4144
item.QualifiedName.QualifiedModuleName.Equals(selection.Value.QualifiedName)
4245
&& ModuleTypes.Contains(item.DeclarationType));
4346

47+
if (interfaceClass == null)
48+
{
49+
return false;
50+
}
51+
4452
// interface class must have members to be implementable
4553
var hasMembers = _state.AllUserDeclarations.Any(item =>
4654
item.DeclarationType.HasFlag(DeclarationType.Member)
4755
&& item.ParentDeclaration != null
4856
&& item.ParentDeclaration.Equals(interfaceClass));
57+
58+
if (!hasMembers)
59+
{
60+
return false;
61+
}
62+
63+
var parseTree = _state.GetParseTree(interfaceClass.QualifiedName.QualifiedModuleName);
64+
var context = ((ParserRuleContext)parseTree).FindChildren<VBAParser.ImplementsStmtContext>();
4965

5066
// true if active code pane is for a class/document/form module
51-
return interfaceClass != null && hasMembers;
67+
return !context.Any();
5268
}
5369

5470
protected override void OnExecute(object parameter)

0 commit comments

Comments
 (0)