Skip to content

Commit 20052b9

Browse files
authored
Merge pull request #2127 from rubberduck-vba/next
Release 2.0.7
2 parents 1d60053 + f2d2d67 commit 20052b9

File tree

147 files changed

+3755
-1540
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+3755
-1540
lines changed

Installer Build Script.iss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ OutputDir={#OutputDirectory}
2727
OutputBaseFilename=Rubberduck.Setup.{#AppVersion}
2828
Compression=lzma
2929
SolidCompression=yes
30+
SignTool=RubberduckSignTool /d $qRubberduck Installer$q $f
3031

3132
ArchitecturesAllowed=x86 x64
3233
ArchitecturesInstallIn64BitMode=x64

RetailCoder.VBE/API/ParserState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public void Initialize(VBE vbe)
6363
throw new InvalidOperationException("ParserState is already initialized.");
6464
}
6565

66-
_state = new RubberduckParserState(vbe, new Sinks(vbe));
66+
_state = new RubberduckParserState(new Sinks(vbe));
6767
_state.StateChanged += _state_StateChanged;
6868

6969
Func<IVBAPreprocessor> preprocessorFactory = () => new VBAPreprocessor(double.Parse(vbe.Version, CultureInfo.InvariantCulture));
7070
_attributeParser = new AttributeParser(new ModuleExporter(), preprocessorFactory);
71-
_parser = new RubberduckParser(_state, _attributeParser, preprocessorFactory,
71+
_parser = new RubberduckParser(vbe, _state, _attributeParser, preprocessorFactory,
7272
new List<ICustomDeclarationLoader> { new DebugDeclarations(_state), new FormEventDeclarations(_state), new AliasDeclarations(_state) });
7373
}
7474

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/IParseTreeInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public ParseTreeResults()
2525
public IEnumerable<QualifiedContext> ObsoleteLetContexts;
2626
public IEnumerable<QualifiedContext> ArgListsWithOneByRefParam;
2727
public IEnumerable<QualifiedContext> EmptyStringLiterals;
28-
public IEnumerable<QualifiedContext<VBAParser.AnnotationContext>> MalformedAnnotations;
28+
public IEnumerable<QualifiedContext> MalformedAnnotations;
2929
}
3030
}

RetailCoder.VBE/Inspections/InspectionsUI.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/Inspections/InspectionsUI.de.resx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@
304304
<value>Variable wird genutzt ohne das ihr ein Wert zugewiesen wurde.</value>
305305
</data>
306306
<data name="UntypedFunctionUsageInspectionMeta" xml:space="preserve">
307-
<value>Eine gibt eine Funktion, die einen String Äquivalnet zurückgibt. Diese sollte bevorzugt genutzt werden, um implitizite Typumwandlungen zu vermeiden.</value>
307+
<value>Eine gibt eine Funktion, die einen String Äquivalent zurückgibt. Diese sollte bevorzugt genutzt werden, um implitizite Typumwandlungen zu vermeiden.
308+
Falls der Parameter 'null' sein kann, bitte dieses Auftreten ignorieren. 'null' an die Funktion zu übergeben, die einen String erwartet würde zu einem "Type Mismatch"-Laufzeitfehler führen.</value>
308309
</data>
309310
<data name="UntypedFunctionUsageInspectionName" xml:space="preserve">
310311
<value>Nutzung einer Funktion, die einen 'String Variant' zurückgibt.</value>
@@ -554,4 +555,13 @@
554555
<data name="MultipleDeclarationsInspectionResultFormat" xml:space="preserve">
555556
<value>Instruktion enthält Mehrfachdeklaration</value>
556557
</data>
558+
<data name="MalformedAnnotationInspectionName">
559+
<value>Unlesbare Annotation</value>
560+
</data>
561+
<data name="MalformedAnnotationInspectionResultFormat">
562+
<value>Annotation '{0}' ist nicht lesbar</value>
563+
</data>
564+
<data name="MalformedAnnotationInspectionMeta">
565+
<value>Eine Annotation in einem Kommentar konnte nicht gelesen werden.</value>
566+
</data>
557567
</root>

RetailCoder.VBE/Inspections/InspectionsUI.resx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@
304304
<value>Variable is used but not assigned</value>
305305
</data>
306306
<data name="UntypedFunctionUsageInspectionMeta" xml:space="preserve">
307-
<value>A string-returning equivalent function exists and should preferably be used to avoid implicit type conversions.</value>
307+
<value>A string-returning equivalent function exists and should preferably be used to avoid implicit type conversions.
308+
If the parameter can be null, ignore this inspection result; passing a null value to a function expecting a string would raise a type mismatch runtime error.</value>
308309
</data>
309310
<data name="UntypedFunctionUsageInspectionName" xml:space="preserve">
310311
<value>Use of variant-returning string function</value>
@@ -564,4 +565,4 @@
564565
<data name="MalformedAnnotationInspectionResultFormat" xml:space="preserve">
565566
<value>Malformed '{0}' annotation.</value>
566567
</data>
567-
</root>
568+
</root>

RetailCoder.VBE/Inspections/Inspector.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public Inspector(IGeneralConfigService configService, IEnumerable<IInspection> i
2525
_inspections = inspections;
2626

2727
_configService = configService;
28-
configService.SettingsChanged += ConfigServiceLanguageChanged;
28+
configService.SettingsChanged += ConfigServiceSettingsChanged;
2929
}
3030

