@@ -45,7 +45,8 @@ pub fn capture_opt(m: &QueryMatch, name: &str) -> Result<Option<Cursor>> {
45
45
}
46
46
47
47
/// Validation options to control which lints generate a diagnostic
48
- #[ derive( Debug , Clone ) ]
48
+ #[ derive( Debug , Clone , bon:: Builder ) ]
49
+ #[ non_exhaustive]
49
50
pub struct ValidationOptions {
50
51
/// Whether overridden, public and external functions should have an `@inheritdoc`
51
52
pub inheritdoc : bool ,
@@ -105,7 +106,8 @@ pub trait Validate {
105
106
/// An identifier (named or unnamed) and its span
106
107
///
107
108
/// Unnamed identifiers are used for unnamed return params.
108
- #[ derive( Debug , Clone ) ]
109
+ #[ derive( Debug , Clone , bon:: Builder ) ]
110
+ #[ builder( on( String , into) ) ]
109
111
pub struct Identifier {
110
112
pub name : Option < String > ,
111
113
pub span : TextRange ,
@@ -124,7 +126,8 @@ pub enum Visibility {
124
126
}
125
127
126
128
/// Attributes for a function or state variable (visibility and override)
127
- #[ derive( Debug , Clone , Copy , Default ) ]
129
+ #[ derive( Debug , Clone , Copy , Default , bon:: Builder ) ]
130
+ #[ non_exhaustive]
128
131
pub struct Attributes {
129
132
pub visibility : Visibility ,
130
133
pub r#override : bool ,
@@ -185,6 +188,70 @@ impl Definition {
185
188
Definition :: Variable ( def) => def. validate ( options) ,
186
189
}
187
190
}
191
+
192
+ /// Retrieve the inner constructor definition
193
+ pub fn as_constructor ( self ) -> Option < ConstructorDefinition > {
194
+ match self {
195
+ Definition :: Constructor ( def) => Some ( def) ,
196
+ _ => None ,
197
+ }
198
+ }
199
+
200
+ /// Retrieve the inner enum definition
201
+ pub fn as_enum ( self ) -> Option < EnumDefinition > {
202
+ match self {
203
+ Definition :: Enumeration ( def) => Some ( def) ,
204
+ _ => None ,
205
+ }
206
+ }
207
+
208
+ /// Retrieve the inner error definition
209
+ pub fn as_error ( self ) -> Option < ErrorDefinition > {
210
+ match self {
211
+ Definition :: Error ( def) => Some ( def) ,
212
+ _ => None ,
213
+ }
214
+ }
215
+
216
+ /// Retrieve the inner event definition
217
+ pub fn as_event ( self ) -> Option < EventDefinition > {
218
+ match self {
219
+ Definition :: Event ( def) => Some ( def) ,
220
+ _ => None ,
221
+ }
222
+ }
223
+
224
+ /// Retrieve the inner function definition
225
+ pub fn as_function ( self ) -> Option < FunctionDefinition > {
226
+ match self {
227
+ Definition :: Function ( def) => Some ( def) ,
228
+ _ => None ,
229
+ }
230
+ }
231
+
232
+ /// Retrieve the inner modifier definition
233
+ pub fn as_modifier ( self ) -> Option < ModifierDefinition > {
234
+ match self {
235
+ Definition :: Modifier ( def) => Some ( def) ,
236
+ _ => None ,
237
+ }
238
+ }
239
+
240
+ /// Retrieve the inner struct definition
241
+ pub fn as_struct ( self ) -> Option < StructDefinition > {
242
+ match self {
243
+ Definition :: Struct ( def) => Some ( def) ,
244
+ _ => None ,
245
+ }
246
+ }
247
+
248
+ /// Retrieve the inner variable declaration
249
+ pub fn as_variable ( self ) -> Option < VariableDeclaration > {
250
+ match self {
251
+ Definition :: Variable ( def) => Some ( def) ,
252
+ _ => None ,
253
+ }
254
+ }
188
255
}
189
256
190
257
/// Find source item definitions from a root CST cursor
0 commit comments