From 9ef6a1d728b6570ee3c52754f527c7fee5a7d74b Mon Sep 17 00:00:00 2001 From: Bastien Jansen Date: Sun, 10 Mar 2024 11:49:01 +0100 Subject: [PATCH] refact: remove usage of deprecated classes --- .../plugin/ANTLRv4FileTypeFactory.java | 12 ------- .../plugin/ANTLRv4PluginController.java | 14 ++++---- .../intellij/plugin/preview/InputPanel.java | 34 +++++++++++++++---- .../intellij/plugin/preview/PreviewPanel.java | 11 ++++-- src/main/resources/META-INF/plugin.xml | 3 +- 5 files changed, 43 insertions(+), 31 deletions(-) delete mode 100644 src/main/java/org/antlr/intellij/plugin/ANTLRv4FileTypeFactory.java diff --git a/src/main/java/org/antlr/intellij/plugin/ANTLRv4FileTypeFactory.java b/src/main/java/org/antlr/intellij/plugin/ANTLRv4FileTypeFactory.java deleted file mode 100644 index 97816b93..00000000 --- a/src/main/java/org/antlr/intellij/plugin/ANTLRv4FileTypeFactory.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.antlr.intellij.plugin; - -import com.intellij.openapi.fileTypes.FileTypeConsumer; -import com.intellij.openapi.fileTypes.FileTypeFactory; -import org.jetbrains.annotations.NotNull; - -public class ANTLRv4FileTypeFactory extends FileTypeFactory{ - @Override - public void createFileTypes(@NotNull FileTypeConsumer fileTypeConsumer) { - fileTypeConsumer.consume(ANTLRv4FileType.INSTANCE, "g4"); - } -} diff --git a/src/main/java/org/antlr/intellij/plugin/ANTLRv4PluginController.java b/src/main/java/org/antlr/intellij/plugin/ANTLRv4PluginController.java index c5da4d54..f19b58e9 100644 --- a/src/main/java/org/antlr/intellij/plugin/ANTLRv4PluginController.java +++ b/src/main/java/org/antlr/intellij/plugin/ANTLRv4PluginController.java @@ -11,10 +11,10 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; -import com.intellij.openapi.editor.event.EditorFactoryAdapter; import com.intellij.openapi.editor.event.EditorFactoryEvent; -import com.intellij.openapi.editor.event.EditorMouseAdapter; +import com.intellij.openapi.editor.event.EditorFactoryListener; import com.intellij.openapi.editor.event.EditorMouseEvent; +import com.intellij.openapi.editor.event.EditorMouseListener; import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.FileEditorManager; @@ -26,12 +26,11 @@ import com.intellij.openapi.progress.util.BackgroundTaskUtil; import com.intellij.openapi.progress.util.ProgressWindow; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileAdapter; import com.intellij.openapi.vfs.VirtualFileEvent; +import com.intellij.openapi.vfs.VirtualFileListener; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowAnchor; @@ -55,7 +54,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.Objects; /** This object is the controller for the ANTLR plug-in. It receives * events and can send them on to its contained components. For example, @@ -226,7 +224,7 @@ public void installListeners() { EditorFactory factory = EditorFactory.getInstance(); factory.addEditorFactoryListener( - new EditorFactoryAdapter() { + new EditorFactoryListener() { @Override public void editorCreated(@NotNull EditorFactoryEvent event) { final Editor editor = event.getEditor(); @@ -610,7 +608,7 @@ public static VirtualFile getCurrentGrammarFile(Project project) { return null; } - private class GrammarEditorMouseAdapter extends EditorMouseAdapter { + private class GrammarEditorMouseAdapter implements EditorMouseListener { @Override public void mouseClicked(EditorMouseEvent e) { Document doc = e.getEditor().getDocument(); @@ -621,7 +619,7 @@ public void mouseClicked(EditorMouseEvent e) { } } - private class MyVirtualFileAdapter extends VirtualFileAdapter { + private class MyVirtualFileAdapter implements VirtualFileListener { @Override public void contentsChanged(VirtualFileEvent event) { final VirtualFile vfile = event.getFile(); diff --git a/src/main/java/org/antlr/intellij/plugin/preview/InputPanel.java b/src/main/java/org/antlr/intellij/plugin/preview/InputPanel.java index 46c0de9b..f31bd27f 100644 --- a/src/main/java/org/antlr/intellij/plugin/preview/InputPanel.java +++ b/src/main/java/org/antlr/intellij/plugin/preview/InputPanel.java @@ -5,13 +5,25 @@ import com.intellij.codeInsight.hint.HintUtil; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.editor.*; +import com.intellij.openapi.editor.CaretModel; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.EditorFactory; +import com.intellij.openapi.editor.EditorSettings; +import com.intellij.openapi.editor.LogicalPosition; +import com.intellij.openapi.editor.ScrollType; +import com.intellij.openapi.editor.ScrollingModel; import com.intellij.openapi.editor.event.CaretListener; -import com.intellij.openapi.editor.event.DocumentAdapter; import com.intellij.openapi.editor.event.DocumentEvent; +import com.intellij.openapi.editor.event.DocumentListener; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.EditorMarkupModel; -import com.intellij.openapi.editor.markup.*; +import com.intellij.openapi.editor.markup.EffectType; +import com.intellij.openapi.editor.markup.HighlighterLayer; +import com.intellij.openapi.editor.markup.HighlighterTargetArea; +import com.intellij.openapi.editor.markup.MarkupModel; +import com.intellij.openapi.editor.markup.RangeHighlighter; +import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; import com.intellij.openapi.fileEditor.FileDocumentManager; @@ -32,8 +44,16 @@ import org.antlr.intellij.plugin.parsing.PreviewParser; import org.antlr.intellij.plugin.profiler.ProfilerPanel; import org.antlr.runtime.CommonToken; -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.*; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.LexerNoViableAltException; +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.RecognitionException; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.atn.AmbiguityInfo; +import org.antlr.v4.runtime.atn.ContextSensitivityInfo; +import org.antlr.v4.runtime.atn.DecisionEventInfo; +import org.antlr.v4.runtime.atn.LookaheadEventInfo; +import org.antlr.v4.runtime.atn.PredicateEvalInfo; import org.antlr.v4.runtime.misc.Interval; import org.antlr.v4.runtime.misc.Pair; import org.antlr.v4.runtime.misc.Utils; @@ -158,7 +178,7 @@ public void createManualInputPreviewEditor(final PreviewState previewState) { final EditorFactory factory = EditorFactory.getInstance(); Document doc = factory.createDocument(""); doc.addDocumentListener( - new DocumentAdapter() { + new DocumentListener() { @Override public void documentChanged(DocumentEvent e) { previewState.manualInputText = e.getDocument().getCharsSequence(); @@ -217,7 +237,7 @@ public Editor createPreviewEditor(final VirtualFile grammarFile, Document doc, b LOG.info("createEditor: create new editor for "+grammarFile.getPath()+" "+previewPanel.project.getName()); final EditorFactory factory = EditorFactory.getInstance(); doc.addDocumentListener( - new DocumentAdapter() { + new DocumentListener() { @Override public void documentChanged(DocumentEvent event) { previewPanel.updateParseTreeFromDoc(grammarFile); diff --git a/src/main/java/org/antlr/intellij/plugin/preview/PreviewPanel.java b/src/main/java/org/antlr/intellij/plugin/preview/PreviewPanel.java index 4425f31c..d4d2d24c 100644 --- a/src/main/java/org/antlr/intellij/plugin/preview/PreviewPanel.java +++ b/src/main/java/org/antlr/intellij/plugin/preview/PreviewPanel.java @@ -1,14 +1,19 @@ package org.antlr.intellij.plugin.preview; import com.intellij.icons.AllIcons; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.actionSystem.ActionToolbar; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.DefaultActionGroup; +import com.intellij.openapi.actionSystem.ToggleAction; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.SelectionModel; -import com.intellij.openapi.editor.event.CaretAdapter; import com.intellij.openapi.editor.event.CaretEvent; +import com.intellij.openapi.editor.event.CaretListener; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.util.SystemInfo; @@ -106,7 +111,7 @@ private void createGUI() { // Had to set min size / preferred size in InputPanel.form to get slider to allow left shift of divider Splitter splitPane = new Splitter(); inputPanel = getEditorPanel(); - inputPanel.addCaretListener(new CaretAdapter() { + inputPanel.addCaretListener(new CaretListener() { @Override public void caretPositionChanged(@NotNull CaretEvent event) { Caret caret = event.getCaret(); diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index ae5e6a5b..325aa7f7 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -142,7 +142,8 @@ For really big files and slow grammars, there is an appreciable delay when displ - +