Skip to content

Commit a2794f6

Browse files
author
Andrin Meier
committed
replace annoations from comments with IAnnotation
1 parent 1adfd05 commit a2794f6

27 files changed

+233
-130
lines changed

RetailCoder.VBE/Inspections/MultipleFolderAnnotationsInspection.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using Rubberduck.Parsing.Symbols;
44
using Rubberduck.Parsing.VBA;
5+
using Rubberduck.Parsing.Annotations;
56

67
namespace Rubberduck.Inspections
78
{
@@ -21,9 +22,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
2122
var issues = UserDeclarations.Where(declaration =>
2223
(declaration.DeclarationType == DeclarationType.Class
2324
|| declaration.DeclarationType == DeclarationType.Module)
24-
&& declaration.Annotations.Split('\n').Count(annotation =>
25-
annotation.StartsWith(Parsing.Grammar.Annotations.AnnotationMarker +
26-
Parsing.Grammar.Annotations.Folder)) > 1);
25+
&& declaration.Annotations.Count(annotation => annotation.AnnotationType == AnnotationType.Folder) > 1);
2726
return issues.Select(issue =>
2827
new MultipleFolderAnnotationsInspectionResult(this, issue));
2928
}

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerComponentViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Rubberduck.Parsing.Symbols;
88
using Rubberduck.VBEditor;
99
using resx = Rubberduck.UI.CodeExplorer.CodeExplorer;
10+
using Rubberduck.Parsing.Annotations;
1011

1112
namespace Rubberduck.Navigation.CodeExplorer
1213
{
@@ -50,8 +51,8 @@ public bool IsTestModule
5051
{
5152
get
5253
{
53-
return _declaration.DeclarationType == DeclarationType.Module
54-
&& _declaration.Annotations.Split('\n').Contains(Parsing.Grammar.Annotations.TestModule);
54+
return _declaration.DeclarationType == DeclarationType.Module
55+
&& _declaration.Annotations.Any(annotation => annotation.AnnotationType == AnnotationType.TestModule);
5556
}
5657
}
5758

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
1-
using Rubberduck.Parsing.Grammar;
1+
using Rubberduck.VBEditor;
22

33
namespace Rubberduck.Parsing.Annotations
44
{
55
public abstract class AnnotationBase : IAnnotation
66
{
7-
private readonly VBAParser.AnnotationContext _context;
87
private readonly AnnotationType _annotationType;
9-
private readonly AnnotationTargetType _targetType;
8+
private readonly QualifiedSelection _qualifiedSelection;
109

1110
public const string ANNOTATION_MARKER = "'@";
1211

13-
public AnnotationBase(VBAParser.AnnotationContext context, AnnotationType annotationType, AnnotationTargetType targetType)
12+
public AnnotationBase(AnnotationType annotationType, QualifiedSelection qualifiedSelection)
1413
{
15-
_context = context;
1614
_annotationType = annotationType;
17-
_targetType = targetType;
18-
}
19-
20-
public VBAParser.AnnotationContext Context
21-
{
22-
get
23-
{
24-
return _context;
25-
}
15+
_qualifiedSelection = qualifiedSelection;
2616
}
2717

2818
public AnnotationType AnnotationType
@@ -33,17 +23,17 @@ public AnnotationType AnnotationType
3323
}
3424
}
3525

36-
public AnnotationTargetType TargetType
26+
public QualifiedSelection QualifiedSelection
3727
{
3828
get
3929
{
40-
return _targetType;
30+
return _qualifiedSelection;
4131
}
4232
}
4333

4434
public override string ToString()
4535
{
46-
return string.Format("Annotation Type: {0}. TargetType: {1}.", _annotationType, _targetType);
36+
return string.Format("Annotation Type: {0}", _annotationType);
4737
}
4838
}
4939
}

Rubberduck.Parsing/Annotations/AnnotationListener.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Antlr4.Runtime.Misc;
22
using Rubberduck.Parsing.Grammar;
3+
using Rubberduck.VBEditor;
34
using System.Collections.Generic;
45

56
namespace Rubberduck.Parsing.Annotations
@@ -8,11 +9,13 @@ public sealed class AnnotationListener : VBAParserBaseListener
89
{
910
private readonly List<IAnnotation> _annotations;
1011
private readonly IAnnotationFactory _factory;
12+
private readonly QualifiedModuleName _qualifiedName;
1113

12-
public AnnotationListener(IAnnotationFactory factory)
14+
public AnnotationListener(IAnnotationFactory factory, QualifiedModuleName qualifiedName)
1315
{
1416
_annotations = new List<IAnnotation>();
1517
_factory = factory;
18+
_qualifiedName = qualifiedName;
1619
}
1720

1821
public IEnumerable<IAnnotation> Annotations
@@ -25,7 +28,7 @@ public IEnumerable<IAnnotation> Annotations
2528

2629
public override void ExitAnnotation([NotNull] VBAParser.AnnotationContext context)
2730
{
28-
var newAnnotation = _factory.Create(context, AnnotationTargetType.Unknown);
31+
var newAnnotation = _factory.Create(context, new QualifiedSelection(_qualifiedName, context.GetSelection()));
2932
_annotations.Add(newAnnotation);
3033
}
3134
}

