diff options
author | Tor Norbye <tnorbye@google.com> | 2014-08-19 22:27:03 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-08-19 21:25:05 +0000 |
commit | 4ca751c002784c4bfd349cc5240b045b62277c80 (patch) | |
tree | dfc17b31990e2429535609b85f6d080c4fa0d9fe /platform/core-impl/src/com/intellij/pom/core/impl/PomModelImpl.java | |
parent | 890d9a2952301682ffecaed4495f5f65c84c3642 (diff) | |
parent | 060e58b3afea3ea39f5ba1cb5a443ca3ebda28c8 (diff) | |
download | idea-4ca751c002784c4bfd349cc5240b045b62277c80.tar.gz |
Merge "Merge remote-tracking branch 'aosp/upstream-master' into merge"
Diffstat (limited to 'platform/core-impl/src/com/intellij/pom/core/impl/PomModelImpl.java')
-rw-r--r-- | platform/core-impl/src/com/intellij/pom/core/impl/PomModelImpl.java | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/platform/core-impl/src/com/intellij/pom/core/impl/PomModelImpl.java b/platform/core-impl/src/com/intellij/pom/core/impl/PomModelImpl.java index ba5858c52993..2ca35e4227e9 100644 --- a/platform/core-impl/src/com/intellij/pom/core/impl/PomModelImpl.java +++ b/platform/core-impl/src/com/intellij/pom/core/impl/PomModelImpl.java @@ -301,15 +301,30 @@ public class PomModelImpl extends UserDataHolderBase implements PomModel { final PsiToDocumentSynchronizer synchronizer = manager.getSynchronizer(); final PsiElement changeScope = transaction.getChangeScope(); LOG.assertTrue(changeScope != null); - BlockSupportImpl.sendBeforeChildrenChangeEvent((PsiManagerImpl)PsiManager.getInstance(myProject), changeScope, true); + final PsiFile containingFileByTree = getContainingFileByTree(changeScope); + if (changeScope.isPhysical() && synchronizer.toProcessPsiEvent() && isDocumentUncommitted(containingFileByTree)) { + // fail-fast to prevent any psi modifications that would cause psi/document text mismatch + // PsiToDocumentSynchronizer assertions happen inside event processing and are logged by PsiManagerImpl.fireEvent instead of being rethrown + // so it's important to throw something outside event processing + throw new IllegalStateException("Attempt to modify PSI for non-committed Document!"); + } + BlockSupportImpl.sendBeforeChildrenChangeEvent((PsiManagerImpl)PsiManager.getInstance(myProject), changeScope, true); Document document = containingFileByTree == null ? null : manager.getCachedDocument(containingFileByTree); if(document != null) { synchronizer.startTransaction(myProject, document, changeScope); } } + private boolean isDocumentUncommitted(@Nullable PsiFile file) { + if (file == null) return false; + + PsiDocumentManager manager = PsiDocumentManager.getInstance(myProject); + Document cachedDocument = manager.getCachedDocument(file); + return cachedDocument != null && manager.isUncommited(cachedDocument); + } + @Nullable private static PsiFile getContainingFileByTree(@NotNull final PsiElement changeScope) { // there could be pseudo physical trees (JSPX/JSP/etc.) which must not translate |