more thorough SingleRootFileViewProvider.checkLengthConsistency in tests

This commit is contained in:
peter
2017-08-17 12:59:52 +02:00
parent f73a5572c0
commit 0ddef47489
@@ -18,7 +18,9 @@ package com.intellij.psi;
import com.google.common.util.concurrent.Atomics;
import com.intellij.injected.editor.DocumentWindow;
import com.intellij.lang.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
import com.intellij.openapi.command.undo.UndoConstants;
import com.intellij.openapi.diagnostic.Attachment;
import com.intellij.openapi.diagnostic.Logger;
@@ -552,10 +554,10 @@ public class SingleRootFileViewProvider extends UserDataHolderBase implements Fi
int fileLength = myContent.getTextLength();
for (FileElement fileElement : knownTreeRoots) {
int nodeLength = fileElement.getTextLength();
if (nodeLength != fileLength) {
if (!isDocumentConsistentWithPsi(fileLength, fileElement, nodeLength)) {
PsiUtilCore.ensureValid(fileElement.getPsi());
List<Attachment> attachments = ContainerUtil.newArrayList(new Attachment(myVirtualFile.getNameWithoutExtension() + ".tree.txt", fileElement.getText()),
new Attachment(myVirtualFile.getNameWithoutExtension() + ".file.txt", myContent.toString()));
List<Attachment> attachments = ContainerUtil.newArrayList(new Attachment(myVirtualFile.getName(), myContent.getText().toString()),
new Attachment(myVirtualFile.getNameWithoutExtension() + ".tree.txt", fileElement.getText()));
if (document != null) {
attachments.add(new Attachment(myVirtualFile.getNameWithoutExtension() + ".document.txt", document.getText()));
}
@@ -566,6 +568,16 @@ public class SingleRootFileViewProvider extends UserDataHolderBase implements Fi
}
}
private boolean isDocumentConsistentWithPsi(int fileLength, FileElement fileElement, int nodeLength) {
if (nodeLength != fileLength) return false;
if (ApplicationManager.getApplication().isUnitTestMode() && !ApplicationInfoImpl.isInStressTest()) {
return fileElement.textMatches(myContent.getText());
}
return true;
}
@NonNls
@Override
public String toString() {