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()));
}
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);
}
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();
}
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));
}
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()));
}
Aggregations