@@ -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 } ;
@@ -205,6 +214,17 @@ impl SpBracesArgs {
205214 rbrace : node. rbrace . range ( ) ,
206215 } )
207216 }
217+ pub fn from_switch ( node : & SwitchContent ) -> Option < SpBracesArgs > {
218+ if node. cases . is_empty ( ) {
219+ return None ;
220+ }
221+ Some ( SpBracesArgs {
222+ body_start : node. cases . first ( ) . unwrap ( ) . range ( ) ,
223+ body_end : node. cases . last ( ) . unwrap ( ) . range ( ) ,
224+ lbrace : node. lbrace . range ( ) ,
225+ rbrace : node. rbrace . range ( ) ,
226+ } )
227+ }
208228}
209229
210230impl SpBracesRule {
@@ -453,6 +473,34 @@ impl SpPunctArgs {
453473 after_range_list,
454474 } )
455475 }
476+ pub fn from_instantiation ( node : & Instantiation ) -> Option < SpPunctArgs > {
477+ if let Instantiation :: Many ( _, templates_list, _) = node {
478+ let mut before_range_list = vec ! [ ] ;
479+ let mut punct_range_list = vec ! [ ] ;
480+ let mut after_range_list = vec ! [ ] ;
481+ let mut iterator = templates_list. iter ( ) . peekable ( ) ;
482+
483+ while let Some ( ( template_name, comma) ) = iterator. next ( ) {
484+ if let Some ( comma_token) = comma {
485+ before_range_list. push ( template_name. range ( ) ) ;
486+ punct_range_list. push ( comma_token. range ( ) ) ;
487+ if let Some ( ( next_template_name, _) ) = iterator. peek ( ) {
488+ after_range_list. push ( Some ( next_template_name. range ( ) ) ) ;
489+ } else {
490+ after_range_list. push ( None ) ;
491+ }
492+ }
493+ }
494+
495+ Some ( SpPunctArgs {
496+ before_range_list,
497+ punct_range_list,
498+ after_range_list,
499+ } )
500+ } else {
501+ None
502+ }
503+ }
456504}
457505
458506impl SpPunctRule {
@@ -587,6 +635,41 @@ impl NspInparenArgs {
587635 closing : node. rparen . range ( ) ,
588636 } )
589637 }
638+ pub fn from_composite_obj_content ( node : & CompositeObjectContent )
639+ -> Option < NspInparenArgs > {
640+ if node. dimensions . is_empty ( ) {
641+ return None ;
642+ }
643+ let dimension = node. dimensions . first ( ) . unwrap ( ) ;
644+ Some ( NspInparenArgs {
645+ opening : dimension. 0 . range ( ) ,
646+ content_start : dimension. 1 . range ( ) ,
647+ content_end : dimension. 3 . range ( ) ,
648+ closing : dimension. 4 . range ( ) ,
649+ } )
650+ }
651+ pub fn from_instantiation ( node : & Instantiation )
652+ -> Option < NspInparenArgs > {
653+ if let Instantiation :: Many ( lparen, templates, rparen) = node {
654+ Some ( NspInparenArgs {
655+ opening : lparen. range ( ) ,
656+ content_start : templates. range ( ) ,
657+ content_end : templates. range ( ) ,
658+ closing : rparen. range ( ) ,
659+ } )
660+ } else {
661+ None
662+ }
663+ }
664+ pub fn from_paren_expression ( node : & ParenExpressionContent )
665+ -> Option < NspInparenArgs > {
666+ Some ( NspInparenArgs {
667+ opening : node. lparen . range ( ) ,
668+ content_start : node. expr . range ( ) ,
669+ content_end : node. expr . range ( ) ,
670+ closing : node. rparen . range ( ) ,
671+ } )
672+ }
590673 pub fn from_function_call ( node : & FunctionCallContent )
591674 -> Option < NspInparenArgs > {
592675 let content_start_range;
0 commit comments