void () { String filePath = getTestName(false) + ".java"; PsiFile file = myFixture.configureByFile(filePath); SelectionModel model = myFixture.getEditor().getSelectionModel(); int start = model.getSelectionStart(); int end = model.getSelectionEnd(); if (start == end) { fail("No selection!"); } TextRange range = new TextRange(start, end); PsiElement element = file.findElementAt(start); while (element != null && element != file && (!range.equals(element.getTextRange()) || element.getParent().getTextRange().equals(range))) { element = element.getParent(); } String selectedText = model.getSelectedText(); assertNotNull("Failed to find element at selection: " + selectedText, element); assertTrue("Selected element is not an expression: " + selectedText, element instanceof PsiExpression); PsiExpression expression = (PsiExpression)element; TrackingRunner.DfaProblemType problemType = getProblemType(selectedText, expression); TrackingRunner.CauseItem item = TrackingRunner.findProblemCause(false, expression, problemType); assertNotNull(item); String dump = item.dump(getEditor().getDocument()); PsiComment firstComment = PsiTreeUtil.findChildOfType(file, PsiComment.class); if (firstComment == null) { fail("Comment not found"); } String text = firstComment.getText(); String prefix = StringUtil.substringBefore(text, "\n") + "\n"; String suffix = StringUtil.substringAfterLast(text, "\n"); String actual = prefix + dump + suffix; if (!text.equals(actual)) { PsiElement fileCopy = file.copy(); PsiTreeUtil.findChildOfType(fileCopy, PsiComment.class) .replace(JavaPsiFacade.getElementFactory(getProject()).createCommentFromText(actual, null)); int diff = actual.length() - text.length(); String actualFile = fileCopy.getText(); String origPath = myFixture.getTestDataPath() + "/" + filePath; actualFile = actualFile.substring(0, start + diff) + "<selection>" + actualFile.substring(start + diff, end + diff) + "</selection>" + actualFile.substring(end + diff); String expectedFile; try { expectedFile = Files.readString(Paths.get(origPath)); } catch (IOException e) { throw new UncheckedIOException(e); } throw new FileComparisonFailure("Dump differs", expectedFile, actualFile, origPath); } assertEquals(text, actual); }