Skip to content

Commit 51ce8a7

Browse files
committed
Expose IIndenter on ICodeBuilder
Also corrects merge error and minor changes to signatures and comments
1 parent 7714e66 commit 51ce8a7

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

Rubberduck.Refactorings/Common/CodeBuilder.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,20 @@ bool TryBuildPropertySetCodeBlock(Declaration prototype,
8787
/// No validation or conflict analysis is applied to the identifiers.
8888
/// </remarks>
8989
/// <param name="prototype">DeclarationType with flags: Variable, Constant, UserDefinedTypeMember, or Function</param>
90-
bool TryBuildUDTMemberDeclaration(string identifier, Declaration prototype, out string declaration);
90+
bool TryBuildUDTMemberDeclaration(Declaration prototype, string identifier, out string declaration);
91+
92+
IIndenter Indenter { get; }
9193
}
9294

9395
public class CodeBuilder : ICodeBuilder
9496
{
95-
private readonly IIndenter _indenter;
96-
9797
public CodeBuilder(IIndenter indenter)
9898
{
99-
_indenter = indenter;
99+
Indenter = indenter;
100100
}
101101

102+
public IIndenter Indenter { get; }
103+
102104
public string BuildMemberBlockFromPrototype(ModuleBodyElementDeclaration declaration,
103105
string content = null,
104106
Accessibility accessibility = Accessibility.Public,
@@ -135,6 +137,9 @@ private bool TryBuildPropertyBlockFromTarget<T>(T prototype, DeclarationType let
135137

136138
var propertyValueParam = parameterIdentifier ?? Resources.Refactorings.Refactorings.CodeBuilder_DefaultPropertyRHSParam;
137139

140+
//TODO: Improve generated Array properties
141+
//Add logic to conditionally return Arrays or Variant depending on Office version.
142+
//Ability to return an Array from a Function or Property was added in Office 2000 http://www.cpearson.com/excel/passingandreturningarrays.htm
138143
var asType = prototype.IsArray
139144
? $"{Tokens.Variant}"
140145
: IsEnumField(prototype) && prototype.AsTypeDeclaration.Accessibility.Equals(Accessibility.Private)
@@ -151,7 +156,7 @@ private bool TryBuildPropertyBlockFromTarget<T>(T prototype, DeclarationType let
151156
? string.Join(Environment.NewLine, $"{AccessibilityToken(accessibility)} {TypeToken(letSetGetType)} {propertyIdentifier}() {asTypeClause}", content, EndStatement(letSetGetType))
152157
: string.Join(Environment.NewLine, $"{AccessibilityToken(accessibility)} {TypeToken(letSetGetType)} {propertyIdentifier}({letSetParamExpression})", content, EndStatement(letSetGetType));
153158

154-
codeBlock = string.Join(Environment.NewLine, _indenter.Indent(codeBlock));
159+
codeBlock = string.Join(Environment.NewLine, Indenter.Indent(codeBlock));
155160
return true;
156161
}
157162

@@ -270,12 +275,12 @@ public bool TryBuildUserDefinedTypeDeclaration(string udtIdentifier, IEnumerable
270275

271276
blockLines.Add($"{Tokens.End} {Tokens.Type}");
272277

273-
declaration = string.Join(Environment.NewLine, _indenter.Indent(blockLines));
278+
declaration = string.Join(Environment.NewLine, Indenter.Indent(blockLines));
274279

275280
return true;
276281
}
277282

278-
public bool TryBuildUDTMemberDeclaration(string udtMemberIdentifier, Declaration prototype, out string declaration)
283+
public bool TryBuildUDTMemberDeclaration(Declaration prototype, string udtMemberIdentifier, out string declaration)
279284
{
280285
declaration = string.Empty;
281286

RubberduckTests/CodeBuilderTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ public void UDT_NullIdentifierInPrototypeList_NoResult()
545545
[Category(nameof(CodeBuilder))]
546546
public void UDT_NullPrototype_NoResult()
547547
{
548-
var result = CreateCodeBuilder().TryBuildUDTMemberDeclaration(_defaultUDTIdentifier, null, out var declaration);
548+
var result = CreateCodeBuilder().TryBuildUDTMemberDeclaration(null, _defaultUDTIdentifier, out var declaration);
549549
Assert.IsFalse(result);
550550
Assert.IsTrue(string.IsNullOrEmpty(declaration));
551551
}
@@ -561,7 +561,7 @@ public void UDT_NullUDTIdentifierBuildUDTMember_NoResult()
561561
var target = state.DeclarationFinder.DeclarationsWithType(DeclarationType.Variable)
562562
.Single(d => d.IdentifierName == "test");
563563

564-
var result = CreateCodeBuilder().TryBuildUDTMemberDeclaration(null, target, out var declaration);
564+
var result = CreateCodeBuilder().TryBuildUDTMemberDeclaration(target, null, out var declaration);
565565

566566
Assert.IsFalse(result);
567567
Assert.IsTrue(string.IsNullOrEmpty(declaration));
@@ -645,7 +645,7 @@ private static string ImprovedArgumentListTest(ModuleBodyElementDeclaration mbed
645645
=> CreateCodeBuilder().ImprovedArgumentList(mbed);
646646

647647
private static string MemberBlockFromPrototypeTest(ModuleBodyElementDeclaration mbed, MemberBlockFromPrototypeTestParams testParams)
648-
=> CreateCodeBuilder().BuildMemberBlockFromPrototype(mbed, testParams.Accessibility, testParams.Content, testParams.NewIdentifier);
648+
=> CreateCodeBuilder().BuildMemberBlockFromPrototype(mbed, testParams.Content, testParams.Accessibility, testParams.NewIdentifier);
649649

650650
private static ICodeBuilder CreateCodeBuilder()
651651
=> new CodeBuilder(new Indenter(null, CreateIndenterSettings));

0 commit comments

Comments
 (0)