@@ -2938,8 +2938,7 @@ impl JavaAnalyzer {
29382938
29392939 fn extract_class_modifiers ( & self , content : & str , class_name : & str ) -> Vec < String > {
29402940 let regex = Regex :: new ( & format ! (
2941- r"((?:public|private|protected|abstract|final|static)\s+)*class\s+{}" ,
2942- class_name
2941+ r"((?:public|private|protected|abstract|final|static)\s+)*class\s+{class_name}"
29432942 ) )
29442943 . unwrap ( ) ;
29452944 regex
@@ -3604,8 +3603,7 @@ impl JavaAnalyzer {
36043603 . collect:: <String >( )
36053604 ) ;
36063605 let getter_pattern = format ! (
3607- r"(?m)^\s*(?:public|protected)\s+\w+(?:<[^>]+>)?\s+{}\s*\(\s*\)" ,
3608- getter_name
3606+ r"(?m)^\s*(?:public|protected)\s+\w+(?:<[^>]+>)?\s+{getter_name}\s*\(\s*\)"
36093607 ) ;
36103608 let has_getter = Regex :: new ( & getter_pattern)
36113609 . unwrap ( )
@@ -3623,8 +3621,7 @@ impl JavaAnalyzer {
36233621 . collect:: <String >( )
36243622 ) ;
36253623 let setter_pattern = format ! (
3626- r"(?m)^\s*(?:public|protected)\s+(?:void|{0})\s+{1}\s*\([^)]+\)" ,
3627- class_name, setter_name
3624+ r"(?m)^\s*(?:public|protected)\s+(?:void|{class_name})\s+{setter_name}\s*\([^)]+\)"
36283625 ) ;
36293626 let has_setter = Regex :: new ( & setter_pattern)
36303627 . unwrap ( )
@@ -3637,8 +3634,7 @@ impl JavaAnalyzer {
36373634 // Check for validation in setter (basic pattern matching)
36383635 let validation_in_setter = if has_setter {
36393636 let setter_content_pattern = format ! (
3640- r"(?s){}[^{{]*\{{[^}}]*(?:if|throw|validate|check|assert)[^}}]*\}}" ,
3641- setter_name
3637+ r"(?s){setter_name}[^{{]*\{{[^}}]*(?:if|throw|validate|check|assert)[^}}]*\}}"
36423638 ) ;
36433639 Regex :: new ( & setter_content_pattern)
36443640 . unwrap ( )
@@ -4163,10 +4159,9 @@ impl JavaAnalyzer {
41634159 violations. push ( SOLIDViolation {
41644160 principle : SOLIDPrinciple :: SingleResponsibility ,
41654161 class_name : class_name. clone ( ) ,
4166- description : format ! (
4167- "Class {} has {} different types of responsibilities" ,
4168- class_name, responsibility_count
4169- ) ,
4162+ description : format ! (
4163+ "Class {class_name} has {responsibility_count} different types of responsibilities"
4164+ ) ,
41704165 severity : if responsibility_count > 3 {
41714166 ViolationSeverity :: High
41724167 } else {
@@ -4209,8 +4204,7 @@ impl JavaAnalyzer {
42094204 principle : SOLIDPrinciple :: InterfaceSegregation ,
42104205 class_name : interface_name. clone ( ) ,
42114206 description : format ! (
4212- "Interface {} has {} methods, which is too many" ,
4213- interface_name, method_count
4207+ "Interface {interface_name} has {method_count} methods, which is too many"
42144208 ) ,
42154209 severity : if method_count > 10 {
42164210 ViolationSeverity :: High
@@ -4254,8 +4248,7 @@ impl JavaAnalyzer {
42544248 principle : SOLIDPrinciple :: DependencyInversion ,
42554249 class_name : class_name. clone ( ) ,
42564250 description : format ! (
4257- "Direct instantiation of {} appears {} times" ,
4258- class_name, count
4251+ "Direct instantiation of {class_name} appears {count} times"
42594252 ) ,
42604253 severity : ViolationSeverity :: Medium ,
42614254 recommendation :
@@ -4304,8 +4297,7 @@ impl JavaAnalyzer {
43044297 for ( annotation, component_type) in component_patterns {
43054298 // Find all occurrences of the annotation
43064299 let annotation_regex = Regex :: new ( & format ! (
4307- r"{}(?:\([^)]*\))?\s+(?:public\s+)?class\s+(\w+)" ,
4308- annotation
4300+ r"{annotation}(?:\([^)]*\))?\s+(?:public\s+)?class\s+(\w+)"
43094301 ) ) ?;
43104302
43114303 for captures in annotation_regex. captures_iter ( content) {
@@ -4402,8 +4394,7 @@ impl JavaAnalyzer {
44024394
44034395 // Find the class definition and extract all annotations above it
44044396 let class_regex = Regex :: new ( & format ! (
4405- r"((?:@\w+(?:\([^)]*\))?\s*)*)\s*(?:public\s+)?class\s+{}" ,
4406- class_name
4397+ r"((?:@\w+(?:\([^)]*\))?\s*)*)\s*(?:public\s+)?class\s+{class_name}"
44074398 ) )
44084399 . unwrap ( ) ;
44094400
@@ -4447,8 +4438,7 @@ impl JavaAnalyzer {
44474438 fn extract_component_scope ( & self , content : & str , class_name : & str ) -> String {
44484439 // Look for @Scope annotation
44494440 let scope_regex = Regex :: new ( & format ! (
4450- r#"@Scope\s*\(\s*["']([^"']+)["']\s*\).*?class\s+{}"# ,
4451- class_name
4441+ r#"@Scope\s*\(\s*["']([^"']+)["']\s*\).*?class\s+{class_name}"#
44524442 ) )
44534443 . unwrap ( ) ;
44544444
@@ -4462,8 +4452,7 @@ impl JavaAnalyzer {
44624452 fn extract_class_content ( & self , content : & str , class_name : & str ) -> String {
44634453 // Find class definition and extract content between braces
44644454 let class_regex = Regex :: new ( & format ! (
4465- r"class\s+{}\s*\{{([^{{}}]*(?:\{{[^{{}}]*\}}[^{{}}]*)*)\}}" ,
4466- class_name
4455+ r"class\s+{class_name}\s*\{{([^{{}}]*(?:\{{[^{{}}]*\}}[^{{}}]*)*)\}}"
44674456 ) )
44684457 . unwrap ( ) ;
44694458
@@ -4476,11 +4465,8 @@ impl JavaAnalyzer {
44764465
44774466 fn assess_di_best_practices ( & self , content : & str , field_name : & str ) -> bool {
44784467 // Check if field is final (constructor injection) or properly encapsulated
4479- let field_regex = Regex :: new ( & format ! (
4480- r"(?:private\s+)?(?:final\s+)?\w+\s+{}" ,
4481- field_name
4482- ) )
4483- . unwrap ( ) ;
4468+ let field_regex =
4469+ Regex :: new ( & format ! ( r"(?:private\s+)?(?:final\s+)?\w+\s+{field_name}" ) ) . unwrap ( ) ;
44844470
44854471 if let Some ( field_match) = field_regex. find ( content) {
44864472 let field_def = field_match. as_str ( ) ;
@@ -5679,8 +5665,7 @@ impl JavaAnalyzer {
56795665
56805666 // Find implemented interfaces
56815667 let implements_regex = Regex :: new ( & format ! (
5682- r"record\s+{}\s*\([^)]*\)\s*implements\s+([\w\s,]+)" ,
5683- record_name
5668+ r"record\s+{record_name}\s*\([^)]*\)\s*implements\s+([\w\s,]+)"
56845669 ) ) ?;
56855670 let implements_interfaces = if let Some ( captures) = implements_regex. captures ( content) {
56865671 captures
0 commit comments