@@ -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 );
0 commit comments