From f2b3c32bc68d5de05c22fa05d9c62832e3229178 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 3 Apr 2017 21:51:26 +0200 Subject: [PATCH] tests: when launching intentions, remember the top-level file because it might become invalid after applying intention --- .../fixtures/impl/CodeInsightTestFixtureImpl.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index e20ba1965d8a..27835eebd26f 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -1805,7 +1805,8 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig // if (!FileModificationService.getInstance().prepareFileForWrite(file)) return; ReadonlyStatusHandlerImpl handler = (ReadonlyStatusHandlerImpl)ReadonlyStatusHandler.getInstance(file.getProject()); - setReadOnly(file, true); + VirtualFile vFile = InjectedLanguageUtil.getTopLevelFile(file).getVirtualFile(); + setReadOnly(vFile, true); handler.setClearReadOnlyInTests(true); AtomicBoolean result = new AtomicBoolean(); try { @@ -1819,14 +1820,14 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } finally { handler.setClearReadOnlyInTests(false); - setReadOnly(file, false); + setReadOnly(vFile, false); } return result.get(); } - private static void setReadOnly(PsiFile file, boolean readOnlyStatus) { + private static void setReadOnly(VirtualFile vFile, boolean readOnlyStatus) { try { - WriteAction.run(() -> ReadOnlyAttributeUtil.setReadOnlyAttribute(InjectedLanguageUtil.getTopLevelFile(file).getVirtualFile(), readOnlyStatus)); + WriteAction.run(() -> ReadOnlyAttributeUtil.setReadOnlyAttribute(vFile, readOnlyStatus)); } catch (IOException e) { throw new UncheckedIOException(e);