Using variables inside the search syntax¶
There are certain scenarios where we want to match parts of the code against other parts. For example, when we define a logger, we want to make sure that we pass the name of the current class. These recipes use variables in the search part. This document will describe the quickest way to write such recipes.
Which variables are available?¶
The quickest way to list all available variables is to switch to the quick fix tab, and add
a rewrite
action. This will show a table below the input box with all the possible variables. All
these variables can also be used inside the search portion.
See also
Take a look at Templating for how to manipulate the variables.
Example¶
search:
instanceCreation:
args:
1:
not:
value: "{{{ containingClass.name }}}"
type: "java.lang.String"
type: "Logger"
class SomeClass {
Logger correct = new Logger("SomeClass");
Logger incorrect = new Logger("AnotherClass");
}