Skip to content

Commit cb63f09

Browse files
committed
Merge branch 'GrammarIsFun' of https://github.com/retailcoder/Rubberduck
2 parents a7788c7 + a8d6337 commit cb63f09

31 files changed

+101
-181
lines changed

RetailCoder.VBE/Inspections/AssignedByValParameterInspectionResult.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using Antlr4.Runtime;
4-
using Microsoft.Vbe.Interop;
54
using Rubberduck.Parsing.Grammar;
65
using Rubberduck.VBEditor;
76

@@ -15,16 +14,17 @@ public AssignedByValParameterInspectionResult(string inspection, CodeInspectionS
1514
{
1615
}
1716

18-
public override IDictionary<string, Action<VBE>> GetQuickFixes()
17+
public override IDictionary<string, Action> GetQuickFixes()
1918
{
20-
return new Dictionary<string, Action<VBE>>
19+
return new Dictionary<string, Action>
2120
{
2221
{"Pass parameter by reference", PassParameterByReference}
2322
//,{"Introduce local variable", IntroduceLocalVariable}
2423
};
2524
}
2625

27-
private void PassParameterByReference(VBE vbe)
26+
//note: vbe parameter is not used
27+
private void PassParameterByReference()
2828
{
2929
var parameter = Context.GetText();
3030
var newContent = string.Concat(Tokens.ByRef, " ", parameter.Replace(Tokens.ByVal, string.Empty).Trim());
@@ -36,10 +36,5 @@ private void PassParameterByReference(VBE vbe)
3636
var result = lines.Replace(parameter, newContent);
3737
module.ReplaceLine(selection.StartLine, result);
3838
}
39-
40-
private void IntroduceLocalVariable(VBE vbe)
41-
{
42-
var parameter = Context.GetText().Replace(Tokens.ByVal, string.Empty).Trim();
43-
}
4439
}
4540
}

RetailCoder.VBE/Inspections/CodeInspectionResultBase.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using Antlr4.Runtime;
54
using Microsoft.Vbe.Interop;
65
using Rubberduck.Parsing;
@@ -24,7 +23,9 @@ protected CodeInspectionResultBase(string inspection, CodeInspectionSeverity typ
2423
protected CodeInspectionResultBase(string inspection, CodeInspectionSeverity type, QualifiedModuleName qualifiedName, ParserRuleContext context, CommentNode comment = null)
2524
{
2625
if (context == null && comment == null)
26+
{
2727
throw new ArgumentNullException("[context] and [comment] cannot both be null.");
28+
}
2829

2930
_name = inspection;
3031
_type = type;
@@ -72,22 +73,7 @@ public virtual QualifiedSelection QualifiedSelection
7273
/// </summary>
7374
/// <returns>Returns a <c>Dictionary&lt;string&gt;, Action&lt;VBE&gt;</c>
7475
/// where the keys are descriptions for each quick fix, and
75-
/// each value is a method returning <c>void</c> and taking a <c>VBE</c> parameter.</returns>
76-
public abstract IDictionary<string, Action<VBE>> GetQuickFixes();
77-
78-
public VBComponent FindComponent(VBE vbe)
79-
{
80-
var vbProject = vbe.VBProjects.Cast<VBProject>()
81-
.SingleOrDefault(project => project.Protection != vbext_ProjectProtection.vbext_pp_locked
82-
&& project.Equals(QualifiedName.Project));
83-
84-
if (vbProject == null)
85-
{
86-
return null;
87-
}
88-
89-
return vbProject.VBComponents.Cast<VBComponent>()
90-
.SingleOrDefault(component => component.Equals(QualifiedName.Component));
91-
}
76+
/// each value is a parameterless method returning <c>void</c>.</returns>
77+
public abstract IDictionary<string, Action> GetQuickFixes();
9278
}
9379
}

RetailCoder.VBE/Inspections/ICodeInspectionResult.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
using System.Collections.Generic;
33
using Antlr4.Runtime;
44
using Microsoft.Vbe.Interop;
5-
using Rubberduck.Parsing.Nodes;
65
using Rubberduck.VBEditor;
76

