Skip to content

Commit c284087

Browse files
committed
[FIX] StructureView fixed & test for StructureView added
1 parent 0fb20d6 commit c284087

File tree

4 files changed

+136
-3
lines changed

4 files changed

+136
-3
lines changed

src/main/java/net/seesharpsoft/intellij/plugins/csv/structureview/CsvStructureViewElement.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public TreeElement[] getChildren() {
108108
}
109109
}
110110

111-
private static class Header extends CsvStructureViewElement {
111+
public static class Header extends CsvStructureViewElement {
112112
private CsvColumnInfo<PsiElement> columnInfo;
113113

114114
public Header(PsiElement element, CsvColumnInfo<PsiElement> columnInfo) {
@@ -124,7 +124,7 @@ public TreeElement[] getChildren() {
124124
TreeElement[] children = new TreeElement[elements.size() - 1];
125125
for (PsiElement element : elements) {
126126
if (rowIndex > 0) {
127-
children[rowIndex - 1] = new Field(element == null ? CsvHelper.createEmptyCsvField(element.getProject()) : element, rowIndex - 1);
127+
children[rowIndex - 1] = new Field(element == null ? CsvHelper.createEmptyCsvField(this.element.getProject()) : element, rowIndex - 1);
128128
}
129129
++rowIndex;
130130
}
@@ -144,7 +144,7 @@ public Icon getIcon(boolean unused) {
144144
}
145145
}
146146

147-
private static class Field extends CsvStructureViewElement {
147+
public static class Field extends CsvStructureViewElement {
148148
private int rowIndex;
149149

150150
public Field(PsiElement element, int rowIndex) {

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<b>FIX:</b> CSV column info tooltip trumps spellchecker tooltip (but keeps the visualization of a typo)<br>
4343
<b>FIX:</b> Show tooltip even when caret is at the last position withing the CSV file<br>
4444
<b>FIX:</b> Support for suppressing inspections not relevant for CSV (e.g. 'Problematic Whitespace')<br>
45+
<b>FIX:</b> Structure View: proper handling of <undefined> elements (instead of endless loading)<br>
4546
+ several code & performance improvements
4647
<br><br>
4748
]]>
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package net.seesharpsoft.intellij.plugins.csv.structureview;
2+
3+
import com.intellij.ide.structureView.StructureViewTreeElement;
4+
import com.intellij.ide.util.treeView.smartTree.TreeElement;
5+
import com.intellij.navigation.ItemPresentation;
6+
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
7+
8+
public class CsvStructureViewTest extends LightCodeInsightFixtureTestCase {
9+
10+
@Override
11+
protected String getTestDataPath() {
12+
return "./src/test/resources/structureview";
13+
}
14+
15+
private void doCheckTreeElement(TreeElement element, Class expectedClazz, String expectedText, String expectedLocation) {
16+
assertInstanceOf(element, expectedClazz);
17+
assertInstanceOf(element, ItemPresentation.class);
18+
19+
ItemPresentation presentation = (ItemPresentation) element;
20+
assertEquals(expectedText, presentation.getPresentableText());
21+
if (expectedLocation != null) {
22+
assertEquals(expectedLocation, presentation.getLocationString());
23+
}
24+
}
25+
26+
public void testStructureView() {
27+
myFixture.configureByFile("StructureViewTestData.csv");
28+
myFixture.testStructureView(structureViewComponent -> {
29+
StructureViewTreeElement root = structureViewComponent.getTreeModel().getRoot();
30+
doCheckTreeElement(root, CsvStructureViewElement.File.class, "FirstName, LastName\n" +
31+
"Peter,Lustig,42\n" +
32+
"Martin\n" +
33+
",Fuchs\n", null);
34+
assertEquals(3, root.getChildren().length);
35+
36+
TreeElement header = root.getChildren()[0];
37+
doCheckTreeElement(
38+
header,
39+
CsvStructureViewElement.Header.class,
40+
"FirstName",
41+
"Header (4 entries)"
42+
);
43+
44+
TreeElement field = header.getChildren()[0];
45+
doCheckTreeElement(
46+
field,
47+
CsvStructureViewElement.Field.class,
48+
"Peter",
49+
"(1)"
50+
);
51+
field = header.getChildren()[1];
52+
doCheckTreeElement(
53+
field,
54+
CsvStructureViewElement.Field.class,
55+
"Martin",
56+
"(2)"
57+
);
58+
field = header.getChildren()[2];
59+
doCheckTreeElement(
60+
field,
61+
CsvStructureViewElement.Field.class,
62+
"",
63+
"(3)"
64+
);
65+
field = header.getChildren()[3];
66+
doCheckTreeElement(
67+
field,
68+
CsvStructureViewElement.Field.class,
69+
"",
70+
"(4)"
71+
);
72+
73+
/**
74+
* LastName header
75+
*/
76+
header = root.getChildren()[1];
77+
doCheckTreeElement(
78+
header,
79+
CsvStructureViewElement.Header.class,
80+
"LastName",
81+
"Header (3 entries)"
82+
);
83+
84+
field = header.getChildren()[0];
85+
doCheckTreeElement(
86+
field,
87+
CsvStructureViewElement.Field.class,
88+
"Lustig",
89+
"(1)"
90+
);
91+
field = header.getChildren()[1];
92+
doCheckTreeElement(
93+
field,
94+
CsvStructureViewElement.Field.class,
95+
"<undefined>",
96+
"(2)"
97+
);
98+
field = header.getChildren()[2];
99+
doCheckTreeElement(
100+
field,
101+
CsvStructureViewElement.Field.class,
102+
"Fuchs",
103+
"(3)"
104+
);
105+
106+
/**
107+
* Empty header
108+
*/
109+
header = root.getChildren()[2];
110+
doCheckTreeElement(
111+
header,
112+
CsvStructureViewElement.Header.class,
113+
"<undefined>",
114+
"Header (1 entries)"
115+
);
116+
117+
field = header.getChildren()[0];
118+
doCheckTreeElement(
119+
field,
120+
CsvStructureViewElement.Field.class,
121+
"42",
122+
"(1)"
123+
);
124+
});
125+
}
126+
127+
128+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FirstName, LastName
2+
Peter,Lustig,42
3+
Martin
4+
,Fuchs

0 commit comments

Comments
 (0)