Skip to content

Commit 98434a8

Browse files
wilkinsonaphilwebb
authored andcommitted
Upgrade to IntelliJ IDEA 2021.2
Closes gh-294
1 parent c18dc7d commit 98434a8

File tree

8 files changed

+35
-82
lines changed

8 files changed

+35
-82
lines changed

spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-plugin/src/main/java/io/spring/format/formatter/intellij/SpringFormat.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 the original author or authors.
2+
* Copyright 2017-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,6 +65,7 @@ public class SpringFormat {
6565
private PropertiesComponent properties;
6666

6767
protected SpringFormat(Project project) {
68+
logger.info("Initializing Spring Format for project " + project.getName());
6869
this.project = project;
6970
this.statusIndicator = new StatusIndicator(project);
7071
this.properties = PropertiesComponent.getInstance(project);
@@ -84,6 +85,7 @@ private void dispose() {
8485
}
8586

8687
private void update(State state) {
88+
logger.info("Updating state of " + this.project.getName() + " to " + state);
8789
this.lock.lock();
8890
try {
8991
CodeStyleManager manager = CodeStyleManager.getInstance(this.project);

spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-plugin/src/main/java/io/spring/format/formatter/intellij/codestyle/DelegatingCodeStyleManager.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 the original author or authors.
2+
* Copyright 2017-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -105,15 +105,10 @@ public void reformatText(PsiFile file, int startOffset, int endOffset) throws In
105105
}
106106

107107
@Override
108-
public void reformatText(PsiFile file, Collection<TextRange> ranges) throws IncorrectOperationException {
108+
public void reformatText(PsiFile file, Collection<? extends TextRange> ranges) throws IncorrectOperationException {
109109
this.delegate.reformatText(file, ranges);
110110
}
111111

112-
@Override
113-
public void reformatTextWithContext(PsiFile file, Collection<TextRange> ranges) throws IncorrectOperationException {
114-
this.delegate.reformatTextWithContext(file, ranges);
115-
}
116-
117112
@Override
118113
public void reformatTextWithContext(PsiFile file, ChangedRangesInfo info) throws IncorrectOperationException {
119114
this.delegate.reformatTextWithContext(file, info);

spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-plugin/src/main/java/io/spring/format/formatter/intellij/codestyle/SpringCodeStyleManager.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 the original author or authors.
2+
* Copyright 2017-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222

2323
import com.intellij.openapi.util.TextRange;
2424
import com.intellij.psi.PsiFile;
25+
import com.intellij.psi.codeStyle.ChangedRangesInfo;
2526
import com.intellij.psi.codeStyle.CodeStyleManager;
2627
import com.intellij.util.IncorrectOperationException;
2728

@@ -51,16 +52,16 @@ public void reformatText(PsiFile file, int startOffset, int endOffset) throws In
5152
}
5253

5354
@Override
54-
public void reformatText(PsiFile file, Collection<TextRange> ranges) throws IncorrectOperationException {
55+
public void reformatText(PsiFile file, Collection<? extends TextRange> ranges) throws IncorrectOperationException {
5556
reformat(file, () -> ranges, () -> super.reformatText(file, ranges));
5657
}
5758

5859
@Override
59-
public void reformatTextWithContext(PsiFile file, Collection<TextRange> ranges) throws IncorrectOperationException {
60-
reformat(file, () -> ranges, () -> super.reformatTextWithContext(file, ranges));
60+
public void reformatTextWithContext(PsiFile file, ChangedRangesInfo info) throws IncorrectOperationException {
61+
reformat(file, () -> info.allChangedRanges, () -> super.reformatTextWithContext(file, info));
6162
}
6263

63-
private void reformat(PsiFile file, Supplier<Collection<TextRange>> ranges, Runnable delegate) {
64+
private void reformat(PsiFile file, Supplier<Collection<? extends TextRange>> ranges, Runnable delegate) {
6465
if (this.springReformatter.canReformat(file)) {
6566
this.springReformatter.reformat(file, ranges.get());
6667
}

spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-plugin/src/main/java/io/spring/format/formatter/intellij/codestyle/SpringReformatter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public boolean canReformat(PsiFile file) {
7575
return JAVA_FILE_TYPE.equals(file.getFileType());
7676
}
7777

78-
public void reformat(PsiFile file, Collection<TextRange> ranges) {
78+
public void reformat(PsiFile file, Collection<? extends TextRange> ranges) {
7979
this.application.get().assertWriteAccessAllowed();
8080
this.documentManager.get().commitAllDocuments();
8181
if (!file.isWritable()) {
@@ -101,7 +101,7 @@ private void throwNotWritableException(PsiElement element) throws IncorrectOpera
101101
CoreBundle.message("cannot.modify.a.read.only.file", virtualFile.getPresentableUrl()));
102102
}
103103

104-
private void reformat(PsiFile file, Collection<TextRange> ranges, Document document) {
104+
private void reformat(PsiFile file, Collection<? extends TextRange> ranges, Document document) {
105105
if (document != null && file.getVirtualFile() != null) {
106106
JavaFormatConfig javaFormatConfig = JavaFormatConfig.findFrom(file.getVirtualFile().toNioPath());
107107
Formatter formatter = new Formatter(javaFormatConfig);

spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-plugin/src/main/java/io/spring/format/formatter/intellij/codestyle/monitor/GradleMonitor.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 the original author or authors.
2+
* Copyright 2017-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.util.Collection;
2020

2121
import com.intellij.openapi.components.ServiceManager;
22+
import com.intellij.openapi.diagnostic.Logger;
2223
import com.intellij.openapi.externalSystem.model.DataNode;
2324
import com.intellij.openapi.externalSystem.model.ExternalProjectInfo;
2425
import com.intellij.openapi.externalSystem.model.task.TaskData;
@@ -38,6 +39,8 @@
3839
*/
3940
public class GradleMonitor extends Monitor {
4041

42+
private static final Logger logger = Logger.getInstance(GradleMonitor.class);
43+
4144
private static final String FORMAT_TASK = "io.spring.javaformat.gradle.FormatTask";
4245

4346
public GradleMonitor(Project project, Trigger trigger) {
@@ -47,6 +50,7 @@ public GradleMonitor(Project project, Trigger trigger) {
4750
}
4851

4952
private void check() {
53+
logger.info("Checking " + getProject().getName() + " for use of Spring Java Format");
5054
ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class);
5155
boolean hasFormatPlugin = hasFormatPlugin(
5256
projectDataManager.getExternalProjectsData(getProject(), GradleConstants.SYSTEM_ID));
@@ -56,6 +60,7 @@ private void check() {
5660
private boolean hasFormatPlugin(Collection<ExternalProjectInfo> projectInfos) {
5761
for (ExternalProjectInfo projectInfo : projectInfos) {
5862
if (hasFormatPlugin(projectInfo.getExternalProjectStructure())) {
63+
logger.info(projectInfo + " uses Spring Java Format");
5964
return true;
6065
}
6166
}

spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-plugin/src/test/java/io/spring/format/formatter/intellij/codestyle/DelegatingCodeStyleManagerTests.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
import com.intellij.util.ThrowableRunnable;
3232
import org.junit.jupiter.api.BeforeEach;
3333
import org.junit.jupiter.api.Test;
34+
import org.mockito.ArgumentCaptor;
3435
import org.mockito.Mock;
3536
import org.mockito.MockitoAnnotations;
3637

3738
import static org.assertj.core.api.Assertions.assertThat;
39+
import static org.mockito.ArgumentMatchers.eq;
3840
import static org.mockito.Mockito.mock;
3941
import static org.mockito.Mockito.verify;
4042

@@ -133,7 +135,9 @@ public void reformatTextWithRangeCollectionShouldCallDelegate() throws Exception
133135
@Test
134136
public void reformatTextWithContextShouldCallDelegate() throws Exception {
135137
this.delegating.reformatTextWithContext(this.file, this.ranges);
136-
verify(this.delegate).reformatTextWithContext(this.file, this.ranges);
138+
ArgumentCaptor<ChangedRangesInfo> changedRanges = ArgumentCaptor.forClass(ChangedRangesInfo.class);
139+
verify(this.delegate).reformatTextWithContext(eq(this.file), changedRanges.capture());
140+
assertThat(changedRanges.getValue().allChangedRanges).containsExactlyElementsOf(this.ranges);
137141
}
138142

139143
@Test

spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-plugin/src/test/java/io/spring/format/formatter/intellij/codestyle/SpringCodeStyleManagerTests.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@
2323

2424
import com.intellij.openapi.util.TextRange;
2525
import com.intellij.psi.PsiFile;
26+
import com.intellij.psi.codeStyle.ChangedRangesInfo;
2627
import com.intellij.psi.codeStyle.CodeStyleManager;
2728
import org.junit.jupiter.api.BeforeEach;
2829
import org.junit.jupiter.api.Test;
30+
import org.mockito.ArgumentCaptor;
2931
import org.mockito.Mock;
3032
import org.mockito.MockitoAnnotations;
3133

34+
import static org.assertj.core.api.Assertions.assertThat;
3235
import static org.mockito.ArgumentMatchers.any;
36+
import static org.mockito.ArgumentMatchers.eq;
3337
import static org.mockito.BDDMockito.given;
3438
import static org.mockito.Mockito.verify;
3539
import static org.mockito.Mockito.verifyZeroInteractions;
@@ -96,7 +100,9 @@ public void reformatTextWithContextWhenCantFormatShouldCallDelegate() {
96100
given(this.springReformatter.canReformat(any())).willReturn(false);
97101
Collection<TextRange> ranges = Arrays.asList(new TextRange(10, 20));
98102
this.styleManager.reformatTextWithContext(this.file, ranges);
99-
verify(this.delegate).reformatTextWithContext(this.file, ranges);
103+
ArgumentCaptor<ChangedRangesInfo> changedRanges = ArgumentCaptor.forClass(ChangedRangesInfo.class);
104+
verify(this.delegate).reformatTextWithContext(eq(this.file), changedRanges.capture());
105+
assertThat(changedRanges.getValue().allChangedRanges).containsExactlyElementsOf(ranges);
100106
}
101107

102108
@Test

spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-runtime/pom.xml

+4-64
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
<name>Spring JavaFormat IntelliJ IDEA Runtime</name>
1414
<properties>
1515
<main.basedir>${basedir}/../..</main.basedir>
16-
<intellij.binary>https://download.jetbrains.com/idea/ideaIC-2020.3.tar.gz</intellij.binary>
17-
<intellij.source>https://github.com/JetBrains/intellij-community/archive/idea/203.5981.155.zip</intellij.source>
18-
<intellij.root>idea-IC-203.5981.155</intellij.root>
16+
<intellij.binary>https://download.jetbrains.com/idea/ideaIC-2021.2.tar.gz</intellij.binary>
17+
<intellij.source>https://github.com/JetBrains/intellij-community/archive/idea/212.4746.92.zip</intellij.source>
18+
<intellij.root>idea-IC-212.4746.92</intellij.root>
1919
</properties>
2020
<build>
2121
<plugins>
@@ -112,15 +112,6 @@
112112
<zip
113113
destfile="${project.build.directory}/intellij-source/util-sources.zip"
114114
basedir="${project.build.directory}/intellij-source/platform/util/src" />
115-
<zip
116-
destfile="${project.build.directory}/intellij-source/platform-util-ui-sources.zip"
117-
basedir="${project.build.directory}/intellij-source/platform/util/ui/src" />
118-
<zip
119-
destfile="${project.build.directory}/intellij-source/extensions-sources.zip"
120-
basedir="${project.build.directory}/intellij-source/platform/extensions/src" />
121-
<zip
122-
destfile="${project.build.directory}/intellij-source/platform-service-container-sources.zip"
123-
basedir="${project.build.directory}/intellij-source/platform/service-container/src" />
124115
<zip
125116
destfile="${project.build.directory}/intellij-source/maven-sources.zip"
126117
basedir="${project.build.directory}/intellij-source/plugins/maven/src" />
@@ -193,57 +184,6 @@
193184
<generatePom>true</generatePom>
194185
</configuration>
195186
</execution>
196-
<execution>
197-
<id>install-intellij-platform-util-ui</id>
198-
<phase>install</phase>
199-
<inherited>false</inherited>
200-
<goals>
201-
<goal>install-file</goal>
202-
</goals>
203-
<configuration>
204-
<file>${project.build.directory}/intellij/platform-util-ui.jar</file>
205-
<sources>${project.build.directory}/intellij-source/platform-util-ui-sources.zip</sources>
206-
<groupId>io.spring.javaformat.intellij.idea</groupId>
207-
<artifactId>platform-util-ui</artifactId>
208-
<version>${project.version}</version>
209-
<packaging>jar</packaging>
210-
<generatePom>true</generatePom>
211-
</configuration>
212-
</execution>
213-
<execution>
214-
<id>install-intellij-extensions</id>
215-
<phase>install</phase>
216-
<inherited>false</inherited>
217-
<goals>
218-
<goal>install-file</goal>
219-
</goals>
220-
<configuration>
221-
<file>${project.build.directory}/intellij/extensions.jar</file>
222-
<sources>${project.build.directory}/intellij-source/extensions-sources.zip</sources>
223-
<groupId>io.spring.javaformat.intellij.idea</groupId>
224-
<artifactId>extensions</artifactId>
225-
<version>${project.version}</version>
226-
<packaging>jar</packaging>
227-
<generatePom>true</generatePom>
228-
</configuration>
229-
</execution>
230-
<execution>
231-
<id>install-intellij-platform-service-container</id>
232-
<phase>install</phase>
233-
<inherited>false</inherited>
234-
<goals>
235-
<goal>install-file</goal>
236-
</goals>
237-
<configuration>
238-
<file>${project.build.directory}/intellij/platform-serviceContainer.jar</file>
239-
<sources>${project.build.directory}/intellij-source/platform-service-container-sources.zip</sources>
240-
<groupId>io.spring.javaformat.intellij.idea</groupId>
241-
<artifactId>platform-service-container</artifactId>
242-
<version>${project.version}</version>
243-
<packaging>jar</packaging>
244-
<generatePom>true</generatePom>
245-
</configuration>
246-
</execution>
247187
<execution>
248188
<id>install-intellij-idea</id>
249189
<phase>install</phase>
@@ -301,7 +241,7 @@
301241
<goal>install-file</goal>
302242
</goals>
303243
<configuration>
304-
<file>${project.build.directory}/intellij/gradle-common.jar</file>
244+
<file>${project.build.directory}/intellij/gradle.jar</file>
305245
<sources>${project.build.directory}/intellij-source/gradle-sources.zip</sources>
306246
<groupId>io.spring.javaformat.intellij.idea</groupId>
307247
<artifactId>gradle</artifactId>

0 commit comments

Comments
 (0)