31-
private void ConfigServiceLanguageChanged(object sender, EventArgs e)
31+
private void ConfigServiceSettingsChanged(object sender, EventArgs e)
3232
{
3333
UpdateInspectionSeverity();
3434
}
@@ -125,7 +125,7 @@ public void Dispose()
125125
{
126126
if (_configService != null)
127127
{
128-
_configService.SettingsChanged -= ConfigServiceLanguageChanged;
128+
_configService.SettingsChanged -= ConfigServiceSettingsChanged;
129129
}
130130
}
131131
}

RetailCoder.VBE/Inspections/MalformedAnnotationInspection.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
2727

2828
var results = new List<MalformedAnnotationInspectionResult>();
2929

30-
foreach (var context in ParseTreeResults.MalformedAnnotations)
30+
foreach (var result in ParseTreeResults.MalformedAnnotations)
3131
{
32-
if (context.Context.annotationName().GetText() == AnnotationType.Ignore.ToString() ||
33-
context.Context.annotationName().GetText() == AnnotationType.Folder.ToString())
32+
var context = (VBAParser.AnnotationContext)result.Context;
33+
34+
if (context.annotationName().GetText() == AnnotationType.Ignore.ToString() ||
35+
context.annotationName().GetText() == AnnotationType.Folder.ToString())
3436
{
35-
if (context.Context.annotationArgList() == null)
37+
if (context.annotationArgList() == null)
3638
{
3739
results.Add(new MalformedAnnotationInspectionResult(this,
38-
new QualifiedContext<VBAParser.AnnotationContext>(context.ModuleName,
39-
context.Context)));
40+
new QualifiedContext<VBAParser.AnnotationContext>(result.ModuleName,
41+
context)));
4042
}
4143
}
4244
}

RetailCoder.VBE/Inspections/ObsoleteCommentSyntaxInspectionResult.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public override void Fix()
4848
return;
4949
}
5050

51-
var content = module.get_Lines(Selection.Selection.StartLine, Selection.Selection.LineCount);
51+
var content = module.Lines[Selection.Selection.StartLine, Selection.Selection.LineCount];
5252

5353
int markerPosition;
5454
if (!content.HasComment(out markerPosition))
@@ -59,7 +59,7 @@ public override void Fix()
5959
var code = string.Empty;
6060
if (markerPosition > 0)
6161
{
62-
code = content.Substring(0, markerPosition - 1);
62+
code = content.Substring(0, markerPosition).TrimEnd();
6363
}
6464

6565
if (_comment.QualifiedSelection.Selection.LineCount > 1)
@@ -89,7 +89,7 @@ public override void Fix()
8989
return;
9090
}
9191

92-
var content = module.get_Lines(Selection.Selection.StartLine, Selection.Selection.LineCount);
92+
var content = module.Lines[Selection.Selection.StartLine, Selection.Selection.LineCount];
9393

9494
int markerPosition;
9595
if (!content.HasComment(out markerPosition))
@@ -100,7 +100,7 @@ public override void Fix()
100100
var code = string.Empty;
101101
if (markerPosition > 0)
102102
{
103-
code = content.Substring(0, markerPosition - 1);
103+
code = content.Substring(0, markerPosition);
104104
}
105105

106106
var newContent = code + Tokens.CommentMarker + " " + _comment.CommentText;

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/Inspections/UseMeaningfulNameInspection.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using Rubberduck.Parsing.Symbols;
56
using Rubberduck.Parsing.VBA;
7+
using Rubberduck.Settings;
8+
using Rubberduck.SettingsProvider;
69
using Rubberduck.UI;
710

811
namespace Rubberduck.Inspections
912
{
1013
public sealed class UseMeaningfulNameInspection : InspectionBase
1114
{
1215
private readonly IMessageBox _messageBox;
16+
private readonly IPersistanceService<CodeInspectionSettings> _settings;
1317

14-
public UseMeaningfulNameInspection(IMessageBox messageBox, RubberduckParserState state)
18+
public UseMeaningfulNameInspection(IMessageBox messageBox, RubberduckParserState state, IPersistanceService<CodeInspectionSettings> settings)
1519
: base(state, CodeInspectionSeverity.Suggestion)
1620
{
1721
_messageBox = messageBox;
22+
_settings = settings;
1823
}
1924

2025
public override string Description { get { return InspectionsUI.UseMeaningfulNameInspectionName; } }
2126
public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } }
2227

2328
public override IEnumerable<InspectionResultBase> GetInspectionResults()
2429
{
30+
var whitelistedNames = new List<string>();
31+
32+
try
33+
{
34+
whitelistedNames = _settings.Load(new CodeInspectionSettings()).WhitelistedIdentifiers.Select(s => s.Identifier).ToList();
35+
}
36+
catch (IOException) { }
37+
2538
var issues = UserDeclarations
26-
.Where(declaration => declaration.DeclarationType != DeclarationType.ModuleOption &&
39+
.Where(declaration => declaration.DeclarationType != DeclarationType.ModuleOption &&
40+
!whitelistedNames.Contains(declaration.IdentifierName) &&
2741
(declaration.IdentifierName.Length < 3 ||
2842
char.IsDigit(declaration.IdentifierName.Last()) ||
2943
!declaration.IdentifierName.Any(c =>

RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspectionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public override void Fix()
6666
return;
6767
}
6868

69-
var fixedCodeLine = codeLine.Replace(originalInstruction, fix);
69+
var fixedCodeLine = codeLine.Remove(Context.Start.Column, originalInstruction.Length).Insert(Context.Start.Column, fix);
7070
codeModule.ReplaceLine(Selection.Selection.StartLine, fixedCodeLine);
7171
}
7272

0 commit comments

Comments
 (0)