Skip to content

Commit

Permalink
Fix `java.lang.RuntimeException: Document is locked by write PSI oper…
Browse files Browse the repository at this point in the history
…ations` errors

Also update to `google-java-format` 1.17.0

Fixes #960

FUTURE_COPYBARA_INTEGRATE_REVIEW=#960 from facboy:master 89f7902
PiperOrigin-RevId: 560727815
  • Loading branch information
facboy authored and google-java-format Team committed Aug 29, 2023
1 parent 4ebb6f5 commit 7f75410
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
18 changes: 9 additions & 9 deletions idea_plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

plugins { id("org.jetbrains.intellij") version "1.13.3" }
plugins { id("org.jetbrains.intellij") version "1.15.0" }

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

apply(plugin = "java")

repositories { mavenCentral() }

val googleJavaFormatVersion = "1.16.0"
val googleJavaFormatVersion = "1.17.0"

java {
sourceCompatibility = JavaVersion.VERSION_11
Expand All @@ -37,7 +37,7 @@ intellij {

tasks {
patchPluginXml {
version.set("${googleJavaFormatVersion}.2")
version.set("${googleJavaFormatVersion}.0")
sinceBuild.set("213")
untilBuild.set("")
}
Expand All @@ -49,12 +49,12 @@ tasks {

withType<Test>().configureEach {
jvmArgs(
"--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,24 @@ public boolean supports(@NotNull PsiFile file) {

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

final String origText = document.getText();
String text;
try {
text =
ImportOrderer.reorderImports(
RemoveUnusedImports.removeUnusedImports(document.getText()), style);
text = ImportOrderer.reorderImports(RemoveUnusedImports.removeUnusedImports(origText), style);
} catch (FormatterException e) {
Notifications.displayParsingErrorNotification(project, file.getName());
return Runnables.doNothing();
}

return () -> document.setText(text);
return () -> {
if (documentManager.isDocumentBlockedByPsi(document)) {
documentManager.doPostponedOperationsAndUnblockDocument(document);
String newText = document.getText();
if (!newText.equals(origText)) {
return;
}
}
document.setText(text);
};
}
}

0 comments on commit 7f75410

Please sign in to comment.