Rubberduck.Parsing/Annotations/AnnotationTargetType.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

Rubberduck.Parsing/Annotations/FolderAnnotation.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Rubberduck.Parsing.Grammar;
1+
using Rubberduck.VBEditor;
22
using System.Collections.Generic;
33
using System.Linq;
44

@@ -8,8 +8,10 @@ public sealed class FolderAnnotation : AnnotationBase
88
{
99
private readonly string _folderName;
1010

11-
public FolderAnnotation(VBAParser.AnnotationContext context, AnnotationTargetType targetType, IEnumerable<string> parameters)
12-
: base(context, AnnotationType.Folder, targetType)
11+
public FolderAnnotation(
12+
QualifiedSelection qualifiedSelection,
13+
IEnumerable<string> parameters)
14+
: base(AnnotationType.Folder, qualifiedSelection)
1315
{
1416
if (parameters.Count() != 1)
1517
{
@@ -28,7 +30,7 @@ public string FolderName
2830

2931
public override string ToString()
3032
{
31-
return string.Format("Folder: {0}.", _folderName);
33+
return string.Format("Folder: {0}", _folderName);
3234
}
3335
}
3436
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using Rubberduck.Parsing.Grammar;
2+
using Rubberduck.VBEditor;
23

34
namespace Rubberduck.Parsing.Annotations
45
{
56
public interface IAnnotation
67
{
78
AnnotationType AnnotationType { get; }
8-
VBAParser.AnnotationContext Context { get; }
9-
AnnotationTargetType TargetType { get; }
9+
QualifiedSelection QualifiedSelection { get; }
1010
}
1111
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using Antlr4.Runtime;
2-
using Rubberduck.Parsing.Grammar;
3-
using Rubberduck.Parsing.Symbols;
1+
using Rubberduck.Parsing.Grammar;
2+
using Rubberduck.VBEditor;
43

54
namespace Rubberduck.Parsing.Annotations
65
{
76
public interface IAnnotationFactory
87
{
9-
IAnnotation Create(VBAParser.AnnotationContext annotationContext, AnnotationTargetType targetType);
8+
IAnnotation Create(VBAParser.AnnotationContext context, QualifiedSelection qualifiedSelection);
109
}
1110
}

Rubberduck.Parsing/Annotations/IgnoreAnnotation.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Rubberduck.Parsing.Grammar;
2+
using Rubberduck.VBEditor;
23
using System.Collections.Generic;
34
using System.Linq;
45

@@ -8,8 +9,10 @@ public sealed class IgnoreAnnotation : AnnotationBase
89
{
910
private readonly IEnumerable<string> _inspectionNames;
1011

11-
public IgnoreAnnotation(VBAParser.AnnotationContext context, AnnotationTargetType targetType, IEnumerable<string> parameters)
12-
: base(context, AnnotationType.Ignore, targetType)
12+
public IgnoreAnnotation(
13+
QualifiedSelection qualifiedSelection,
14+
IEnumerable<string> parameters)
15+
: base(AnnotationType.Ignore, qualifiedSelection)
1316
{
1417
if (!parameters.Any())
1518
{
@@ -33,7 +36,7 @@ public bool IsIgnored(string inspectionName)
3336

3437
public override string ToString()
3538
{
36-
return string.Format("Ignored inspections: {0}.", string.Join(", ", _inspectionNames));
39+
return string.Format("Ignored inspections: {0}", string.Join(", ", _inspectionNames));
3740
}
3841
}
3942
}

Rubberduck.Parsing/Annotations/ModuleCleanupAnnotation.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
using Rubberduck.Parsing.Grammar;
2+
using Rubberduck.VBEditor;
23
using System.Collections.Generic;
34

45
namespace Rubberduck.Parsing.Annotations
56
{
67
public sealed class ModuleCleanupAnnotation : AnnotationBase
78
{
8-
public ModuleCleanupAnnotation(VBAParser.AnnotationContext context, AnnotationTargetType targetType, IEnumerable<string> parameters)
9-
: base(context, AnnotationType.TestMethod, targetType)
9+
public ModuleCleanupAnnotation(
10+
QualifiedSelection qualifiedSelection,
11+
IEnumerable<string> parameters)
12+
: base(AnnotationType.TestMethod, qualifiedSelection)
1013
{
1114
}
1215
}

0 commit comments

Comments
 (0)