@NotNull
  public static InlineHandler.Settings inlineMethodSettings(GrMethod method, Editor editor, boolean invokedOnReference) {

    final Project project = method.getProject();
    if (method.isConstructor()) {
      String message = GroovyRefactoringBundle.message("refactoring.cannot.be.applied.to.constructors", getRefactoringName());
      showErrorMessage(message, project, editor);
      return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
    }

    if (invokedOnReference) {
      PsiReference reference = editor != null ? TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset()) : null;
      if (reference == null) return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;

      PsiElement element = reference.getElement();

      if (!(element instanceof GrExpression && element.getParent() instanceof GrCallExpression call)) {
        String message = GroovyRefactoringBundle.message("refactoring.is.available.only.for.method.calls", getRefactoringName());
        showErrorMessage(message, project, editor);
        return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
      }

      if (PsiTreeUtil.getParentOfType(element, GrParameter.class) != null) {
        String message = GroovyRefactoringBundle.message("refactoring.is.not.supported.in.parameter.initializers", getRefactoringName());
        showErrorMessage(message, project, editor);
        return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
      }


      GroovyRefactoringUtil.highlightOccurrences(project, editor, new GrExpression[]{call});
      if (hasBadReturns(method) && !isTailMethodCall(call)) {
        String message = GroovyRefactoringBundle.message("refactoring.is.not.supported.when.return.statement.interrupts.the.execution.flow",
                                                         getRefactoringName());
        showErrorMessage(message, project, editor);
        return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
      }
    }
    else {
      if (hasBadReturns(method)) {
        String message = GroovyRefactoringBundle.message("refactoring.is.not.supported.when.return.statement.interrupts.the.execution.flow",
                                                         getRefactoringName());
        showErrorMessage(message, project, editor);
        return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
      }
    }

    if (method.getBlock() == null) {
      String message = method.hasModifierProperty(PsiModifier.ABSTRACT)
                       ? GroovyRefactoringBundle.message("refactoring.cannot.be.applied.to.abstract.methods", getRefactoringName())
                       : GroovyRefactoringBundle.message("refactoring.cannot.be.applied.no.sources.attached", getRefactoringName());
      showErrorMessage(message, project, editor);
      return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
    }

    return inlineMethodDialogResult(method, project, invokedOnReference);
  }
@NotNull
  public static InlineHandler.Settings inlineMethodSettings(GrMethod method, Editor editor, boolean invokedOnReference)