Skip to content

Commit b87158e

Browse files
authoredDec 15, 2022
Merge pull request #389 from SeeSharpSoft/fix_bugs
Prepare bug fix release
2 parents 0c29728 + 3fcf289 commit b87158e

File tree

12 files changed

+115
-67
lines changed

12 files changed

+115
-67
lines changed
 

‎.github/workflows/PublishStable.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ jobs:
1818
include:
1919
- ideaVersion: 2022.2.1
2020
gkVersion: 2021.1.2
21-
- ideaVersion: LATEST-EAP-SNAPSHOT
21+
- ideaVersion: 2022.3.1
2222
gkVersion: 2021.1.2
23+
# - ideaVersion: LATEST-EAP-SNAPSHOT
24+
# gkVersion: 2021.1.2
2325

2426
steps:
2527
- uses: actions/checkout@v2

‎CHANGELOG

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
3.0.2
2+
Dec 15, 2022
3+
4+
FIX: Detected bulk mode status update from DocumentBulkUpdateListener #384
5+
FIX: Argument for @NotNull parameter 'parent' of PsiHelper.getNthChildOfType must not be null #372
6+
FIX: Argument for @NotNull parameter 'element' of PsiHelper.getSiblingOfType must not be null #375
7+
FIX: Cannot invoke "Document.getText()" because "document" is null #388
8+
FIX: Cannot invoke "PsiFile.getProject()" because the return value of "CsvPsiTreeUpdater.getPsiFile()" is null #378
9+
FIX: Argument for @NotNull parameter 'replacement' of CsvPsiTreeUpdater$ReplacePsiAction.<init> must not be null #380
10+
FIX: provide project parameter for opening link
11+
FIX: Cannot invoke "Document.insertString(int, java.lang.CharSequence)" because "document" is null #386
12+
FIX: first extension sanity check
13+
114
3.0.1
215
Nov 12, 2022
316

‎build.gradle

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
// https://github.com/JetBrains/gradle-intellij-plugin
3-
id 'org.jetbrains.intellij' version '1.9.0'
3+
id 'org.jetbrains.intellij' version '1.10.1'
44
id 'jacoco'
55
id 'com.github.kt3k.coveralls' version '2.8.4'
66
id 'com.github.ManifestClasspath' version '0.1.0-RELEASE'
@@ -73,7 +73,7 @@ var final EAP_BUILD = '223'
7373
var idea_version = System.getenv().getOrDefault('IDEA_VERSION', '2022.2.1')
7474
var build_version = idea_version == EAP_VERSION ? EAP_BUILD : idea_version.substring(2, 4) + idea_version.charAt(5) // extract e.g. '221' from '2022.1.1'
7575

76-
version '3.0.1-' + build_version
76+
version '3.0.2-' + build_version
7777

