I'm trying to work with IntelliJ's structural search to find any local variables declared final. I'm using the following:
class $Class$ {
$ReturnType$ $Method$ ($ParameterType$ $Parameter$) {
$S$; [0,inf]
final $Type$ $Name$ = $Init$;
$St$; [0,inf]
}
}
This seems to match, for example, as expected:
public static void main (String[] args) {
System.out.println("Hello world");
final double q = 1;
}
But it seems to fail on nested statements, for example:
public static void main (String[] args) {
if (true) {
final double q = 1;
}
}
Is there a way to match these within an arbitrary number of nested statements?
Use a template like below. It finds all final variables and checks if they are local using a script modifier.
Depending on your use case, you may also be able to use the "Unnecessary 'final' on local variable or parameter" inspection using
Code | Analyze Code | Run Inspection by Name.