Skip to content

Commit cfadbfe

Browse files
committed
Clean up Extract Interface and Move Closer To Usage
1 parent 352334c commit cfadbfe

File tree

4 files changed

+82
-55
lines changed

4 files changed

+82
-55
lines changed

RetailCoder.VBE/Refactorings/ExtractInterface/ExtractInterfaceModel.cs

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,40 @@ public class ExtractInterfaceModel
2424
public string InterfaceName { get; set; }
2525
public List<InterfaceMember> Members { get; set; }
2626

27-
private readonly static DeclarationType[] DeclarationTypes =
27+
private static DeclarationType[] DeclarationTypes
2828
{
29-
DeclarationType.Class,
30-
DeclarationType.Document,
31-
DeclarationType.UserForm
32-
};
29+
get
30+
{
31+
return new[]
32+
{
33+
DeclarationType.Class,
34+
DeclarationType.Document,
35+
DeclarationType.UserForm
36+
};
37+
}
38+
}
3339

34-
public readonly string[] PrimitiveTypes =
40+
public static string[] PrimitiveTypes
3541
{
36-
Tokens.Boolean,
37-
Tokens.Byte,
38-
Tokens.Date,
39-
Tokens.Decimal,
40-
Tokens.Double,
41-
Tokens.Long,
42-
Tokens.LongLong,
43-
Tokens.LongPtr,
44-
Tokens.Integer,
45-
Tokens.Single,
46-
Tokens.String,
47-
Tokens.StrPtr
48-
};
42+
get
43+
{
44+
return new[]
45+
{
46+
Tokens.Boolean,
47+
Tokens.Byte,
48+
Tokens.Date,
49+
Tokens.Decimal,
50+
Tokens.Double,
51+
Tokens.Long,
52+
Tokens.LongLong,
53+
Tokens.LongPtr,
54+
Tokens.Integer,
55+
Tokens.Single,
56+
Tokens.String,
57+
Tokens.StrPtr
58+
};
59+
}
60+
}
4961

5062
public ExtractInterfaceModel(RubberduckParserState parseResult, QualifiedSelection selection)
5163
{

RetailCoder.VBE/Refactorings/MoveCloserToUsage/MoveCloserToUsageRefactoring.cs

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Windows.Forms;
45
using Rubberduck.Common;
56
using Rubberduck.Parsing.Symbols;
67
using Rubberduck.Parsing.VBA;
@@ -31,8 +32,8 @@ public void Refactor()
3132
}
3233
else
3334
{
34-
_messageBox.Show("Invalid Selection.", "Rubberduck - Move Closer To Usage", System.Windows.Forms.MessageBoxButtons.OK,
35-
System.Windows.Forms.MessageBoxIcon.Exclamation);
35+
_messageBox.Show(RubberduckUI.MoveCloserToUsage_InvalidSelection, RubberduckUI.MoveCloserToUsage_Caption, MessageBoxButtons.OK,
36+
MessageBoxIcon.Exclamation);
3637
}
3738
}
3839

@@ -45,24 +46,25 @@ public void Refactor(Declaration target)
4546
{
4647
if (target.DeclarationType != DeclarationType.Variable)
4748
{
48-
throw new ArgumentException(@"Invalid Argument", "target");
49+
// ReSharper disable once LocalizableElement
50+
throw new ArgumentException("Invalid Argument. DeclarationType must be 'Variable'", "target");
4951
}
5052

5153
if (!target.References.Any())
5254
{
5355
var message = string.Format(RubberduckUI.MoveCloserToUsage_TargetHasNoReferences, target.IdentifierName);
5456

55-
_messageBox.Show(message, RubberduckUI.MoveCloserToUsage_Caption, System.Windows.Forms.MessageBoxButtons.OK,
56-
System.Windows.Forms.MessageBoxIcon.Exclamation);
57+
_messageBox.Show(message, RubberduckUI.MoveCloserToUsage_Caption, MessageBoxButtons.OK,
58+
MessageBoxIcon.Exclamation);
5759

5860
return;
5961
}
6062

6163
if (TargetIsReferencedFromMultipleMethods(target))
6264
{
6365
var message = string.Format(RubberduckUI.MoveCloserToUsage_TargetIsUsedInMultipleMethods, target.IdentifierName);
64-
_messageBox.Show(message, RubberduckUI.MoveCloserToUsage_Caption, System.Windows.Forms.MessageBoxButtons.OK,
65-
System.Windows.Forms.MessageBoxIcon.Exclamation);
66+
_messageBox.Show(message, RubberduckUI.MoveCloserToUsage_Caption, MessageBoxButtons.OK,
67+
MessageBoxIcon.Exclamation);
6668

6769
return;
6870
}
@@ -140,35 +142,36 @@ private void RemoveVariable(Declaration target)
140142

141143
private string RemoveExtraComma(string str, int numParams, int indexRemoved)
142144
{
143-
// Example use cases for this method (fields and variables):
144-
// Dim fizz as Boolean, dizz as Double
145-
// Private fizz as Boolean, dizz as Double
146-
// Public fizz as Boolean, _
147-
// dizz as Double
148-
// Private fizz as Boolean _
149-
// , dizz as Double _
150-
// , iizz as Integer
151-
152-
// Before this method is called, the parameter to be removed has
153-
// already been removed. This means 'str' will look like:
154-
// Dim fizz as Boolean,
155-
// Private , dizz as Double
156-
// Public fizz as Boolean, _
157-
//
158-
// Private _
159-
// , dizz as Double _
160-
// , iizz as Integer
161-
162-
// This method is responsible for removing the redundant comma
163-
// and returning a string similar to:
164-
// Dim fizz as Boolean
165-
// Private dizz as Double
166-
// Public fizz as Boolean _
167-
//
168-
// Private _
169-
// dizz as Double _
170-
// , iizz as Integer
171-
145+
/* Example use cases for this method (fields and variables):
146+
* Dim fizz as Boolean, dizz as Double
147+
* Private fizz as Boolean, dizz as Double
148+
* Public fizz as Boolean, _
149+
* dizz as Double
150+
* Private fizz as Boolean _
151+
* , dizz as Double _
152+
* , iizz as Integer
153+
154+
* Before this method is called, the parameter to be removed has
155+
* already been removed. This means 'str' will look like:
156+
* Dim fizz as Boolean,
157+
* Private , dizz as Double
158+
* Public fizz as Boolean, _
159+
*
160+
* Private _
161+
* , dizz as Double _
162+
* , iizz as Integer
163+
164+
* This method is responsible for removing the redundant comma
165+
* and returning a string similar to:
166+
* Dim fizz as Boolean
167+
* Private dizz as Double
168+
* Public fizz as Boolean _
169+
*
170+
* Private _
171+
* dizz as Double _
172+
* , iizz as Integer
173+
*/
174+
172175
var commaToRemove = numParams == indexRemoved ? indexRemoved - 1 : indexRemoved;
173176

174177
return str.Remove(str.NthIndexOf(',', commaToRemove), 1);

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,4 +1297,7 @@ Are you sure you want to proceed with this rename?</value>
12971297
<data name="ImplementInterface_InvalidSelectionMessage" xml:space="preserve">
12981298
<value>The current selection is not valid.</value>
12991299
</data>
1300+
<data name="MoveCloserToUsage_InvalidSelection" xml:space="preserve">
1301+
<value>Invalid Selection.</value>
1302+
</data>
13001303
</root>

0 commit comments

Comments
 (0)