Netbeans declarative syntax for a statement inside a try-block

I would like to test and convert a specific expression into a try-with-ressources form. But I feel that the syntax of the declarative hint format eludes me for this.

I tried:

<!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$ 

But the template applied to my code never matches. Here is a sample code that I expected would match:

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

Any idea why this is not consistent? Especially because I think the example from the documentation matches mine, with the exception of finally :

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

Update. Jackpot- Rules seems to use the same syntax, probably because it uses the same code base.

+7
java refactoring netbeans
source share
2 answers

This refactoring is very cumbersome and poorly documented. You must modify your template according to this example.

 <!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$ 

However, I do not know how to do this if you have other methods that also call 3 arguments.

+1
source share

According to me, the code uses a return, which, I think, cannot be used instead of $ after $. Therefore, if you remove this from your code, it may match.

0
source share

All Articles