Skip to content

Commit

Permalink
Revert "Adding bugfix for issue antlr#569"
Browse files Browse the repository at this point in the history
This reverts commit c25e023.
  • Loading branch information
parrt committed Nov 24, 2022
1 parent 220b9a8 commit 8629eff
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
14 changes: 3 additions & 11 deletions src/test/java/org/antlr/intellij/plugin/TestUtils.java
Original file line number Diff line number Diff line change
@@ -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<Exception> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
});
}
Expand Down
50 changes: 0 additions & 50 deletions src/test/java/org/antlr/intellij/plugin/editor/Issue569Test.java

This file was deleted.

0 comments on commit 8629eff

Please sign in to comment.