Skip to content

Commit

Permalink
refact: don't use deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bjansen-caps committed Apr 1, 2023
1 parent 81e5697 commit 2b2d1b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.tree.ErrorNode;

/** Adapt ANTLR's DefaultErrorStrategy so that we add error nodes
* for EOF if reached at start of resync's consumeUntil().
Expand All @@ -16,7 +17,8 @@ public class ErrorStrategyAdaptor extends DefaultErrorStrategy {
protected void consumeUntil(Parser recognizer, IntervalSet set) {
Token o = recognizer.getCurrentToken();
if ( o.getType()==Token.EOF ) {
recognizer.getRuleContext().addErrorNode(o);
ErrorNode errorNode = recognizer.createErrorNode(recognizer.getRuleContext(), o);
recognizer.getRuleContext().addErrorNode(errorNode);
}
super.consumeUntil(recognizer, set);
}
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/org/antlr/intellij/adaptor/psi/Trees.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
package org.antlr.intellij.adaptor.psi;

import com.intellij.lang.Language;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.project.Project;
Expand Down Expand Up @@ -226,14 +225,10 @@ public static PsiElement createLeafFromText(Project project, Language language,
public static void replacePsiFileFromText(final Project project, Language language, final PsiFile psiFile, String text) {
final PsiFile newPsiFile = createFile(project, language, text);
if ( newPsiFile==null ) return;
WriteCommandAction<Void> setTextAction = new WriteCommandAction<Void>(project) {
@Override
protected void run(@NotNull Result result) throws Throwable {
psiFile.deleteChildRange(psiFile.getFirstChild(), psiFile.getLastChild());
psiFile.addRange(newPsiFile.getFirstChild(), newPsiFile.getLastChild());
}
};
setTextAction.execute();
WriteCommandAction.runWriteCommandAction(project, () -> {
psiFile.deleteChildRange(psiFile.getFirstChild(), psiFile.getLastChild());
psiFile.addRange(newPsiFile.getFirstChild(), newPsiFile.getLastChild());
});
}

public static PsiFile createFile(Project project, Language language, String text) {
Expand Down

0 comments on commit 2b2d1b4

Please sign in to comment.