Niklas
Niklas

Reputation: 25391

Intellij Structural Search non final

Using the Copy existing template... I found the structural search for loops:

for ($Type$ $Variable$ : $Expression$) {
  $Statement$;
}

I want to enhance it so that it does only find for loops where the variable is not final.

It should find:

for (String string : strings) {
    // Statements
}

However not:

for (final String string : strings) {
    // Statements
}

Right now it obviously finds both since there's no differentiation between final and non-final. How can I add this extra check?

Upvotes: 2

Views: 663

Answers (1)

Bas Leijdekkers
Bas Leijdekkers

Reputation: 26462

  • Start with the existing template foreach loops.
  • Click Edit Variables... and select the Variable variable.
  • In the Script Constraints text field enter !__context__.hasModifierProperty("final").

Click OK and Find and you should get your desired result. See also the existing template static fields that are not final for an example.

Upvotes: 7

Related Questions