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

Fix: Support intellij 212 (2021.2 EAP) #502

Merged
merged 2 commits into from
Jul 5, 2021
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-502.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: fix
fix:
description: Support Intellij 212 API level (2021.2 EAP). The type signature changed
from `Collection<TextRange>` to `Collection<? extends TextRange>`. This is inspired
by same fix in bazel intellij plugin to avoid compiling multiple versions
links:
- https://github.com/palantir/palantir-java-format/pull/502
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*
* 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.
* default implementation throws an UnsupportedOperationException.
* See https://youtrack.jetbrains.com/issue/IDEA-244645 for more details.
*/
@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -93,7 +93,7 @@ public void reformatText(PsiFile file, int startOffset, int endOffset) throws In
}

@Override
public void reformatText(PsiFile file, Collection<TextRange> ranges) throws IncorrectOperationException {
public void reformatText(PsiFile file, Collection ranges) throws IncorrectOperationException {
delegate.reformatText(file, ranges);
}

Expand All @@ -104,7 +104,7 @@ public void reformatTextWithContext(PsiFile psiFile, ChangedRangesInfo changedRa
}

@Override
public void reformatTextWithContext(PsiFile file, Collection<TextRange> ranges) throws IncorrectOperationException {
public void reformatTextWithContext(PsiFile file, Collection ranges) throws IncorrectOperationException {
delegate.reformatTextWithContext(file, ranges);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public PalantirCodeStyleManager(@NotNull Project project) {
}

static Map<TextRange, String> getReplacements(
FormatterService formatter, String text, Collection<TextRange> ranges) {
FormatterService formatter, String text, Collection<? extends TextRange> ranges) {
try {
ImmutableMap.Builder<TextRange, String> replacements = ImmutableMap.builder();
formatter.getFormatReplacements(text, toRanges(ranges)).forEach(replacement -> {
Expand All @@ -103,7 +103,7 @@ static Map<TextRange, String> getReplacements(
}
}

private static Collection<Range<Integer>> toRanges(Collection<TextRange> textRanges) {
private static Collection<Range<Integer>> toRanges(Collection<? extends TextRange> textRanges) {
return textRanges.stream()
.map(textRange -> Range.closedOpen(textRange.getStartOffset(), textRange.getEndOffset()))
.collect(Collectors.toList());
Expand All @@ -125,7 +125,7 @@ public void reformatText(PsiFile file, int startOffset, int endOffset) throws In
}

@Override
public void reformatText(PsiFile file, Collection<TextRange> ranges) throws IncorrectOperationException {
public void reformatText(PsiFile file, Collection ranges) throws IncorrectOperationException {
if (overrideFormatterForFile(file)) {
formatInternal(file, ranges);
} else {
Expand All @@ -140,7 +140,7 @@ public void reformatTextWithContext(PsiFile psiFile, ChangedRangesInfo changedRa
}

@Override
public void reformatTextWithContext(PsiFile file, Collection<TextRange> ranges) {
public void reformatTextWithContext(PsiFile file, Collection ranges) {
if (overrideFormatterForFile(file)) {
formatInternal(file, ranges);
} else {
Expand Down Expand Up @@ -176,7 +176,7 @@ private boolean overrideFormatterForFile(PsiFile file) {
&& PalantirJavaFormatSettings.getInstance(getProject()).isEnabled();
}

private void formatInternal(PsiFile file, Collection<TextRange> ranges) {
private void formatInternal(PsiFile file, Collection<? extends TextRange> ranges) {
ApplicationManager.getApplication().assertWriteAccessAllowed();
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
documentManager.commitAllDocuments();
Expand Down Expand Up @@ -220,7 +220,7 @@ private static URL[] listDirAsUrlsUnchecked(Path dir) {
* <p>Overriding methods will need to modify the document with the result of the external formatter (usually using
* {@link #performReplacements(Document, Map)}.
*/
private void format(Document document, Collection<TextRange> ranges) {
private void format(Document document, Collection<? extends TextRange> ranges) {
PalantirJavaFormatSettings settings = PalantirJavaFormatSettings.getInstance(getProject());
FormatterService formatter = implementationCache.get(settings.getImplementationClassPath());

Expand Down