Reputation: 3260
I find the Structural Search and Replace feature in IntelliJ IDEs very powerful.
While browsing through the existing templates and discovering my new super powers I came accross the template called "logging without if
".
My spider sense urged me to check out the "without" part as it uses invert condition
in Complete Match
.
However, I am baffled by the expression used in Complete Match
.
Here it is:
if('_a) { 'st*; }
Please help me understand how this expression is used.
UPDATE 2017/01/19:
As pointed out by @Faibbus, the docs say that _a
and _st
are variables.
My confusion is with the variable names.
The names _a
and _st
only appear here, and nowhere else in the template.
What makes them variables? All other variables in Structural Search are surrounded by $dollar$
signs.
What is the role of the underscores as variable prefix?, what does the apostrophe do in that expression?
I don't find it clear at all. What am I missing?
Upvotes: 2
Views: 721
Reputation: 26462
The expression is using an internal search criteria language. With this language it is possible to specify a complete search query in text without needing all the text fields and checkboxes of the usual Structural Search dialog. This language maybe shouldn't have been exposed and will be more hidden in IntelliJ IDEA 2017.2.
That said, here's a short explanation of the features of the language used:
- a single tick mark indicates a variable. So there are two variables, _a
and st
.
- a variable not starting with an underscore indicates this variable is target of the search. There can be only one target per query. So st
is the target.
- the *
indicates zero or more times.
- the rest of the query is a regular Java fragment
For other features of this search criteria language you can check out the source if you are interested.
Upvotes: 1