Intention Actions and Quick Fixes Basics
While inspections provide quick-fixes for code that has potential problems, intentions help you apply automatic changes to the code that is correct.
To get a list of intentions applicable to the code at the caret, just press Alt+Enter.
In this section:
- Optimize statements and manage braces
- String concatenation
- Switch between loop declaration styles
- Math expressions
- Disable intention
Optimize statements and manage braces
Since the IDE is aware of the data flow in your code, it can help you optimize Boolean conditions and transform if/else statements:
With intentions you can, for example, automatically add and remove braces for your statements:
If you have String concatenation, the IDE can help you replace it with a String.format expression or a StringBuilder pattern.
Switch between loop declaration styles
With intentions you can also switch between loop declaration styles or even reverse its direction.
If you have a complicated math expression, the IDE will offer you to simplify an expression or possibly clarify it with parentheses.
If you don’t want to see a certain intention, you can disable it by selecting the right arrow on the intention.
Find the complete list of intentions (several hundred in total), grouped by language and framework, in the Intentions page of the Settings dialog. Here you can enable/disable whole groups of intentions: