Skip to content

Commit afe99ed

Browse files
committed
Merge pull request #20 from retailcoder/CodeExplorer
merge changes from Codeexplorer branch
2 parents e07acae + dadb2e4 commit afe99ed

File tree

93 files changed

+1408
-2558
lines changed

Some content is hidden

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

93 files changed

+1408
-2558
lines changed

RetailCoder.VBE/App.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private async void hooks_MessageReceived(object sender, HookEventArgs e)
9292
}
9393

9494
var component = _vbe.ActiveCodePane.CodeModule.Parent;
95-
_parser.ParseComponentAsync(component);
95+
_parser.ParseComponent(component);
9696

9797
AwaitNextKey();
9898
return;

RetailCoder.VBE/Inspections/AssignedByValParameterInspection.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using Rubberduck.Parsing;
43
using Rubberduck.Parsing.Grammar;
54
using Rubberduck.Parsing.Symbols;
65
using Rubberduck.Parsing.VBA;
76
using Rubberduck.UI;
87

98
namespace Rubberduck.Inspections
109
{
11-
public class AssignedByValParameterInspection : IInspection
10+
public sealed class AssignedByValParameterInspection : InspectionBase
1211
{
13-
public AssignedByValParameterInspection()
12+
public AssignedByValParameterInspection(RubberduckParserState state)
13+
: base(state)
1414
{
1515
Severity = CodeInspectionSeverity.Warning;
1616
}
1717

18-
public string Name { get { return "AssignedByValParameterInspection"; } }
19-
public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } }
20-
public string Description { get { return RubberduckUI.ByValParameterIsAssigned_; } }
21-
public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } }
22-
public CodeInspectionSeverity Severity { get; set; }
18+
public override string Description { get { return InspectionsUI.AssignedByValParameterInspectionName; } }
19+
public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } }
2320

24-
private string AnnotationName { get { return Name.Replace("Inspection", string.Empty); } }
25-
26-
public IEnumerable<CodeInspectionResultBase> GetInspectionResults(RubberduckParserState state)
21+
public override IEnumerable<CodeInspectionResultBase> GetInspectionResults()
2722
{
28-
var name = AnnotationName;
29-
var assignedByValParameters =
30-
state.AllUserDeclarations.Where(declaration => !declaration.IsInspectionDisabled(name)
31-
&& declaration.DeclarationType == DeclarationType.Parameter
23+
var assignedByValParameters = UserDeclarations.Where(declaration =>
24+
declaration.DeclarationType == DeclarationType.Parameter
3225
&& ((VBAParser.ArgContext)declaration.Context).BYVAL() != null
3326
&& declaration.References.Any(reference => reference.IsAssignment));
3427

RetailCoder.VBE/Inspections/CodeInspectionResultBase.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using Antlr4.Runtime;
45
using Rubberduck.Parsing;
@@ -82,6 +83,11 @@ public QualifiedSelection QualifiedSelection
8283

8384
public virtual CodeInspectionQuickFix DefaultQuickFix { get { return QuickFixes.FirstOrDefault(); } }
8485

86+
public int CompareTo(ICodeInspectionResult other)
87+
{
88+
return Inspection.CompareTo(other.Inspection);
89+
}
90+
8591
public override string ToString()
8692
{
8793
var module = QualifiedSelection.QualifiedName;
@@ -93,5 +99,22 @@ public override string ToString()
9399
module.ComponentName,
94100
QualifiedSelection.Selection.StartLine);
95101
}
102+
103+
public int CompareTo(object obj)
104+
{
105+
return CompareTo(obj as ICodeInspectionResult);
106+
}
107+
108+
public string ToCsvString()
109+
{
110+
var module = QualifiedSelection.QualifiedName;
111+
return string.Format(
112+
"{0}, {1}, {2}, {3}, {4}",
113+
Inspection.Severity,
114+
Name,
115+
module.ProjectName,
116+
module.ComponentName,
117+
QualifiedSelection.Selection.StartLine);
118+
}
96119
}
97120
}

RetailCoder.VBE/Inspections/ConstantNotUsedInspection.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@
66

77
namespace Rubberduck.Inspections
88
{
9-
public class ConstantNotUsedInspection : IInspection
9+
public sealed class ConstantNotUsedInspection : InspectionBase
1010
{
11-
public ConstantNotUsedInspection()
11+
public ConstantNotUsedInspection(RubberduckParserState state)
12+
: base(state)
1213
{
1314
Severity = CodeInspectionSeverity.Warning;
1415
}
1516

16-
public string Name { get { return "ConstantNotUsedInspection"; } }
17-
public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } }
18-
public string Description { get { return RubberduckUI.ConstantNotUsed_; } }
19-
public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } }
20-
public CodeInspectionSeverity Severity { get; set; }
17+
public override string Description { get { return RubberduckUI.ConstantNotUsed_; } }
18+
public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } }
2119

22-
public IEnumerable<CodeInspectionResultBase> GetInspectionResults(RubberduckParserState state)
20+
public override IEnumerable<CodeInspectionResultBase> GetInspectionResults()
2321
{
24-
var results = state.AllUserDeclarations.Where(declaration =>
22+
var results = UserDeclarations.Where(declaration =>
2523
declaration.DeclarationType == DeclarationType.Constant && !declaration.References.Any());
2624

2725
return results.Select(issue =>

RetailCoder.VBE/Inspections/DefaultProjectNameInspection.cs

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

88
namespace Rubberduck.Inspections
99
{
10-
public class DefaultProjectNameInspection : IInspection
10+
public sealed class DefaultProjectNameInspection : InspectionBase
1111
{
1212
private readonly ICodePaneWrapperFactory _wrapperFactory;
1313

14-
public DefaultProjectNameInspection()
14+
public DefaultProjectNameInspection(RubberduckParserState state)
15+
: base(state)
1516
{
1617
_wrapperFactory = new CodePaneWrapperFactory();
1718
Severity = CodeInspectionSeverity.Suggestion;
1819
}
1920

20-
public string Name { get { return "DefaultProjectNameInspection"; } }
21-
public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } }
22-
public string Description { get { return RubberduckUI.GenericProjectName_; } }
23-
public CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } }
24-
public CodeInspectionSeverity Severity { get; set; }
21+
public override string Description { get { return RubberduckUI.GenericProjectName_; } }
22+
public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } }
2523

26-
public IEnumerable<CodeInspectionResultBase> GetInspectionResults(RubberduckParserState state)
24+
public override IEnumerable<CodeInspectionResultBase> GetInspectionResults()
2725
{
28-
var issues = state.AllUserDeclarations
26+
var issues = UserDeclarations
2927
.Where(declaration => declaration.DeclarationType == DeclarationType.Project
3028
&& declaration.IdentifierName.StartsWith("VBAProject"))
31-
.Select(issue => new DefaultProjectNameInspectionResult(this, issue, state, _wrapperFactory))
29+
.Select(issue => new DefaultProjectNameInspectionResult(this, issue, State, _wrapperFactory))
3230
.ToList();
3331

3432
return issues;

RetailCoder.VBE/Inspections/DefaultProjectNameInspectionResult.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ public DefaultProjectNameInspectionResult(IInspection inspection, Declaration ta
3232
public class RenameProjectQuickFix : CodeInspectionQuickFix
3333
{
3434
private readonly Declaration _target;
35-
private readonly RubberduckParserState _parseResult;
35+
private readonly RubberduckParserState _state;
3636
private readonly ICodePaneWrapperFactory _wrapperFactory;
3737

38-
public RenameProjectQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState parseResult, ICodePaneWrapperFactory wrapperFactory)
38+
public RenameProjectQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState state, ICodePaneWrapperFactory wrapperFactory)
3939
: base(context, selection, string.Format(RubberduckUI.Rename_DeclarationType, RubberduckUI.ResourceManager.GetString("DeclarationType_" + DeclarationType.Project, RubberduckUI.Culture)))
4040
{
4141
_target = target;
42-
_parseResult = parseResult;
42+
_state = state;
4343
_wrapperFactory = wrapperFactory;
4444
}
4545

@@ -49,8 +49,8 @@ public override void Fix()
4949

5050
using (var view = new RenameDialog())
5151
{
52-
var factory = new RenamePresenterFactory(vbe, view, _parseResult, new MessageBox(), _wrapperFactory);
53-
var refactoring = new RenameRefactoring(factory, new ActiveCodePaneEditor(vbe, _wrapperFactory), new MessageBox());
52+
var factory = new RenamePresenterFactory(vbe, view, _state, new MessageBox(), _wrapperFactory);
53+
var refactoring = new RenameRefactoring(factory, new ActiveCodePaneEditor(vbe, _wrapperFactory), new MessageBox(), _state);
5454
refactoring.Refactor(_target);
5555
}
5656
}

