From 1c17d184d4460926b4bcc43bc064e9bae91b0b34 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 1 Apr 2011 12:33:47 +0200 Subject: [PATCH] EA-26424 (attempt to repair PSI after inconsistent commit) --- .../psi/impl/PsiDocumentManagerImpl.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/psi/impl/PsiDocumentManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/PsiDocumentManagerImpl.java index f12efff9ca47..78a7ed91b58e 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/PsiDocumentManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/PsiDocumentManagerImpl.java @@ -480,20 +480,32 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec return true; } - private void assertAfterCommit(Document document, PsiFile file, String oldPsiText) { + private void assertAfterCommit(final Document document, final PsiFile file, final String oldPsiText) { if (myTreeElementBeingReparsedSoItWontBeCollected.getTextLength() != document.getTextLength()) { + final String documentText = document.getText(); if (ApplicationManagerEx.getApplicationEx().isInternal()) { String fileText = file.getText(); - String documentText = document.getText(); - throw new AssertionError("commitDocument left PSI inconsistent; file len=" + myTreeElementBeingReparsedSoItWontBeCollected.getTextLength() + - "; doc len=" + document.getTextLength() + - "; doc.getText() == file.getText(): " + Comparing.equal(fileText, documentText) + - ";\n file psi text=" + fileText + - ";\n doc text=" + documentText + - ";\n old psi file text=" + oldPsiText); + LOG.error("commitDocument left PSI inconsistent; file len=" + myTreeElementBeingReparsedSoItWontBeCollected.getTextLength() + + "; doc len=" + document.getTextLength() + + "; doc.getText() == file.getText(): " + Comparing.equal(fileText, documentText) + + ";\n file psi text=" + fileText + + ";\n doc text=" + documentText + + ";\n old psi file text=" + oldPsiText); + } + else { + LOG.error("commitDocument left PSI inconsistent: " + file); } - throw new AssertionError("commitDocument left PSI inconsistent: " + file); + file.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, Boolean.TRUE); + try { + myBlockSupport.reparseRange(file, 0, documentText.length(), 0, documentText); + if (myTreeElementBeingReparsedSoItWontBeCollected.getTextLength() != document.getTextLength()) { + LOG.error("PSI is broken beyond repair in: " + file); + } + } + finally { + file.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, null); + } } }