IntelliJ Code Style and Formatting Configuration¶
IntelliJ IDEA provides extensive configuration options for code style and formatting, allowing developers to customize how code is organized, indented, and imported. These settings ensure consistency across codebases and can be automated to occur during file saves.
Import Optimization¶
The IDE can be configured to manage imports automatically, reducing code clutter and handling package references.
- Wildcard Imports: Settings are available to optimize imports, which typically involves removing unused imports and replacing fully qualified names or wildcards (
import *) with specific class imports^[600-developer-intellij.md]. - Auto-Import: The "Enable auto-import" feature allows the IDE to add import statements automatically as code is typed, removing the need for manual intervention^[600-developer-intellij.md].
Java Formatting¶
Specific code style rules can be defined for Java files to control the visual layout of the source code.
- Alignment and Wrapping: Developers can configure code alignment and wrapping rules via the code style settings interface^[600-developer-intellij.md].
- Completion Case Sensitivity: To make code suggestions more flexible, the "Case sensitive completion" option can be set to "None", allowing the IDE to suggest keywords without strict adherence to casing^[600-developer-intellij.md].
Save Actions¶
Productivity can be increased by configuring "Save Actions," a feature that performs specific formatting tasks automatically when a file is saved.
- Activation: Once configured, a modified file will display an asterisk (
*) on its tab, indicating that changes are pending the defined actions upon saving^[600-developer-intellij.md]. - Automation: This feature automates tasks such as organizing imports or reformatting code, ensuring that the "clean" version of the file is always saved^[600-developer-intellij.md].
Related Concepts¶
- [[Save Actions]]
- [[IntelliJ IDEA|IntelliJ]]
Sources¶
600-developer-intellij.md