Skip to content

Commit 7f75410

Browse files
facboygoogle-java-format Team
authored and
google-java-format Team
committed
Fix java.lang.RuntimeException: Document is locked by write PSI operations errors
Also update to `google-java-format` 1.17.0 Fixes #960 FUTURE_COPYBARA_INTEGRATE_REVIEW=#960 from facboy:master 89f7902 PiperOrigin-RevId: 560727815
1 parent 4ebb6f5 commit 7f75410

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

idea_plugin/build.gradle.kts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
plugins { id("org.jetbrains.intellij") version "1.13.3" }
17+
plugins { id("org.jetbrains.intellij") version "1.15.0" }
1818

1919
apply(plugin = "org.jetbrains.intellij")
2020

2121
apply(plugin = "java")
2222

2323
repositories { mavenCentral() }
2424

25-
val googleJavaFormatVersion = "1.16.0"
25+
val googleJavaFormatVersion = "1.17.0"
2626

2727
java {
2828
sourceCompatibility = JavaVersion.VERSION_11
@@ -37,7 +37,7 @@ intellij {
3737

3838
tasks {
3939
patchPluginXml {
40-
version.set("${googleJavaFormatVersion}.2")
40+
version.set("${googleJavaFormatVersion}.0")
4141
sinceBuild.set("213")
4242
untilBuild.set("")
4343
}
@@ -49,12 +49,12 @@ tasks {
4949

5050
withType<Test>().configureEach {
5151
jvmArgs(
52-
"--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
53-
"--add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
54-
"--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
55-
"--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
56-
"--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
57-
"--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
52+
"--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
53+
"--add-exports", "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
54+
"--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
55+
"--add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
56+
"--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
57+
"--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
5858
)
5959
}
6060
}

idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatImportOptimizer.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,24 @@ public boolean supports(@NotNull PsiFile file) {
5555

5656
JavaFormatterOptions.Style style = GoogleJavaFormatSettings.getInstance(project).getStyle();
5757

58+
final String origText = document.getText();
5859
String text;
5960
try {
60-
text =
61-
ImportOrderer.reorderImports(
62-
RemoveUnusedImports.removeUnusedImports(document.getText()), style);
61+
text = ImportOrderer.reorderImports(RemoveUnusedImports.removeUnusedImports(origText), style);
6362
} catch (FormatterException e) {
6463
Notifications.displayParsingErrorNotification(project, file.getName());
6564
return Runnables.doNothing();
6665
}
6766

68-
return () -> document.setText(text);
67+
return () -> {
68+
if (documentManager.isDocumentBlockedByPsi(document)) {
69+
documentManager.doPostponedOperationsAndUnblockDocument(document);
70+
String newText = document.getText();
71+
if (!newText.equals(origText)) {
72+
return;
73+
}
74+
}
75+
document.setText(text);
76+
};
6977
}
7078
}

0 commit comments

Comments
 (0)