void (PsiElement element, Map<PsiElement, String> replacements, StringBuilder out) { if (element instanceof PsiReferenceExpression referenceExpression) { final PsiElement target = referenceExpression.resolve(); final String replacement = replacements.get(target); out.append(replacement != null ? replacement : element.getText()); return; } final PsiElement[] children = element.getChildren(); if (children.length > 0) { for (PsiElement child : children) { buildText(child, replacements, out); } } else { out.append(element.getText()); } }