Search in sources :

Example 1 with LogEventException

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;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Attachment(com.intellij.openapi.diagnostic.Attachment) LogEventException(com.intellij.diagnostic.LogEventException)

Example 2 with LogEventException

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()));
    }
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Attachment(com.intellij.openapi.diagnostic.Attachment) LogEventException(com.intellij.diagnostic.LogEventException)

Example 3 with LogEventException

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()));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileASTNode(com.intellij.lang.FileASTNode) FileViewProvider(com.intellij.psi.FileViewProvider) Attachment(com.intellij.openapi.diagnostic.Attachment) Document(com.intellij.openapi.editor.Document) LogEventException(com.intellij.diagnostic.LogEventException) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) EditorWindow(com.intellij.injected.editor.EditorWindow)

Aggregations

LogEventException (com.intellij.diagnostic.LogEventException)3 Attachment (com.intellij.openapi.diagnostic.Attachment)3 TextRange (com.intellij.openapi.util.TextRange)2 EditorWindow (com.intellij.injected.editor.EditorWindow)1 FileASTNode (com.intellij.lang.FileASTNode)1 Document (com.intellij.openapi.editor.Document)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 FileViewProvider (com.intellij.psi.FileViewProvider)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1