|
| 1 | +using System.Collections.Generic; |
| 2 | +using Rubberduck.Parsing; |
| 3 | +using Rubberduck.Parsing.Annotations; |
| 4 | +using Rubberduck.Parsing.VBA; |
| 5 | +using Rubberduck.Parsing.Grammar; |
| 6 | + |
| 7 | +namespace Rubberduck.Inspections |
| 8 | +{ |
| 9 | + public sealed class MalformedAnnotationInspection : InspectionBase, IParseTreeInspection |
| 10 | + { |
| 11 | + public MalformedAnnotationInspection(RubberduckParserState state) |
| 12 | + : base(state, CodeInspectionSeverity.Error) |
| 13 | + { |
| 14 | + } |
| 15 | + |
| 16 | + public override string Meta { get { return InspectionsUI.MalformedAnnotationInspectionMeta; } } |
| 17 | + public override string Description { get { return InspectionsUI.MalformedAnnotationInspectionResultFormat; } } |
| 18 | + public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } } |
| 19 | + public ParseTreeResults ParseTreeResults { get; set; } |
| 20 | + |
| 21 | + public override IEnumerable<InspectionResultBase> GetInspectionResults() |
| 22 | + { |
| 23 | + if (ParseTreeResults == null) |
| 24 | + { |
| 25 | + return new InspectionResultBase[] { }; |
| 26 | + } |
| 27 | + |
| 28 | + var results = new List<MalformedAnnotationInspectionResult>(); |
| 29 | + |
| 30 | + foreach (var context in ParseTreeResults.MalformedAnnotations) |
| 31 | + { |
| 32 | + if (context.Context.annotationName().GetText() == AnnotationType.Ignore.ToString() || |
| 33 | + context.Context.annotationName().GetText() == AnnotationType.Folder.ToString()) |
| 34 | + { |
| 35 | + if (context.Context.annotationArgList() == null) |
| 36 | + { |
| 37 | + results.Add(new MalformedAnnotationInspectionResult(this, |
| 38 | + new QualifiedContext<VBAParser.AnnotationContext>(context.ModuleName, |
| 39 | + context.Context))); |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + return results; |
| 45 | + } |
| 46 | + |
| 47 | + public class MalformedAnnotationStatementListener : VBAParserBaseListener |
| 48 | + { |
| 49 | + private readonly IList<VBAParser.AnnotationContext> _contexts = new List<VBAParser.AnnotationContext>(); |
| 50 | + public IEnumerable<VBAParser.AnnotationContext> Contexts { get { return _contexts; } } |
| 51 | + |
| 52 | + public override void ExitAnnotation(VBAParser.AnnotationContext context) |
| 53 | + { |
| 54 | + if (context.annotationName() != null) |
| 55 | + { |
| 56 | + _contexts.Add(context); |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + public class MalformedAnnotationInspectionResult : InspectionResultBase |
| 63 | + { |
| 64 | + public MalformedAnnotationInspectionResult(IInspection inspection, QualifiedContext<VBAParser.AnnotationContext> qualifiedContext) |
| 65 | + : base(inspection, qualifiedContext.ModuleName, qualifiedContext.Context) |
| 66 | + { |
| 67 | + } |
| 68 | + |
| 69 | + public override string Description |
| 70 | + { |
| 71 | + get { return string.Format(Inspection.Description, ((VBAParser.AnnotationContext)Context).annotationName()); } |
| 72 | + } |
| 73 | + } |
| 74 | +} |
0 commit comments