tests: when launching intentions, remember the top-level file because it might become invalid after applying intention

This commit is contained in:
peter
2017-04-03 21:52:34 +02:00
parent 7a8270cc14
commit f2b3c32bc6
@@ -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);