You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9d5ece4
Browse filesBrowse the repository at this point in the historyBrowse files
Optimize imports with open-java-format in IntelliJ IDEA
The formatting service now has OPTIMIZE_IMPORTS, so every way the IDE
optimizes imports asks its optimizer instead of the IDE's own
JavaImportOptimizer: Optimize Imports, Reformat with "Optimize
imports", Actions on Save, the check before a commit, the quick fix for
an unused import and "Optimize imports on the fly". The optimizer calls
FormatterService.fixImports, which since #221 fixes the imports alone:
the unused ones removed, the others sorted, as the command line does.
Reformat with "Optimize imports" starts the formatter in the background
and the optimizer right after it, on the same document. The platform
applies the formatter's text only if the document has not changed
since the request started, and IntelliJ IDEA registers no
DocumentMerger, so whichever wrote second lost: the formatting or the
imports. While a format of the plugin is running on a document, the
optimizer now hands the imports over to it, and the format fixes them
after the layout, as the command line does. Once the format has its
text, the optimizer leaves the document alone until the text is in.
The optimizer holds a read action while the formatter runs, which
"Optimize imports on the fly" makes typing wait for (#253).
Copy file name to clipboardExpand all lines: open-java-format-idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingService.java
Copy file name to clipboardExpand all lines: open-java-format-idea-plugin/src/main/resources/META-INF/plugin.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@
9
9
Gradle build no longer sets one. Only tags the marketplace renders: p, a, b, code, ul, ol, li. -->
10
10
<description><![CDATA[
11
11
<p>Formats Java code with <a href="https://github.com/openjavaformat/open-java-format">open-java-format</a>, a maintained fork of palantir-java-format: 120 columns, 4-space indents and lambda-friendly line breaking.</p>
12
-
<p>With the plugin enabled, <b>Reformat Code</b> runs open-java-format instead of the IDE's built-in Java formatter, so the IDE and your build produce identical files. The IDE's own Java code style settings no longer apply.</p>
12
+
<p>With the plugin enabled, <b>Reformat Code</b> runs open-java-format instead of the IDE's built-in Java formatter, and <b>Optimize Imports</b> removes unused imports and sorts the others as open-java-format does, so the IDE and your build produce identical files. The IDE's own Java code style settings no longer apply.</p>
13
13
<p>The formatter runs in a process of its own, on the IDE's runtime, so the project SDK can be any version. A project that applies the <code>dev.openjavaformat.java-format</code> Gradle plugin takes the formatter version from the build; every other project uses the version bundled with this plugin.</p>
14
14
<p>For many files at once, tick <b>Use native binary</b> on the plugin's settings page: the plugin downloads the formatter compiled to a native binary for your platform, which starts without a JVM, in a Maven, Gradle or any other project. A binary of your own works too.</p>
15
15
<p>Requires IntelliJ IDEA 2024.2 or later, or another IDE with Java support such as Android Studio.</p>
0 commit comments