private static void doReplacements(final Project project,
                                     MultiMap<String, PsiExpression> calls,
                                     List<XmlAttribute> xmlAttributes,
                                     MultiMap<String, PsiAnnotation> annotations,
                                     PsiClass iconClass) {
    final HashMap<String, String> mappings = new HashMap<>();
    collectFields(iconClass, "", mappings);

    GlobalSearchScope useScope = (GlobalSearchScope)iconClass.getUseScope();

    for (final XmlAttribute att : xmlAttributes) {
      if (!att.isValid()) continue;
      String value = att.getValue();
      final String replacement = mappings.get(value);
      if (replacement != null) {
        final PsiFile file = att.getContainingFile();
        if (useScope.contains(file.getVirtualFile())) {
          WriteCommandAction.writeCommandAction(project, file).run(() -> att.setValue(replacement));
        }
      }
    }

    final JVMElementFactory factory = JVMElementFactories.getFactory(JavaLanguage.INSTANCE, project);
    for (Map.Entry<String, Collection<PsiExpression>> entry : calls.entrySet()) {
      String path = entry.getKey();
      final String replacement = mappings.get(path);
      if (replacement != null) {
        for (final PsiExpression call : entry.getValue()) {
          if (!call.isValid()) continue;

          final PsiFile file = call.getContainingFile();
          if (useScope.contains(file.getVirtualFile())) {
            WriteCommandAction.writeCommandAction(project, file).run(() -> {
              if (call instanceof PsiLiteralExpression) {
                call.replace(factory.createExpressionFromText("\"" + replacement + "\"", call));
              }
              else {
                JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
                String packageName = replacement.startsWith("AllIcons.") ? "com.intellij.icons." : "icons.";
                PsiElement expr = factory.createExpressionFromText(packageName + replacement, call);
                styleManager.shortenClassReferences(call.replace(expr));
              }
            });
          }
        }
      }
    }

    for (Map.Entry<String, Collection<PsiAnnotation>> entry : annotations.entrySet()) {
      String path = entry.getKey();
      final String replacement = mappings.get(path);
      if (replacement != null) {
        for (final PsiAnnotation annotation : entry.getValue()) {
          if (annotation instanceof PsiCompiledElement) continue;
          if (!annotation.isValid()) continue;

          PsiFile file = annotation.getContainingFile();
          if (useScope.contains(file.getVirtualFile())) {
            WriteCommandAction.writeCommandAction(project, file).run(() -> {
              //noinspection ResultOfMethodCallIgnored -- load tree?
              annotation.getNode();
              annotation.setDeclaredAttributeValue(
                "icon",
                JavaPsiFacade.getElementFactory(annotation.getProject())
                             .createAnnotationFromText("@A(\"" + replacement + "\")", null).findDeclaredAttributeValue(null));
            });
          }
        }
      }
    }
  }
private static void doReplacements(final Project project,
                                     MultiMap<String, PsiExpression> calls,
                                     List<XmlAttribute> xmlAttributes,
                                     MultiMap<String, PsiAnnotation> annotations,
                                     PsiClass iconClass)