@@ -37,8 +37,14 @@ class Attributable extends @attributable {
37
37
}
38
38
39
39
private string getAttributeName ( Attribute a ) {
40
- exists ( string type | type = a .getType ( ) .getName ( ) |
41
- if type .matches ( "%Attribute" ) then result = type .prefix ( type .length ( ) - 9 ) else result = type
40
+ exists ( string type , string pattern |
41
+ type = a .getType ( ) .getName ( ) and pattern = "(.*)Attribute(<.*>)?"
42
+ |
43
+ type .regexpMatch ( pattern ) and
44
+ result = concat ( int i | i = [ 1 , 2 ] | type .regexpCapture ( pattern , i ) order by i )
45
+ or
46
+ not type .regexpMatch ( pattern ) and
47
+ result = type
42
48
)
43
49
}
44
50
@@ -99,6 +105,31 @@ class Attribute extends TopLevelExprParent, @attribute {
99
105
override string getAPrimaryQlClass ( ) { result = "Attribute" }
100
106
}
101
107
108
+ /**
109
+ * A generic attribute, for example `[...]` on line 1 in
110
+ *
111
+ * ```csharp
112
+ * [MyGenericAttribute<int>(0)]
113
+ * public void SomeMethod(string s) { }
114
+ * ```
115
+ */
116
+ class GenericAttribute extends Attribute {
117
+ private ConstructedClass type ;
118
+
119
+ GenericAttribute ( ) { type = this .getType ( ) }
120
+
121
+ /** Gets the total number of type arguments. */
122
+ int getNumberOfTypeArguments ( ) { result = count ( int i | type_arguments ( _, i , type ) ) }
123
+
124
+ /** Gets the `i`th type argument, if any. */
125
+ Type getTypeArgument ( int i ) { result = type .getTypeArgument ( i ) }
126
+
127
+ /** Get a type argument. */
128
+ Type getATypeArgument ( ) { result = this .getTypeArgument ( _) }
129
+
130
+ override string getAPrimaryQlClass ( ) { result = "GenericAttribute" }
131
+ }
132
+
102
133
/**
103
134
* An attribute with default kind, for example `[...]` on line 1 in
104
135
* ```csharp
@@ -110,6 +141,17 @@ class DefaultAttribute extends Attribute, @attribute_default {
110
141
override string getAPrimaryQlClass ( ) { result = "DefaultAttribute" }
111
142
}
112
143
144
+ /**
145
+ * A generic attribute with default kind, for example `[...]` on line 1 in
146
+ * ```csharp
147
+ * [MyAttribute<string>(0)]
148
+ * int SomeMethod() { return 1; }
149
+ * ```
150
+ */
151
+ class GenericDefaultAttribute extends GenericAttribute , DefaultAttribute {
152
+ override string getAPrimaryQlClass ( ) { result = "GenericDefaultAttribute" }
153
+ }
154
+
113
155
/**
114
156
* An attribute with return kind, for example `[...]` on line 1 in
115
157
* ```csharp
@@ -123,6 +165,17 @@ class ReturnAttribute extends Attribute, @attribute_return {
123
165
override string getAPrimaryQlClass ( ) { result = "ReturnAttribute" }
124
166
}
125
167
168
+ /**
169
+ * A generic attribute with return kind, for example `[...]` on line 1 in
170
+ * ```csharp
171
+ * [return: MyAttribute<object>(0)]
172
+ * int SomeMethod() { return 1; }
173
+ * ```
174
+ */
175
+ class GenericReturnAttribute extends GenericAttribute , ReturnAttribute {
176
+ override string getAPrimaryQlClass ( ) { result = "GenericReturnAttribute" }
177
+ }
178
+
126
179
/**
127
180
* An attribute with assembly kind, for example `[...]` on line 1 in
128
181
* ```csharp
@@ -135,6 +188,16 @@ class AssemblyAttribute extends Attribute, @attribute_assembly {
135
188
override string getAPrimaryQlClass ( ) { result = "AssemblyAttribute" }
136
189
}
137
190
191
+ /**
192
+ * A generic attribute with assembly kind, for example `[...]` on line 1 in
193
+ * ```csharp
194
+ * [assembly: MyAttribute<string>(0)]
195
+ * ```
196
+ */
197
+ class GenericAssemblyAttribute extends GenericAttribute , AssemblyAttribute {
198
+ override string getAPrimaryQlClass ( ) { result = "GenericAssemblyAttribute" }
199
+ }
200
+
138
201
/**
139
202
* An attribute with module kind, for example `[...]` on line 1 in
140
203
* ```csharp
@@ -146,3 +209,13 @@ class ModuleAttribute extends Attribute, @attribute_module {
146
209
147
210
override string getAPrimaryQlClass ( ) { result = "ModuleAttribute" }
148
211
}
212
+
213
+ /**
214
+ * A generic attribute with module kind, for example `[...]` on line 1 in
215
+ * ```csharp
216
+ * [module: MyAttribute<string>(0)]
217
+ * ```
218
+ */
219
+ class GenericModuleAttribute extends GenericAttribute , ModuleAttribute {
220
+ override string getAPrimaryQlClass ( ) { result = "GenericModuleAttribute" }
221
+ }
0 commit comments