@Override
  public IntentionPreviewInfo generatePreview(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiType type) {
    Project project = file.getProject();
    int offset = editor.getCaretModel().getOffset();
    PsiElement at = file.findElementAt(offset);
    PsiElement anchorStatement = CommonJavaRefactoringUtil.getParentStatement(at, false);
    if (anchorStatement == null) return IntentionPreviewInfo.EMPTY;
    SuggestedNameInfo suggestedNameInfo = getSuggestedVariableNames(project, type, at);
    assert suggestedNameInfo.names.length > 0;
    Document document = editor.getDocument();
    String initialVariableName = insertArgument(project, document, offset, suggestedNameInfo);
    PsiLocalVariable localVariable = addLocalVariable(project, anchorStatement, type, initialVariableName);
    PsiExpression initializer = localVariable.getInitializer();
    PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document); // reformat before deleting initializer
    if (initializer != null) {
      TextRange initRange = initializer.getTextRange();
      document.deleteString(initRange.getStartOffset(), initRange.getEndOffset());
    }
    return IntentionPreviewInfo.DIFF;
  }
@Override
  public IntentionPreviewInfo generatePreview(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiType type)