assert pom transactions and psi->doc sync happen on valid psi
authorpeter <peter@jetbrains.com>
Mon, 7 Nov 2016 07:04:55 +0000 (08:04 +0100)
committerpeter <peter@jetbrains.com>
Mon, 7 Nov 2016 07:05:24 +0000 (08:05 +0100)
platform/core-impl/src/com/intellij/pom/core/impl/PomModelImpl.java
platform/core-impl/src/com/intellij/psi/SingleRootFileViewProvider.java
platform/core-impl/src/com/intellij/psi/impl/PsiToDocumentSynchronizer.java

index d6a969f20d8500cf977753ad248bb7edf60ffffa..c8e74c2e68bf655493d5d895d7eb593c15e3c38d 100644 (file)
@@ -42,6 +42,7 @@ import com.intellij.psi.*;
 import com.intellij.psi.codeStyle.CodeStyleManager;
 import com.intellij.psi.impl.*;
 import com.intellij.psi.impl.smartPointers.SmartPointerManagerImpl;
+import com.intellij.psi.impl.source.DummyHolder;
 import com.intellij.psi.impl.source.PsiFileImpl;
 import com.intellij.psi.impl.source.text.BlockSupportImpl;
 import com.intellij.psi.impl.source.text.DiffLog;
@@ -53,6 +54,7 @@ import com.intellij.psi.text.BlockSupport;
 import com.intellij.psi.tree.IElementType;
 import com.intellij.psi.tree.IReparseableLeafElementType;
 import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.psi.util.PsiUtilCore;
 import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.ThrowableRunnable;
 import com.intellij.util.containers.ContainerUtil;
@@ -348,6 +350,10 @@ public class PomModelImpl extends UserDataHolderBase implements PomModel {
     final PsiElement changeScope = transaction.getChangeScope();
 
     final PsiFile containingFileByTree = getContainingFileByTree(changeScope);
+    if (containingFileByTree != null && !(containingFileByTree instanceof DummyHolder) && !manager.isCommitInProgress()) {
+      PsiUtilCore.ensureValid(containingFileByTree);
+    }
+
     boolean physical = changeScope.isPhysical();
     if (physical && synchronizer.toProcessPsiEvent()) {
       // fail-fast to prevent any psi modifications that would cause psi/document text mismatch
index f10b3824bccbff01bfb4ae811717bf7f317a7084..f2916d25bfc11dc1544b1026befa9c0d480991ee 100644 (file)
@@ -558,6 +558,7 @@ public class SingleRootFileViewProvider extends UserDataHolderBase implements Fi
     for (FileElement fileElement : knownTreeRoots) {
       int nodeLength = fileElement.getTextLength();
       if (nodeLength != fileLength) {
+        PsiUtilCore.ensureValid(fileElement.getPsi());
         // exceptions here should be assigned to peter
         LOG.error("Inconsistent " + fileElement.getElementType() + " tree in " + this + "; nodeLength=" + nodeLength + "; fileLength=" + fileLength);
       }
index 12671dd28e39e8c16bdc40357074609302dc0dee..210a537edde685967d76a0e2727b0f78c4439440 100644 (file)
@@ -29,6 +29,7 @@ import com.intellij.openapi.util.TextRange;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.*;
 import com.intellij.psi.impl.source.tree.ForeignLeafPsiElement;
+import com.intellij.psi.util.PsiUtilCore;
 import com.intellij.util.ExceptionUtil;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.messages.MessageBus;
@@ -120,6 +121,7 @@ public class PsiToDocumentSynchronizer extends PsiTreeChangeAdapter {
   }
 
   static void performAtomically(@NotNull PsiFile file, @NotNull Runnable runnable) {
+    PsiUtilCore.ensureValid(file);
     assert !isInsideAtomicChange(file);
     file.putUserData(PSI_DOCUMENT_ATOMIC_ACTION, Boolean.TRUE);