mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-121518 Cannot edit files in IDEA after project opening:
initial folding in opening thread, assertions relaxed
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
public class Bar {
|
||||
public String doIt() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.editor.impl;
|
||||
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jdom.JDOMException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class JavaFileEditorManagerTest extends FileEditorManagerTestCase {
|
||||
|
||||
public void testAsyncOpening() throws JDOMException, ExecutionException, InterruptedException, IOException {
|
||||
openFiles("<component name=\"FileEditorManager\">\n" +
|
||||
" <leaf>\n" +
|
||||
" <file leaf-file-name=\"Bar.java\" pinned=\"false\" current=\"true\" current-in-tab=\"true\">\n" +
|
||||
" <entry file=\"file://$PROJECT_DIR$/src/Bar.java\">\n" +
|
||||
" <provider selected=\"true\" editor-type-id=\"text-editor\">\n" +
|
||||
" <state vertical-scroll-proportion=\"0.032882012\" vertical-offset=\"0\" max-vertical-offset=\"517\">\n" +
|
||||
" <caret line=\"1\" column=\"26\" selection-start=\"45\" selection-end=\"45\" />\n" +
|
||||
" <folding>\n" +
|
||||
" <element signature=\"e#69#70#0\" expanded=\"true\" />\n" +
|
||||
" </folding>\n" +
|
||||
" </state>\n" +
|
||||
" </provider>\n" +
|
||||
" </entry>\n" +
|
||||
" </file>\n" +
|
||||
" </leaf>\n" +
|
||||
" </component>");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + "/java/java-tests/testData/fileEditorManager";
|
||||
}
|
||||
}
|
||||
@@ -184,17 +184,17 @@ public class DaemonListeners implements Disposable {
|
||||
!worthBothering(editor.getDocument(), editor.getProject())) {
|
||||
return; //no need to stop daemon if something happened in the console
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!editor.getComponent().isShowing() && !application.isUnitTestMode() ||
|
||||
myProject.isDisposed()) {
|
||||
return;
|
||||
if (!application.isUnitTestMode()) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!editor.getComponent().isShowing() || myProject.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
myDaemonCodeAnalyzer.hideLastIntentionHint();
|
||||
}
|
||||
myDaemonCodeAnalyzer.hideLastIntentionHint();
|
||||
}
|
||||
}, ModalityState.current());
|
||||
}, ModalityState.current());
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
|
||||
+15
-22
@@ -39,7 +39,6 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.ui.LightweightHint;
|
||||
import com.intellij.util.containers.WeakList;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -217,32 +216,26 @@ public class CodeFoldingManagerImpl extends CodeFoldingManager implements Projec
|
||||
|
||||
PsiDocumentManager.getInstance(myProject).commitDocument(document);
|
||||
|
||||
Runnable operation = new Runnable() {
|
||||
Runnable runnable = updateFoldRegions(editor, true, true);
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
}
|
||||
if (myProject.isDisposed() || editor.isDisposed()) return;
|
||||
foldingModel.runBatchFoldingOperation(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Runnable runnable = updateFoldRegions(editor, true, true);
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
DocumentFoldingInfo documentFoldingInfo = getDocumentFoldingInfo(document);
|
||||
Editor[] editors = EditorFactory.getInstance().getEditors(document, myProject);
|
||||
for (Editor otherEditor : editors) {
|
||||
if (otherEditor == editor) continue;
|
||||
documentFoldingInfo.loadFromEditor(otherEditor);
|
||||
break;
|
||||
}
|
||||
if (myProject.isDisposed() || editor.isDisposed()) return;
|
||||
foldingModel.runBatchFoldingOperation(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DocumentFoldingInfo documentFoldingInfo = getDocumentFoldingInfo(document);
|
||||
Editor[] editors = EditorFactory.getInstance().getEditors(document, myProject);
|
||||
for (Editor otherEditor : editors) {
|
||||
if (otherEditor == editor) continue;
|
||||
documentFoldingInfo.loadFromEditor(otherEditor);
|
||||
break;
|
||||
}
|
||||
documentFoldingInfo.setToEditor(editor);
|
||||
documentFoldingInfo.setToEditor(editor);
|
||||
|
||||
documentFoldingInfo.clear();
|
||||
}
|
||||
});
|
||||
documentFoldingInfo.clear();
|
||||
}
|
||||
};
|
||||
UIUtil.invokeLaterIfNeeded(operation);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-5
@@ -21,6 +21,7 @@ import com.intellij.lang.folding.FoldingBuilder;
|
||||
import com.intellij.lang.folding.FoldingDescriptor;
|
||||
import com.intellij.lang.folding.LanguageFolding;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ex.ApplicationManagerEx;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -38,7 +39,6 @@ import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
class DocumentFoldingInfo implements JDOMExternalizable, CodeFoldingState {
|
||||
@@ -64,7 +64,7 @@ class DocumentFoldingInfo implements JDOMExternalizable, CodeFoldingState {
|
||||
}
|
||||
|
||||
void loadFromEditor(@NotNull Editor editor) {
|
||||
assertDispatchThread();
|
||||
assertDispatchThread(editor);
|
||||
LOG.assertTrue(!editor.isDisposed());
|
||||
clear();
|
||||
|
||||
@@ -95,12 +95,12 @@ class DocumentFoldingInfo implements JDOMExternalizable, CodeFoldingState {
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertDispatchThread() {
|
||||
assert SwingUtilities.isEventDispatchThread() : Thread.currentThread();
|
||||
private static void assertDispatchThread(@NotNull Editor editor) {
|
||||
ApplicationManagerEx.getApplicationEx().assertIsDispatchThread(editor.getComponent());
|
||||
}
|
||||
|
||||
void setToEditor(@NotNull final Editor editor) {
|
||||
assertDispatchThread();
|
||||
assertDispatchThread(editor);
|
||||
final PsiManager psiManager = PsiManager.getInstance(myProject);
|
||||
if (psiManager.isDisposed()) return;
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -201,7 +200,6 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedDocumentList
|
||||
}
|
||||
|
||||
private void runBatchFoldingOperation(final Runnable operation, final boolean dontCollapseCaret, final boolean moveCaret) {
|
||||
LOG.assertTrue(SwingUtilities.isEventDispatchThread(), Thread.currentThread().toString());
|
||||
assertIsDispatchThreadForEditor();
|
||||
boolean oldDontCollapseCaret = myDoNotCollapseCaret;
|
||||
myDoNotCollapseCaret |= dontCollapseCaret;
|
||||
|
||||
+9
-35
@@ -17,29 +17,20 @@ package com.intellij.openapi.fileEditor;
|
||||
|
||||
import com.intellij.ide.ui.UISettings;
|
||||
import com.intellij.mock.Mock;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.ExpandMacroToPathMap;
|
||||
import com.intellij.openapi.fileEditor.impl.EditorWithProviderComposite;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.serialization.PathMacroUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
@@ -77,17 +68,18 @@ public class FileEditorManagerTest extends FileEditorManagerTestCase {
|
||||
|
||||
openFiles(" <component name=\"FileEditorManager\">\n" +
|
||||
" <leaf>\n" +
|
||||
" <file leaf-file-name=\"foo.xsd\" pinned=\"false\" current=\"true\" current-in-tab=\"true\">\n" +
|
||||
" <entry selected=\"true\" file=\"file://$PROJECT_DIR$/src/1.txt\">\n" +
|
||||
" <provider editor-type-id=\"mock\" selected=\"true\">\n" +
|
||||
" <state />\n" +
|
||||
" </provider>\n" +
|
||||
" <provider editor-type-id=\"text-editor\">\n" +
|
||||
" <state/>\n" +
|
||||
" <file leaf-file-name=\"Bar.java\" pinned=\"false\" current=\"false\" current-in-tab=\"false\">\n" +
|
||||
" <entry file=\"file://$PROJECT_DIR$/src/Bar.java\">\n" +
|
||||
" <provider selected=\"true\" editor-type-id=\"text-editor\">\n" +
|
||||
" <state vertical-scroll-proportion=\"0.0\" vertical-offset=\"0\" max-vertical-offset=\"187\">\n" +
|
||||
" <caret line=\"1\" column=\"26\" selection-start=\"45\" selection-end=\"45\" />\n" +
|
||||
" <folding>\n" +
|
||||
" <element signature=\"e#69#70#0\" expanded=\"true\" />\n" +
|
||||
" </folding>\n" +
|
||||
" </state>\n" +
|
||||
" </provider>\n" +
|
||||
" </entry>\n" +
|
||||
" </file>\n" +
|
||||
" </leaf>\n" +
|
||||
" </component>\n");
|
||||
FileEditor[] selectedEditors = myManager.getSelectedEditors();
|
||||
assertEquals(1, selectedEditors.length);
|
||||
@@ -157,24 +149,6 @@ public class FileEditorManagerTest extends FileEditorManagerTestCase {
|
||||
assertEquals(Arrays.asList(fileNames), names);
|
||||
}
|
||||
|
||||
private void openFiles(String s) throws IOException, JDOMException, InterruptedException, ExecutionException {
|
||||
Document document = JDOMUtil.loadDocument(s);
|
||||
Element rootElement = document.getRootElement();
|
||||
ExpandMacroToPathMap map = new ExpandMacroToPathMap();
|
||||
map.addMacroExpand(PathMacroUtil.PROJECT_DIR_MACRO_NAME, getTestDataPath());
|
||||
map.substitute(rootElement, true, true);
|
||||
|
||||
myManager.readExternal(rootElement);
|
||||
|
||||
Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myManager.getMainSplitters().openFiles();
|
||||
}
|
||||
});
|
||||
future.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + "/platform/platform-tests/testData/fileEditorManager";
|
||||
|
||||
+40
@@ -1,13 +1,27 @@
|
||||
package com.intellij.openapi.fileEditor;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.ExpandMacroToPathMap;
|
||||
import com.intellij.openapi.components.impl.ComponentManagerImpl;
|
||||
import com.intellij.openapi.fileEditor.ex.FileEditorProviderManager;
|
||||
import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl;
|
||||
import com.intellij.openapi.fileEditor.impl.FileEditorProviderManagerImpl;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
|
||||
import com.intellij.ui.docking.DockManager;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.jps.model.serialization.PathMacroUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
@@ -40,4 +54,30 @@ public abstract class FileEditorManagerTestCase extends LightPlatformCodeInsight
|
||||
protected VirtualFile getFile(String path) {
|
||||
return LocalFileSystem.getInstance().refreshAndFindFileByPath(getTestDataPath() + path);
|
||||
}
|
||||
|
||||
protected void openFiles(String s) throws IOException, JDOMException, InterruptedException, ExecutionException {
|
||||
Document document = JDOMUtil.loadDocument(s);
|
||||
Element rootElement = document.getRootElement();
|
||||
ExpandMacroToPathMap map = new ExpandMacroToPathMap();
|
||||
map.addMacroExpand(PathMacroUtil.PROJECT_DIR_MACRO_NAME, getTestDataPath());
|
||||
map.substitute(rootElement, true, true);
|
||||
|
||||
myManager.readExternal(rootElement);
|
||||
|
||||
Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myManager.getMainSplitters().openFiles();
|
||||
}
|
||||
});
|
||||
while (true) {
|
||||
try {
|
||||
future.get(100, TimeUnit.MILLISECONDS);
|
||||
return;
|
||||
}
|
||||
catch (TimeoutException e) {
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user