diff --git a/changelog/@unreleased/pr-313.v2.yml b/changelog/@unreleased/pr-313.v2.yml new file mode 100644 index 000000000..c99c56349 --- /dev/null +++ b/changelog/@unreleased/pr-313.v2.yml @@ -0,0 +1,7 @@ +type: fix +fix: + description: Explicitly extend the IntelliJ CodeStyleManagerImpl so that any methods + added in newer releases are inherited automatically with a reasonable default + implementation. + links: + - https://github.com/palantir/palantir-java-format/pull/313 diff --git a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/CodeStyleManagerDecorator.java b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/CodeStyleManagerDecorator.java index b6e49038b..bb4cc5aff 100644 --- a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/CodeStyleManagerDecorator.java +++ b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/CodeStyleManagerDecorator.java @@ -30,6 +30,7 @@ import com.intellij.psi.codeStyle.DocCommentSettings; import com.intellij.psi.codeStyle.FormattingModeAwareIndentAdjuster; import com.intellij.psi.codeStyle.Indent; +import com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl; import com.intellij.util.IncorrectOperationException; import com.intellij.util.ThrowableRunnable; import java.util.Collection; @@ -38,13 +39,22 @@ /** * Decorates the {@link CodeStyleManager} abstract class by delegating to a concrete implementation instance (likely * IJ's default instance). + * + * Explicitly extend the IntelliJ {@link #CodeStyleManagerImpl} so that any methods added in newer releases are + * inherited automatically with a reasonable default implementation. + * + * The https://github.com/JetBrains/intellij-community/commit/2d5740176cc9206db2d5ab5d8f67cec74b85a017 + * added a CodeManager#scheduleReformatWhenSettingsComputed(PsiFile) method in idea/202.5103.13 where the + * default implementation throws an UnsuportedOperationException. + * See https://youtrack.jetbrains.com/issue/IDEA-244645 for more details. */ @SuppressWarnings("deprecation") -class CodeStyleManagerDecorator extends CodeStyleManager implements FormattingModeAwareIndentAdjuster { +class CodeStyleManagerDecorator extends CodeStyleManagerImpl implements FormattingModeAwareIndentAdjuster { private final CodeStyleManager delegate; - CodeStyleManagerDecorator(CodeStyleManager delegate) { + CodeStyleManagerDecorator(Project project, CodeStyleManager delegate) { + super(project); this.delegate = delegate; } diff --git a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirCodeStyleManager.java b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirCodeStyleManager.java index 2dd68be93..1e37a8cb3 100644 --- a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirCodeStyleManager.java +++ b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirCodeStyleManager.java @@ -82,12 +82,12 @@ final class PalantirCodeStyleManager extends CodeStyleManagerDecorator { Caffeine.newBuilder().maximumSize(1).build(PalantirCodeStyleManager::createFormatter); public PalantirCodeStyleManager(@NotNull Project project) { - super(new CodeStyleManagerImpl(project)); + super(project, new CodeStyleManagerImpl(project)); } @NonInjectable PalantirCodeStyleManager(@NotNull CodeStyleManager original) { - super(original); + super(original.getProject(), original); } static Map getReplacements(