Skip to content

Commit 9fed0b3

Browse files
committed
Add RequiredArguments to IAnnotation
It specifies the minimal number of arguments for the annotation.
1 parent 03bf899 commit 9fed0b3

20 files changed

+65
-99
lines changed

Rubberduck.Parsing/Annotations/AnnotationBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ namespace Rubberduck.Parsing.Annotations
66
public abstract class AnnotationBase : IAnnotation
77
{
88
public bool AllowMultiple { get; }
9+
public int RequiredArguments { get; }
910
public string Name { get; }
1011
public AnnotationTarget Target { get; }
1112

12-
protected AnnotationBase(string name, AnnotationTarget target, bool allowMultiple = false)
13+
protected AnnotationBase(string name, AnnotationTarget target, int requiredArguments = 0, bool allowMultiple = false)
1314
{
1415
Name = name;
1516
Target = target;
1617
AllowMultiple = allowMultiple;
18+
RequiredArguments = requiredArguments;
1719
}
1820

1921
public virtual IReadOnlyList<string> ProcessAnnotationArguments(IEnumerable<string> arguments)
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Linq;
4-
using Rubberduck.Parsing.Grammar;
5-
using Rubberduck.VBEditor;
63

74
namespace Rubberduck.Parsing.Annotations
85
{
96
public abstract class FixedAttributeValueAnnotationBase : AnnotationBase, IAttributeAnnotation
107
{
11-
private readonly string attribute;
12-
private readonly IReadOnlyList<string> attributeValues;
8+
private readonly string _attribute;
9+
private readonly IReadOnlyList<string> _attributeValues;
1310

1411
protected FixedAttributeValueAnnotationBase(string name, AnnotationTarget target, string attribute, IEnumerable<string> attributeValues, bool allowMultiple = false)
15-
: base(name, target, allowMultiple)
12+
: base(name, target, allowMultiple: allowMultiple)
1613
{
1714
// IEnumerable makes specifying the compile-time constant list easier on us
18-
this.attributeValues = attributeValues.ToList();
19-
this.attribute = attribute;
15+
_attributeValues = attributeValues.ToList();
16+
_attribute = attribute;
2017
}
2118

2219
public IReadOnlyList<string> AnnotationToAttributeValues(IReadOnlyList<string> annotationValues)
2320
{
24-
return attributeValues;
21+
return _attributeValues;
2522
}
2623

2724
public string Attribute(IReadOnlyList<string> annotationValues)
2825
{
29-
return attribute;
26+
return _attribute;
3027
}
3128

3229
public IReadOnlyList<string> AttributeToAnnotationValues(IReadOnlyList<string> attributeValues)
@@ -37,7 +34,7 @@ public IReadOnlyList<string> AttributeToAnnotationValues(IReadOnlyList<string> a
3734

3835
public bool MatchesAttributeDefinition(string attributeName, IReadOnlyList<string> attributeValues)
3936
{
40-
return attribute == attributeName && this.attributeValues.SequenceEqual(attributeValues);
37+
return _attribute == attributeName && this._attributeValues.SequenceEqual(attributeValues);
4138
}
4239
}
4340
}

Rubberduck.Parsing/Annotations/Concrete/FlexibleAttributeAnnotationBase.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using Rubberduck.Common;
4-
using Rubberduck.Parsing.Grammar;
5-
using Rubberduck.VBEditor;
64

75
namespace Rubberduck.Parsing.Annotations
86
{
97
public abstract class FlexibleAttributeAnnotationBase : AnnotationBase, IAttributeAnnotation
108
{
119
protected FlexibleAttributeAnnotationBase(string name, AnnotationTarget target, bool allowMultiple = false)
12-
: base(name, target, allowMultiple)
13-
{ }
10+
: base(name, target, 2, allowMultiple) //We need at least the attribute name and one value for it.
11+
{}
1412

1513
public IReadOnlyList<string> AnnotationToAttributeValues(IReadOnlyList<string> annotationValues)
1614
{

Rubberduck.Parsing/Annotations/Concrete/FlexibleAttributeValueAnnotationBase.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using Rubberduck.Common;
5-
using Rubberduck.Parsing.Grammar;
6-
using Rubberduck.VBEditor;
75

86
namespace Rubberduck.Parsing.Annotations
97
{
@@ -13,7 +11,7 @@ public abstract class FlexibleAttributeValueAnnotationBase : AnnotationBase, IAt
1311
private readonly int _numberOfValues;
1412

1513
protected FlexibleAttributeValueAnnotationBase(string name, AnnotationTarget target, string attribute, int numberOfValues)
16-
: base(name, target)
14+
: base(name, target, numberOfValues)
1715
{
1816
_attribute = attribute;
1917
_numberOfValues = numberOfValues;
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
using Rubberduck.VBEditor;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using Rubberduck.Parsing.Grammar;
5-
6-
namespace Rubberduck.Parsing.Annotations
1+
namespace Rubberduck.Parsing.Annotations
72
{
83
/// <summary>
94
/// Used for specifying the Code Explorer folder a appears under.
105
/// </summary>
116
public sealed class FolderAnnotation : AnnotationBase
127
{
138
public FolderAnnotation()
14-
: base("Folder", AnnotationTarget.Module)
15-
{ }
9+
: base("Folder", AnnotationTarget.Module, 1)
10+
{}
1611
}
1712
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
using Rubberduck.VBEditor;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using Rubberduck.Parsing.Grammar;
5-
6-
namespace Rubberduck.Parsing.Annotations
1+
namespace Rubberduck.Parsing.Annotations
72
{
83
/// <summary>
94
/// Used for ignoring specific inspection results from a specified set of inspections.
105
/// </summary>
116
public sealed class IgnoreAnnotation : AnnotationBase
127
{
138
public IgnoreAnnotation()
14-
: base("Ignore", AnnotationTarget.General, true)
15-
{ }
9+
: base("Ignore", AnnotationTarget.General, 1, true)
10+
{}
1611
}
1712
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
3-
using Rubberduck.Parsing.Grammar;
4-
using Rubberduck.VBEditor;
5-
6-
namespace Rubberduck.Parsing.Annotations
1+
namespace Rubberduck.Parsing.Annotations
72
{
83
/// <summary>
94
/// This annotation allows ignoring inspection results of defined inspections for a whole module
105
/// </summary>
116
public sealed class IgnoreModuleAnnotation : AnnotationBase
127
{
138
public IgnoreModuleAnnotation()
14-
: base("IgnoreModule", AnnotationTarget.Module, true)
15-
{ }
9+
: base("IgnoreModule", AnnotationTarget.Module, 1, true)
10+
{}
1611
}
1712
}

Rubberduck.Parsing/Annotations/Concrete/IgnoreTestAnnotation.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System.Collections.Generic;
2-
using Rubberduck.Parsing.Grammar;
3-
using Rubberduck.VBEditor;
4-
5-
namespace Rubberduck.Parsing.Annotations
1+
namespace Rubberduck.Parsing.Annotations
62
{
73
/// <summary>
84
/// Used to indicate the test engine that a unit test is to be ignored.

Rubberduck.Parsing/Annotations/Concrete/InterfaceAnnotation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ public sealed class InterfaceAnnotation : AnnotationBase
77
{
88
public InterfaceAnnotation()
99
: base("Interface", AnnotationTarget.Module)
10-
{ }
10+
{}
1111
}
1212
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using Rubberduck.VBEditor;
2-
using System.Collections.Generic;
3-
using Rubberduck.Parsing.Grammar;
4-
5-
namespace Rubberduck.Parsing.Annotations
1+
namespace Rubberduck.Parsing.Annotations
62
{
73
/// <summary>
84
/// Marks a method that the test engine will execute after all unit tests in a test module have executed.
@@ -11,6 +7,6 @@ public sealed class ModuleCleanupAnnotation : AnnotationBase, ITestAnnotation
117
{
128
public ModuleCleanupAnnotation()
139
: base("ModuleCleanup", AnnotationTarget.Member)
14-
{ }
10+
{}
1511
}
1612
}

0 commit comments

Comments
 (0)