String () { PsiFile file = myFixture.getFile(); List<PsiReference> referenceList = getReferencesInFile(file); Collection<PsiElement> elements = referenceList.stream() .map(ref -> ref.resolve()) .filter(e -> e != null) .collect(Collectors.toCollection(() -> new LinkedHashSet<>())); Editor editor = myFixture.getEditor(); StringBuilder sb = new StringBuilder(); for (PsiElement element : elements) { String usage = myFixture.getUsageViewTreeTextRepresentation(element); sb .append("- element: '") .append(element.getText()) .append("'\n") .append(" position: '") .append(editor.offsetToLogicalPosition(element.getTextOffset())) .append("'\n") .append(" view: |") .append('\n') .append(YAMLTextUtil.indentText(usage, 4)) .append('\n') ; } return sb.toString(); }