RetailCoder.VBE/Inspections/EmptyStringLiteralInspection.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,21 @@
66

77
namespace Rubberduck.Inspections
88
{
9-
public class EmptyStringLiteralInspection : IInspection
9+
public sealed class EmptyStringLiteralInspection : InspectionBase
1010
{
11-
public EmptyStringLiteralInspection()
11+
public EmptyStringLiteralInspection(RubberduckParserState state)
12+
: base(state)
1213
{
1314
Severity = CodeInspectionSeverity.Warning;
1415
}
1516

16-
public string Name { get { return "EmptyStringLiteralInspection"; } }
17-
public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } }
18-
public string Description { get { return InspectionsUI.EmptyStringLiteralInspection; } }
19-
public CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } }
20-
public CodeInspectionSeverity Severity { get; set; }
17+
public override string Description { get { return InspectionsUI.EmptyStringLiteralInspection; } }
18+
public override CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } }
2119

22-
public IEnumerable<CodeInspectionResultBase> GetInspectionResults(RubberduckParserState state)
23-
{
24-
return
25-
state.EmptyStringLiterals.Select(
26-
context =>
27-
new EmptyStringLiteralInspectionResult(this,
20+
public override IEnumerable<CodeInspectionResultBase> GetInspectionResults()
21+
{
22+
return State.EmptyStringLiterals.Select(
23+
context => new EmptyStringLiteralInspectionResult(this,
2824
new QualifiedContext<ParserRuleContext>(context.ModuleName, context.Context)));
2925
}
3026
}

RetailCoder.VBE/Inspections/ICodeInspectionResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
namespace Rubberduck.Inspections
77
{
8-
public interface ICodeInspectionResult
8+
public interface ICodeInspectionResult : IComparable<ICodeInspectionResult>, IComparable
99
{
1010
IEnumerable<CodeInspectionQuickFix> QuickFixes { get; }
1111
CodeInspectionQuickFix DefaultQuickFix { get; }
1212
ParserRuleContext Context { get; }
1313
string Name { get; }
1414
QualifiedSelection QualifiedSelection { get; }
1515
IInspection Inspection { get; }
16+
string ToCsvString();
1617
}
1718
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
using System.Collections.Generic;
2-
using Rubberduck.Parsing.VBA;
1+
using System;
2+
using System.Collections.Generic;
33

44
namespace Rubberduck.Inspections
55
{
66
/// <summary>
77
/// An interface that abstracts a runnable code inspection.
88
/// </summary>
9-
public interface IInspection : IInspectionModel
9+
public interface IInspection : IInspectionModel, IComparable<IInspection>, IComparable
1010
{
1111
/// <summary>
1212
/// Runs code inspection on specified parse trees.
1313
/// </summary>
1414
/// <returns>Returns inspection results, if any.</returns>
15-
IEnumerable<CodeInspectionResultBase> GetInspectionResults(RubberduckParserState state);
15+
IEnumerable<CodeInspectionResultBase> GetInspectionResults();
1616

1717
/// <summary>
1818
/// Gets a string that contains additional/meta information about an inspection.
1919
/// </summary>
2020
string Meta { get; }
21+
2122
}
2223
}

RetailCoder.VBE/Inspections/IInspectionModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public interface IInspectionModel
1010
/// </summary>
1111
string Name { get; }
1212

13+
string AnnotationName { get; }
14+
1315
/// <summary>
1416
/// Gets a short description for the code inspection.
1517
/// </summary>

0 commit comments

Comments
 (0)