Search in sources :

Example 1 with RuntimeExceptionWithAttachments

use of com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments in project intellij-community by JetBrains.

the class UpToDateStubIndexMismatch method stubTreeAndIndexDoNotMatch.

@NotNull
public RuntimeException stubTreeAndIndexDoNotMatch(@NotNull String _message, @NotNull ObjectStubTree stubTree, @NotNull PsiFileWithStubSupport psiFile) {
    VirtualFile file = psiFile.getViewProvider().getVirtualFile();
    StubTree stubTreeFromIndex = (StubTree) readFromVFile(psiFile.getProject(), file);
    Document document = FileDocumentManager.getInstance().getDocument(file);
    IndexingStampInfo indexingStampInfo = getIndexingStampInfo(file);
    boolean upToDate = indexingStampInfo != null && indexingStampInfo.isUpToDate(document, file, psiFile);
    String msg = _message + "\nPlease report the problem to JetBrains with the files attached\n";
    if (upToDate) {
        msg += "INDEXED VERSION IS THE CURRENT ONE";
    }
    msg += " file=" + psiFile;
    msg += ", file.class=" + psiFile.getClass();
    msg += ", file.lang=" + psiFile.getLanguage();
    msg += ", modStamp=" + psiFile.getModificationStamp();
    if (!(psiFile instanceof PsiCompiledElement)) {
        String text = psiFile.getText();
        PsiFile fromText = PsiFileFactory.getInstance(psiFile.getProject()).createFileFromText(psiFile.getName(), psiFile.getFileType(), text);
        if (fromText.getLanguage().equals(psiFile.getLanguage())) {
            boolean consistent = DebugUtil.psiToString(psiFile, true).equals(DebugUtil.psiToString(fromText, true));
            if (consistent) {
                msg += "\n tree consistent";
            } else {
                msg += "\n AST INCONSISTENT, perhaps after incremental reparse; " + fromText;
            }
        }
    }
    msg += "\n stub debugInfo=" + stubTree.getDebugInfo();
    msg += "\nlatestIndexedStub=" + stubTreeFromIndex;
    if (stubTreeFromIndex != null) {
        msg += "\n   same size=" + (stubTree.getPlainList().size() == stubTreeFromIndex.getPlainList().size());
        msg += "\n   debugInfo=" + stubTreeFromIndex.getDebugInfo();
    }
    FileViewProvider viewProvider = psiFile.getViewProvider();
    msg += "\n viewProvider=" + viewProvider;
    msg += "\n viewProvider stamp: " + viewProvider.getModificationStamp();
    msg += "; file stamp: " + file.getModificationStamp();
    msg += "; file modCount: " + file.getModificationCount();
    msg += "; file length: " + file.getLength();
    if (document != null) {
        msg += "\n doc saved: " + !FileDocumentManager.getInstance().isDocumentUnsaved(document);
        msg += "; doc stamp: " + document.getModificationStamp();
        msg += "; doc size: " + document.getTextLength();
        msg += "; committed: " + PsiDocumentManager.getInstance(psiFile.getProject()).isCommitted(document);
    }
    msg += "\nin many projects: " + hasPsiInManyProjects(file);
    msg += "\nindexing info: " + indexingStampInfo;
    Attachment[] attachments = createAttachments(stubTree, psiFile, file, stubTreeFromIndex);
    // separate methods and separate exception classes for EA to treat these situations differently
    return upToDate ? handleUpToDateMismatch(msg, attachments) : new RuntimeExceptionWithAttachments(msg, attachments);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RuntimeExceptionWithAttachments(com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments) Attachment(com.intellij.openapi.diagnostic.Attachment) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with RuntimeExceptionWithAttachments

use of com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments in project intellij-community by JetBrains.

the class StubBasedPsiElementBase method failedToBindStubToAst.

private ASTNode failedToBindStubToAst(@NotNull PsiFileImpl file, @NotNull final FileElement fileElement) {
    VirtualFile vFile = file.getVirtualFile();
    StubTree stubTree = file.getStubTree();
    final String stubString = stubTree != null ? ((PsiFileStubImpl) stubTree.getRoot()).printTree() : null;
    final String astString = RecursionManager.doPreventingRecursion("failedToBindStubToAst", true, () -> DebugUtil.treeToString(fileElement, true));
    @NonNls final String message = "Failed to bind stub to AST for element " + getClass() + " in " + (vFile == null ? "<unknown file>" : vFile.getPath()) + "\nFile:\n" + file + "@" + System.identityHashCode(file);
    final String creationTraces = ourTraceStubAstBinding ? dumpCreationTraces(fileElement) : null;
    List<Attachment> attachments = new ArrayList<>();
    if (stubString != null) {
        attachments.add(new Attachment("stubTree.txt", stubString));
    }
    if (astString != null) {
        attachments.add(new Attachment("ast.txt", astString));
    }
    if (creationTraces != null) {
        attachments.add(new Attachment("creationTraces.txt", creationTraces));
    }
    throw new RuntimeExceptionWithAttachments(message, attachments.toArray(Attachment.EMPTY_ARRAY));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) RuntimeExceptionWithAttachments(com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments) ArrayList(java.util.ArrayList) Attachment(com.intellij.openapi.diagnostic.Attachment)

Aggregations

Attachment (com.intellij.openapi.diagnostic.Attachment)2 RuntimeExceptionWithAttachments (com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Document (com.intellij.openapi.editor.Document)1 ArrayList (java.util.ArrayList)1 NonNls (org.jetbrains.annotations.NonNls)1 NotNull (org.jetbrains.annotations.NotNull)1