File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -432,3 +432,44 @@ switch (r) {
432432    case  R  _ - >  {}
433433}
434434``` 
435+ 
436+ ### ` useSwitchForInstanceofPattern `  
437+ 
438+ Convert if/else chains to pattern matching switch statements.
439+ 
440+ For example:
441+ 
442+ ``` java 
443+ int  i, j;
444+ double  d;
445+ boolean  b;
446+ if  (x instanceof  Integer  xint) {
447+     i =  xint. intValue();
448+ } else  if  (x instanceof  Double  xdouble) {
449+     d =  xdouble. doubleValue();
450+ } else  if  (x instanceof  Boolean  xboolean) {
451+     b =  xboolean. booleanValue();
452+ } else  {
453+     i =  0 ;
454+     d =  0.0D ;
455+     b =  false ;
456+ }
457+ ``` 
458+ 
459+ becomes:
460+ 
461+ ``` java 
462+ int  i, j;
463+ double  d;
464+ boolean  b;
465+ switch  (x) {
466+     case  Integer  xint - >  i =  xint. intValue();
467+     case  Double  xdouble - >  d =  xdouble. doubleValue();
468+     case  Boolean  xboolean - >  b =  xboolean. booleanValue();
469+     case  null , default  - >  {
470+         i =  0 ;
471+         d =  0.0D ;
472+         b =  false ;
473+     }
474+ }
475+ ``` 
Original file line number Diff line number Diff line change 13141314                " tryWithResource" 
13151315                " renameFileToType" 
13161316                " organizeImports" 
1317-                 " renameUnusedLocalVariables" 
1317+                 " renameUnusedLocalVariables" 
1318+                 " useSwitchForInstanceofPattern" 
13181319              ]
13191320            },
13201321            "default" : [
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments