assert text length consistency between FileElement and view provider

This commit is contained in:
peter
2015-12-03 19:56:12 +01:00
parent b580d8eccb
commit a08b984bf8
@@ -386,14 +386,21 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
@Override
public String getText() {
final ASTNode tree = derefTreeElement();
if (!isValid()) {
// even invalid PSI can calculate its text by concatenating its children
final ASTNode tree = derefTreeElement();
if (tree != null) return tree.getText();
throw new PsiInvalidElementAccessException(this);
}
return getViewProvider().getContents().toString();
String string = getViewProvider().getContents().toString();
if (tree != null && string.length() != tree.getTextLength()) {
throw new AssertionError("File text mismatch: tree.length=" + tree.getTextLength() +
"; psi.length=" + string.length() +
"; this=" + this +
"; vp=" + getViewProvider());
}
return string;
}
@Override