diff --git a/src/main/java/org/antlr/intellij/plugin/ANTLRv4PluginController.java b/src/main/java/org/antlr/intellij/plugin/ANTLRv4PluginController.java index 3e1a7464..03ee11bc 100644 --- a/src/main/java/org/antlr/intellij/plugin/ANTLRv4PluginController.java +++ b/src/main/java/org/antlr/intellij/plugin/ANTLRv4PluginController.java @@ -6,7 +6,6 @@ import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManager; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.components.ProjectComponent; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; @@ -21,8 +20,6 @@ import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.FileEditorManagerEvent; import com.intellij.openapi.fileEditor.FileEditorManagerListener; -import com.intellij.openapi.fileTypes.FileTypeManager; -import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; @@ -57,6 +54,7 @@ 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, @@ -115,16 +113,6 @@ public static ANTLRv4PluginController getInstance(Project project) { @Override public void initComponent() { - - final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); - final String defaultExtension = ANTLRv4FileType.INSTANCE.getDefaultExtension(); - - WriteCommandAction.runWriteCommandAction(this.project, () -> - fileTypeManager.removeAssociatedExtension(FileTypes.PLAIN_TEXT, defaultExtension)); - - WriteCommandAction.runWriteCommandAction(this.project, () -> - fileTypeManager.associateExtension(ANTLRv4FileType.INSTANCE, defaultExtension)); - } @Override diff --git a/src/test/java/org/antlr/intellij/plugin/TestUtils.java b/src/test/java/org/antlr/intellij/plugin/TestUtils.java index 7298b8f7..7e1b0bf1 100644 --- a/src/test/java/org/antlr/intellij/plugin/TestUtils.java +++ b/src/test/java/org/antlr/intellij/plugin/TestUtils.java @@ -1,33 +1,25 @@ package org.antlr.intellij.plugin; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.EditorFactory; import com.intellij.util.ThrowableRunnable; import com.intellij.util.lang.CompoundRuntimeException; + import java.io.PrintWriter; import java.io.StringWriter; public class TestUtils { - - public static void releaseEditorIfNotDisposed(Editor editor) { - if (!editor.isDisposed()) EditorFactory.getInstance().releaseEditor(editor); - } - public static void tearDownIgnoringObjectNotDisposedException(ThrowableRunnable delegate) throws Exception { try { delegate.run(); } catch (RuntimeException e) { // We don't want to release the editor in the Tool Output tool window, so we ignore // ObjectNotDisposedExceptions related to this particular editor - if ( e.getClass().getName().startsWith("com.intellij.openapi.util.TraceableDisposable$") + if ( e.getClass().getName().equals("com.intellij.openapi.util.TraceableDisposable$ObjectNotDisposedException") || e instanceof CompoundRuntimeException ) { StringWriter stringWriter = new StringWriter(); e.printStackTrace(new PrintWriter(stringWriter)); String stack = stringWriter.toString(); - System.out.println(e.getStackTrace()[0].getClassName()); if ( stack.contains("ANTLRv4PluginController.createToolWindows") || - - stack.contains("Issue559") || stack.contains("Issue540") || stack.contains("Issue569") || + stack.contains("Issue559Test") || stack.contains("Issue540Test") || stack.contains("org.antlr.intellij.plugin.preview.InputPanel.createPreviewEditor") ) { return; } diff --git a/src/test/java/org/antlr/intellij/plugin/editor/Issue540Test.java b/src/test/java/org/antlr/intellij/plugin/editor/Issue540Test.java index 3f36e7d0..619a6006 100644 --- a/src/test/java/org/antlr/intellij/plugin/editor/Issue540Test.java +++ b/src/test/java/org/antlr/intellij/plugin/editor/Issue540Test.java @@ -3,6 +3,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; @@ -98,9 +99,8 @@ protected void tearDown() throws Exception { FileUtils.forceDeleteOnExit(LEXER_FILE); FileUtils.forceDeleteOnExit(PARSER_FILE); FileUtils.forceDeleteOnExit(new File(getTestDataGenPath())); - TestUtils.tearDownIgnoringObjectNotDisposedException(() -> { - super.tearDown(); - }); + EditorFactory.getInstance().releaseEditor(myFixture.getEditor()); + TestUtils.tearDownIgnoringObjectNotDisposedException(super::tearDown); } } \ No newline at end of file diff --git a/src/test/java/org/antlr/intellij/plugin/editor/Issue559Test.java b/src/test/java/org/antlr/intellij/plugin/editor/Issue559Test.java index d6db1e9d..8034e226 100644 --- a/src/test/java/org/antlr/intellij/plugin/editor/Issue559Test.java +++ b/src/test/java/org/antlr/intellij/plugin/editor/Issue559Test.java @@ -1,5 +1,6 @@ package org.antlr.intellij.plugin.editor; +import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; @@ -51,7 +52,7 @@ protected String getTestDataPath() { @Override protected void tearDown() throws Exception { TestUtils.tearDownIgnoringObjectNotDisposedException(() -> { - TestUtils.releaseEditorIfNotDisposed(myFixture.getEditor()); + EditorFactory.getInstance().releaseEditor(myFixture.getEditor()); super.tearDown(); }); } diff --git a/src/test/java/org/antlr/intellij/plugin/editor/Issue569Test.java b/src/test/java/org/antlr/intellij/plugin/editor/Issue569Test.java deleted file mode 100644 index cf49bb62..00000000 --- a/src/test/java/org/antlr/intellij/plugin/editor/Issue569Test.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.antlr.intellij.plugin.editor; - -import com.intellij.openapi.command.WriteCommandAction; -import com.intellij.openapi.editor.EditorFactory; -import com.intellij.openapi.fileTypes.FileTypeManager; -import com.intellij.openapi.fileTypes.FileTypes; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.testFramework.fixtures.BasePlatformTestCase; -import org.antlr.intellij.plugin.ANTLRv4FileType; -import org.antlr.intellij.plugin.ANTLRv4PluginController; -import org.antlr.intellij.plugin.TestUtils; -import org.junit.Test; - -public class Issue569Test extends BasePlatformTestCase { - - @Test - public void test_shouldReassignExtensionType() { - - // Reassign extension temporarily - WriteCommandAction.runWriteCommandAction(getProject(), () -> - FileTypeManager.getInstance().associateExtension(FileTypes.PLAIN_TEXT, "g4")); - - // Test File - VirtualFile file = myFixture.configureByFile("FooParser.g4").getVirtualFile(); - assertEquals(file.getFileType(), FileTypes.PLAIN_TEXT); - - // Create controller and initialize it - ANTLRv4PluginController controller = ANTLRv4PluginController.getInstance(getProject()); - assertNotNull(controller); - controller.initComponent(); - - // Check if file type is reassigned - assertEquals(file.getFileType(), ANTLRv4FileType.INSTANCE); - - } - - @Override - protected String getTestDataPath() { - return "src/test/resources/references"; - } - - @Override - protected void tearDown() throws Exception { - TestUtils.tearDownIgnoringObjectNotDisposedException(() -> { - EditorFactory.getInstance().releaseEditor(myFixture.getEditor()); - super.tearDown(); - }); - } - -} \ No newline at end of file