代码之家  ›  专栏  ›  技术社区  ›  Joe

intellij在结构上将“thows oneexception,twoexception”替换为“only exception”

  •  0
  • Joe  · 技术社区  · 8 年前

    与 IntelliJ's s Structural Search and Replace 我要替换以下代码段:

    @Test
    public void myTest() throws ExecutionException, InterruptedException {}
    

    使用:

    @Test
    public void myTest() throws Exception {}
    

    目标是简化一些测试。如何配置文本约束来进行替换?

    IntelliJ Structural Replace

    1 回复  |  直到 8 年前
        1
  •  1
  •   Bas Leijdekkers    8 年前

    您还需要将@test注释添加到模板中。然后,搜索模板变为:

    @Test
    $ReturnType$ $Method$($ParameterType$ $Parameter$) throws $ExceptionType$;
    

    替换模板:

    @Test
    $ReturnType$ $Method$($ParameterType$ $Parameter$) throws Exception;
    

    限制条件:

    $Parameter$ 最小/最大 [0,unlimited]
    $ExceptionType$ 最小/最大 [0,无限制]