Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans declarative hint syntax for a statement inside a try-block

I'd like to inspect and transform a specific statement into a try-with-ressources form. But I have the feeling the syntax of the declarative hints 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 applied on my code the pattern never matches. Here is some example code section which I expected to 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 does not match? Esp. because I think the example from the documentation matches mine, except for the finally:

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

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

like image 635
towi Avatar asked May 22 '15 12:05

towi


1 Answers

This refactoring is very cumbersome and poorly documented. You must change your pattern 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 don't know how to handle this if you have other methods calling 3 arguments as well.

like image 115
rst Avatar answered Nov 14 '22 23:11

rst