Search in sources :

Example 26 with Attachment

use of com.intellij.openapi.diagnostic.Attachment 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)

Example 27 with Attachment

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

the class UpToDateStubIndexMismatch method createAttachments.

@NotNull
private static Attachment[] createAttachments(@NotNull ObjectStubTree stubTree, @NotNull PsiFileWithStubSupport psiFile, VirtualFile file, @Nullable StubTree stubTreeFromIndex) {
    List<Attachment> attachments = ContainerUtil.newArrayList();
    attachments.add(new Attachment(file.getPath() + "_file.txt", psiFile instanceof PsiCompiledElement ? "compiled" : psiFile.getText()));
    attachments.add(new Attachment("stubTree.txt", ((PsiFileStubImpl) stubTree.getRoot()).printTree()));
    if (stubTreeFromIndex != null) {
        attachments.add(new Attachment("stubTreeFromIndex.txt", ((PsiFileStubImpl) stubTreeFromIndex.getRoot()).printTree()));
    }
    return attachments.toArray(Attachment.EMPTY_ARRAY);
}
Also used : Attachment(com.intellij.openapi.diagnostic.Attachment) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with Attachment

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

the class PsiUtilCore method getPsiFile.

/**
   * Tries to find PSI file for a virtual file and throws assertion error with debug info if it is null.
   */
@NotNull
public static PsiFile getPsiFile(@NotNull Project project, @NotNull VirtualFile file) {
    PsiManager psiManager = PsiManager.getInstance(project);
    PsiFile psi = psiManager.findFile(file);
    if (psi != null)
        return psi;
    FileType fileType = file.getFileType();
    FileViewProvider viewProvider = psiManager.findViewProvider(file);
    Document document = FileDocumentManager.getInstance().getDocument(file);
    boolean ignored = !(file instanceof LightVirtualFile) && FileTypeRegistry.getInstance().isFileIgnored(file);
    VirtualFile vDir = file.getParent();
    PsiDirectory psiDir = vDir == null ? null : PsiManager.getInstance(project).findDirectory(vDir);
    FileIndexFacade indexFacade = FileIndexFacade.getInstance(project);
    StringBuilder sb = new StringBuilder();
    sb.append("valid=").append(file.isValid()).append(" isDirectory=").append(file.isDirectory()).append(" hasDocument=").append(document != null).append(" length=").append(file.getLength());
    sb.append("\nproject=").append(project.getName()).append(" default=").append(project.isDefault()).append(" open=").append(project.isOpen());
    sb.append("\nfileType=").append(fileType.getName()).append("/").append(fileType.getClass().getName());
    sb.append("\nisIgnored=").append(ignored);
    sb.append(" underIgnored=").append(indexFacade.isUnderIgnored(file));
    sb.append(" inLibrary=").append(indexFacade.isInLibrarySource(file) || indexFacade.isInLibraryClasses(file));
    sb.append(" parentDir=").append(vDir == null ? "no-vfs" : vDir.isDirectory() ? "has-vfs-dir" : "has-vfs-file").append("/").append(psiDir == null ? "no-psi" : "has-psi");
    sb.append("\nviewProvider=").append(viewProvider == null ? "null" : viewProvider.getClass().getName());
    if (viewProvider != null) {
        List<PsiFile> files = viewProvider.getAllFiles();
        sb.append(" language=").append(viewProvider.getBaseLanguage().getID());
        sb.append(" physical=").append(viewProvider.isPhysical());
        sb.append(" rootCount=").append(files.size());
        for (PsiFile o : files) {
            sb.append("\n  root=").append(o.getLanguage().getID()).append("/").append(o.getClass().getName());
        }
    }
    LOG.error("no PSI for file '" + file.getName() + "'", new Attachment(file.getPresentableUrl(), sb.toString()));
    throw new AssertionError();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Attachment(com.intellij.openapi.diagnostic.Attachment) Document(com.intellij.openapi.editor.Document) FileType(com.intellij.openapi.fileTypes.FileType) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with Attachment

use of com.intellij.openapi.diagnostic.Attachment 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)

Example 30 with Attachment

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

the class BlockSupportImpl method reportInconsistentLength.

private static void reportInconsistentLength(PsiFile file, CharSequence newFileText, ASTNode node, int start, int end) {
    String message = "Index out of bounds: type=" + node.getElementType() + "; file=" + file + "; file.class=" + file.getClass() + "; start=" + start + "; end=" + end + "; length=" + node.getTextLength();
    String newTextBefore = newFileText.subSequence(0, start).toString();
    String oldTextBefore = file.getText().subSequence(0, start).toString();
    if (oldTextBefore.equals(newTextBefore)) {
        message += "; oldTextBefore==newTextBefore";
    }
    LOG.error(message, new Attachment(file.getName() + "_oldNodeText.txt", node.getText()), new Attachment(file.getName() + "_oldFileText.txt", file.getText()), new Attachment(file.getName() + "_newFileText.txt", newFileText.toString()));
}
Also used : Attachment(com.intellij.openapi.diagnostic.Attachment)

Aggregations

Attachment (com.intellij.openapi.diagnostic.Attachment)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 NotNull (org.jetbrains.annotations.NotNull)10 Project (com.intellij.openapi.project.Project)6 ArrayList (java.util.ArrayList)6 Document (com.intellij.openapi.editor.Document)5 TextRange (com.intellij.openapi.util.TextRange)4 LogEventException (com.intellij.diagnostic.LogEventException)3 Logger (com.intellij.openapi.diagnostic.Logger)3 PsiElement (com.intellij.psi.PsiElement)3 PsiFile (com.intellij.psi.PsiFile)3 LogMessageEx (com.intellij.diagnostic.LogMessageEx)2 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)2 Pair (com.intellij.openapi.util.Pair)2 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)2 List (java.util.List)2 NonNls (org.jetbrains.annotations.NonNls)2 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)1 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)1 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1