结构替换删除异常

发布于 2024-12-28 18:32:11 字数 655 浏览 4 评论 0原文

我想删除一个不应该存在的异常。我找不到允许在方法声明中删除的模式。

此代码:

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

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

应该转换为:

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

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

以下模式检索我想要的内容,但我找不到正确的替换模式。

class $Class$ { 
   $ReturnType$ $MethodName$($ParameterType$ $Parameter$) throws ShouldHaveNeverExisted;
}

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百思不得你姐 2025-01-04 18:32:11

搜索模式:

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

替换模式:

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

主要注意事项是“编辑变量”并打开 $Method$ 变量的“此变量是搜索目标”复选框(每次尝试时,不幸的是)。此外,$SomeStatement$ 的最大计数必须不受限制。

然后 IDEA 11.0.1 确实可以正确搜索。即使对于 throws 子句中的任何顺序的异常也是如此。它甚至在单击“预览替换”按钮时显示正确的结果。
但实际上只是删除找到的方法。 :(

这似乎是一个错误。请有人确认。

顺便说一句。如果您要在任何地方摆脱此异常,为什么不直接将“throws ShouldHaveNeverExisted”替换为“”,并使用常规“Edit\Find\Replace in Path Ctrl+” Shift+R”?

或者您可以在异常的类上按 Del 并选中“安全删除(带用法搜索)”。

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)".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文