|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Linq; |
| 3 | +using Antlr4.Runtime; |
| 4 | +using Rubberduck.Inspections.Abstract; |
| 5 | +using Rubberduck.Inspections.Results; |
| 6 | +using Rubberduck.Parsing; |
| 7 | +using Rubberduck.Parsing.Grammar; |
| 8 | +using Rubberduck.Parsing.Inspections.Abstract; |
| 9 | +using Rubberduck.Parsing.VBA; |
| 10 | +using Rubberduck.Resources.Inspections; |
| 11 | +using Rubberduck.VBEditor; |
| 12 | + |
| 13 | +namespace Rubberduck.Inspections.Inspections.Concrete |
| 14 | +{ |
| 15 | + public sealed class ObsoleteCallingConventionInspection : ParseTreeInspectionBase |
| 16 | + { |
| 17 | + public ObsoleteCallingConventionInspection(RubberduckParserState state) |
| 18 | + : base(state) |
| 19 | + { |
| 20 | + Listener = new ObsoleteCallingConventionListener(); |
| 21 | + } |
| 22 | + |
| 23 | + public override IInspectionListener Listener { get; } |
| 24 | + |
| 25 | + protected override IEnumerable<IInspectionResult> DoGetInspectionResults() |
| 26 | + { |
| 27 | + return Listener.Contexts |
| 28 | + .Where(context => ((VBAParser.DeclareStmtContext) context.Context).CDECL() != null && |
| 29 | + !IsIgnoringInspectionResultFor(context.ModuleName, context.Context.Start.Line)) |
| 30 | + .Select(context => new QualifiedContextInspectionResult(this, |
| 31 | + string.Format(InspectionResults.ObsoleteCallingConventionInspection, |
| 32 | + ((VBAParser.DeclareStmtContext) context.Context).identifier().GetText()), context)); |
| 33 | + } |
| 34 | + |
| 35 | + public class ObsoleteCallingConventionListener : VBAParserBaseListener, IInspectionListener |
| 36 | + { |
| 37 | + private readonly List<QualifiedContext<ParserRuleContext>> _contexts = new List<QualifiedContext<ParserRuleContext>>(); |
| 38 | + public IReadOnlyList<QualifiedContext<ParserRuleContext>> Contexts => _contexts; |
| 39 | + |
| 40 | + public QualifiedModuleName CurrentModuleName { get; set; } |
| 41 | + |
| 42 | + public void ClearContexts() |
| 43 | + { |
| 44 | + _contexts.Clear(); |
| 45 | + } |
| 46 | + |
| 47 | + public override void ExitDeclareStmt(VBAParser.DeclareStmtContext context) |
| 48 | + { |
| 49 | + _contexts.Add(new QualifiedContext<ParserRuleContext>(CurrentModuleName, context)); |
| 50 | + base.ExitDeclareStmt(context); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments