Skip to content

Commit 120ad5f

Browse files
committed
Merge with conflicts
2 parents 5c6c020 + 4ee7f82 commit 120ad5f

File tree

10 files changed

+119
-67
lines changed

10 files changed

+119
-67
lines changed

RetailCoder.VBE/Inspections/EncapsulatePublicFieldInspection.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55

66
namespace Rubberduck.Inspections
77
{
8+
using SmartIndenter;
9+
810
public sealed class EncapsulatePublicFieldInspection : InspectionBase
911
{
10-
public EncapsulatePublicFieldInspection(RubberduckParserState state)
12+
private readonly IIndenter _indenter;
13+
14+
public EncapsulatePublicFieldInspection(RubberduckParserState state, IIndenter indenter)
1115
: base(state, CodeInspectionSeverity.Suggestion)
1216
{
17+
_indenter = indenter;
1318
}
1419

1520
public override string Meta { get { return InspectionsUI.EncapsulatePublicFieldInspectionMeta; } }
@@ -21,7 +26,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
2126
var issues = UserDeclarations
2227
.Where(declaration => declaration.DeclarationType == DeclarationType.Variable
2328
&& declaration.Accessibility == Accessibility.Public)
24-
.Select(issue => new EncapsulatePublicFieldInspectionResult(this, issue, State))
29+
.Select(issue => new EncapsulatePublicFieldInspectionResult(this, issue, State, _indenter))
2530
.ToList();
2631

2732
return issues;

RetailCoder.VBE/Inspections/EncapsulatePublicFieldInspectionResult.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99

1010
namespace Rubberduck.Inspections
1111
{
12+
using SmartIndenter;
13+
1214
public class EncapsulatePublicFieldInspectionResult : InspectionResultBase
1315
{
1416
private readonly IEnumerable<CodeInspectionQuickFix> _quickFixes;
1517

16-
public EncapsulatePublicFieldInspectionResult(IInspection inspection, Declaration target, RubberduckParserState state)
18+
public EncapsulatePublicFieldInspectionResult(IInspection inspection, Declaration target, RubberduckParserState state, IIndenter indenter)
1719
: base(inspection, target)
1820
{
1921
_quickFixes = new CodeInspectionQuickFix[]
2022
{
21-
new EncapsulateFieldQuickFix(target.Context, target.QualifiedSelection, target, state),
23+
new EncapsulateFieldQuickFix(target.Context, target.QualifiedSelection, target, state, indenter),
2224
new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName)
2325
};
2426
}
@@ -38,22 +40,24 @@ public class EncapsulateFieldQuickFix : CodeInspectionQuickFix
3840
{
3941
private readonly Declaration _target;
4042
private readonly RubberduckParserState _state;
43+
private readonly IIndenter _indenter;
4144

42-
public EncapsulateFieldQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState state)
45+
public EncapsulateFieldQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState state, IIndenter indenter)
4346
: base(context, selection, string.Format(InspectionsUI.EncapsulatePublicFieldInspectionQuickFix, target.IdentifierName))
4447
{
4548
_target = target;
4649
_state = state;
50+
_indenter = indenter;
4751
}
4852

4953
public override void Fix()
5054
{
5155
var vbe = Selection.QualifiedName.Project.VBE;
5256

53-
using (var view = new EncapsulateFieldDialog())
57+
using (var view = new EncapsulateFieldDialog(_indenter))
5458
{
5559
var factory = new EncapsulateFieldPresenterFactory(vbe, _state, view);
56-
var refactoring = new EncapsulateFieldRefactoring(vbe, factory);
60+
var refactoring = new EncapsulateFieldRefactoring(vbe, _indenter, factory);
5761
refactoring.Refactor(_target);
5862
IsCancelled = view.DialogResult != DialogResult.OK;
5963
}

RetailCoder.VBE/Inspections/ParameterNotUsedInspection.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using Microsoft.Vbe.Interop;
43
using Rubberduck.Common;
54
using Rubberduck.Parsing.Symbols;
65
using Rubberduck.Parsing.VBA;
7-
using Rubberduck.Refactorings.RemoveParameters;
86
using Rubberduck.UI;
9-
using Rubberduck.UI.Refactorings;
107

118
namespace Rubberduck.Inspections
129
{
1310
public sealed class ParameterNotUsedInspection : InspectionBase
1411
{
15-
private readonly VBE _vbe;
1612
private readonly IMessageBox _messageBox;
1713

18-
public ParameterNotUsedInspection(VBE vbe, RubberduckParserState state, IMessageBox messageBox)
14+
public ParameterNotUsedInspection(RubberduckParserState state, IMessageBox messageBox)
1915
: base(state)
2016
{
21-
_vbe = vbe;
2217
_messageBox = messageBox;
2318
}
2419

@@ -41,16 +36,14 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
4136
&& parameter.ParentDeclaration.DeclarationType != DeclarationType.LibraryProcedure);
4237

4338
var unused = parameters.Where(parameter => !parameter.References.Any()).ToList();
44-
var quickFixRefactoring =
45-
new RemoveParametersRefactoring(_vbe, new RemoveParametersPresenterFactory(_vbe, new RemoveParametersDialog(), State, _messageBox));
4639

4740
var issues = from issue in unused.Where(parameter =>
4841
!IsInterfaceMemberParameter(parameter, interfaceMemberScopes)
4942
&& !builtInHandlers.Contains(parameter.ParentDeclaration))
5043
let isInterfaceImplementationMember = IsInterfaceMemberImplementationParameter(issue, interfaceImplementationMemberScopes)
5144
select new ParameterNotUsedInspectionResult(this, issue,
5245
((dynamic) issue.Context).unrestrictedIdentifier(), issue.QualifiedName,
53-
isInterfaceImplementationMember, quickFixRefactoring, State);
46+
isInterfaceImplementationMember, issue.Project.VBE, State, _messageBox);
5447

5548
return issues.ToList();
5649
}

RetailCoder.VBE/Inspections/ParameterNotUsedInspectionResult.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
using Rubberduck.Parsing.VBA;
55
using Rubberduck.Refactorings.RemoveParameters;
66
using Rubberduck.VBEditor;
7+
using Microsoft.Vbe.Interop;
8+
using Rubberduck.UI;
9+
using Rubberduck.UI.Refactorings;
710

811
namespace Rubberduck.Inspections
912
{
@@ -13,12 +16,12 @@ public class ParameterNotUsedInspectionResult : InspectionResultBase
1316

1417
public ParameterNotUsedInspectionResult(IInspection inspection, Declaration target,
1518
ParserRuleContext context, QualifiedMemberName qualifiedName, bool isInterfaceImplementation,
16-
RemoveParametersRefactoring refactoring, RubberduckParserState state)
19+
VBE vbe, RubberduckParserState state, IMessageBox messageBox)
1720
: base(inspection, qualifiedName.QualifiedModuleName, context, target)
1821
{
1922
_quickFixes = isInterfaceImplementation ? new CodeInspectionQuickFix[] {} : new CodeInspectionQuickFix[]
2023
{
21-
new RemoveUnusedParameterQuickFix(Context, QualifiedSelection, refactoring, state),
24+
new RemoveUnusedParameterQuickFix(Context, QualifiedSelection, vbe, state, messageBox),
2225
new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName),
2326
};
2427
}
@@ -33,20 +36,28 @@ public override string Description
3336

3437
public class RemoveUnusedParameterQuickFix : CodeInspectionQuickFix
3538
{
36-
private readonly RemoveParametersRefactoring _quickFixRefactoring;
39+
private readonly VBE _vbe;
3740
private readonly RubberduckParserState _state;
41+
private readonly IMessageBox _messageBox;
3842

3943
public RemoveUnusedParameterQuickFix(ParserRuleContext context, QualifiedSelection selection,
40-
RemoveParametersRefactoring quickFixRefactoring, RubberduckParserState state)
44+
VBE vbe, RubberduckParserState state, IMessageBox messageBox)
4145
: base(context, selection, InspectionsUI.RemoveUnusedParameterQuickFix)
4246
{
43-
_quickFixRefactoring = quickFixRefactoring;
47+
_vbe = vbe;
4448
_state = state;
49+
_messageBox = messageBox;
4550
}
4651

4752
public override void Fix()
4853
{
49-
_quickFixRefactoring.QuickFix(_state, Selection);
54+
using (var dialog = new RemoveParametersDialog())
55+
{
56+
var refactoring = new RemoveParametersRefactoring(_vbe,
57+
new RemoveParametersPresenterFactory(_vbe, dialog, _state, _messageBox));
58+
59+
refactoring.QuickFix(_state, Selection);
60+
}
5061
}
5162
}
5263
}