7878
apply plugin: 'org.jetbrains.intellij'
7979
intellij {
@@ -107,15 +107,17 @@ Feedback is welcome!
107107
PS: The previous versions are still available on the project page.
108108
109109
110-
Update 3.0.1
111-
112-
FIX: cannot init component state (componentName=CsvFileAttributes) #359
113-
FIX: cannot invoke "add(Object)" because "this.myUncommittedActions" is null #361
114-
FIX: cannot invoke "createNotification(...)" because "notificationGroup" is null #362
115-
FIX: cannot invoke "getManager()" because the return value of "getPsiFile()" is null #363
116-
FIX: image in plugin description
117-
FIX: plugin update restart
110+
Update 3.0.2
118111
112+
FIX: Detected bulk mode status update from DocumentBulkUpdateListener #384
113+
FIX: Argument for @NotNull parameter 'parent' of PsiHelper.getNthChildOfType must not be null #372
114+
FIX: Argument for @NotNull parameter 'element' of PsiHelper.getSiblingOfType must not be null #375
115+
FIX: Cannot invoke "Document.getText()" because "document" is null #388
116+
FIX: Cannot invoke "PsiFile.getProject()" because the return value of "CsvPsiTreeUpdater.getPsiFile()" is null #378
117+
FIX: Argument for @NotNull parameter 'replacement' of CsvPsiTreeUpdater\$ReplacePsiAction.<init> must not be null #380
118+
FIX: provide project parameter for opening link
119+
FIX: Cannot invoke "Document.insertString(int, java.lang.CharSequence)" because "document" is null #386
120+
FIX: first extension sanity check
119121
120122
</pre>"""
121123
}
@@ -164,10 +166,3 @@ tasks.named("generateLexer").configure {
164166
compileJava {
165167
dependsOn generateLexer
166168
}
167-
168-
// TODO https://youtrack.jetbrains.com/issue/IDEA-298989 - remove after gradle plugin v1.9.1 or v1.10.0 released
169-
setupDependencies {
170-
doLast {
171-
fileTree("$buildDir/instrumented/instrumentCode") { include("**/*TableEditorSwing.class") }.files.forEach { delete(it) }
172-
}
173-
}

‎src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvHelper.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static boolean isCsvFile(String extension) {
7575
}
7676

7777
public static boolean isCsvFile(Project project, VirtualFile file) {
78-
if (project == null || file == null) {
78+
if (project == null || file == null || !isCsvFile(file.getExtension())) {
7979
return false;
8080
}
8181
final Language language = LanguageUtil.getLanguageForPsi(project, file);
@@ -312,10 +312,6 @@ public static String quoteCsvField(String content,
312312
}
313313
if (quotingEnforced || isQuotingRequired(content, valueSeparator)) {
314314
String result = content;
315-
// if (escapeCharacter != CsvEscapeCharacter.QUOTE) {
316-
// result = result.replaceAll(escapeCharacter.getRegexPattern(),
317-
// escapeCharacter.getRegexPattern() + escapeCharacter.getRegexPattern());
318-
// }
319315
result = result.replaceAll("\"", escapeCharacter.getRegexPattern() + "\"");
320316
return "\"" + result + "\"";
321317
}

‎src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvPlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private static void openLink(Project project, String link) {
3737
if (link.startsWith("#")) {
3838
((ShowSettingsUtilImpl) ShowSettingsUtil.getInstance()).showSettingsDialog(project, link.substring(1), null);
3939
} else {
40-
BrowserUtil.browse(link);
40+
BrowserUtil.browse(link, project);
4141
}
4242
}
4343

‎src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableModelBase.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ public void setValue(String value, int rowIndex, int columnIndex) {
157157
}
158158

159159
private int getColumnCount(int rowIndex) {
160-
return getColumnCount(PsiHelper.getNthChildOfType(getPsiTreeUpdater().getPsiFile(), rowIndex, CsvRecord.class));
160+
PsiFile psiFile = getPsiFile();
161+
if (psiFile == null) return 0;
162+
return getColumnCount(PsiHelper.getNthChildOfType(psiFile, rowIndex, CsvRecord.class));
161163
}
162164

163165
private int getColumnCount(PsiElement record) {

‎src/main/java/net/seesharpsoft/intellij/plugins/csv/inspection/CsvValidationInspection.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ public String getFamilyName() {
121121
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
122122
PsiElement element = descriptor.getPsiElement();
123123
Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
124-
List<Integer> quotePositions = new ArrayList<>();
124+
if (document == null) return;
125125

126+
List<Integer> quotePositions = new ArrayList<>();
126127
int quotePosition = CsvIntentionHelper.getOpeningQuotePosition(element);
127128
if (quotePosition != -1) {
128129
quotePositions.add(quotePosition);
@@ -147,6 +148,8 @@ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descri
147148
try {
148149
PsiElement element = descriptor.getPsiElement();
149150
Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
151+
if (document == null) return;
152+
150153
CsvValueSeparator separator = CsvHelper.getValueSeparator(element.getContainingFile());
151154
String text = document.getText();
152155
document.setText(text.substring(0, element.getTextOffset()) + separator.getCharacter() + text.substring(element.getTextOffset()));
@@ -166,6 +169,8 @@ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descri
166169
try {
167170
PsiElement element = descriptor.getPsiElement();
168171
Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
172+
if (document == null) return;
173+
169174
document.setText(document.getText() + "\"");
170175
} catch (IncorrectOperationException e) {
171176
LOG.error(e);

‎src/main/java/net/seesharpsoft/intellij/plugins/csv/intention/CsvIntentionHelper.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ public static Collection<PsiElement> getAllElements(PsiFile file) {
4747

4848
public static void quoteAll(@NotNull Project project, @NotNull PsiFile psiFile) {
4949
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
50-
List<Integer> quotePositions = new ArrayList<>();
50+
if (document == null) return;
5151

52+
List<Integer> quotePositions = new ArrayList<>();
5253
PsiTreeUtil.processElements(psiFile, CsvField.class, field -> {
5354
if (PsiHelper.getElementType(field.getFirstChild()) != CsvTypes.QUOTE) {
5455
quotePositions.add(field.getTextRange().getStartOffset());
@@ -63,6 +64,8 @@ public static void quoteAll(@NotNull Project project, @NotNull PsiFile psiFile)
6364

6465
public static void quoteValue(@NotNull Project project, @NotNull final PsiElement field) {
6566
Document document = PsiDocumentManager.getInstance(project).getDocument(field.getContainingFile());
67+
if (document == null) return;
68+
6669
List<Integer> quotePositions = new ArrayList<>();
6770
if (PsiHelper.getElementType(field.getFirstChild()) != CsvTypes.QUOTE) {
6871
quotePositions.add(field.getTextRange().getStartOffset());
@@ -75,9 +78,9 @@ public static void quoteValue(@NotNull Project project, @NotNull final PsiElemen
7578

7679
public static void unquoteAll(@NotNull Project project, @NotNull PsiFile psiFile) {
7780
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
81+
if (document == null) return;
7882

7983
final List<PsiElement> quotePositions = new ArrayList<>();
80-
8184
PsiTreeUtil.processElements(psiFile, CsvField.class, field -> {
8285
if (getChildren(field).stream().noneMatch(element -> PsiHelper.getElementType(element) == CsvTypes.ESCAPED_TEXT)) {
8386
Pair<PsiElement, PsiElement> positions = getQuotePositions(field);
@@ -115,7 +118,7 @@ private static Pair<PsiElement, PsiElement> getQuotePositions(PsiElement element
115118
return null;
116119
}
117120

118-
public static void addQuotes(final Document document, List<Integer> quotePositions) {
121+
public static void addQuotes(@NotNull final Document document, List<Integer> quotePositions) {
119122
int offset = 0;
120123
String quote = "\"";
121124
quotePositions.sort(Integer::compareTo);

‎src/main/java/net/seesharpsoft/intellij/plugins/csv/intention/CsvShiftColumnIntentionAction.java

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ protected static void changeLeftAndRightColumnOrder(@NotNull Project project,
2424
CsvColumnInfo<PsiElement> leftColumnInfo,
2525
CsvColumnInfo<PsiElement> rightColumnInfo) {
2626
Document document = PsiDocumentManager.getInstance(project).getDocument(csvFile);
27+
if (document == null) return;
28+
2729
document.setText(
2830
changeLeftAndRightColumnOrder(document.getText(), CsvHelper.getValueSeparator(csvFile), leftColumnInfo, rightColumnInfo)
2931
);

‎src/main/java/net/seesharpsoft/intellij/plugins/csv/psi/CsvPsiTreeUpdater.java

+66-36
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,46 @@
2424

2525
public class CsvPsiTreeUpdater implements PsiFileHolder, Suspendable {
2626

27-
private final PsiFileHolder myPsiFileHolder;
27+
protected final EventListenerList myEventListenerList = new EventListenerList();
2828

29-
private final PsiFileFactory myFileFactory;
29+
private final PsiFileHolder myPsiFileHolder;
3030

31-
private final CsvPsiParserFileType myFileType;
31+
private PsiFileFactory myFileFactory;
3232

33-
protected final EventListenerList myEventListenerList = new EventListenerList();
33+
private CsvPsiParserFileType myFileType;
3434

3535
private List<PsiAction> myUncommittedActions = new ArrayList<>();
3636

3737
public CsvPsiTreeUpdater(@NotNull PsiFileHolder psiFileHolder) {
3838
myPsiFileHolder = psiFileHolder;
39-
myFileFactory = PsiFileFactory.getInstance(getPsiFile().getProject());
40-
myFileType = new CsvPsiParserFileType(CsvHelper.getValueSeparator(psiFileHolder.getPsiFile()), CsvHelper.getEscapeCharacter(psiFileHolder.getPsiFile()));
4139
}
4240

4341
private FileType getFileType() {
44-
myFileType.setSeparator(CsvHelper.getValueSeparator(getPsiFile()));
45-
myFileType.setEscapeCharacter(CsvHelper.getEscapeCharacter(getPsiFile()));
42+
PsiFile psiFile = getPsiFile();
43+
if (psiFile == null) return null;
44+
45+
if (myFileType == null) {
46+
myFileType = new CsvPsiParserFileType(CsvHelper.getValueSeparator(psiFile), CsvHelper.getEscapeCharacter(psiFile));
47+
} else {
48+
myFileType.setSeparator(CsvHelper.getValueSeparator(psiFile));
49+
myFileType.setEscapeCharacter(CsvHelper.getEscapeCharacter(psiFile));
50+
}
4651
return myFileType;
4752
}
4853

54+
private PsiFileFactory getFileFactory() {
55+
PsiFile psiFile = getPsiFile();
56+
if (psiFile == null) return null;
57+
58+
if (myFileFactory == null) {
59+
myFileFactory = PsiFileFactory.getInstance(getPsiFile().getProject());
60+
}
61+
return myFileFactory;
62+
}
63+
4964
private PsiFile createFile(@NotNull String text) {
50-
return myFileFactory.createFileFromText("a.csv", getFileType(), text);
65+
PsiFileFactory fileFactory = getFileFactory();
66+
return fileFactory == null ? null : getFileFactory().createFileFromText("a.csv", getFileType(), text);
5167
}
5268

5369
private boolean isIndicatingComment(@NotNull String text) {
@@ -63,7 +79,7 @@ private boolean isIndicatingComment(@NotNull String text) {
6379
return SyntaxTraverser.psiTraverser(createFile(sanitizedValue)).filter(CsvField.class).first();
6480
}
6581

66-
public @NotNull CsvRecord createRecord() {
82+
public @Nullable CsvRecord createRecord() {
6783
return SyntaxTraverser.psiTraverser(createFile("\n")).filter(CsvRecord.class).first();
6884
}
6985

@@ -73,6 +89,8 @@ private boolean isIndicatingComment(@NotNull String text) {
7389

7490
public Document getDocument() {
7591
PsiFile psiFile = getPsiFile();
92+
if (psiFile == null) return null;
93+
7694
return PsiDocumentManager.getInstance(psiFile.getProject()).getDocument(psiFile);
7795
}
7896

@@ -244,12 +262,16 @@ public void deleteRow(@NotNull PsiElement row) {
244262
}
245263

246264
public void deleteRows(Collection<Integer> indices) {
247-
Set<PsiElement> toDelete = new HashSet<>();
248265
PsiFile psiFile = getPsiFile();
266+
if (psiFile == null) return;
267+
268+
Set<PsiElement> toDelete = new HashSet<>();
249269
List<Integer> sortedIndices = new ArrayList<>(indices);
250270
Collections.sort(sortedIndices);
251271
for (int rowIndex : sortedIndices) {
252272
CsvRecord row = PsiHelper.getNthChildOfType(psiFile, rowIndex, CsvRecord.class);
273+
if (row == null) continue;
274+
253275
boolean removePreviousLF = rowIndex > 0;
254276
PsiElement lf = PsiHelper.getSiblingOfType(row, CsvTypes.CRLF, removePreviousLF);
255277
if (lf == null || toDelete.contains(lf)) {
@@ -318,34 +340,34 @@ private void doAddField(@NotNull PsiElement anchor, @Nullable String text, boole
318340
public synchronized void commit() {
319341
if (isSuspended() || myUncommittedActions == null || myUncommittedActions.size() == 0) return;
320342

321-
suspend();
322343
List<PsiAction> actionsToCommit = new ArrayList<>(myUncommittedActions);
323-
if (!doCommit(() -> {
324-
try {
325-
actionsToCommit.forEach(PsiAction::execute);
326-
} finally {
327-
resume();
328-
fireCommitted();
329-
}
330-
})) {
331-
resume();
332-
} else {
333-
myUncommittedActions.clear();
334-
}
344+
myUncommittedActions.clear();
345+
346+
doCommit(() -> actionsToCommit.forEach(PsiAction::execute));
335347
}
336348

337349
private boolean doCommit(@NotNull Runnable runnable) {
338-
if (!getPsiFile().isWritable()) return false;
339-
350+
PsiFile psiFile = getPsiFile();
340351
Document document = getDocument();
341352

353+
if (psiFile == null || !psiFile.isWritable() || document == null || !document.isWritable())
354+
{
355+
return false;
356+
}
357+
358+
suspend();
342359
ApplicationManager.getApplication().runWriteAction(() -> {
343-
CommandProcessor.getInstance().executeCommand(
344-
getPsiFile().getProject(),
345-
() -> DocumentUtil.executeInBulk(document, runnable),
346-
"CSV Editor changes",
347-
null,
348-
document);
360+
try {
361+
CommandProcessor.getInstance().executeCommand(
362+
getPsiFile().getProject(),
363+
() -> DocumentUtil.executeInBulk(document, runnable),
364+
"CSV Editor changes",
365+
null,
366+
document);
367+
} finally {
368+
resume();
369+
fireCommitted();
370+
}
349371
});
350372

351373
return true;
@@ -394,18 +416,20 @@ private static class AddSiblingPsiAction extends PsiAction {
394416
private final PsiElement myElementToAdd;
395417
private final boolean myBefore;
396418

397-
AddSiblingPsiAction(@NotNull PsiElement anchor, @NotNull PsiElement elementToAdd) {
419+
AddSiblingPsiAction(@NotNull PsiElement anchor, @Nullable PsiElement elementToAdd) {
398420
this(anchor, elementToAdd, false);
399421
}
400422

401-
AddSiblingPsiAction(@NotNull PsiElement anchor, @NotNull PsiElement elementToAdd, boolean before) {
423+
AddSiblingPsiAction(@NotNull PsiElement anchor, @Nullable PsiElement elementToAdd, boolean before) {
402424
super(anchor);
403425
myElementToAdd = elementToAdd;
404426
myBefore = before;
405427
}
406428

407429
@Override
408430
public void execute() {
431+
if (myElementToAdd == null) return;
432+
409433
PsiElement anchor = getAnchor();
410434
if (anchor.getParent() == null) return;
411435
if (myBefore) {
@@ -420,13 +444,15 @@ private static class AddChildPsiAction extends PsiAction {
420444

421445
private final PsiElement myElementToAdd;
422446

423-
AddChildPsiAction(@NotNull PsiElement parent, @NotNull PsiElement elementToAdd) {
447+
AddChildPsiAction(@NotNull PsiElement parent, @Nullable PsiElement elementToAdd) {
424448
super(parent);
425449
myElementToAdd = elementToAdd;
426450
}
427451

428452
@Override
429453
public void execute() {
454+
if (myElementToAdd == null) return;
455+
430456
PsiElement anchor = getAnchor();
431457
anchor.add(myElementToAdd);
432458
}
@@ -436,13 +462,15 @@ private static class ReplacePsiAction extends PsiAction {
436462

437463
private final PsiElement myReplacement;
438464

439-
ReplacePsiAction(@NotNull PsiElement anchor, @NotNull PsiElement replacement) {
465+
ReplacePsiAction(@NotNull PsiElement anchor, @Nullable PsiElement replacement) {
440466
super(anchor);
441467
myReplacement = replacement;
442468
}
443469

444470
@Override
445471
public void execute() {
472+
if (myReplacement == null) return;
473+
446474
getAnchor().replace(myReplacement);
447475
}
448476
}
@@ -491,6 +519,8 @@ public void execute() {
491519

492520
PsiDocumentManager manager = PsiDocumentManager.getInstance(psiFile.getProject());
493521
Document document = manager.getDocument(psiFile);
522+
if (document == null) return;
523+
494524
manager.doPostponedOperationsAndUnblockDocument(document);
495525

496526
int offset = 0;

‎src/main/java/net/seesharpsoft/intellij/psi/PsiHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static PsiElement getLastSiblingOfType(@NotNull final PsiElement element,
103103
return prevSibling == element ? null : prevSibling;
104104
}
105105

106-
public static PsiElement findFirst(@NotNull final PsiElement root, @NotNull IElementType type) {
106+
public static PsiElement findFirst(@Nullable final PsiElement root, @NotNull IElementType type) {
107107
return SyntaxTraverser.psiTraverser(root).filterTypes(elementType -> elementType == type).filter(PsiElement.class).first();
108108
}
109109

‎src/main/java/net/seesharpsoft/intellij/util/Suspendable.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ default void dispose() {
2828
class SuspensionMonitor {
2929
private final Map<Suspendable, Integer> suspendableCounterMap = new ConcurrentHashMap<>();
3030

31-
private Integer getSuspendableCounter(Suspendable suspendable) {
31+
private synchronized Integer getSuspendableCounter(Suspendable suspendable) {
3232
if (suspendableCounterMap.containsKey(suspendable)) return suspendableCounterMap.get(suspendable);
3333
return null;
3434
}

0 commit comments

Comments
 (0)
Please sign in to comment.