Skip to content

Commit d36271f

Browse files
committed
Merge branch 'master' of https://github.com/retailcoder/Rubberduck into UnitTesting
2 parents 716c39c + 109ada8 commit d36271f

24 files changed

+653
-82
lines changed

RetailCoder.VBE/Inspections/CodeInspectionResultBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public CodeInspectionResultBase(string inspection, Instruction instruction, Code
3939
/// <summary>
4040
/// Gets all available "quick fixes" for a code inspection result.
4141
/// </summary>
42-
/// <returns></returns>
42+
/// <returns>Returns a <c>Dictionary&lt;string&gt;, Action&lt;VBE&gt;</c>
43+
/// where the keys are descriptions for each quick fix, and
44+
/// each value is a method returning <c>void</c> and taking a <c>VBE</c> parameter.</returns>
4345
public abstract IDictionary<string, Action<VBE>> GetQuickFixes();
4446

4547
/// <summary>

RetailCoder.VBE/Inspections/ImplicitByRefParameterInspection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using System.Runtime.InteropServices;
4+
using System.Security.Cryptography.X509Certificates;
45
using Rubberduck.VBA.Parser;
56

67
namespace Rubberduck.Inspections
@@ -20,7 +21,8 @@ public ImplicitByRefParameterInspection()
2021
public IEnumerable<CodeInspectionResultBase> GetInspectionResults(SyntaxTreeNode node)
2122
{
2223
var procedures = node.FindAllProcedures().Where(procedure => procedure.Parameters.Any(parameter => !string.IsNullOrEmpty(parameter.Instruction.Value)));
23-
var targets = procedures.Where(procedure => procedure.Parameters.Any(parameter => parameter.IsImplicitByRef));
24+
var targets = procedures.Where(procedure => procedure.Parameters.Any(parameter => parameter.IsImplicitByRef)
25+
&& !procedure.Instruction.Line.IsMultiline);
2426

2527
return targets.SelectMany(procedure => procedure.Parameters.Where(parameter => parameter.IsImplicitByRef)
2628
.Select(parameter => new ImplicitByRefParameterInspectionResult(Name, parameter.Instruction, Severity)));

RetailCoder.VBE/Inspections/ImplicitByRefParameterInspectionResult.cs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Runtime.InteropServices;
45
using Microsoft.Vbe.Interop;
6+
using Rubberduck.Extensions;
57
using Rubberduck.VBA.Parser;
8+
using Rubberduck.VBA.Parser.Grammar;
69

710
namespace Rubberduck.Inspections
811
{
@@ -19,20 +22,50 @@ public override IDictionary<string, Action<VBE>> GetQuickFixes()
1922
return !Handled
2023
? new Dictionary<string, Action<VBE>>
2124
{
22-
{"Pass parameter by reference explicitly.", PassParameterByRef},
23-
{"Pass parameter by value.", PassParameterByVal}
25+
{"Pass parameter by value", PassParameterByVal},
26+
{"Pass parameter by reference explicitly", PassParameterByRef}
2427
}
2528
: new Dictionary<string, Action<VBE>>();
2629
}
2730

2831
private void PassParameterByRef(VBE vbe)
2932
{
30-
throw new NotImplementedException();
33+
if (!Instruction.Line.IsMultiline)
34+
{
35+
var newContent = string.Concat(ReservedKeywords.ByRef, " ", Instruction.Value);
36+
var oldContent = Instruction.Line.Content;
37+
38+
var result = oldContent.Replace(Instruction.Value, newContent);
39+
40+
var module = vbe.FindCodeModules(Instruction.Line.ProjectName, Instruction.Line.ComponentName).First();
41+
module.ReplaceLine(Instruction.Line.StartLineNumber, result);
42+
Handled = true;
43+
}
44+
else
45+
{
46+
// todo: implement for multiline
47+
throw new NotImplementedException("This method is not [yet] implemented for multiline instructions.");
48+
}
3149
}
3250

3351
private void PassParameterByVal(VBE vbe)
3452
{
35-
throw new NotImplementedException();
53+
if (!Instruction.Line.IsMultiline)
54+
{
55+
var newContent = string.Concat(ReservedKeywords.ByVal, " ", Instruction.Value);
56+
var oldContent = Instruction.Line.Content;
57+
58+
var result = oldContent.Replace(Instruction.Value, newContent);
59+
60+
var module = vbe.FindCodeModules(Instruction.Line.ProjectName, Instruction.Line.ComponentName).First();
61+
module.ReplaceLine(Instruction.Line.StartLineNumber, result);
62+
Handled = true;
63+
}
64+
else
65+
{
66+
// todo: implement for multiline
67+
throw new NotImplementedException("This method is not yet implemented for multiline instructions.");
68+
}
3669
}
3770
}
3871
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Runtime.InteropServices;
4+
using Rubberduck.VBA.Parser;
5+
using Rubberduck.VBA.Parser.Grammar;
6+
7+
namespace Rubberduck.Inspections
8+
{
9+
[ComVisible(false)]
10+
public class ImplicitVariantReturnTypeInspection : IInspection
11+
{
12+
public ImplicitVariantReturnTypeInspection()
13+
{
14+
Severity = CodeInspectionSeverity.Suggestion;
15+
}
16+
17+
public string Name { get { return "Function returns an implicit Variant"; } }
18+
public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } }
19+
public CodeInspectionSeverity Severity { get; set; }
20+
21+
public IEnumerable<CodeInspectionResultBase> GetInspectionResults(SyntaxTreeNode node)
22+
{
23+
var procedures = node.FindAllProcedures().Where(procedure => procedure.HasReturnType);
24+
var targets = procedures.Where(procedure => string.IsNullOrEmpty(procedure.SpecifiedReturnType)
25+
&& !procedure.Instruction.Content.EndsWith(string.Concat(" ", ReservedKeywords.As, " ", ReservedKeywords.Variant))
26+
&& !procedure.Instruction.Line.IsMultiline);
27+
28+
return targets.Select(procedure => new ImplicitVariantReturnTypeInspectionResult(Name, procedure.Instruction, Severity));
29+
}
30+
}
31+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Microsoft.Vbe.Interop;
5+
using Rubberduck.Extensions;
6+
using Rubberduck.VBA.Parser;
7+
using Rubberduck.VBA.Parser.Grammar;
8+
9+
namespace Rubberduck.Inspections
10+
{
11+
public class ImplicitVariantReturnTypeInspectionResult : CodeInspectionResultBase
12+
{
13+
public ImplicitVariantReturnTypeInspectionResult(string name, Instruction instruction, CodeInspectionSeverity severity)
14+
: base(name, instruction, severity)
15+
{
16+
}
17+
18+
public override IDictionary<string, Action<VBE>> GetQuickFixes()
19+
{
20+
return !Handled
21+
? new Dictionary<string, Action<VBE>>
22+
{
23+
{"Return explicit Variant", ReturnExplicitVariant}
24+
}
25+
: new Dictionary<string, Action<VBE>>();
26+
}
27+
28+
private void ReturnExplicitVariant(VBE vbe)
29+
{
30+
if (!Instruction.Line.IsMultiline)
31+
{
32+
var newContent = string.Concat(Instruction.Value, " ", ReservedKeywords.As, " ", ReservedKeywords.Variant);
33+
var oldContent = Instruction.Line.Content;
34+
35+
var result = oldContent.Replace(Instruction.Value, newContent);
36+
37+
var module = vbe.FindCodeModules(Instruction.Line.ProjectName, Instruction.Line.ComponentName).First();
38+
module.ReplaceLine(Instruction.Line.StartLineNumber, result);
39+
Handled = true;
40+
}
41+
else
42+
{
43+
// todo: implement for multiline
44+
throw new NotImplementedException("This method is not [yet] implemented for multiline instructions.");
45+
}
46+
}
47+
}
48+
}

RetailCoder.VBE/Inspections/ObsoleteCommentSyntaxInspectionResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public override IDictionary<string, Action<VBE>> GetQuickFixes()
2121
return !Handled
2222
? new Dictionary<string, Action<VBE>>
2323
{
24-
{"Replace Rem reserved keyword with single quote.", ReplaceWithSingleQuote},
25-
{"Remove comment.", RemoveComment}
24+
{"Replace Rem reserved keyword with single quote", ReplaceWithSingleQuote},
25+
{"Remove comment", RemoveComment}
2626
}
2727
: new Dictionary<string, Action<VBE>>();
2828
}

RetailCoder.VBE/Inspections/OptionExplicitInspectionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override IDictionary<string, Action<VBE>> GetQuickFixes()
2121
return !Handled
2222
? new Dictionary<string, Action<VBE>>
2323
{
24-
{"Specify Option Explicit.", SpecifyOptionExplicit}
24+
{"Specify Option Explicit", SpecifyOptionExplicit}
2525
}
2626
: new Dictionary<string, Action<VBE>>();
2727
}

RetailCoder.VBE/Properties/Resources.Designer.cs

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

0 commit comments

Comments
 (0)