RetailCoder.VBE/Refactorings/EncapsulateField/EncapsulateFieldRefactoring.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55
using Rubberduck.Parsing.VBA;
66
using Rubberduck.VBEditor;
77
using Rubberduck.VBEditor.Extensions;
8+
using Rubberduck.SmartIndenter;
9+
using Selection = Rubberduck.VBEditor.Selection;
810

911
namespace Rubberduck.Refactorings.EncapsulateField
1012
{
1113
public class EncapsulateFieldRefactoring : IRefactoring
1214
{
1315
private readonly VBE _vbe;
16+
private readonly IIndenter _indenter;
1417
private readonly IRefactoringPresenterFactory<IEncapsulateFieldPresenter> _factory;
1518
private EncapsulateFieldModel _model;
1619

17-
public EncapsulateFieldRefactoring(VBE vbe, IRefactoringPresenterFactory<IEncapsulateFieldPresenter> factory)
20+
public EncapsulateFieldRefactoring(VBE vbe, IIndenter indenter, IRefactoringPresenterFactory<IEncapsulateFieldPresenter> factory)
1821
{
1922
_vbe = vbe;
23+
_indenter = indenter;
2024
_factory = factory;
2125
}
2226

@@ -205,10 +209,13 @@ private string GetPropertyText()
205209
string.Format(" Set {0} = {1}", _model.TargetDeclaration.IdentifierName, _model.ParameterName),
206210
"End Property" + Environment.NewLine);
207211

208-
return string.Join(string.Empty,
212+
var propertyText = string.Join(string.Empty,
209213
getterText,
210214
(_model.ImplementLetSetterType ? letterText : string.Empty),
211215
(_model.ImplementSetSetterType ? setterText : string.Empty)).TrimEnd() + Environment.NewLine;
216+
217+
var propertyTextLines = propertyText.Split(new[] {Environment.NewLine}, StringSplitOptions.None);
218+
return string.Join(Environment.NewLine, _indenter.Indent(propertyTextLines, "test", false));
212219
}
213220
}
214221
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44
using Rubberduck.Parsing.VBA;
55
using Rubberduck.Refactorings.EncapsulateField;
66
using Rubberduck.UI.Refactorings;
7+
using Rubberduck.SmartIndenter;
8+
using Rubberduck.Settings;
79

