@Nullable
  private static @NlsContexts.DialogMessage String getCannotRefactorMessage(PsiMember member) {
    if (member == null) {
      return JavaRefactoringBundle.message("locate.caret.inside.a.method");
    }
    if (member instanceof PsiMethod method) {
      if (method.isConstructor()) {
        return JavaRefactoringBundle.message("replace.with.method.call.does.not.work.for.constructors");
      }
      final PsiCodeBlock body = method.getBody();
      if (body == null) {
        return JavaRefactoringBundle.message("method.does.not.have.a.body", member.getName());
      }
      final PsiStatement[] statements = body.getStatements();
      if (statements.length == 0) {
        return JavaRefactoringBundle.message("method.has.an.empty.body", member.getName());
      }
    } else if (member instanceof PsiField field) {
      if (field.getInitializer() == null) {
        return JavaRefactoringBundle.message("dialog.message.field.doesnt.have.initializer", member.getName());
      }
      final PsiClass containingClass = field.getContainingClass();
      if (!field.hasModifierProperty(PsiModifier.FINAL) || !field.hasModifierProperty(PsiModifier.STATIC) ||
          containingClass == null || containingClass.getQualifiedName() == null) {
        return JavaRefactoringBundle.message("dialog.message.replace.duplicates.works.with.constants.only");
      }
    } else {
      return JavaRefactoringBundle.message("dialog.message.caret.should.be.inside.method.or.constant");
    }
    return null;
  }
@Nullable
  private static @NlsContexts.DialogMessage String getCannotRefactorMessage(PsiMember member)