aliteralmind
aliteralmind

Reputation: 20163

IntelliJ structural replace to find all if statements with no braces (having only one line if condition is met), and surround it with braces?

How can IntelliJ's structural replace feature be used to find all if statements having exactly one line (that's executed when the condition is met)

if (isNice)
   doSomething();

and surround them with curly braces?

if (isNice) {
   doSomething();
}

Surprisingly, this

if ($expression$)
   $expression2$;

is finding if blocks with or without curlys...although I'm not sure this is on the right path to begin with...

Upvotes: 4

Views: 780

Answers (1)

Bas Leijdekkers
Bas Leijdekkers

Reputation: 26462

What you want is currently not possible with Structural Search and Replace. There is however a different way to achieve the desired result: the Control flow statement without braces inspection. It has a quick fix to add braces.

Upvotes: 4

Related Questions