2015-05-22 24 views
7

我想要檢查並將轉換爲具有try-with-ressources形式的特定語句。但我有這種感覺,declarative hints format的語法不適合我。Netbeans聲明式提示語句,用於嘗試塊內的語句

我想:

<!description="Stmt into try-with-resources"> 
try { 
    $before$; 
    someMethod($arg1, $arg2, $arg3); 
    $after$; 
} catch $catches$ 
=> 
try (Resource res = acquire($arg1, $arg2, $arg3))  { 
    $before$; 
    res.use(); 
    $after$; 
} catch $catches$ 

但應用在我的代碼模式永遠不匹配。下面是一些示例代碼段,這是我預期相符:

public boolean step(String input) { 
    String id = getId(ID); 
    try { 
    SomethingBefore(); 
    someMethod(10, "label", name); 
    return true; 
    } catch (Exception ex) { 
    log.error("problem", ex); 
    return true; 
    } 
} 

知道爲什麼這不匹配? ESP。因爲我覺得從文檔的例子匹配礦,除了finally

try { 
    $statements$; 
} catch $catches$ 
    finally { 
    $finally$; 
} 

更新:看來,Jackpot -Rules使用相同的語法,可能是因爲它使用相同的代碼庫。

回答

1

此重構非常繁瑣且記錄不完整。你必須根據這個例子

<!description="Stmt into try-with-resources"> 
try { 
    $before$; 
    $name($arg1, $arg2, $arg3); 
    $after$; 
} catch $catches$ 
=> 
try (Resource res = acquire($arg1, $arg2, $arg3))  { 
    $before$; 
    res.use(); 
    $after$; 
} catch $catches$ 

改變你的模式。然而,我不知道如何處理這一點,如果你有其他的方法調用3個參數爲好。

0

根據我在代碼中返回正在使用,我不認爲可以用在$美元后的地方。所以如果你從你的代碼中刪除它可能會匹配。