87
namespace Rubberduck.Inspections
98
{
109
public interface ICodeInspectionResult
1110
{
12-
CommentNode Comment { get; }
11+
IDictionary<string, Action> GetQuickFixes();
1312
ParserRuleContext Context { get; }
14-
VBComponent FindComponent(VBE vbe);
15-
IDictionary<string, Action<VBE>> GetQuickFixes();
1613
string Name { get; }
1714
QualifiedSelection QualifiedSelection { get; }
1815
CodeInspectionSeverity Severity { get; }

RetailCoder.VBE/Inspections/IInspection.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,6 @@
33

44
namespace Rubberduck.Inspections
55
{
6-
/// <summary>
7-
/// An interface that abstracts the data structure for a code inspection
8-
/// </summary>
9-
public interface IInspectionModel
10-
{
11-
/// <summary>
12-
/// Gets a short description for the code inspection.
13-
/// </summary>
14-
string Name { get; }
15-
16-
/// <summary>
17-
/// Gets a value indicating the type of the code inspection.
18-
/// </summary>
19-
CodeInspectionType InspectionType { get; }
20-
21-
/// <summary>
22-
/// Gets a value indicating the severity level of the code inspection.
23-
/// </summary>
24-
CodeInspectionSeverity Severity { get; set; }
25-
}
26-
276
/// <summary>
287
/// An interface that abstracts a runnable code inspection.
298
/// </summary>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Rubberduck.Inspections
2+
{
3+
/// <summary>
4+
/// An interface that abstracts the data structure for a code inspection
5+
/// </summary>
6+
public interface IInspectionModel
7+
{
8+
/// <summary>
9+
/// Gets a short description for the code inspection.
10+
/// </summary>
11+
string Name { get; }
12+
13+
/// <summary>
14+
/// Gets a value indicating the type of the code inspection.
15+
/// </summary>
16+
CodeInspectionType InspectionType { get; }
17+
18+
/// <summary>
19+
/// Gets a value indicating the severity level of the code inspection.
20+
/// </summary>
21+
CodeInspectionSeverity Severity { get; set; }
22+
}
23+
}

RetailCoder.VBE/Inspections/IdentifierNotAssignedInspectionResult.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ public IdentifierNotAssignedInspectionResult(string inspection, CodeInspectionSe
1414
{
1515
}
1616

17-
public override IDictionary<string, Action<VBE>> GetQuickFixes()
17+
public override IDictionary<string, Action> GetQuickFixes()
1818
{
1919
return
20-
new Dictionary<string, Action<VBE>>
20+
new Dictionary<string, Action>
2121
{
2222
{"Remove unassigned variable", RemoveUnusedDeclaration}
2323
};
2424
}
2525

26-
protected override void RemoveUnusedDeclaration(VBE vbe)
26+
protected override void RemoveUnusedDeclaration()
2727
{
2828
var module = QualifiedName.Component.CodeModule;
2929
var selection = QualifiedSelection.Selection;

RetailCoder.VBE/Inspections/IdentifierNotUsedInspectionResult.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ public IdentifierNotUsedInspectionResult(string inspection, CodeInspectionSeveri
1414
{
1515
}
1616

17-
public override IDictionary<string, Action<VBE>> GetQuickFixes()
17+
public override IDictionary<string, Action> GetQuickFixes()
1818
{
1919
return
20-
new Dictionary<string, Action<VBE>>
20+
new Dictionary<string, Action>
2121
{
2222
{"Remove unused declaration", RemoveUnusedDeclaration}
2323
};
2424
}
2525

26-
protected virtual void RemoveUnusedDeclaration(VBE vbe)
26+
protected virtual void RemoveUnusedDeclaration()
2727
{
2828
var module = QualifiedName.Component.CodeModule;
2929
var selection = QualifiedSelection.Selection;

RetailCoder.VBE/Inspections/ImplicitByRefParameterInspectionResult.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,35 @@ public ImplicitByRefParameterInspectionResult(string inspection, CodeInspectionS
1515

1616
private new VBAParser.ArgContext Context { get { return base.Context as VBAParser.ArgContext; } }
1717

18-
public override IDictionary<string, Action<VBE>> GetQuickFixes()
18+
public override IDictionary<string, Action> GetQuickFixes()
1919
{
2020
if ((Context.LPAREN() != null && Context.RPAREN() != null) || Context.PARAMARRAY() != null)
2121
{
2222
// array parameters & paramarrays must be passed by reference
23-
return new Dictionary<string, Action<VBE>>
23+
return new Dictionary<string, Action>
2424
{
2525
{"Pass parameter by reference explicitly", PassParameterByRef}
2626
};
2727
}
2828

29-
return new Dictionary<string, Action<VBE>>
29+
return new Dictionary<string, Action>
3030
{
3131
{"Pass parameter by reference explicitly", PassParameterByRef},
3232
{"Pass parameter by value", PassParameterByVal}
3333
};
3434
}
3535

36-
private void PassParameterByRef(VBE vbe)
36+
private void PassParameterByRef()
3737
{
38-
ChangeParameterPassing(vbe, Tokens.ByRef);
38+
ChangeParameterPassing(Tokens.ByRef);
3939
}
4040

41-
private void PassParameterByVal(VBE vbe)
41+
private void PassParameterByVal()
4242
{
43-
ChangeParameterPassing(vbe, Tokens.ByVal);
43+
ChangeParameterPassing(Tokens.ByVal);
4444
}
4545

46-
private void ChangeParameterPassing(VBE vbe, string newValue)
46+
private void ChangeParameterPassing(string newValue)
4747
{
4848
var parameter = Context.GetText();
4949
var newContent = string.Concat(newValue, " ", parameter);

RetailCoder.VBE/Inspections/ImplicitPublicMemberInspectionResult.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ public ImplicitPublicMemberInspectionResult(string inspection, CodeInspectionSev
1414
{
1515
}
1616

17-
public override IDictionary<string, Action<VBE>> GetQuickFixes()
17+
public override IDictionary<string, Action> GetQuickFixes()
1818
{
19-
return new Dictionary<string, Action<VBE>>
19+
return new Dictionary<string, Action>
2020
{
2121
{ "Specify Public access modifier explicitly", SpecifyPublicModifier}
2222
};
2323
}
2424

25-
private void SpecifyPublicModifier(VBE vbe)
25+
private void SpecifyPublicModifier()
2626
{
2727
var oldContent = Context.GetText();
2828
var newContent = Tokens.Public + ' ' + oldContent;

RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspectionResult.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ public ImplicitVariantReturnTypeInspectionResult(string name, CodeInspectionSeve
1717
{
1818
}
1919

20-
public override IDictionary<string, Action<VBE>> GetQuickFixes()
20+
public override IDictionary<string, Action> GetQuickFixes()
2121
{
2222
return
23-
new Dictionary<string, Action<VBE>>
23+
new Dictionary<string, Action>
2424
{
2525
{"Return explicit Variant", ReturnExplicitVariant}
2626
};
2727
}
2828

29-
private void ReturnExplicitVariant(VBE vbe)
29+
private void ReturnExplicitVariant()
3030
{
3131
// note: turns a multiline signature into a one-liner signature.
3232
// bug: removes all comments.

0 commit comments

Comments
 (0)