2012-01-25 24 views
3

我想刪除了應該不可能存在異常。我無法找到允許在方法聲明中刪除的模式。結構替換刪除異常

此代碼:

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

回答

3

搜索模式:

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

替換模式:

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

主要告誡就是「編輯變量」,打開「這個變量是搜索的目標」複選框(每次嘗試時,unfortunately)。另外$SomeStatement$的最大數量必須是無限的。

然後IDEA 11.0.1沒有正確地進行搜索。即使對於throws條款中的任何例外順序。它甚至在「預覽替換」按鈕點擊時顯示正確的結果。 但實際上只是刪除找到的方法。 :(

這似乎是一個錯誤,請,有人確認。

順便說一句,如果你擺脫這個例外的任何地方,爲什麼不直接替換「拋出ShouldHaveNeverExisted」與「」定期「編輯\查找\在路徑替換按Ctrl + Shift + R「?

或者你可以只打德爾對異常的類,並檢查‘安全刪除(與使用搜索)’。

+1

我試過,但沒有第一和最後一行,想法表明該模式不支持!!!我可以通過Ctrl + Shift + R解決我的問題,但我想在結構查找和替換上取得進展。 – GaetanZ

+0

我幾乎設法使它工作。查看更新後的答案。 – Vadzim

+0

@Vadzim你有沒有得到這個工作正確?我得到相同*預覽是正確的,實際替換刪除方法*行爲。 –