Skip to content

Commit f659173

Browse files
committed
Add DefaultPropertyValueParamIdentifier property
Exposes a single method for generating a default Let\Set RHS property parameter IdentifierName.
1 parent 723bbac commit f659173

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

Rubberduck.Refactorings/Common/CodeBuilder.cs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Rubberduck.Parsing.Grammar;
1+
using Rubberduck.Common;
2+
using Rubberduck.Parsing.Grammar;
23
using Rubberduck.Parsing.Symbols;
34
using System;
45
using System.Collections.Generic;
@@ -11,19 +12,13 @@ public interface ICodeBuilder
1112
/// <summary>
1213
/// Returns ModuleBodyElementDeclaration signature with an ImprovedArgument list
1314
/// </summary>
14-
/// <param name="declaration"></param>
15-
/// <returns></returns>
1615
string ImprovedFullMemberSignature(ModuleBodyElementDeclaration declaration);
1716

1817
/// <summary>
1918
/// Returns a ModuleBodyElementDeclaration block
2019
/// with an ImprovedArgument List
2120
/// </summary>
22-
/// <param name="declaration"></param>
2321
/// <param name="content">Main body content/logic of the member</param>
24-
/// <param name="accessibility"></param>
25-
/// <param name="newIdentifier"></param>
26-
/// <returns></returns>
2722
string BuildMemberBlockFromPrototype(ModuleBodyElementDeclaration declaration,
2823
string content = null,
2924
string accessibility = null,
@@ -34,19 +29,14 @@ string BuildMemberBlockFromPrototype(ModuleBodyElementDeclaration declaration,
3429
/// 1. Explicitly declares Property Let\Set value parameter as ByVal
3530
/// 2. Ensures UserDefined Type parameters are declared either explicitly or implicitly as ByRef
3631
/// </summary>
37-
/// <param name="declaration"></param>
38-
/// <returns></returns>
3932
string ImprovedArgumentList(ModuleBodyElementDeclaration declaration);
4033

4134
/// <summary>
4235
/// Generates a Property Get codeblock based on the prototype declaration
4336
/// </summary>
4437
/// <param name="prototype">VariableDeclaration or UserDefinedTypeMember</param>
45-
/// <param name="propertyIdentifier"></param>
46-
/// <param name="accessibility"></param>
4738
/// <param name="content">Member body content. Formatting is the responsibility of the caller</param>
48-
/// <param name="parameterIdentifier">Defaults to 'value' unless otherwise specified</param>
49-
/// <returns></returns>
39+
/// <param name="parameterIdentifier">Defaults to '<paramref name="propertyIdentifier"/>Value' unless otherwise specified</param>
5040
bool TryBuildPropertyGetCodeBlock(Declaration prototype,
5141
string propertyIdentifier,
5242
out string codeBlock,
@@ -57,11 +47,8 @@ bool TryBuildPropertyGetCodeBlock(Declaration prototype,
5747
/// Generates a Property Let codeblock based on the prototype declaration
5848
/// </summary>
5949
/// <param name="prototype">VariableDeclaration or UserDefinedTypeMember</param>
60-
/// <param name="propertyIdentifier"></param>
61-
/// <param name="accessibility"></param>
62-
/// <param name="content">Membmer body content. Formatting is the responsibility of the caller</param>
63-
/// <param name="parameterIdentifier">Defaults to 'value' unless otherwise specified</param>
64-
/// <returns></returns>
50+
/// <param name="content">Member body content. Formatting is the responsibility of the caller</param>
51+
/// <param name="parameterIdentifier">Defaults to '<paramref name="propertyIdentifier"/>Value' unless otherwise specified</param>
6552
bool TryBuildPropertyLetCodeBlock(Declaration prototype,
6653
string propertyIdentifier,
6754
out string codeBlock,
@@ -73,21 +60,28 @@ bool TryBuildPropertyLetCodeBlock(Declaration prototype,
7360
/// Generates a Property Set codeblock based on the prototype declaration
7461
/// </summary>
7562
/// <param name="prototype">VariableDeclaration or UserDefinedTypeMember</param>
76-
/// <param name="propertyIdentifier"></param>
77-
/// <param name="accessibility"></param>
78-
/// <param name="content">Membmer body content. Formatting is the responsibility of the caller</param>
79-
/// <param name="parameterIdentifier">Defaults to 'value' unless otherwise specified</param>
80-
/// <returns></returns>
63+
/// <param name="content">Member body content. Formatting is the responsibility of the caller</param>
64+
/// <param name="parameterIdentifier">Defaults to '<paramref name="propertyIdentifier"/>Value' unless otherwise specified</param>
8165
bool TryBuildPropertySetCodeBlock(Declaration prototype,
8266
string propertyIdentifier,
8367
out string codeBlock,
8468
string accessibility = null,
8569
string content = null,
8670
string parameterIdentifier = null);
71+
/// <summary>
72+
/// Generates a default RHS property parameter IdentifierName
73+
/// </summary>
74+
/// <param name="propertyIdentifier">Let/Set Property IdentifierName</param>
75+
string DefaultPropertyValueParamIdentifier(string propertyIdentifier);
8776
}
8877

8978
public class CodeBuilder : ICodeBuilder
9079
{
80+
private static string ParameterSuffix => Resources.RubberduckUI.EncapsulateField_DefaultPropertyParameter.Capitalize();
81+
82+
public string DefaultPropertyValueParamIdentifier(string propertyIdentifier)
83+
=> $"{propertyIdentifier.ToLowerCaseFirstLetter()}{ParameterSuffix}";
84+
9185
public string BuildMemberBlockFromPrototype(ModuleBodyElementDeclaration declaration,
9286
string content = null,
9387
string accessibility = null,
@@ -127,7 +121,7 @@ private bool TryBuildPropertyBlockFromTarget<T>(T prototype, DeclarationType let
127121
return false;
128122
}
129123

130-
var propertyValueParam = parameterIdentifier ?? Resources.RubberduckUI.EncapsulateField_DefaultPropertyParameter;
124+
var propertyValueParam = parameterIdentifier ?? DefaultPropertyValueParamIdentifier(propertyIdentifier);
131125

132126
var asType = prototype.IsArray
133127
? $"{Tokens.Variant}"

RubberduckTests/CodeBuilderTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NUnit.Framework;
2+
using Rubberduck.Common;
23
using Rubberduck.Parsing.Symbols;
34
using Rubberduck.Refactorings;
45
using RubberduckTests.Mocks;
@@ -10,6 +11,7 @@ namespace RubberduckTests
1011
[TestFixture]
1112
public class CodeBuilderTests
1213
{
14+
private static string Param(string property) => $"{property.ToLowerCaseFirstLetter()}Value";
1315

1416
[TestCase("fizz", DeclarationType.Variable, "Integer")]
1517
[TestCase("FirstValue", DeclarationType.UserDefinedTypeMember, "Long")]
@@ -192,8 +194,7 @@ Private fuzz As ETestType2
192194
declarationType,
193195
testParams,
194196
PropertyLetBlockFromPrototypeTest);
195-
196-
StringAssert.Contains($"Property Let {testParams.Identifier}(ByVal value As {typeName})", result);
197+
StringAssert.Contains($"Property Let {testParams.Identifier}(ByVal {Param(testParams.Identifier)} As {typeName})", result);
197198
}
198199

199200
[TestCase("fizz", DeclarationType.Variable, "Variant")]
@@ -219,7 +220,7 @@ Private fizz As Variant
219220
testParams,
220221
PropertySetBlockFromPrototypeTest);
221222

222-
StringAssert.Contains($"Property Set {testParams.Identifier}(ByVal value As {typeName})", result);
223+
StringAssert.Contains($"Property Set {testParams.Identifier}(ByVal {Param(testParams.Identifier)} As {typeName})", result);
223224
}
224225

225226
[TestCase(DeclarationType.PropertyLet)]

0 commit comments

Comments
 (0)