Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Structural replace to delete an exception

I want to delete an exception that should have never existed. I can not find the pattern that allows the deletion in the method declarations.

This code :

public void method1(String param) throws ShouldHaveNeverExisted{
   System.out.println("Yo");
   //... 
}

public void method2WithoutParam() throws ShouldHaveNeverExisted{
   System.out.println("Yo");
   //... 
}

Should be transform in :

public void method1(String param){
   System.out.println("Yo");
   //... 
}

public void method2WithoutParam(){
   System.out.println("Yo");
   //... 
}

The following pattern retrieve what I want but I can't find the correct replacement pattern.

class $Class$ { 
   $ReturnType$ $MethodName$($ParameterType$ $Parameter$) throws ShouldHaveNeverExisted;
}
like image 363
GaetanZ Avatar asked Mar 01 '26 20:03

GaetanZ


1 Answers

Search pattern:

class $Class$ {
  $RetType$ $Method$($ParameterType$ $Parameter$) throws ShouldHaveNeverExisted, $ExceptionType$ {
      $SomeStatement$;
  }
}

Replacement pattern:

class $Class$ {
  $RetType$ $Method$($ParameterType$ $Parameter$) throws $ExceptionType$ {
      $SomeStatement$;
  }
}

The main caveat is to "Edit variables" and turn on "This variable is target of the search" checkbox for $Method$ variable (on every try, unfortunately). Also $SomeStatement$'s max count must be unlimited.

Then IDEA 11.0.1 does search correctly. Even for any order of exceptions in throws clause. And it even shows correct result on "Preview Replacement" button click. But then actually just deletes methods found. :(

This seems to be a bug. Please, someone confirm.

BTW. If you're getting rid of this exception anywhere, why not just replace "throws ShouldHaveNeverExisted" with "" with regular "Edit\Find\Replace in Path Ctrl+Shift+R"?

Or you could just hit Del on exception's class and check "Safe delete (with usage search)".

like image 180
Vadzim Avatar answered Mar 03 '26 10:03

Vadzim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!