810
namespace Rubberduck.UI.Command.Refactorings
911
{
10-
using Rubberduck.Settings;
11-
1212
[ComVisible(false)]
1313
public class RefactorEncapsulateFieldCommand : RefactorCommandBase
1414
{
1515
private readonly RubberduckParserState _state;
16+
private readonly Indenter _indenter;
1617

17-
public RefactorEncapsulateFieldCommand(VBE vbe, RubberduckParserState state)
18+
public RefactorEncapsulateFieldCommand(VBE vbe, RubberduckParserState state, Indenter indenter)
1819
: base(vbe)
1920
{
2021
_state = state;
22+
_indenter = indenter;
2123
}
2224

2325
protected override bool CanExecuteImpl(object parameter)
@@ -44,10 +46,10 @@ protected override void ExecuteImpl(object parameter)
4446
return;
4547
}
4648

47-
using (var view = new EncapsulateFieldDialog())
49+
using (var view = new EncapsulateFieldDialog(_indenter))
4850
{
4951
var factory = new EncapsulateFieldPresenterFactory(Vbe, _state, view);
50-
var refactoring = new EncapsulateFieldRefactoring(Vbe, factory);
52+
var refactoring = new EncapsulateFieldRefactoring(Vbe, _indenter, factory);
5153
refactoring.Refactor();
5254
}
5355
}

RetailCoder.VBE/UI/Refactorings/EncapsulateFieldDialog.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
namespace Rubberduck.UI.Refactorings
99
{
10+
using SmartIndenter;
11+
1012
public partial class EncapsulateFieldDialog : Form, IEncapsulateFieldDialog
1113
{
14+
private readonly IIndenter _indenter;
15+
1216
public string NewPropertyName
1317
{
1418
get { return PropertyNameTextBox.Text; }
@@ -75,8 +79,9 @@ public bool MustImplementSetSetterType
7579
}
7680
}
7781

78-
public EncapsulateFieldDialog()
82+
public EncapsulateFieldDialog(IIndenter indenter)
7983
{
84+
_indenter = indenter;
8085
InitializeComponent();
8186
LocalizeDialog();
8287

@@ -151,9 +156,12 @@ private string GetPropertyText()
151156
string.Format(" Set {0} = {1}", TargetDeclaration.IdentifierName, ParameterName),
152157
"End Property");
153158

154-
return getterText +
159+
var propertyText = getterText +
155160
(MustImplementLetSetterType ? letterText : string.Empty) +
156161
(MustImplementSetSetterType ? setterText : string.Empty);
162+
163+
var propertyTextLines = propertyText.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
164+
return string.Join(Environment.NewLine, _indenter.Indent(propertyTextLines, "test", false));
157165
}
158166

159167
private void ValidatePropertyName()

RubberduckTests/Inspections/EncapsulatePublicFieldInspectionTests.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
using Microsoft.VisualStudio.TestTools.UnitTesting;
55
using Moq;
66
using Rubberduck.Inspections;
7-
using Rubberduck.Inspections.Rubberduck.Inspections;
87
using Rubberduck.Parsing;
98
using Rubberduck.Parsing.VBA;
10-
using Rubberduck.Settings;
119
using Rubberduck.VBEditor.Extensions;
1210
using Rubberduck.VBEditor.VBEHost;
1311
using RubberduckTests.Mocks;
@@ -35,7 +33,7 @@ public void PublicField_ReturnsResult()
3533
parser.Parse(new CancellationTokenSource());
3634
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
3735

38-
var inspection = new EncapsulatePublicFieldInspection(parser.State);
36+
var inspection = new EncapsulatePublicFieldInspection(parser.State, null);
3937
var inspectionResults = inspection.GetInspectionResults();
4038

4139
Assert.AreEqual(1, inspectionResults.Count());
@@ -61,7 +59,7 @@ public void MultiplePublicFields_ReturnMultipleResult()
6159
parser.Parse(new CancellationTokenSource());
6260
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
6361

64-
var inspection = new EncapsulatePublicFieldInspection(parser.State);
62+
var inspection = new EncapsulatePublicFieldInspection(parser.State, null);
6563
var inspectionResults = inspection.GetInspectionResults();
6664

6765
Assert.AreEqual(3, inspectionResults.Count());
@@ -85,7 +83,7 @@ public void PrivateField_DoesNotReturnResult()
8583
parser.Parse(new CancellationTokenSource());
8684
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
8785

88-
var inspection = new EncapsulatePublicFieldInspection(parser.State);
86+
var inspection = new EncapsulatePublicFieldInspection(parser.State, null);
8987
var inspectionResults = inspection.GetInspectionResults();
9088

9189
Assert.AreEqual(0, inspectionResults.Count());
@@ -110,7 +108,7 @@ public void PublicNonField_DoesNotReturnResult()
110108
parser.Parse(new CancellationTokenSource());
111109
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
112110

113-
var inspection = new EncapsulatePublicFieldInspection(parser.State);
111+
var inspection = new EncapsulatePublicFieldInspection(parser.State, null);
114112
var inspectionResults = inspection.GetInspectionResults();
115113

116114
Assert.AreEqual(0, inspectionResults.Count());
@@ -135,7 +133,7 @@ public void PublicField_Ignored_DoesNotReturnResult()
135133
parser.Parse(new CancellationTokenSource());
136134
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
137135

138-
var inspection = new EncapsulatePublicFieldInspection(parser.State);
136+
var inspection = new EncapsulatePublicFieldInspection(parser.State, null);
139137
var inspectionResults = inspection.GetInspectionResults();
140138

141139
Assert.IsFalse(inspectionResults.Any());
@@ -165,7 +163,7 @@ public void EncapsulatePublicField_IgnoreQuickFixWorks()
165163
parser.Parse(new CancellationTokenSource());
166164
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
167165

168-
var inspection = new EncapsulatePublicFieldInspection(parser.State);
166+
var inspection = new EncapsulatePublicFieldInspection(parser.State, null);
169167
var inspectionResults = inspection.GetInspectionResults();
170168

171169
inspectionResults.First().QuickFixes.Single(s => s is IgnoreOnceQuickFix).Fix();
@@ -177,7 +175,7 @@ public void EncapsulatePublicField_IgnoreQuickFixWorks()
177175
[TestCategory("Inspections")]
178176
public void InspectionType()
179177
{
180-
var inspection = new EncapsulatePublicFieldInspection(null);
178+
var inspection = new EncapsulatePublicFieldInspection(null, null);
181179
Assert.AreEqual(CodeInspectionType.MaintainabilityAndReadabilityIssues, inspection.InspectionType);
182180
}
183181

@@ -186,7 +184,7 @@ public void InspectionType()
186184
public void InspectionName()
187185
{
188186
const string inspectionName = "EncapsulatePublicFieldInspection";
189-
var inspection = new EncapsulatePublicFieldInspection(null);
187+
var inspection = new EncapsulatePublicFieldInspection(null, null);
190188

191189
Assert.AreEqual(inspectionName, inspection.Name);
192190
}

0 commit comments

Comments
 (0)