private PsiElement replaceParameterReferences(PsiElement argument,
                                                @Nullable final List<? super PsiReferenceExpression> localVarRefs,
                                                final boolean replaceFieldsWithInitializers) throws IncorrectOperationException {
    if (argument instanceof PsiReferenceExpression ref && ref.resolve() instanceof PsiParameter parameter) {
      if (myLocalsForParameters.containsKey(parameter)) {
        return argument.replace(getParameterReference(parameter));
      }
      int index = myConstructorParameters.getParameterIndex(parameter);
      return argument.replace(myConstructorArguments[index]);
    }

    final List<Pair<PsiReferenceExpression, PsiParameter>> parameterReferences = new ArrayList<>();
    final Map<PsiElement, PsiElement> elementsToReplace = new HashMap<>();
    argument.accept(new JavaRecursiveElementWalkingVisitor() {
      @Override public void visitReferenceExpression(final @NotNull PsiReferenceExpression expression) {
        super.visitReferenceExpression(expression);
        final PsiElement psiElement = expression.resolve();
        if (psiElement instanceof PsiParameter parameter && parameter.getDeclarationScope() == myConstructor) {
          parameterReferences.add(Pair.create(expression, parameter));
        }
        else if ((psiElement instanceof PsiField || psiElement instanceof PsiMethod) &&
                 ((PsiMember) psiElement).getContainingClass() == myClass.getSuperClass()) {
          PsiMember member = (PsiMember) psiElement;
          if (member.hasModifierProperty(PsiModifier.STATIC) &&
              expression.getQualifierExpression() == null) {
            final String qualifiedText = myClass.getSuperClass().getQualifiedName() + "." + member.getName();
            try {
              final PsiExpression replacement = myElementFactory.createExpressionFromText(qualifiedText, myClass);
              elementsToReplace.put(expression, replacement); 
            }
            catch (IncorrectOperationException e) {
              LOG.error(e);
            }
          }
        }
        else if (psiElement instanceof PsiVariable) {
          if (localVarRefs != null) {
            localVarRefs.add(expression);
          }
          if (replaceFieldsWithInitializers && psiElement instanceof PsiField field && field.getContainingClass() == myClass) {
            final PsiExpression initializer = field.getInitializer();
            if (initializer != null && isConstant(initializer)) {
              elementsToReplace.put(expression, initializer);
            }
          }
        }
      }
    });
    for (Pair<PsiReferenceExpression, PsiParameter> pair: parameterReferences) {
      PsiReferenceExpression ref = pair.first;
      PsiParameter param = pair.second;
      if (myLocalsForParameters.containsKey(param)) {
        ref.replace(getParameterReference(param));
      }
      else {
        int index = myConstructorParameters.getParameterIndex(param);
        if (ref == argument) {
          argument = argument.replace(myConstructorArguments[index]);
        }
        else {
          ref.replace(myConstructorArguments[index]);
        }
      }
    }
    return CommonJavaRefactoringUtil.replaceElementsWithMap(argument, elementsToReplace);
  }
private PsiElement replaceParameterReferences(PsiElement argument,
                                                @Nullable final List<? super PsiReferenceExpression> localVarRefs,
                                                final boolean replaceFieldsWithInitializers)