@@ -9,14 +9,23 @@ use crate::lint::{rules::{Rule, RuleType},
99 DMLStyleError } ;
1010use crate :: analysis:: parsing:: tree:: { LeafToken , TreeElement , ZeroRange } ;
1111use crate :: analysis:: parsing:: expression:: { BinaryExpressionContent ,
12- FunctionCallContent , IndexContent ,
12+ FunctionCallContent ,
13+ IndexContent ,
14+ ParenExpressionContent ,
1315 PostUnaryExpressionContent ,
1416 TertiaryExpressionContent ,
1517 UnaryExpressionContent } ;
16- use crate :: analysis:: parsing:: statement:: { AfterContent , CompoundContent , ExpressionStmtContent ,
17- ForContent , IfContent , VariableDeclContent ,
18+ use crate :: analysis:: parsing:: statement:: { AfterContent ,
19+ CompoundContent ,
20+ ExpressionStmtContent ,
21+ ForContent ,
22+ IfContent ,
23+ SwitchContent ,
24+ VariableDeclContent ,
1825 WhileContent } ;
19- use crate :: analysis:: parsing:: structure:: { MethodContent ,
26+ use crate :: analysis:: parsing:: structure:: { CompositeObjectContent ,
27+ Instantiation ,
28+ MethodContent ,
2029 ObjectStatementsContent } ;
2130
2231use crate :: span:: { ZeroIndexed , Range } ;
@@ -206,6 +215,17 @@ impl SpBracesArgs {
206215 rbrace : node. rbrace . range ( ) ,
207216 } )
208217 }
218+ pub fn from_switch ( node : & SwitchContent ) -> Option < SpBracesArgs > {
219+ if node. cases . is_empty ( ) {
220+ return None ;
221+ }
222+ Some ( SpBracesArgs {
223+ body_start : node. cases . first ( ) . unwrap ( ) . range ( ) ,
224+ body_end : node. cases . last ( ) . unwrap ( ) . range ( ) ,
225+ lbrace : node. lbrace . range ( ) ,
226+ rbrace : node. rbrace . range ( ) ,
227+ } )
228+ }
209229}
210230
211231impl SpBracesRule {
@@ -465,6 +485,34 @@ impl SpPunctArgs {
465485 after_range_list,
466486 } )
467487 }
488+ pub fn from_instantiation ( node : & Instantiation ) -> Option < SpPunctArgs > {
489+ if let Instantiation :: Many ( _, templates_list, _) = node {
490+ let mut before_range_list = vec ! [ ] ;
491+ let mut punct_range_list = vec ! [ ] ;
492+ let mut after_range_list = vec ! [ ] ;
493+ let mut iterator = templates_list. iter ( ) . peekable ( ) ;
494+
495+ while let Some ( ( template_name, comma) ) = iterator. next ( ) {
496+ if let Some ( comma_token) = comma {
497+ before_range_list. push ( template_name. range ( ) ) ;
498+ punct_range_list. push ( comma_token. range ( ) ) ;
499+ if let Some ( ( next_template_name, _) ) = iterator. peek ( ) {
500+ after_range_list. push ( Some ( next_template_name. range ( ) ) ) ;
501+ } else {
502+ after_range_list. push ( None ) ;
503+ }
504+ }
505+ }
506+
507+ Some ( SpPunctArgs {
508+ before_range_list,
509+ punct_range_list,
510+ after_range_list,
511+ } )
512+ } else {
513+ None
514+ }
515+ }
468516}
469517
470518impl SpPunctRule {
@@ -600,6 +648,41 @@ impl NspInparenArgs {
600648 closing : node. rparen . range ( ) ,
601649 } )
602650 }
651+ pub fn from_composite_obj_content ( node : & CompositeObjectContent )
652+ -> Option < NspInparenArgs > {
653+ if node. dimensions . is_empty ( ) {
654+ return None ;
655+ }
656+ let dimension = node. dimensions . first ( ) . unwrap ( ) ;
657+ Some ( NspInparenArgs {
658+ opening : dimension. 0 . range ( ) ,
659+ content_start : dimension. 1 . range ( ) ,
660+ content_end : dimension. 3 . range ( ) ,
661+ closing : dimension. 4 . range ( ) ,
662+ } )
663+ }
664+ pub fn from_instantiation ( node : & Instantiation )
665+ -> Option < NspInparenArgs > {
666+ if let Instantiation :: Many ( lparen, templates, rparen) = node {
667+ Some ( NspInparenArgs {
668+ opening : lparen. range ( ) ,
669+ content_start : templates. range ( ) ,
670+ content_end : templates. range ( ) ,
671+ closing : rparen. range ( ) ,
672+ } )
673+ } else {
674+ None
675+ }
676+ }
677+ pub fn from_paren_expression ( node : & ParenExpressionContent )
678+ -> Option < NspInparenArgs > {
679+ Some ( NspInparenArgs {
680+ opening : node. lparen . range ( ) ,
681+ content_start : node. expr . range ( ) ,
682+ content_end : node. expr . range ( ) ,
683+ closing : node. rparen . range ( ) ,
684+ } )
685+ }
603686 pub fn from_function_call ( node : & FunctionCallContent )
604687 -> Option < NspInparenArgs > {
605688 let content_start_range;
0 commit comments