diff --git a/RetailCoder.VBE/App.cs b/RetailCoder.VBE/App.cs index 765f49e4bb..d7f8099cf4 100644 --- a/RetailCoder.VBE/App.cs +++ b/RetailCoder.VBE/App.cs @@ -92,7 +92,7 @@ private async void hooks_MessageReceived(object sender, HookEventArgs e) } var component = _vbe.ActiveCodePane.CodeModule.Parent; - _parser.ParseComponentAsync(component); + _parser.ParseComponent(component); AwaitNextKey(); return; diff --git a/RetailCoder.VBE/Inspections/AssignedByValParameterInspection.cs b/RetailCoder.VBE/Inspections/AssignedByValParameterInspection.cs index 48d4e89f2b..e60544a03f 100644 --- a/RetailCoder.VBE/Inspections/AssignedByValParameterInspection.cs +++ b/RetailCoder.VBE/Inspections/AssignedByValParameterInspection.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Rubberduck.Parsing; using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; @@ -8,27 +7,21 @@ namespace Rubberduck.Inspections { - public class AssignedByValParameterInspection : IInspection + public sealed class AssignedByValParameterInspection : InspectionBase { - public AssignedByValParameterInspection() + public AssignedByValParameterInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "AssignedByValParameterInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ByValParameterIsAssigned_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return InspectionsUI.AssignedByValParameterInspectionName; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - private string AnnotationName { get { return Name.Replace("Inspection", string.Empty); } } - - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var name = AnnotationName; - var assignedByValParameters = - state.AllUserDeclarations.Where(declaration => !declaration.IsInspectionDisabled(name) - && declaration.DeclarationType == DeclarationType.Parameter + var assignedByValParameters = UserDeclarations.Where(declaration => + declaration.DeclarationType == DeclarationType.Parameter && ((VBAParser.ArgContext)declaration.Context).BYVAL() != null && declaration.References.Any(reference => reference.IsAssignment)); diff --git a/RetailCoder.VBE/Inspections/CodeInspectionResultBase.cs b/RetailCoder.VBE/Inspections/CodeInspectionResultBase.cs index 436f34666f..8f330da302 100644 --- a/RetailCoder.VBE/Inspections/CodeInspectionResultBase.cs +++ b/RetailCoder.VBE/Inspections/CodeInspectionResultBase.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Antlr4.Runtime; using Rubberduck.Parsing; @@ -82,6 +83,11 @@ public QualifiedSelection QualifiedSelection public virtual CodeInspectionQuickFix DefaultQuickFix { get { return QuickFixes.FirstOrDefault(); } } + public int CompareTo(ICodeInspectionResult other) + { + return Inspection.CompareTo(other.Inspection); + } + public override string ToString() { var module = QualifiedSelection.QualifiedName; @@ -93,5 +99,22 @@ public override string ToString() module.ComponentName, QualifiedSelection.Selection.StartLine); } + + public int CompareTo(object obj) + { + return CompareTo(obj as ICodeInspectionResult); + } + + public string ToCsvString() + { + var module = QualifiedSelection.QualifiedName; + return string.Format( + "{0}, {1}, {2}, {3}, {4}", + Inspection.Severity, + Name, + module.ProjectName, + module.ComponentName, + QualifiedSelection.Selection.StartLine); + } } } diff --git a/RetailCoder.VBE/Inspections/ConstantNotUsedInspection.cs b/RetailCoder.VBE/Inspections/ConstantNotUsedInspection.cs index 48d570c1ba..3c47df7c9d 100644 --- a/RetailCoder.VBE/Inspections/ConstantNotUsedInspection.cs +++ b/RetailCoder.VBE/Inspections/ConstantNotUsedInspection.cs @@ -6,22 +6,20 @@ namespace Rubberduck.Inspections { - public class ConstantNotUsedInspection : IInspection + public sealed class ConstantNotUsedInspection : InspectionBase { - public ConstantNotUsedInspection() + public ConstantNotUsedInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "ConstantNotUsedInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ConstantNotUsed_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.ConstantNotUsed_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var results = state.AllUserDeclarations.Where(declaration => + var results = UserDeclarations.Where(declaration => declaration.DeclarationType == DeclarationType.Constant && !declaration.References.Any()); return results.Select(issue => diff --git a/RetailCoder.VBE/Inspections/DefaultProjectNameInspection.cs b/RetailCoder.VBE/Inspections/DefaultProjectNameInspection.cs index ed31b8442c..f2aa31327e 100644 --- a/RetailCoder.VBE/Inspections/DefaultProjectNameInspection.cs +++ b/RetailCoder.VBE/Inspections/DefaultProjectNameInspection.cs @@ -7,28 +7,26 @@ namespace Rubberduck.Inspections { - public class DefaultProjectNameInspection : IInspection + public sealed class DefaultProjectNameInspection : InspectionBase { private readonly ICodePaneWrapperFactory _wrapperFactory; - public DefaultProjectNameInspection() + public DefaultProjectNameInspection(RubberduckParserState state) + : base(state) { _wrapperFactory = new CodePaneWrapperFactory(); Severity = CodeInspectionSeverity.Suggestion; } - public string Name { get { return "DefaultProjectNameInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.GenericProjectName_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.GenericProjectName_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var issues = state.AllUserDeclarations + var issues = UserDeclarations .Where(declaration => declaration.DeclarationType == DeclarationType.Project && declaration.IdentifierName.StartsWith("VBAProject")) - .Select(issue => new DefaultProjectNameInspectionResult(this, issue, state, _wrapperFactory)) + .Select(issue => new DefaultProjectNameInspectionResult(this, issue, State, _wrapperFactory)) .ToList(); return issues; diff --git a/RetailCoder.VBE/Inspections/DefaultProjectNameInspectionResult.cs b/RetailCoder.VBE/Inspections/DefaultProjectNameInspectionResult.cs index ec9b7ea784..9ffd2da8cc 100644 --- a/RetailCoder.VBE/Inspections/DefaultProjectNameInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/DefaultProjectNameInspectionResult.cs @@ -32,14 +32,14 @@ public DefaultProjectNameInspectionResult(IInspection inspection, Declaration ta public class RenameProjectQuickFix : CodeInspectionQuickFix { private readonly Declaration _target; - private readonly RubberduckParserState _parseResult; + private readonly RubberduckParserState _state; private readonly ICodePaneWrapperFactory _wrapperFactory; - public RenameProjectQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState parseResult, ICodePaneWrapperFactory wrapperFactory) + public RenameProjectQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState state, ICodePaneWrapperFactory wrapperFactory) : base(context, selection, string.Format(RubberduckUI.Rename_DeclarationType, RubberduckUI.ResourceManager.GetString("DeclarationType_" + DeclarationType.Project, RubberduckUI.Culture))) { _target = target; - _parseResult = parseResult; + _state = state; _wrapperFactory = wrapperFactory; } @@ -49,8 +49,8 @@ public override void Fix() using (var view = new RenameDialog()) { - var factory = new RenamePresenterFactory(vbe, view, _parseResult, new MessageBox(), _wrapperFactory); - var refactoring = new RenameRefactoring(factory, new ActiveCodePaneEditor(vbe, _wrapperFactory), new MessageBox()); + var factory = new RenamePresenterFactory(vbe, view, _state, new MessageBox(), _wrapperFactory); + var refactoring = new RenameRefactoring(factory, new ActiveCodePaneEditor(vbe, _wrapperFactory), new MessageBox(), _state); refactoring.Refactor(_target); } } diff --git a/RetailCoder.VBE/Inspections/EmptyStringLiteralInspection.cs b/RetailCoder.VBE/Inspections/EmptyStringLiteralInspection.cs index 543e72ffd3..71a93832f7 100644 --- a/RetailCoder.VBE/Inspections/EmptyStringLiteralInspection.cs +++ b/RetailCoder.VBE/Inspections/EmptyStringLiteralInspection.cs @@ -6,25 +6,21 @@ namespace Rubberduck.Inspections { - public class EmptyStringLiteralInspection : IInspection + public sealed class EmptyStringLiteralInspection : InspectionBase { - public EmptyStringLiteralInspection() + public EmptyStringLiteralInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "EmptyStringLiteralInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return InspectionsUI.EmptyStringLiteralInspection; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return InspectionsUI.EmptyStringLiteralInspection; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) - { - return - state.EmptyStringLiterals.Select( - context => - new EmptyStringLiteralInspectionResult(this, + public override IEnumerable GetInspectionResults() + { + return State.EmptyStringLiterals.Select( + context => new EmptyStringLiteralInspectionResult(this, new QualifiedContext(context.ModuleName, context.Context))); } } diff --git a/RetailCoder.VBE/Inspections/ICodeInspectionResult.cs b/RetailCoder.VBE/Inspections/ICodeInspectionResult.cs index 19b42582b3..4cc2d9c94a 100644 --- a/RetailCoder.VBE/Inspections/ICodeInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/ICodeInspectionResult.cs @@ -5,7 +5,7 @@ namespace Rubberduck.Inspections { - public interface ICodeInspectionResult + public interface ICodeInspectionResult : IComparable, IComparable { IEnumerable QuickFixes { get; } CodeInspectionQuickFix DefaultQuickFix { get; } @@ -13,5 +13,6 @@ public interface ICodeInspectionResult string Name { get; } QualifiedSelection QualifiedSelection { get; } IInspection Inspection { get; } + string ToCsvString(); } } diff --git a/RetailCoder.VBE/Inspections/IInspection.cs b/RetailCoder.VBE/Inspections/IInspection.cs index cd51a37b1f..6ecd408060 100644 --- a/RetailCoder.VBE/Inspections/IInspection.cs +++ b/RetailCoder.VBE/Inspections/IInspection.cs @@ -1,22 +1,23 @@ -using System.Collections.Generic; -using Rubberduck.Parsing.VBA; +using System; +using System.Collections.Generic; namespace Rubberduck.Inspections { /// /// An interface that abstracts a runnable code inspection. /// - public interface IInspection : IInspectionModel + public interface IInspection : IInspectionModel, IComparable, IComparable { /// /// Runs code inspection on specified parse trees. /// /// Returns inspection results, if any. - IEnumerable GetInspectionResults(RubberduckParserState state); + IEnumerable GetInspectionResults(); /// /// Gets a string that contains additional/meta information about an inspection. /// string Meta { get; } + } } diff --git a/RetailCoder.VBE/Inspections/IInspectionModel.cs b/RetailCoder.VBE/Inspections/IInspectionModel.cs index b2e364fb15..a07cfaf4e6 100644 --- a/RetailCoder.VBE/Inspections/IInspectionModel.cs +++ b/RetailCoder.VBE/Inspections/IInspectionModel.cs @@ -10,6 +10,8 @@ public interface IInspectionModel /// string Name { get; } + string AnnotationName { get; } + /// /// Gets a short description for the code inspection. /// diff --git a/RetailCoder.VBE/Inspections/IdentifierNotAssignedInspectionResult.cs b/RetailCoder.VBE/Inspections/IdentifierNotAssignedInspectionResult.cs index e08ccedff7..01ced0e460 100644 --- a/RetailCoder.VBE/Inspections/IdentifierNotAssignedInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/IdentifierNotAssignedInspectionResult.cs @@ -15,9 +15,10 @@ public IdentifierNotAssignedInspectionResult(IInspection inspection, Declaration ParserRuleContext context, QualifiedModuleName qualifiedName) : base(inspection, target, context, qualifiedName) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { new RemoveUnassignedIdentifierQuickFix(Context, QualifiedSelection), + new IgnoreOnceQuickFix(context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/IdentifierNotUsedInspectionResult.cs b/RetailCoder.VBE/Inspections/IdentifierNotUsedInspectionResult.cs index 10d0ecc573..4585382a10 100644 --- a/RetailCoder.VBE/Inspections/IdentifierNotUsedInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/IdentifierNotUsedInspectionResult.cs @@ -15,9 +15,10 @@ public IdentifierNotUsedInspectionResult(IInspection inspection, Declaration tar ParserRuleContext context, QualifiedModuleName qualifiedName) : base(inspection, string.Format(inspection.Description, target.IdentifierName), qualifiedName, context) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { new RemoveUnusedDeclarationQuickFix(context, QualifiedSelection), + new IgnoreOnceQuickFix(context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/IgnoreOnceQuickFix.cs b/RetailCoder.VBE/Inspections/IgnoreOnceQuickFix.cs new file mode 100644 index 0000000000..063b15d5c6 --- /dev/null +++ b/RetailCoder.VBE/Inspections/IgnoreOnceQuickFix.cs @@ -0,0 +1,44 @@ +using Antlr4.Runtime; +using Rubberduck.Parsing.VBA; +using Rubberduck.VBEditor; + +namespace Rubberduck.Inspections +{ + public class IgnoreOnceQuickFix : CodeInspectionQuickFix + { + private readonly string _annotationText; + private readonly string _inspectionName; + + public IgnoreOnceQuickFix(ParserRuleContext context, QualifiedSelection selection, string inspectionName) + : base(context, selection, InspectionsUI.IgnoreOnce) + { + _inspectionName = inspectionName; + _annotationText = "'" + Parsing.Grammar.Annotations.AnnotationMarker + + Parsing.Grammar.Annotations.IgnoreInspection + ' ' + inspectionName; + } + + public override bool CanFixInModule { get { return false; } } // not quite "once" if applied to entire module + public override bool CanFixInProject { get { return false; } } // use "disable this inspection" instead of ignoring across the project + + public override void Fix() + { + var codeModule = Selection.QualifiedName.Component.CodeModule; + var insertLine = Selection.Selection.StartLine; + + var codeLine = insertLine == 1 ? string.Empty : codeModule.get_Lines(insertLine - 1, 1); + var annotationText = _annotationText; + var ignoreAnnotation = "'" + Parsing.Grammar.Annotations.AnnotationMarker + Parsing.Grammar.Annotations.IgnoreInspection; + + int commentStart; + if (codeLine.HasComment(out commentStart) && codeLine.Substring(commentStart).StartsWith(ignoreAnnotation)) + { + annotationText = codeLine + ' ' + _inspectionName; + codeModule.ReplaceLine(insertLine - 1, annotationText); + } + else + { + codeModule.InsertLines(insertLine, annotationText); + } + } + } +} \ No newline at end of file diff --git a/RetailCoder.VBE/Inspections/ImplicitActiveSheetReferenceInspection.cs b/RetailCoder.VBE/Inspections/ImplicitActiveSheetReferenceInspection.cs index 545f556648..632fb6569f 100644 --- a/RetailCoder.VBE/Inspections/ImplicitActiveSheetReferenceInspection.cs +++ b/RetailCoder.VBE/Inspections/ImplicitActiveSheetReferenceInspection.cs @@ -11,28 +11,26 @@ namespace Rubberduck.Inspections { - public class ImplicitActiveSheetReferenceInspection : IInspection + public sealed class ImplicitActiveSheetReferenceInspection : InspectionBase { private readonly Func _hostApp; - public ImplicitActiveSheetReferenceInspection(VBE vbe) + public ImplicitActiveSheetReferenceInspection(VBE vbe, RubberduckParserState state) + : base(state) { _hostApp = vbe.HostApplication; Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "ImplicitActiveSheetReferenceInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ImplicitActiveSheetReference_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.ImplicitActiveSheetReference_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } private static readonly string[] Targets = { "Cells", "Range", "Columns", "Rows" }; - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { if (_hostApp().ApplicationName != "Excel") { @@ -40,7 +38,7 @@ public IEnumerable GetInspectionResults(RubberduckPars // if host isn't Excel, the ExcelObjectModel declarations shouldn't be loaded anyway. } - var issues = state.AllDeclarations.Where(item => item.IsBuiltIn + var issues = Declarations.Where(item => item.IsBuiltIn && item.ParentScope == "Excel.Global" && Targets.Contains(item.IdentifierName) && item.References.Any()) @@ -53,14 +51,17 @@ public IEnumerable GetInspectionResults(RubberduckPars public class ImplicitActiveSheetReferenceInspectionResult : CodeInspectionResultBase { - //private readonly IEnumerable _quickFixes; + private readonly IEnumerable _quickFixes; public ImplicitActiveSheetReferenceInspectionResult(IInspection inspection, string result, ParserRuleContext context, QualifiedModuleName qualifiedName) : base(inspection, result, qualifiedName, context) { - //_quickFixes = new CodeInspectionQuickFix[]{}; + _quickFixes = new CodeInspectionQuickFix[] + { + new IgnoreOnceQuickFix(context, QualifiedSelection, Inspection.AnnotationName), + }; } - //public override IEnumerable QuickFixes { get { return _quickFixes; } } + public override IEnumerable QuickFixes { get { return _quickFixes; } } } } diff --git a/RetailCoder.VBE/Inspections/ImplicitActiveWorkbookReferenceInspection.cs b/RetailCoder.VBE/Inspections/ImplicitActiveWorkbookReferenceInspection.cs index 116f895eec..40203211f8 100644 --- a/RetailCoder.VBE/Inspections/ImplicitActiveWorkbookReferenceInspection.cs +++ b/RetailCoder.VBE/Inspections/ImplicitActiveWorkbookReferenceInspection.cs @@ -9,28 +9,26 @@ namespace Rubberduck.Inspections { - public class ImplicitActiveWorkbookReferenceInspection : IInspection + public sealed class ImplicitActiveWorkbookReferenceInspection : InspectionBase { private readonly Lazy _hostApp; - public ImplicitActiveWorkbookReferenceInspection(VBE vbe) + public ImplicitActiveWorkbookReferenceInspection(VBE vbe, RubberduckParserState state) + : base(state) { _hostApp = new Lazy(vbe.HostApplication); Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "ImplicitActiveWorkbookReferenceInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ImplicitActiveWorkbookReference_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.ImplicitActiveWorkbookReference_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } private static readonly string[] Targets = { "Worksheets", "Sheets", "Names", }; - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { if (!_hostApp.IsValueCreated || _hostApp.Value == null || _hostApp.Value.ApplicationName != "Excel") { @@ -38,10 +36,10 @@ public IEnumerable GetInspectionResults(RubberduckPars // if host isn't Excel, the ExcelObjectModel declarations shouldn't be loaded anyway. } - var issues = state.AllDeclarations.Where(item => item.IsBuiltIn - && item.ParentScope == "Excel.Global" - && Targets.Contains(item.IdentifierName) - && item.References.Any()) + var issues = Declarations.Where(item => item.IsBuiltIn + && item.ParentScope == "Excel.Global" + && Targets.Contains(item.IdentifierName) + && item.References.Any()) .SelectMany(declaration => declaration.References); return issues.Select(issue => diff --git a/RetailCoder.VBE/Inspections/ImplicitByRefParameterInspection.cs b/RetailCoder.VBE/Inspections/ImplicitByRefParameterInspection.cs index dbda9962d1..6e93554e60 100644 --- a/RetailCoder.VBE/Inspections/ImplicitByRefParameterInspection.cs +++ b/RetailCoder.VBE/Inspections/ImplicitByRefParameterInspection.cs @@ -9,28 +9,22 @@ namespace Rubberduck.Inspections { - public class ImplicitByRefParameterInspection : IInspection + public sealed class ImplicitByRefParameterInspection : InspectionBase { - public ImplicitByRefParameterInspection() + public ImplicitByRefParameterInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "ImplicitByRefParameterInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ImplicitByRef_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.ImplicitByRef_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - private string AnnotationName { get { return Name.Replace("Inspection", string.Empty); } } - - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var declarations = state.AllUserDeclarations.ToList(); - - var interfaceMembers = declarations.FindInterfaceImplementationMembers(); + var interfaceMembers = UserDeclarations.FindInterfaceImplementationMembers(); - var issues = (from item in declarations + var issues = (from item in UserDeclarations where !item.IsInspectionDisabled(AnnotationName) && item.DeclarationType == DeclarationType.Parameter && !interfaceMembers.Select(m => m.Scope).Contains(item.ParentScope) @@ -39,6 +33,7 @@ public IEnumerable GetInspectionResults(RubberduckPars select new QualifiedContext(item.QualifiedName, arg)) .Select(issue => new ImplicitByRefParameterInspectionResult(this, string.Format(Description, issue.Context.ambiguousIdentifier().GetText()), issue)); + return issues; } } diff --git a/RetailCoder.VBE/Inspections/ImplicitByRefParameterInspectionResult.cs b/RetailCoder.VBE/Inspections/ImplicitByRefParameterInspectionResult.cs index 68db2d0469..1458dc7397 100644 --- a/RetailCoder.VBE/Inspections/ImplicitByRefParameterInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/ImplicitByRefParameterInspectionResult.cs @@ -15,9 +15,10 @@ public class ImplicitByRefParameterInspectionResult : CodeInspectionResultBase public ImplicitByRefParameterInspectionResult(IInspection inspection, string result, QualifiedContext qualifiedContext) : base(inspection, result, qualifiedContext.ModuleName, qualifiedContext.Context) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { new ImplicitByRefParameterQuickFix(Context, QualifiedSelection, RubberduckUI.Inspections_PassParamByRefExplicitly, Tokens.ByRef), + new IgnoreOnceQuickFix(qualifiedContext.Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/ImplicitPublicMemberInspection.cs b/RetailCoder.VBE/Inspections/ImplicitPublicMemberInspection.cs index e5ae30731a..7f72021a06 100644 --- a/RetailCoder.VBE/Inspections/ImplicitPublicMemberInspection.cs +++ b/RetailCoder.VBE/Inspections/ImplicitPublicMemberInspection.cs @@ -8,18 +8,16 @@ namespace Rubberduck.Inspections { - public class ImplicitPublicMemberInspection : IInspection + public sealed class ImplicitPublicMemberInspection : InspectionBase { - public ImplicitPublicMemberInspection() + public ImplicitPublicMemberInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "ImplicitPublicMemberInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ImplicitPublicMember_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.ImplicitPublicMember_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } private static readonly DeclarationType[] ProcedureTypes = { @@ -30,11 +28,9 @@ public ImplicitPublicMemberInspection() DeclarationType.PropertySet }; - private string AnnotationName { get { return Name.Replace("Inspection", string.Empty); } } - - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var issues = from item in state.AllUserDeclarations + var issues = from item in UserDeclarations where !item.IsInspectionDisabled(AnnotationName) && ProcedureTypes.Contains(item.DeclarationType) && item.Accessibility == Accessibility.Implicit diff --git a/RetailCoder.VBE/Inspections/ImplicitPublicMemberInspectionResult.cs b/RetailCoder.VBE/Inspections/ImplicitPublicMemberInspectionResult.cs index 2c40b68937..c5b85f36d8 100644 --- a/RetailCoder.VBE/Inspections/ImplicitPublicMemberInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/ImplicitPublicMemberInspectionResult.cs @@ -15,9 +15,10 @@ public class ImplicitPublicMemberInspectionResult : CodeInspectionResultBase public ImplicitPublicMemberInspectionResult(IInspection inspection, string result, QualifiedContext qualifiedContext) : base(inspection, result, qualifiedContext.ModuleName, qualifiedContext.Context) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { new SpecifyExplicitPublicModifierQuickFix(Context, QualifiedSelection), + new IgnoreOnceQuickFix(qualifiedContext.Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspection.cs b/RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspection.cs index 46bfbee76f..7a6c65b753 100644 --- a/RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspection.cs +++ b/RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspection.cs @@ -8,18 +8,16 @@ namespace Rubberduck.Inspections { - public class ImplicitVariantReturnTypeInspection : IInspection + public sealed class ImplicitVariantReturnTypeInspection : InspectionBase { - public ImplicitVariantReturnTypeInspection() + public ImplicitVariantReturnTypeInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "ImplicitVariantReturnTypeInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ImplicitVariantReturnType_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.ImplicitVariantReturnType_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } private static readonly DeclarationType[] ProcedureTypes = { @@ -28,11 +26,9 @@ public ImplicitVariantReturnTypeInspection() DeclarationType.LibraryFunction }; - private string AnnotationName { get { return Name.Replace("Inspection", string.Empty); } } - - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var issues = from item in state.AllUserDeclarations + var issues = from item in UserDeclarations where !item.IsInspectionDisabled(AnnotationName) && ProcedureTypes.Contains(item.DeclarationType) && !item.IsTypeSpecified() diff --git a/RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspectionResult.cs b/RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspectionResult.cs index 1eabc68b79..76f8dae6d8 100644 --- a/RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspectionResult.cs @@ -17,9 +17,10 @@ public class ImplicitVariantReturnTypeInspectionResult : CodeInspectionResultBas public ImplicitVariantReturnTypeInspectionResult(IInspection inspection, string name, QualifiedContext qualifiedContext) : base(inspection, name, qualifiedContext.ModuleName, qualifiedContext.Context) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { new SetExplicitVariantReturnTypeQuickFix(Context, QualifiedSelection, RubberduckUI.Inspections_ReturnExplicitVariant), + new IgnoreOnceQuickFix(qualifiedContext.Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/InspectionBase.cs b/RetailCoder.VBE/Inspections/InspectionBase.cs new file mode 100644 index 0000000000..a5367fc921 --- /dev/null +++ b/RetailCoder.VBE/Inspections/InspectionBase.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Rubberduck.Parsing.Symbols; +using Rubberduck.Parsing.VBA; + +namespace Rubberduck.Inspections +{ + public abstract class InspectionBase : IInspection + { + protected readonly RubberduckParserState State; + protected InspectionBase(RubberduckParserState state) + { + State = state; + } + + public abstract string Description { get; } + public abstract CodeInspectionType InspectionType { get; } + public abstract IEnumerable GetInspectionResults(); + + public virtual string Name { get { return GetType().Name; } } + public virtual CodeInspectionSeverity Severity { get; set; } + public virtual string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } + // ReSharper disable once UnusedMember.Global: it's referenced in xaml + public virtual string InspectionTypeName { get { return InspectionsUI.ResourceManager.GetString(InspectionType.ToString()); } } + public virtual string AnnotationName { get { return Name.Replace("Inspection", string.Empty); } } + + protected virtual IEnumerable Declarations + { + get { return State.AllDeclarations.Where(declaration => !declaration.IsInspectionDisabled(AnnotationName)); } + } + + protected virtual IEnumerable UserDeclarations + { + get { return State.AllUserDeclarations.Where(declaration => !declaration.IsInspectionDisabled(AnnotationName)); } + } + + public int CompareTo(IInspection other) + { + return string.Compare(InspectionType + Name, other.InspectionType + other.Name, StringComparison.Ordinal); + } + + public int CompareTo(object obj) + { + return CompareTo(obj as IInspection); + } + } +} \ No newline at end of file diff --git a/RetailCoder.VBE/Inspections/InspectionsUI.Designer.cs b/RetailCoder.VBE/Inspections/InspectionsUI.Designer.cs index 57e6a3c879..8bd9d25b34 100644 --- a/RetailCoder.VBE/Inspections/InspectionsUI.Designer.cs +++ b/RetailCoder.VBE/Inspections/InspectionsUI.Designer.cs @@ -78,6 +78,15 @@ internal static string AssignedByValParameterInspectionName { } } + /// + /// Looks up a localized string similar to Code quality issues. + /// + internal static string CodeQualityIssues { + get { + return ResourceManager.GetString("CodeQualityIssues", resourceCulture); + } + } + /// /// Looks up a localized string similar to Constant value is declared but Rubberduck could not find any reference to it. Consider removing the unused declaration.. /// @@ -150,6 +159,15 @@ internal static string EmptyStringLiteralInspectionQuickFix { } } + /// + /// Looks up a localized string similar to Ignore once. + /// + internal static string IgnoreOnce { + get { + return ResourceManager.GetString("IgnoreOnce", resourceCulture); + } + } + /// /// Looks up a localized string similar to Implicit references to the active sheet make the code frail and harder to debug. Consider making these references explicit when they're intended, and prefer working off object references.. /// @@ -240,6 +258,24 @@ internal static string ImplicitVariantReturnTypeInspectionName { } } + /// + /// Looks up a localized string similar to Language opportunities. + /// + internal static string LanguageOpportunities { + get { + return ResourceManager.GetString("LanguageOpportunities", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Maintainability & readability issues. + /// + internal static string MaintainabilityAndReadabilityIssues { + get { + return ResourceManager.GetString("MaintainabilityAndReadabilityIssues", resourceCulture); + } + } + /// /// Looks up a localized string similar to Consider continuing long signatures between parameters. Splitting a parameter declaration across multiple lines arguably hurts readability.. /// @@ -276,6 +312,33 @@ internal static string MultipleDeclarationsInspectionName { } } + /// + /// Looks up a localized string similar to '{0}' has more than one namespace declaration.. + /// + internal static string MultipleFolderAnnotationsInspection { + get { + return ResourceManager.GetString("MultipleFolderAnnotationsInspection", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Rubberduck only uses the first '@Folder' annotation in a code module; consider removing extraneous ones.. + /// + internal static string MultipleFolderAnnotationsInspectionMeta { + get { + return ResourceManager.GetString("MultipleFolderAnnotationsInspectionMeta", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Component has more than one folder annotation.. + /// + internal static string MultipleFolderAnnotationsInspectionName { + get { + return ResourceManager.GetString("MultipleFolderAnnotationsInspectionName", resourceCulture); + } + } + /// /// Looks up a localized string similar to This is likely a bug. The return value of a function or property getter must be assigned before exiting, otherwise the program will not be working with expected results. If a function has no meaningful return value, consider declaring it as a 'Sub' procedure instead.. /// @@ -432,9 +495,9 @@ internal static string ParameterCanBeByValInspectionMeta { /// /// Looks up a localized string similar to Parameter can be passed by value. /// - internal static string ParameterCanByByValInspectionName { + internal static string ParameterCanBeByValInspectionName { get { - return ResourceManager.GetString("ParameterCanByByValInspectionName", resourceCulture); + return ResourceManager.GetString("ParameterCanBeByValInspectionName", resourceCulture); } } diff --git a/RetailCoder.VBE/Inspections/InspectionsUI.resx b/RetailCoder.VBE/Inspections/InspectionsUI.resx index 2931a2ebaf..9bcec43793 100644 --- a/RetailCoder.VBE/Inspections/InspectionsUI.resx +++ b/RetailCoder.VBE/Inspections/InspectionsUI.resx @@ -123,6 +123,9 @@ ByVal parameter is assigned + + Code quality issues + Constant value is declared but Rubberduck could not find any reference to it. Consider removing the unused declaration. @@ -147,6 +150,9 @@ Replace empty string with the 'vbNullString' constant + + Ignore once + Implicit references to the active sheet make the code frail and harder to debug. Consider making these references explicit when they're intended, and prefer working off object references. @@ -177,6 +183,12 @@ Return type is implicitly 'Variant' + + Language opportunities + + + Maintainability & readability issues + Consider continuing long signatures between parameters. Splitting a parameter declaration across multiple lines arguably hurts readability. @@ -189,6 +201,15 @@ Instruction contains multiple declarations + + '{0}' has more than one namespace declaration. + + + Rubberduck only uses the first '@Folder' annotation in a code module; consider removing extraneous ones. + + + Component has more than one folder annotation. + This is likely a bug. The return value of a function or property getter must be assigned before exiting, otherwise the program will not be working with expected results. If a function has no meaningful return value, consider declaring it as a 'Sub' procedure instead. @@ -240,7 +261,7 @@ A parameter that is passed by reference but that isn't assigned a new value/reference, could be passed by value instead. - + Parameter can be passed by value diff --git a/RetailCoder.VBE/Inspections/Inspector.cs b/RetailCoder.VBE/Inspections/Inspector.cs index ebb10fe37a..9373df924f 100644 --- a/RetailCoder.VBE/Inspections/Inspector.cs +++ b/RetailCoder.VBE/Inspections/Inspector.cs @@ -68,7 +68,7 @@ public async Task> FindIssuesAsync(RubberduckParser new Task(() => { token.ThrowIfCancellationRequested(); - var inspectionResults = inspection.GetInspectionResults(state); + var inspectionResults = inspection.GetInspectionResults(); var results = inspectionResults as IList ?? inspectionResults.ToList(); if (results.Any()) diff --git a/RetailCoder.VBE/Inspections/MultilineParameterInspection.cs b/RetailCoder.VBE/Inspections/MultilineParameterInspection.cs index e4c8dd92cf..a69ad04ecf 100644 --- a/RetailCoder.VBE/Inspections/MultilineParameterInspection.cs +++ b/RetailCoder.VBE/Inspections/MultilineParameterInspection.cs @@ -7,22 +7,20 @@ namespace Rubberduck.Inspections { - public class MultilineParameterInspection : IInspection + public sealed class MultilineParameterInspection : InspectionBase { - public MultilineParameterInspection() + public MultilineParameterInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "MultilineParameterInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.MultilineParameter_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.MultilineParameter_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var multilineParameters = from p in state.AllUserDeclarations + var multilineParameters = from p in UserDeclarations .Where(item => item.DeclarationType == DeclarationType.Parameter) where p.Context.GetSelection().LineCount > 1 select p; diff --git a/RetailCoder.VBE/Inspections/MultipleDeclarationsInspection.cs b/RetailCoder.VBE/Inspections/MultipleDeclarationsInspection.cs index b747a2bcd9..16cc7eec1f 100644 --- a/RetailCoder.VBE/Inspections/MultipleDeclarationsInspection.cs +++ b/RetailCoder.VBE/Inspections/MultipleDeclarationsInspection.cs @@ -8,24 +8,20 @@ namespace Rubberduck.Inspections { - public class MultipleDeclarationsInspection : IInspection + public sealed class MultipleDeclarationsInspection : InspectionBase { - public MultipleDeclarationsInspection() + public MultipleDeclarationsInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "MultipleDeclarationsInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.MultipleDeclarations; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.MultipleDeclarations; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } - private string AnnotationName { get { return Name.Replace("Inspection", string.Empty); } } - - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var issues = state.AllUserDeclarations + var issues = UserDeclarations .Where(item => !item.IsInspectionDisabled(AnnotationName)) .Where(item => item.DeclarationType == DeclarationType.Variable || item.DeclarationType == DeclarationType.Constant) diff --git a/RetailCoder.VBE/Inspections/MultipleDeclarationsInspectionResult.cs b/RetailCoder.VBE/Inspections/MultipleDeclarationsInspectionResult.cs index 8659ee5e0d..3cd2818c60 100644 --- a/RetailCoder.VBE/Inspections/MultipleDeclarationsInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/MultipleDeclarationsInspectionResult.cs @@ -16,9 +16,10 @@ public class MultipleDeclarationsInspectionResult : CodeInspectionResultBase public MultipleDeclarationsInspectionResult(IInspection inspection, string result, QualifiedContext qualifiedContext) : base(inspection, result, qualifiedContext.ModuleName, qualifiedContext.Context) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { new SplitMultipleDeclarationsQuickFix(Context, QualifiedSelection), + new IgnoreOnceQuickFix(qualifiedContext.Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/MultipleFolderAnnotationsInspection.cs b/RetailCoder.VBE/Inspections/MultipleFolderAnnotationsInspection.cs new file mode 100644 index 0000000000..dea500658e --- /dev/null +++ b/RetailCoder.VBE/Inspections/MultipleFolderAnnotationsInspection.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using System.Linq; +using Rubberduck.Parsing.Symbols; +using Rubberduck.Parsing.VBA; + +namespace Rubberduck.Inspections +{ + public sealed class MultipleFolderAnnotationsInspection : InspectionBase + { + public MultipleFolderAnnotationsInspection(RubberduckParserState state) + : base(state) + { + Severity = CodeInspectionSeverity.Warning; + } + + public override string Description { get { return InspectionsUI.MultipleFolderAnnotationsInspection; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } + + public override IEnumerable GetInspectionResults() + { + var issues = UserDeclarations.Where(declaration => + (declaration.DeclarationType == DeclarationType.Class + || declaration.DeclarationType == DeclarationType.Module) + && declaration.Annotations.Split('\n').Count(annotation => + annotation.StartsWith(Parsing.Grammar.Annotations.AnnotationMarker + + Parsing.Grammar.Annotations.Folder)) > 1); + return issues.Select(issue => + new MultipleFolderAnnotationsInspectionResult(this, string.Format(Description, issue.ComponentName), issue)); + } + } + + public class MultipleFolderAnnotationsInspectionResult : CodeInspectionResultBase + { + public MultipleFolderAnnotationsInspectionResult(IInspection inspection, string result, Declaration target) + : base(inspection, result, target) + { + } + } +} \ No newline at end of file diff --git a/RetailCoder.VBE/Inspections/NonReturningFunctionInspection.cs b/RetailCoder.VBE/Inspections/NonReturningFunctionInspection.cs index 071e5c4a98..395210de09 100644 --- a/RetailCoder.VBE/Inspections/NonReturningFunctionInspection.cs +++ b/RetailCoder.VBE/Inspections/NonReturningFunctionInspection.cs @@ -9,18 +9,16 @@ namespace Rubberduck.Inspections { - public class NonReturningFunctionInspection : IInspection + public sealed class NonReturningFunctionInspection : InspectionBase { - public NonReturningFunctionInspection() + public NonReturningFunctionInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "NonReturningFunctionInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.NonReturningFunction_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.NonReturningFunction_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } private static readonly DeclarationType[] ReturningMemberTypes = { @@ -28,9 +26,9 @@ public NonReturningFunctionInspection() DeclarationType.PropertyGet }; - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var declarations = state.AllUserDeclarations.ToList(); + var declarations = UserDeclarations.ToList(); var interfaceMembers = declarations.FindInterfaceMembers(); var interfaceImplementationMembers = declarations.FindInterfaceImplementationMembers(); diff --git a/RetailCoder.VBE/Inspections/NonReturningFunctionInspectionResult.cs b/RetailCoder.VBE/Inspections/NonReturningFunctionInspectionResult.cs index 05c16f9d89..af80cf8fcb 100644 --- a/RetailCoder.VBE/Inspections/NonReturningFunctionInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/NonReturningFunctionInspectionResult.cs @@ -18,9 +18,10 @@ public NonReturningFunctionInspectionResult(IInspection inspection, string resul { _quickFixes = isInterfaceImplementation ? new CodeInspectionQuickFix[] { } - : new[] + : new CodeInspectionQuickFix[] { new ConvertToProcedureQuickFix(Context, QualifiedSelection), + new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/ObsoleteCallStatementInspection.cs b/RetailCoder.VBE/Inspections/ObsoleteCallStatementInspection.cs index 8a3699d70b..2656e4698f 100644 --- a/RetailCoder.VBE/Inspections/ObsoleteCallStatementInspection.cs +++ b/RetailCoder.VBE/Inspections/ObsoleteCallStatementInspection.cs @@ -7,22 +7,20 @@ namespace Rubberduck.Inspections { - public class ObsoleteCallStatementInspection : IInspection + public sealed class ObsoleteCallStatementInspection : InspectionBase { - public ObsoleteCallStatementInspection() + public ObsoleteCallStatementInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Suggestion; } - public string Name { get { return "ObsoleteCallStatementInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ObsoleteCall; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.ObsoleteCall; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - return state.ObsoleteCallContexts.Select(context => + return State.ObsoleteCallContexts.Select(context => new ObsoleteCallStatementUsageInspectionResult(this, new QualifiedContext(context.ModuleName, context.Context as VBAParser.ExplicitCallStmtContext))); } diff --git a/RetailCoder.VBE/Inspections/ObsoleteCallStatementUsageInspectionResult.cs b/RetailCoder.VBE/Inspections/ObsoleteCallStatementUsageInspectionResult.cs index 942919f776..afb26d534b 100644 --- a/RetailCoder.VBE/Inspections/ObsoleteCallStatementUsageInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/ObsoleteCallStatementUsageInspectionResult.cs @@ -16,9 +16,10 @@ public class ObsoleteCallStatementUsageInspectionResult : CodeInspectionResultBa public ObsoleteCallStatementUsageInspectionResult(IInspection inspection, QualifiedContext qualifiedContext) : base(inspection, inspection.Description, qualifiedContext.ModuleName, qualifiedContext.Context) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { new RemoveExplicitCallStatemntQuickFix(Context, QualifiedSelection), + new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/ObsoleteCommentSyntaxInspection.cs b/RetailCoder.VBE/Inspections/ObsoleteCommentSyntaxInspection.cs index 2b701f4181..9fd5fd23d2 100644 --- a/RetailCoder.VBE/Inspections/ObsoleteCommentSyntaxInspection.cs +++ b/RetailCoder.VBE/Inspections/ObsoleteCommentSyntaxInspection.cs @@ -6,26 +6,24 @@ namespace Rubberduck.Inspections { - public class ObsoleteCommentSyntaxInspection : IInspection + public sealed class ObsoleteCommentSyntaxInspection : InspectionBase { /// /// Parameterless constructor required for discovery of implemented code inspections. /// - public ObsoleteCommentSyntaxInspection() + public ObsoleteCommentSyntaxInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Suggestion; } - public string Name { get { return "ObsoleteCommentSyntaxInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ObsoleteComment; } } - public CodeInspectionType InspectionType { get {return CodeInspectionType.LanguageOpportunities; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.ObsoleteComment; } } + public override CodeInspectionType InspectionType { get {return CodeInspectionType.LanguageOpportunities; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - return (state.Comments.Where(comment => comment.Marker == Tokens.Rem) - .Select(comment => new ObsoleteCommentSyntaxInspectionResult(this, comment))); + return State.AllComments.Where(comment => comment.Marker == Tokens.Rem) + .Select(comment => new ObsoleteCommentSyntaxInspectionResult(this, comment)); } } } \ No newline at end of file diff --git a/RetailCoder.VBE/Inspections/ObsoleteCommentSyntaxInspectionResult.cs b/RetailCoder.VBE/Inspections/ObsoleteCommentSyntaxInspectionResult.cs index b75ffb18f3..44a8fb78dd 100644 --- a/RetailCoder.VBE/Inspections/ObsoleteCommentSyntaxInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/ObsoleteCommentSyntaxInspectionResult.cs @@ -21,6 +21,7 @@ public ObsoleteCommentSyntaxInspectionResult(IInspection inspection, CommentNode { new ReplaceCommentMarkerQuickFix(Context, QualifiedSelection, comment), new RemoveCommentQuickFix(Context, QualifiedSelection, comment), + new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/ObsoleteGlobalInspection.cs b/RetailCoder.VBE/Inspections/ObsoleteGlobalInspection.cs index 19d64c7e91..2ff35b015f 100644 --- a/RetailCoder.VBE/Inspections/ObsoleteGlobalInspection.cs +++ b/RetailCoder.VBE/Inspections/ObsoleteGlobalInspection.cs @@ -8,22 +8,20 @@ namespace Rubberduck.Inspections { - public class ObsoleteGlobalInspection : IInspection + public sealed class ObsoleteGlobalInspection : InspectionBase { - public ObsoleteGlobalInspection() + public ObsoleteGlobalInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Suggestion; } - public string Name { get { return "ObsoleteGlobalInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ObsoleteGlobal; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.ObsoleteGlobal; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var issues = from item in state.AllUserDeclarations + var issues = from item in UserDeclarations where item.Accessibility == Accessibility.Global && item.Context != null select new ObsoleteGlobalInspectionResult(this, Description, new QualifiedContext(item.QualifiedName.QualifiedModuleName, item.Context)); diff --git a/RetailCoder.VBE/Inspections/ObsoleteGlobalInspectionResult.cs b/RetailCoder.VBE/Inspections/ObsoleteGlobalInspectionResult.cs index 357637fe5c..cd6bc11281 100644 --- a/RetailCoder.VBE/Inspections/ObsoleteGlobalInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/ObsoleteGlobalInspectionResult.cs @@ -15,9 +15,10 @@ public class ObsoleteGlobalInspectionResult : CodeInspectionResultBase public ObsoleteGlobalInspectionResult(IInspection inspection, string result, QualifiedContext context) : base(inspection, result, context.ModuleName, context.Context) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { - new ReplaceGlobalModifierQuickFix(Context, QualifiedSelection) + new ReplaceGlobalModifierQuickFix(Context, QualifiedSelection), + new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/ObsoleteLetStatementInspection.cs b/RetailCoder.VBE/Inspections/ObsoleteLetStatementInspection.cs index 9595a081cc..e9481cb7ea 100644 --- a/RetailCoder.VBE/Inspections/ObsoleteLetStatementInspection.cs +++ b/RetailCoder.VBE/Inspections/ObsoleteLetStatementInspection.cs @@ -7,22 +7,20 @@ namespace Rubberduck.Inspections { - public class ObsoleteLetStatementInspection : IInspection + public sealed class ObsoleteLetStatementInspection : InspectionBase { - public ObsoleteLetStatementInspection() + public ObsoleteLetStatementInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Suggestion; } - public string Name { get { return "ObsoleteLetStatementInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ObsoleteLet; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.ObsoleteLet; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - return state.ObsoleteLetContexts.Select(context => + return State.ObsoleteLetContexts.Select(context => new ObsoleteLetStatementUsageInspectionResult(this, new QualifiedContext(context.ModuleName, context.Context))); } } diff --git a/RetailCoder.VBE/Inspections/ObsoleteLetStatementUsageInspectionResult.cs b/RetailCoder.VBE/Inspections/ObsoleteLetStatementUsageInspectionResult.cs index 0fc69a0c2b..cbaca6b6e0 100644 --- a/RetailCoder.VBE/Inspections/ObsoleteLetStatementUsageInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/ObsoleteLetStatementUsageInspectionResult.cs @@ -15,9 +15,10 @@ public class ObsoleteLetStatementUsageInspectionResult : CodeInspectionResultBas public ObsoleteLetStatementUsageInspectionResult(IInspection inspection, QualifiedContext qualifiedContext) : base(inspection, inspection.Description, qualifiedContext.ModuleName, qualifiedContext.Context) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { new RemoveExplicitLetStatementQuickFix(Context, QualifiedSelection), + new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/ObsoleteTypeHintInspection.cs b/RetailCoder.VBE/Inspections/ObsoleteTypeHintInspection.cs index 5d335ad40a..9dd41d50df 100644 --- a/RetailCoder.VBE/Inspections/ObsoleteTypeHintInspection.cs +++ b/RetailCoder.VBE/Inspections/ObsoleteTypeHintInspection.cs @@ -6,22 +6,20 @@ namespace Rubberduck.Inspections { - public class ObsoleteTypeHintInspection : IInspection + public sealed class ObsoleteTypeHintInspection : InspectionBase { - public ObsoleteTypeHintInspection() + public ObsoleteTypeHintInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Suggestion; } - public string Name { get { return "ObsoleteTypeHintInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI._ObsoleteTypeHint_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI._ObsoleteTypeHint_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var results = state.AllUserDeclarations.ToList(); + var results = UserDeclarations.ToList(); var declarations = from item in results where item.HasTypeHint() diff --git a/RetailCoder.VBE/Inspections/ObsoleteTypeHintInspectionResult.cs b/RetailCoder.VBE/Inspections/ObsoleteTypeHintInspectionResult.cs index 51af2af710..320ec47ba9 100644 --- a/RetailCoder.VBE/Inspections/ObsoleteTypeHintInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/ObsoleteTypeHintInspectionResult.cs @@ -18,9 +18,10 @@ public class ObsoleteTypeHintInspectionResult : CodeInspectionResultBase public ObsoleteTypeHintInspectionResult(IInspection inspection, string result, QualifiedContext qualifiedContext, Declaration declaration) : base(inspection, result, qualifiedContext.ModuleName, qualifiedContext.Context) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { new RemoveTypeHintsQuickFix(Context, QualifiedSelection, declaration), + new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/OptionBaseInspection.cs b/RetailCoder.VBE/Inspections/OptionBaseInspection.cs index 40ccc7c6e8..c28ec30642 100644 --- a/RetailCoder.VBE/Inspections/OptionBaseInspection.cs +++ b/RetailCoder.VBE/Inspections/OptionBaseInspection.cs @@ -4,33 +4,24 @@ using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.UI; -using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodePane; namespace Rubberduck.Inspections { - public class OptionBaseInspection : IInspection + public sealed class OptionBaseInspection : InspectionBase { - private readonly ICodePaneWrapperFactory _wrapperFactory; - - public OptionBaseInspection() + public OptionBaseInspection(RubberduckParserState state) + : base(state) { - _wrapperFactory = new CodePaneWrapperFactory(); Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "OptionBaseInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.OptionBase; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } - public CodeInspectionSeverity Severity { get; set; } - - private string AnnotationName { get { return Name.Replace("Inspection", string.Empty); } } + public override string Description { get { return RubberduckUI.OptionBase; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var options = state.AllUserDeclarations - .Where(declaration => !declaration.IsInspectionDisabled(AnnotationName) - && declaration.DeclarationType == DeclarationType.ModuleOption + var options = UserDeclarations + .Where(declaration => declaration.DeclarationType == DeclarationType.ModuleOption && declaration.Context is VBAParser.OptionBaseStmtContext) .ToList(); diff --git a/RetailCoder.VBE/Inspections/OptionExplicitInspection.cs b/RetailCoder.VBE/Inspections/OptionExplicitInspection.cs index af5dea436f..e6f3bc339a 100644 --- a/RetailCoder.VBE/Inspections/OptionExplicitInspection.cs +++ b/RetailCoder.VBE/Inspections/OptionExplicitInspection.cs @@ -7,18 +7,16 @@ namespace Rubberduck.Inspections { - public class OptionExplicitInspection : IInspection + public sealed class OptionExplicitInspection : InspectionBase { - public OptionExplicitInspection() + public OptionExplicitInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "OptionExplicitInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.OptionExplicit; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.OptionExplicit; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } private static readonly DeclarationType[] ModuleTypes = { @@ -26,9 +24,9 @@ public OptionExplicitInspection() DeclarationType.Class }; - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var results = state.AllUserDeclarations.ToList(); + var results = UserDeclarations.ToList(); var options = results .Where(declaration => declaration.DeclarationType == DeclarationType.ModuleOption diff --git a/RetailCoder.VBE/Inspections/ParameterCanBeByValInspection.cs b/RetailCoder.VBE/Inspections/ParameterCanBeByValInspection.cs index a29478d2b1..dad3d1941d 100644 --- a/RetailCoder.VBE/Inspections/ParameterCanBeByValInspection.cs +++ b/RetailCoder.VBE/Inspections/ParameterCanBeByValInspection.cs @@ -8,18 +8,16 @@ namespace Rubberduck.Inspections { - public class ParameterCanBeByValInspection : IInspection + public sealed class ParameterCanBeByValInspection : InspectionBase { - public ParameterCanBeByValInspection() + public ParameterCanBeByValInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { { return "ParameterCanBeByValInspection"; } } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ParameterCanBeByVal_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.ParameterCanBeByVal_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } // if we don't want to suggest passing non-primitive types ByRef (i.e. object types and Variant), then we need this: private static readonly string[] PrimitiveTypes = @@ -38,9 +36,9 @@ public ParameterCanBeByValInspection() Tokens.StrPtr }; - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var declarations = state.AllDeclarations.ToList(); + var declarations = UserDeclarations.ToList(); var interfaceMembers = declarations.FindInterfaceMembers() .Concat(declarations.FindInterfaceImplementationMembers()) diff --git a/RetailCoder.VBE/Inspections/ParameterNotUsedInspection.cs b/RetailCoder.VBE/Inspections/ParameterNotUsedInspection.cs index 8155824b92..3173f10de3 100644 --- a/RetailCoder.VBE/Inspections/ParameterNotUsedInspection.cs +++ b/RetailCoder.VBE/Inspections/ParameterNotUsedInspection.cs @@ -13,13 +13,14 @@ namespace Rubberduck.Inspections { - public class ParameterNotUsedInspection : IInspection + public sealed class ParameterNotUsedInspection : InspectionBase { private readonly VBE _vbe; private readonly IMessageBox _messageBox; private readonly ICodePaneWrapperFactory _wrapperFactory; - public ParameterNotUsedInspection(VBE vbe, IMessageBox messageBox) + public ParameterNotUsedInspection(VBE vbe, RubberduckParserState state, IMessageBox messageBox) + : base(state) { _vbe = vbe; // todo: remove this dependency _messageBox = messageBox; @@ -27,15 +28,12 @@ public ParameterNotUsedInspection(VBE vbe, IMessageBox messageBox) Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "ParameterNotUsedInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ParameterNotUsed_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.ParameterNotUsed_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var declarations = state.AllDeclarations.ToList(); + var declarations = UserDeclarations.ToList(); var interfaceMemberScopes = declarations.FindInterfaceMembers().Select(m => m.Scope).ToList(); var interfaceImplementationMemberScopes = declarations.FindInterfaceImplementationMembers().Select(m => m.Scope).ToList(); @@ -50,11 +48,11 @@ public IEnumerable GetInspectionResults(RubberduckPars var quickFixRefactoring = new RemoveParametersRefactoring( new RemoveParametersPresenterFactory(editor, - new RemoveParametersDialog(), state, _messageBox), editor); + new RemoveParametersDialog(), State, _messageBox), editor); var issues = from issue in unused.Where(parameter => !IsInterfaceMemberParameter(parameter, interfaceMemberScopes)) let isInterfaceImplementationMember = IsInterfaceMemberImplementationParameter(issue, interfaceImplementationMemberScopes) - select new ParameterNotUsedInspectionResult(this, string.Format(Description, issue.IdentifierName), ((dynamic)issue.Context).ambiguousIdentifier(), issue.QualifiedName, isInterfaceImplementationMember, quickFixRefactoring, state); + select new ParameterNotUsedInspectionResult(this, string.Format(Description, issue.IdentifierName), ((dynamic)issue.Context).ambiguousIdentifier(), issue.QualifiedName, isInterfaceImplementationMember, quickFixRefactoring, State); return issues.ToList(); } diff --git a/RetailCoder.VBE/Inspections/ParameterNotUsedInspectionResult.cs b/RetailCoder.VBE/Inspections/ParameterNotUsedInspectionResult.cs index ce4e596073..c79089ce0f 100644 --- a/RetailCoder.VBE/Inspections/ParameterNotUsedInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/ParameterNotUsedInspectionResult.cs @@ -16,9 +16,10 @@ public ParameterNotUsedInspectionResult(IInspection inspection, string result, RemoveParametersRefactoring refactoring, RubberduckParserState parseResult) : base(inspection, result, qualifiedName.QualifiedModuleName, context) { - _quickFixes = isInterfaceImplementation ? new CodeInspectionQuickFix[] {} : new[] + _quickFixes = isInterfaceImplementation ? new CodeInspectionQuickFix[] {} : new CodeInspectionQuickFix[] { new RemoveUnusedParameterQuickFix(Context, QualifiedSelection, refactoring, parseResult), + new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/ProcedureNotUsedInspection.cs b/RetailCoder.VBE/Inspections/ProcedureNotUsedInspection.cs index 7dabd0c820..07fa1e3fc9 100644 --- a/RetailCoder.VBE/Inspections/ProcedureNotUsedInspection.cs +++ b/RetailCoder.VBE/Inspections/ProcedureNotUsedInspection.cs @@ -10,22 +10,20 @@ namespace Rubberduck.Inspections { - public class ProcedureNotUsedInspection : IInspection + public sealed class ProcedureNotUsedInspection : InspectionBase { - public ProcedureNotUsedInspection() + public ProcedureNotUsedInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "ProcedureNotUsedInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.ProcedureNotUsed_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.ProcedureNotUsed_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var declarations = state.AllUserDeclarations.ToList(); + var declarations = UserDeclarations.ToList(); var classes = declarations.Where(item => item.DeclarationType == DeclarationType.Class).ToList(); var modules = declarations.Where(item => item.DeclarationType == DeclarationType.Module).ToList(); diff --git a/RetailCoder.VBE/Inspections/UnassignedVariableUsageInspection.cs b/RetailCoder.VBE/Inspections/UnassignedVariableUsageInspection.cs index 14d00942fd..2a78abad26 100644 --- a/RetailCoder.VBE/Inspections/UnassignedVariableUsageInspection.cs +++ b/RetailCoder.VBE/Inspections/UnassignedVariableUsageInspection.cs @@ -1,37 +1,34 @@ using System.Collections.Generic; using System.Linq; -using Rubberduck.Parsing; using Rubberduck.Parsing.Symbols; using Rubberduck.Parsing.VBA; using Rubberduck.UI; namespace Rubberduck.Inspections { - public class UnassignedVariableUsageInspection //: IInspection // disabled + public sealed class UnassignedVariableUsageInspection : InspectionBase { - public UnassignedVariableUsageInspection() + public UnassignedVariableUsageInspection(RubberduckParserState state) + : base(state) { - Severity = CodeInspectionSeverity.Warning; + Severity = CodeInspectionSeverity.Error; } - public string Name { get { return RubberduckUI.UnassignedVariableUsage_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } + public override string Description { get { return RubberduckUI.UnassignedVariableUsage_; } } - public IEnumerable GetInspectionResults(RubberduckParserState parseResult) + public override IEnumerable GetInspectionResults() { - var usages = parseResult.AllUserDeclarations.Where(declaration => + var usages = UserDeclarations.Where(declaration => declaration.DeclarationType == DeclarationType.Variable && !declaration.References.Any(reference => reference.IsAssignment)) - .SelectMany(declaration => declaration.References); + .SelectMany(declaration => declaration.References) + .Where(usage => !usage.IsInspectionDisabled(AnnotationName)); foreach (var issue in usages) { - //todo: add context to IdentifierReference - //yield return new UnassignedVariableUsageInspectionResult(string.Format(Name, issue.Context.GetText()), Severity, issue.Context, issue.QualifiedName); + yield return new UnassignedVariableUsageInspectionResult(this, string.Format(Description, issue.Context.GetText()), issue.Context, issue.QualifiedModuleName); } - - return null; } } } \ No newline at end of file diff --git a/RetailCoder.VBE/Inspections/UnassignedVariableUsageInspectionResult.cs b/RetailCoder.VBE/Inspections/UnassignedVariableUsageInspectionResult.cs index 50c88b55ac..8f6e65ed32 100644 --- a/RetailCoder.VBE/Inspections/UnassignedVariableUsageInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/UnassignedVariableUsageInspectionResult.cs @@ -14,9 +14,10 @@ public UnassignedVariableUsageInspectionResult(IInspection inspection, string re ParserRuleContext context, QualifiedModuleName qualifiedName) : base(inspection, result, qualifiedName, context) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { - new RemoveUnassignedVariableUsageQuickFix(Context, QualifiedSelection) + new RemoveUnassignedVariableUsageQuickFix(Context, QualifiedSelection), + new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspection.cs b/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspection.cs index 90256e364e..f1c4071363 100644 --- a/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspection.cs +++ b/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspection.cs @@ -7,18 +7,16 @@ namespace Rubberduck.Inspections { - public class UntypedFunctionUsageInspection : IInspection + public sealed class UntypedFunctionUsageInspection : InspectionBase { - public UntypedFunctionUsageInspection() + public UntypedFunctionUsageInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Hint; } - public string Name { get { return "UntypedFunctionUsageInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.UntypedFunctionUsage_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.UntypedFunctionUsage_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } private readonly string[] _tokens = { Tokens.Error, @@ -44,9 +42,9 @@ public UntypedFunctionUsageInspection() Tokens.UCase }; - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var declarations = state.AllDeclarations + var declarations = UserDeclarations .Where(item => item.IsBuiltIn && item.Accessibility == Accessibility.Global && _tokens.Contains(item.IdentifierName)); return declarations.SelectMany(declaration => declaration.References diff --git a/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspectionResult.cs b/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspectionResult.cs index 2d0c7b116c..07694de569 100644 --- a/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspectionResult.cs @@ -12,9 +12,10 @@ public class UntypedFunctionUsageInspectionResult : CodeInspectionResultBase public UntypedFunctionUsageInspectionResult(IInspection inspection, string result, QualifiedModuleName qualifiedName, ParserRuleContext context) : base(inspection, result, qualifiedName, context) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { new UntypedFunctionUsageQuickFix(Context, QualifiedSelection), + new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/UseMeaningfulNameInspection.cs b/RetailCoder.VBE/Inspections/UseMeaningfulNameInspection.cs index a1fe10dad3..9469b5ae9d 100644 --- a/RetailCoder.VBE/Inspections/UseMeaningfulNameInspection.cs +++ b/RetailCoder.VBE/Inspections/UseMeaningfulNameInspection.cs @@ -6,31 +6,29 @@ namespace Rubberduck.Inspections { - public class UseMeaningfulNameInspection : IInspection + public sealed class UseMeaningfulNameInspection : InspectionBase { private readonly IMessageBox _messageBox; private readonly ICodePaneWrapperFactory _wrapperFactory; - public UseMeaningfulNameInspection(IMessageBox messageBox) + public UseMeaningfulNameInspection(IMessageBox messageBox, RubberduckParserState state) + : base(state) { _messageBox = messageBox; _wrapperFactory = new CodePaneWrapperFactory(); Severity = CodeInspectionSeverity.Suggestion; } - public string Name { get { return "UseMeaningfulNameInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return InspectionsUI.UseMeaningfulNameInspection; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return InspectionsUI.UseMeaningfulNameInspection; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var issues = state.AllUserDeclarations + var issues = UserDeclarations .Where(declaration => declaration.IdentifierName.Length < 3 || char.IsDigit(declaration.IdentifierName.Last()) || !declaration.IdentifierName.Any(c => new[] {'a', 'e', 'i', 'o', 'u', 'y'}.Contains(c))) - .Select(issue => new UseMeaningfulNameInspectionResult(this, issue, state, _wrapperFactory, _messageBox)) + .Select(issue => new UseMeaningfulNameInspectionResult(this, issue, State, _wrapperFactory, _messageBox)) .ToList(); return issues; diff --git a/RetailCoder.VBE/Inspections/UseMeaningfulNameInspectionResult.cs b/RetailCoder.VBE/Inspections/UseMeaningfulNameInspectionResult.cs index a687b6af79..e1c8989c91 100644 --- a/RetailCoder.VBE/Inspections/UseMeaningfulNameInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/UseMeaningfulNameInspectionResult.cs @@ -17,9 +17,10 @@ public class UseMeaningfulNameInspectionResult : CodeInspectionResultBase public UseMeaningfulNameInspectionResult(IInspection inspection, Declaration target, RubberduckParserState parserState, ICodePaneWrapperFactory wrapperFactory, IMessageBox messageBox) : base(inspection, string.Format(inspection.Description, RubberduckUI.ResourceManager.GetString("DeclarationType_" + target.DeclarationType, RubberduckUI.Culture), target.IdentifierName), target) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { new RenameDeclarationQuickFix(target.Context, target.QualifiedSelection, target, parserState, wrapperFactory, messageBox), + new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; } @@ -32,15 +33,15 @@ public UseMeaningfulNameInspectionResult(IInspection inspection, Declaration tar public class RenameDeclarationQuickFix : CodeInspectionQuickFix { private readonly Declaration _target; - private readonly RubberduckParserState _parserState; + private readonly RubberduckParserState _state; private readonly ICodePaneWrapperFactory _wrapperFactory; private readonly IMessageBox _messageBox; - public RenameDeclarationQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState parserState, ICodePaneWrapperFactory wrapperFactory, IMessageBox messageBox) + public RenameDeclarationQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState state, ICodePaneWrapperFactory wrapperFactory, IMessageBox messageBox) : base(context, selection, string.Format(RubberduckUI.Rename_DeclarationType, RubberduckUI.ResourceManager.GetString("DeclarationType_" + target.DeclarationType, RubberduckUI.Culture))) { _target = target; - _parserState = parserState; + _state = state; _wrapperFactory = wrapperFactory; _messageBox = messageBox; } @@ -51,8 +52,8 @@ public override void Fix() using (var view = new RenameDialog()) { - var factory = new RenamePresenterFactory(vbe, view, _parserState, _messageBox, _wrapperFactory); - var refactoring = new RenameRefactoring(factory, new ActiveCodePaneEditor(vbe, _wrapperFactory), _messageBox); + var factory = new RenamePresenterFactory(vbe, view, _state, _messageBox, _wrapperFactory); + var refactoring = new RenameRefactoring(factory, new ActiveCodePaneEditor(vbe, _wrapperFactory), _messageBox, _state); refactoring.Refactor(_target); } } diff --git a/RetailCoder.VBE/Inspections/VariableNotAssignedInspection.cs b/RetailCoder.VBE/Inspections/VariableNotAssignedInspection.cs index 9f5562d7bb..81f4a9af06 100644 --- a/RetailCoder.VBE/Inspections/VariableNotAssignedInspection.cs +++ b/RetailCoder.VBE/Inspections/VariableNotAssignedInspection.cs @@ -6,22 +6,20 @@ namespace Rubberduck.Inspections { - public class VariableNotAssignedInspection : IInspection + public sealed class VariableNotAssignedInspection : InspectionBase { - public VariableNotAssignedInspection() + public VariableNotAssignedInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "VariableNotAssignedInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.VariableNotAssigned_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.VariableNotAssigned_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var items = state.AllUserDeclarations.ToList(); + var items = UserDeclarations.ToList(); // ignore arrays. todo: ArrayIndicesNotAccessedInspection var arrays = items.Where(declaration => diff --git a/RetailCoder.VBE/Inspections/VariableNotUsedInspection.cs b/RetailCoder.VBE/Inspections/VariableNotUsedInspection.cs index 872550f491..2ed70f51cf 100644 --- a/RetailCoder.VBE/Inspections/VariableNotUsedInspection.cs +++ b/RetailCoder.VBE/Inspections/VariableNotUsedInspection.cs @@ -6,22 +6,20 @@ namespace Rubberduck.Inspections { - public class VariableNotUsedInspection : IInspection + public sealed class VariableNotUsedInspection : InspectionBase { - public VariableNotUsedInspection() + public VariableNotUsedInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "VariableNotUsedInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.VariableNotUsed_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.VariableNotUsed_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var declarations = state.AllUserDeclarations.Where(declaration => + var declarations = UserDeclarations.Where(declaration => !declaration.IsWithEvents && declaration.DeclarationType == DeclarationType.Variable && declaration.References.All(reference => reference.IsAssignment)); diff --git a/RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspection.cs b/RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspection.cs index 3b88e2ad1c..f3b23f6d7b 100644 --- a/RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspection.cs +++ b/RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspection.cs @@ -6,22 +6,20 @@ namespace Rubberduck.Inspections { - public class VariableTypeNotDeclaredInspection : IInspection + public sealed class VariableTypeNotDeclaredInspection : InspectionBase { - public VariableTypeNotDeclaredInspection() + public VariableTypeNotDeclaredInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "VariableTypeNotDeclaredInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI._TypeNotDeclared_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI._TypeNotDeclared_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var issues = from item in state.AllUserDeclarations + var issues = from item in UserDeclarations where (item.DeclarationType == DeclarationType.Variable || item.DeclarationType == DeclarationType.Constant || item.DeclarationType == DeclarationType.Parameter) diff --git a/RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspectionResult.cs b/RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspectionResult.cs index 7ffb7dab44..0c55448a46 100644 --- a/RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspectionResult.cs @@ -14,9 +14,10 @@ public class VariableTypeNotDeclaredInspectionResult : CodeInspectionResultBase public VariableTypeNotDeclaredInspectionResult(IInspection inspection, string result, ParserRuleContext context, QualifiedModuleName qualifiedName) : base(inspection, result, qualifiedName, context) { - _quickFixes = new[] + _quickFixes = new CodeInspectionQuickFix[] { new DeclareAsExplicitVariantQuickFix(Context, QualifiedSelection), + new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; } diff --git a/RetailCoder.VBE/Inspections/WriteOnlyPropertyInspection.cs b/RetailCoder.VBE/Inspections/WriteOnlyPropertyInspection.cs index ce7195f2d3..5cc6f4cae4 100644 --- a/RetailCoder.VBE/Inspections/WriteOnlyPropertyInspection.cs +++ b/RetailCoder.VBE/Inspections/WriteOnlyPropertyInspection.cs @@ -6,22 +6,20 @@ namespace Rubberduck.Inspections { - public class WriteOnlyPropertyInspection : IInspection + public sealed class WriteOnlyPropertyInspection : InspectionBase { - public WriteOnlyPropertyInspection() + public WriteOnlyPropertyInspection(RubberduckParserState state) + : base(state) { Severity = CodeInspectionSeverity.Warning; } - public string Name { get { return "WriteOnlyPropertyInspection"; } } - public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } } - public string Description { get { return RubberduckUI.WriteOnlyProperty_; } } - public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public CodeInspectionSeverity Severity { get; set; } + public override string Description { get { return RubberduckUI.WriteOnlyProperty_; } } + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } - public IEnumerable GetInspectionResults(RubberduckParserState state) + public override IEnumerable GetInspectionResults() { - var declarations = state.AllUserDeclarations.ToList(); + var declarations = UserDeclarations.ToList(); var setters = declarations .Where(item => (item.Accessibility == Accessibility.Implicit || diff --git a/RetailCoder.VBE/Refactorings/Rename/RenamePresenterFactory.cs b/RetailCoder.VBE/Refactorings/Rename/RenamePresenterFactory.cs index 67575469f0..e823f28013 100644 --- a/RetailCoder.VBE/Refactorings/Rename/RenamePresenterFactory.cs +++ b/RetailCoder.VBE/Refactorings/Rename/RenamePresenterFactory.cs @@ -26,8 +26,7 @@ public RenamePresenterFactory(VBE vbe, IRenameView view, RubberduckParserState p public RenamePresenter Create() { var codePane = _wrapperFactory.Create(_vbe.ActiveCodePane); - var selection = new QualifiedSelection(new QualifiedModuleName(codePane.CodeModule.Parent), - codePane.Selection); + var selection = _vbe.ActiveCodePane == null ? new QualifiedSelection() : new QualifiedSelection(new QualifiedModuleName(codePane.CodeModule.Parent), codePane.Selection); return new RenamePresenter(_view, new RenameModel(_vbe, _parseResult, selection, _messageBox)); } } diff --git a/RetailCoder.VBE/Refactorings/Rename/RenameRefactoring.cs b/RetailCoder.VBE/Refactorings/Rename/RenameRefactoring.cs index ee041a3302..145691095c 100644 --- a/RetailCoder.VBE/Refactorings/Rename/RenameRefactoring.cs +++ b/RetailCoder.VBE/Refactorings/Rename/RenameRefactoring.cs @@ -9,6 +9,7 @@ using Rubberduck.Parsing; using Rubberduck.Parsing.Grammar; using Rubberduck.Parsing.Symbols; +using Rubberduck.Parsing.VBA; using Rubberduck.UI; using Rubberduck.VBEditor; @@ -19,13 +20,15 @@ public class RenameRefactoring : IRefactoring private readonly IRefactoringPresenterFactory _factory; private readonly IActiveCodePaneEditor _editor; private readonly IMessageBox _messageBox; + private readonly RubberduckParserState _state; private RenameModel _model; - public RenameRefactoring(IRefactoringPresenterFactory factory, IActiveCodePaneEditor editor, IMessageBox messageBox) + public RenameRefactoring(IRefactoringPresenterFactory factory, IActiveCodePaneEditor editor, IMessageBox messageBox, RubberduckParserState state) { _factory = factory; _editor = editor; _messageBox = messageBox; + _state = state; } public void Refactor() @@ -212,6 +215,7 @@ private void RenameProject() if (project != null) { project.Name = _model.NewName; + _state.RemoveDeclaration(_model.Target); } } catch (COMException) diff --git a/RetailCoder.VBE/Root/RubberduckModule.cs b/RetailCoder.VBE/Root/RubberduckModule.cs index 419fe7038b..5dfb9d3741 100644 --- a/RetailCoder.VBE/Root/RubberduckModule.cs +++ b/RetailCoder.VBE/Root/RubberduckModule.cs @@ -15,6 +15,7 @@ using Rubberduck.Settings; using Rubberduck.SmartIndenter; using Rubberduck.UI; +using Rubberduck.UI.CodeExplorer; using Rubberduck.UI.CodeInspections; using Rubberduck.UI.Command; using Rubberduck.UI.UnitTesting; @@ -73,6 +74,11 @@ public override void Load() .InSingletonScope() .WithConstructorArgument(new CodeInspectionsWindow { ViewModel = _kernel.Get() }); + Bind().To() + .WhenInjectedInto() + .InSingletonScope() + .WithConstructorArgument(new CodeExplorerWindow { ViewModel = _kernel.Get() }); + BindWindowsHooks(); Debug.Print("completed RubberduckModule.Load()"); } @@ -123,7 +129,7 @@ private void BindCodeInspectionTypes() { var inspections = Assembly.GetExecutingAssembly() .GetTypes() - .Where(type => type.GetInterfaces().Contains(typeof (IInspection))); + .Where(type => type.BaseType == typeof (InspectionBase)); // multibinding for IEnumerable dependency foreach (var inspection in inspections) diff --git a/RetailCoder.VBE/Rubberduck.csproj b/RetailCoder.VBE/Rubberduck.csproj index a06c42535c..f13b1cffbb 100644 --- a/RetailCoder.VBE/Rubberduck.csproj +++ b/RetailCoder.VBE/Rubberduck.csproj @@ -295,13 +295,16 @@ + + True True InspectionsUI.resx + @@ -391,9 +394,12 @@ BusyIndicator.xaml + CodeExplorerControl.xaml + + @@ -1096,8 +1102,8 @@ - - + + diff --git a/RetailCoder.VBE/Settings/CodeInspectionSettings.cs b/RetailCoder.VBE/Settings/CodeInspectionSettings.cs index 67da0cabab..a3640afb98 100644 --- a/RetailCoder.VBE/Settings/CodeInspectionSettings.cs +++ b/RetailCoder.VBE/Settings/CodeInspectionSettings.cs @@ -31,6 +31,9 @@ public class CodeInspectionSetting : IInspectionModel [XmlIgnore] public string Description { get; set; } // not serialized because culture-dependent + [XmlIgnore] + public string AnnotationName { get; set; } + [XmlAttribute] public CodeInspectionSeverity Severity { get; set; } diff --git a/RetailCoder.VBE/UI/CodeExplorer/CodeExplorerComponentViewModel.cs b/RetailCoder.VBE/UI/CodeExplorer/CodeExplorerComponentViewModel.cs new file mode 100644 index 0000000000..8008b0c6b5 --- /dev/null +++ b/RetailCoder.VBE/UI/CodeExplorer/CodeExplorerComponentViewModel.cs @@ -0,0 +1,87 @@ +using System.Collections.Generic; +using System.Linq; +using Microsoft.Vbe.Interop; +using Rubberduck.Parsing.Symbols; + +namespace Rubberduck.UI.CodeExplorer +{ + public class CodeExplorerComponentViewModel : ViewModelBase + { + private readonly Declaration _declaration; + private readonly IEnumerable _members; + + private static readonly DeclarationType[] MemberTypes = + { + DeclarationType.Constant, + DeclarationType.Enumeration, + DeclarationType.Event, + DeclarationType.Function, + DeclarationType.LibraryFunction, + DeclarationType.LibraryProcedure, + DeclarationType.Procedure, + DeclarationType.PropertyGet, + DeclarationType.PropertyLet, + DeclarationType.PropertySet, + DeclarationType.UserDefinedType, + DeclarationType.Variable, + }; + + public CodeExplorerComponentViewModel(Declaration declaration, IEnumerable declarations) + { + _declaration = declaration; + _members = declarations.GroupBy(item => item.Scope) + .SelectMany(grouping => + grouping.Where(item => item.ParentDeclaration != null && item.ParentDeclaration.Equals(declaration) && MemberTypes.Contains(item.DeclarationType)) + .Select(item => new CodeExplorerMemberViewModel(item, grouping))) + .OrderBy(item => item.Name) + .ToList(); + + _customFolder = declaration.CustomFolder; + } + + public IEnumerable Members { get { return _members; } } + + private bool _isErrorState; + public bool IsErrorState { get { return _isErrorState; } set { _isErrorState = value; OnPropertyChanged(); } } + + public bool IsTestModule + { + get + { + return _declaration.DeclarationType == DeclarationType.Module + && _declaration.Annotations.Split('\n').Contains(Parsing.Grammar.Annotations.TestModule); + } + } + + public string Name { get { return _declaration.IdentifierName; } } + + private readonly string _customFolder; + public string CustomFolder { get { return _customFolder; } } + + public string TypeFolder { get { return DeclarationType.ToString(); } } + + private vbext_ComponentType ComponentType { get { return _declaration.QualifiedName.QualifiedModuleName.Component.Type; } } + + private static readonly IDictionary DeclarationTypes = new Dictionary + { + { vbext_ComponentType.vbext_ct_ClassModule, DeclarationType.Class }, + { vbext_ComponentType.vbext_ct_StdModule, DeclarationType.Module }, + { vbext_ComponentType.vbext_ct_Document, DeclarationType.Document }, + { vbext_ComponentType.vbext_ct_MSForm, DeclarationType.UserForm } + }; + + public DeclarationType DeclarationType + { + get + { + DeclarationType result; + if (!DeclarationTypes.TryGetValue(ComponentType, out result)) + { + result = DeclarationType.Class; + } + + return result; + } + } + } +} \ No newline at end of file diff --git a/RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml b/RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml index c100d8ddf5..8bd89934ea 100644 --- a/RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml +++ b/RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml @@ -4,10 +4,12 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:explorer="clr-namespace:Rubberduck.UI.CodeExplorer" + xmlns:symbols="clr-namespace:Rubberduck.Parsing.Symbols;assembly=Rubberduck.Parsing" xmlns:resx="clr-namespace:Rubberduck.UI" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" + xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase" mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="300"> + d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance explorer:CodeExplorerViewModel}"> @@ -76,82 +78,50 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - + + + + + + - + + + - - - - - + + @@ -174,39 +144,28 @@ - - + - + - + -