use of com.intellij.diagnostic.LogEventException in project intellij-community by JetBrains.
the class ExtendWordSelectionHandlerBase method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
final TextRange originalRange = e.getTextRange();
if (originalRange.getEndOffset() > editorText.length()) {
throw new LogEventException("Invalid element range in " + getClass(), "element=" + e + "; range=" + originalRange + "; text length=" + editorText.length() + "; editor=" + editor + "; committed=" + PsiDocumentManager.getInstance(e.getProject()).isCommitted(editor.getDocument()), new Attachment("editor_text.txt", editorText.toString()), new Attachment("psi_text.txt", e.getText()));
}
List<TextRange> ranges = expandToWholeLine(editorText, originalRange, true);
if (ranges.size() == 1 && ranges.contains(originalRange)) {
return expandToWholeLine(editorText, originalRange, false);
}
return ranges;
}
use of com.intellij.diagnostic.LogEventException in project intellij-community by JetBrains.
the class CompletionAssertions method assertCompletionPositionPsiConsistent.
static void assertCompletionPositionPsiConsistent(CompletionContext newContext, int offset, PsiFile fileCopy, PsiFile originalFile, PsiElement insertedElement) {
if (insertedElement == null) {
throw new LogEventException("No element at insertion offset", "offset=" + newContext.getStartOffset() + "\n" + DebugUtil.currentStackTrace(), createFileTextAttachment(fileCopy, originalFile), createAstAttachment(fileCopy, originalFile));
}
if (fileCopy.findElementAt(offset) != insertedElement) {
throw new AssertionError("wrong offset");
}
final TextRange range = insertedElement.getTextRange();
CharSequence fileCopyText = fileCopy.getViewProvider().getContents();
if ((range.getEndOffset() > fileCopyText.length()) || !fileCopyText.subSequence(range.getStartOffset(), range.getEndOffset()).toString().equals(insertedElement.getText())) {
throw new LogEventException("Inconsistent completion tree", "range=" + range + "\n" + DebugUtil.currentStackTrace(), createFileTextAttachment(fileCopy, originalFile), createAstAttachment(fileCopy, originalFile), new Attachment("Element at caret.txt", insertedElement.getText()));
}
}
use of com.intellij.diagnostic.LogEventException in project intellij-community by JetBrains.
the class CompletionAssertions method assertCommitSuccessful.
static void assertCommitSuccessful(Editor editor, PsiFile psiFile) {
Document document = editor.getDocument();
int docLength = document.getTextLength();
int psiLength = psiFile.getTextLength();
PsiDocumentManager manager = PsiDocumentManager.getInstance(psiFile.getProject());
boolean committed = !manager.isUncommited(document);
if (docLength == psiLength && committed) {
return;
}
FileViewProvider viewProvider = psiFile.getViewProvider();
String message = "unsuccessful commit:";
message += "\nmatching=" + (psiFile == manager.getPsiFile(document));
message += "\ninjectedEditor=" + (editor instanceof EditorWindow);
message += "\ninjectedFile=" + InjectedLanguageManager.getInstance(psiFile.getProject()).isInjectedFragment(psiFile);
message += "\ncommitted=" + committed;
message += "\nfile=" + psiFile.getName();
message += "\nfile class=" + psiFile.getClass();
message += "\nfile.valid=" + psiFile.isValid();
message += "\nfile.physical=" + psiFile.isPhysical();
message += "\nfile.eventSystemEnabled=" + viewProvider.isEventSystemEnabled();
message += "\nlanguage=" + psiFile.getLanguage();
message += "\ndoc.length=" + docLength;
message += "\npsiFile.length=" + psiLength;
String fileText = psiFile.getText();
if (fileText != null) {
message += "\npsiFile.text.length=" + fileText.length();
}
FileASTNode node = psiFile.getNode();
if (node != null) {
message += "\nnode.length=" + node.getTextLength();
String nodeText = node.getText();
if (nodeText != null) {
message += "\nnode.text.length=" + nodeText.length();
}
}
VirtualFile virtualFile = viewProvider.getVirtualFile();
message += "\nvirtualFile=" + virtualFile;
message += "\nvirtualFile.class=" + virtualFile.getClass();
message += "\n" + DebugUtil.currentStackTrace();
throw new LogEventException("Commit unsuccessful", message, new Attachment(virtualFile.getPath() + "_file.txt", fileText), createAstAttachment(psiFile, psiFile), new Attachment("docText.txt", document.getText()));
}
Aggregations