Skip to content

Commit 3d8954e

Browse files
committed
[INTERNAL] compatibility fix for v202
1 parent 2b926d4 commit 3d8954e

22 files changed

+107
-61
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ intellij {
7676
pluginName = 'CSV Plugin'
7777
instrumentCode = true
7878
updateSinceUntilBuild = false
79-
downloadSources = true
79+
downloadSources = false
8080
}
8181
publishPlugin {
8282
token = System.getenv().getOrDefault('JI_TOKEN', '')

src/main/java/net/seesharpsoft/intellij/plugins/csv/highlighter/CsvHighlightUsagesHandler.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.Collections;
1616
import java.util.List;
1717

18-
public class CsvHighlightUsagesHandler extends HighlightUsagesHandlerBase<PsiElement> {
18+
public class CsvHighlightUsagesHandler extends HighlightUsagesHandlerBase {
1919

2020
protected CsvHighlightUsagesHandler(@NotNull Editor editor, @NotNull CsvFile file) {
2121
super(editor, file);
@@ -46,20 +46,21 @@ public List<PsiElement> getTargets() {
4646
}
4747

4848
@Override
49-
protected void selectTargets(List<PsiElement> list, Consumer<List<PsiElement>> consumer) {
50-
consumer.consume(list);
51-
}
52-
53-
@Override
54-
public void computeUsages(List<PsiElement> list) {
49+
public void computeUsages(List list) {
5550
CsvColumnInfoMap<PsiElement> columnInfoMap = getCsvFile().getColumnInfoMap();
56-
for (PsiElement listElement : list) {
51+
for (PsiElement listElement : (List<PsiElement>)list) {
5752
CsvColumnInfo<PsiElement> csvColumnInfo = getCsvFile().getColumnInfoMap().getColumnInfo(listElement);
5853
if (csvColumnInfo == null) {
5954
continue;
6055
}
6156
csvColumnInfo.getElements().forEach(element -> this.addOccurrence(columnInfoMap.getRowInfo(element)));
6257
}
58+
59+
}
60+
61+
@Override
62+
protected void selectTargets(List list, Consumer consumer) {
63+
consumer.consume(list);
6364
}
6465

6566
protected void addOccurrence(CsvColumnInfo<PsiElement>.RowInfo rowInfo) {

src/test/java/net/seesharpsoft/intellij/plugins/csv/actions/CsvChangeEscapeCharacterActionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package net.seesharpsoft.intellij.plugins.csv.actions;
22

33
import com.intellij.openapi.actionSystem.Presentation;
4-
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
4+
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
55
import net.seesharpsoft.intellij.plugins.csv.CsvEscapeCharacter;
66
import net.seesharpsoft.intellij.plugins.csv.CsvHelper;
77
import net.seesharpsoft.intellij.plugins.csv.components.CsvFileAttributes;
88

9-
public class CsvChangeEscapeCharacterActionTest extends LightPlatformCodeInsightFixtureTestCase {
9+
public class CsvChangeEscapeCharacterActionTest extends BasePlatformTestCase {
1010

1111
@Override
1212
protected String getTestDataPath() {

src/test/java/net/seesharpsoft/intellij/plugins/csv/actions/CsvChangeSeparatorActionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package net.seesharpsoft.intellij.plugins.csv.actions;
22

33
import com.intellij.openapi.actionSystem.Presentation;
4-
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
4+
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
55
import net.seesharpsoft.intellij.plugins.csv.CsvHelper;
66
import net.seesharpsoft.intellij.plugins.csv.CsvValueSeparator;
77
import net.seesharpsoft.intellij.plugins.csv.components.CsvFileAttributes;
88

9-
public class CsvChangeSeparatorActionTest extends LightPlatformCodeInsightFixtureTestCase {
9+
public class CsvChangeSeparatorActionTest extends BasePlatformTestCase {
1010

1111
@Override
1212
protected String getTestDataPath() {

src/test/java/net/seesharpsoft/intellij/plugins/csv/components/CsvFileAttributesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package net.seesharpsoft.intellij.plugins.csv.components;
22

3-
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
3+
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
44
import net.seesharpsoft.intellij.plugins.csv.CsvEscapeCharacter;
55
import net.seesharpsoft.intellij.plugins.csv.CsvHelper;
66
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
77

8-
public class CsvFileAttributesTest extends LightPlatformCodeInsightFixtureTestCase {
8+
public class CsvFileAttributesTest extends BasePlatformTestCase {
99
@Override
1010
protected String getTestDataPath() {
1111
return "./src/test/resources/components";

src/test/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvAnnotatorTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
44
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
55
import com.intellij.openapi.Disposable;
6+
import com.intellij.openapi.components.ServiceManager;
67
import com.intellij.openapi.project.DumbService;
78
import com.intellij.openapi.project.Project;
89
import com.intellij.openapi.util.Disposer;
@@ -14,7 +15,8 @@
1415
import com.intellij.psi.search.GlobalSearchScope;
1516
import com.intellij.testFramework.EdtTestUtil;
1617
import com.intellij.testFramework.ExpectedHighlightingData;
17-
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
18+
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
19+
import net.seesharpsoft.intellij.plugins.csv.editor.table.ExpectedHighlightingDataWrapper;
1820
import org.jetbrains.annotations.NotNull;
1921

2022
import java.util.Collections;
@@ -23,7 +25,7 @@
2325

2426
import static net.seesharpsoft.intellij.plugins.csv.editor.CsvAnnotator.CSV_COLUMN_INFO_SEVERITY;
2527

26-
public class CsvAnnotatorTest extends LightPlatformCodeInsightFixtureTestCase {
28+
public class CsvAnnotatorTest extends BasePlatformTestCase {
2729

2830
@Override
2931
protected String getTestDataPath() {
@@ -36,7 +38,7 @@ public void testAnnotator() {
3638
}
3739

3840
private long collectAndCheckHighlighting() {
39-
ExpectedHighlightingData data = new ExpectedHighlightingData(myFixture.getEditor().getDocument(), false, false, true, false, this.getHostFile());
41+
ExpectedHighlightingDataWrapper data = new ExpectedHighlightingDataWrapper(myFixture.getEditor().getDocument(), false, false, true);
4042
data.registerHighlightingType("csv_column_info", new ExpectedHighlightingData.ExpectedHighlightingSet(CSV_COLUMN_INFO_SEVERITY, false, true));
4143
data.init();
4244
return this.collectAndCheckHighlighting(data);
@@ -46,21 +48,21 @@ private PsiFile getHostFile() {
4648
return myFixture.getFile();
4749
}
4850

49-
private long collectAndCheckHighlighting(@NotNull ExpectedHighlightingData data) {
51+
private long collectAndCheckHighlighting(@NotNull ExpectedHighlightingDataWrapper data) {
5052
Project project = myFixture.getProject();
5153
EdtTestUtil.runInEdtAndWait(() -> {
5254
PsiDocumentManager.getInstance(project).commitAllDocuments();
5355
});
5456
PsiFileImpl file = (PsiFileImpl)this.getHostFile();
5557
FileElement hardRefToFileElement = file.calcTreeElement();
5658
if (!DumbService.isDumb(project)) {
57-
CacheManager.SERVICE.getInstance(project).getFilesWithWord("XXX", (short)2, GlobalSearchScope.allScope(project), true);
59+
ServiceManager.getService(project, CacheManager.class).getFilesWithWord("XXX", (short)2, GlobalSearchScope.allScope(project), true);
5860
}
5961

6062
long start = System.currentTimeMillis();
6163
Disposable disposable = Disposer.newDisposable();
6264

63-
List infos;
65+
List<HighlightInfo> infos;
6466
try {
6567
infos = myFixture.doHighlighting();
6668
this.removeDuplicatedRangesForInjected(infos);
@@ -69,7 +71,7 @@ private long collectAndCheckHighlighting(@NotNull ExpectedHighlightingData data)
6971
}
7072

7173
long elapsed = System.currentTimeMillis() - start;
72-
data.checkResult(infos, file.getText());
74+
data.checkResultWrapper(file, infos, file.getText());
7375
hardRefToFileElement.hashCode();
7476
return elapsed;
7577
}

src/test/java/net/seesharpsoft/intellij/plugins/csv/editor/CsvFileEditorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import com.intellij.openapi.fileEditor.*;
55
import com.intellij.openapi.fileEditor.ex.FileEditorProviderManager;
66
import com.intellij.openapi.fileEditor.impl.text.TextEditorState;
7-
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
7+
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
88
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
99
import org.jdom.Element;
1010

11-
public class CsvFileEditorTest extends LightPlatformCodeInsightFixtureTestCase {
11+
public class CsvFileEditorTest extends BasePlatformTestCase {
1212

1313
@Override
1414
protected String getTestDataPath() {

src/test/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableEditorProviderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import com.intellij.openapi.fileEditor.FileEditorProvider;
66
import com.intellij.openapi.fileEditor.FileEditorState;
77
import com.intellij.openapi.fileEditor.ex.FileEditorProviderManager;
8-
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
8+
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
99
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
1010
import org.jdom.Element;
1111

1212
import java.util.Objects;
1313

14-
public class CsvTableEditorProviderTest extends LightPlatformCodeInsightFixtureTestCase {
14+
public class CsvTableEditorProviderTest extends BasePlatformTestCase {
1515

1616
@Override
1717
protected String getTestDataPath() {

src/test/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableEditorStateTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package net.seesharpsoft.intellij.plugins.csv.editor.table;
22

3-
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
3+
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
44
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
55
import org.jdom.Element;
66

7-
public class CsvTableEditorStateTest extends LightPlatformCodeInsightFixtureTestCase {
7+
public class CsvTableEditorStateTest extends BasePlatformTestCase {
88

99
@Override
1010
protected String getTestDataPath() {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package net.seesharpsoft.intellij.plugins.csv.editor.table;
2+
3+
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
4+
import com.intellij.openapi.editor.Document;
5+
import com.intellij.psi.PsiFile;
6+
import com.intellij.testFramework.ExpectedHighlightingData;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.lang.reflect.InvocationTargetException;
10+
import java.lang.reflect.Method;
11+
import java.util.Arrays;
12+
import java.util.Collection;
13+
14+
/**
15+
* This class provides a common API for the incompatible change of the 'checkResult' method, that happened in 202.*
16+
*/
17+
public class ExpectedHighlightingDataWrapper extends ExpectedHighlightingData {
18+
19+
public ExpectedHighlightingDataWrapper(@NotNull Document document, boolean checkWarnings, boolean checkWeakWarnings, boolean checkInfos) {
20+
super(document, checkWarnings, checkWeakWarnings, checkInfos);
21+
}
22+
23+
private boolean findMethodAndInvoke(String name, Object... parameters) {
24+
Class[] classes = Arrays.stream(parameters).map(obj -> obj.getClass()).toArray(n -> new Class[n]);
25+
Method methodToCall;
26+
try {
27+
methodToCall = ExpectedHighlightingData.class.getMethod("checkResult", classes);
28+
methodToCall.invoke(this, parameters);
29+
} catch (NoSuchMethodException e) {
30+
return false;
31+
} catch (IllegalAccessException | InvocationTargetException e) {
32+
e.printStackTrace();
33+
return false;
34+
}
35+
return true;
36+
}
37+
38+
public void checkResultWrapper(PsiFile psiFile, Collection<? extends HighlightInfo> infos, String text) {
39+
if(!findMethodAndInvoke("checkResult", PsiFile.class, Collection.class, String.class)) {
40+
findMethodAndInvoke("checkResult", Collection.class, String.class);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)