String (@NotNull PsiJavaCodeReferenceElement ref) { final StringBuilder buffer = new StringBuilder(); ((TreeElement)ref.getNode()).acceptTree(new RecursiveTreeElementWalkingVisitor() { @Override public void visitLeaf(LeafElement leaf) { if (!REF_FILTER.contains(leaf.getElementType())) { String leafText = leaf.getText(); if (buffer.length() > 0 && !leafText.isEmpty() && Character.isJavaIdentifierPart(leafText.charAt(0))) { char lastInBuffer = buffer.charAt(buffer.length() - 1); if (lastInBuffer == '?' || Character.isJavaIdentifierPart(lastInBuffer)) { buffer.append(" "); } } buffer.append(leafText); } } @Override public void visitComposite(CompositeElement composite) { if (!REF_FILTER.contains(composite.getElementType())) { super.visitComposite(composite); } } }); return buffer.toString(); }