Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeStyleManagerDecorator extends CodeStyleManagerImpl #313

Merged
merged 2 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/@unreleased/pr-313.v2.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextRange, String> getReplacements(
Expand Down