@@ -47,8 +47,9 @@ public static Collection<PsiElement> getAllElements(PsiFile file) {
47
47
48
48
public static void quoteAll (@ NotNull Project project , @ NotNull PsiFile psiFile ) {
49
49
Document document = PsiDocumentManager .getInstance (project ).getDocument (psiFile );
50
- List < Integer > quotePositions = new ArrayList <>() ;
50
+ if ( document == null ) return ;
51
51
52
+ List <Integer > quotePositions = new ArrayList <>();
52
53
PsiTreeUtil .processElements (psiFile , CsvField .class , field -> {
53
54
if (PsiHelper .getElementType (field .getFirstChild ()) != CsvTypes .QUOTE ) {
54
55
quotePositions .add (field .getTextRange ().getStartOffset ());
@@ -63,6 +64,8 @@ public static void quoteAll(@NotNull Project project, @NotNull PsiFile psiFile)
63
64
64
65
public static void quoteValue (@ NotNull Project project , @ NotNull final PsiElement field ) {
65
66
Document document = PsiDocumentManager .getInstance (project ).getDocument (field .getContainingFile ());
67
+ if (document == null ) return ;
68
+
66
69
List <Integer > quotePositions = new ArrayList <>();
67
70
if (PsiHelper .getElementType (field .getFirstChild ()) != CsvTypes .QUOTE ) {
68
71
quotePositions .add (field .getTextRange ().getStartOffset ());
@@ -75,9 +78,9 @@ public static void quoteValue(@NotNull Project project, @NotNull final PsiElemen
75
78
76
79
public static void unquoteAll (@ NotNull Project project , @ NotNull PsiFile psiFile ) {
77
80
Document document = PsiDocumentManager .getInstance (project ).getDocument (psiFile );
81
+ if (document == null ) return ;
78
82
79
83
final List <PsiElement > quotePositions = new ArrayList <>();
80
-
81
84
PsiTreeUtil .processElements (psiFile , CsvField .class , field -> {
82
85
if (getChildren (field ).stream ().noneMatch (element -> PsiHelper .getElementType (element ) == CsvTypes .ESCAPED_TEXT )) {
83
86
Pair <PsiElement , PsiElement > positions = getQuotePositions (field );
@@ -115,7 +118,7 @@ private static Pair<PsiElement, PsiElement> getQuotePositions(PsiElement element
115
118
return null ;
116
119
}
117
120
118
- public static void addQuotes (final Document document , List <Integer > quotePositions ) {
121
+ public static void addQuotes (@ NotNull final Document document , List <Integer > quotePositions ) {
119
122
int offset = 0 ;
120
123
String quote = "\" " ;
121
124
quotePositions .sort (Integer ::compareTo );
0 commit comments