public static @NlsContexts.DialogMessage @Nullable String getErrorMessage(PsiExpression expr) {
    final Boolean needParenthesis = expr.getCopyableUserData(NEED_PARENTHESIS);
    if (needParenthesis != null && needParenthesis.booleanValue()) {
      return JavaBundle.message("introduce.variable.change.semantics.warning");
    }
    if (expr instanceof PsiClassObjectAccessExpression && PsiUtilCore.hasErrorElementChild(expr)) {
      return JavaRefactoringBundle.message("selected.block.should.represent.an.expression");
    }
    if (expr instanceof PsiSuperExpression) {
      return JavaRefactoringBundle.message("selected.expression.cannot.be.extracted");
    }
    if (!CodeBlockSurrounder.canSurround(expr)) {
      PsiExpression topLevelExpression = ExpressionUtils.getTopLevelExpression(expr);
      if (topLevelExpression != expr) {
        for (PsiVariable variable : VariableAccessUtils.collectUsedVariables(expr)) {
          if (variable instanceof PsiPatternVariable && PsiTreeUtil.isAncestor(topLevelExpression, variable, true) &&
              !PsiTreeUtil.isAncestor(expr, variable, true)) {
            return JavaRefactoringBundle.message("introduce.variable.message.expression.refers.to.pattern.variable.declared.outside", variable.getName());
          }
        }
      }
      if (topLevelExpression.getParent() instanceof PsiField f && f.getParent() instanceof PsiImplicitClass) {
        return JavaRefactoringBundle.message("introduce.variable.message.cannot.extract.in.implicit.class");
      }
    }
    return null;
  }
public static @NlsContexts.DialogMessage @Nullable String getErrorMessage(PsiExpression expr)