@NotNull
  @Override
  public RenameDialog createRenameDialog(@NotNull final Project project, @NotNull final PsiElement element, PsiElement nameSuggestionContext, Editor editor) {

    return new RenameDialog(project, element, nameSuggestionContext, editor) {
      @Override
      protected void createNewNameComponent() {
        super.createNewNameComponent();
        final String qualifiedName = ((PsiPackage)element).getQualifiedName();
        final String packageName = StringUtil.getPackageName(qualifiedName);
        preselectExtension(packageName.isEmpty() ? 0 : packageName.length() + 1, qualifiedName.length());
      }

      @Override
      public String[] getSuggestedNames() {
        return new String[]{((PsiPackage)element).getQualifiedName()};
      }

      @NotNull
      @Override
      public String getNewName() {
        final PsiPackage psiPackage = (PsiPackage)element;
        final String oldName = psiPackage.getQualifiedName();
        final String newName = super.getNewName();
        if (!Comparing.strEqual(StringUtil.getPackageName(oldName), StringUtil.getPackageName(newName))) {
          return newName;
        }
        return StringUtil.getShortName(newName);
      }

      @Override
      protected void doAction() {
        final PsiPackage psiPackage = (PsiPackage)element;
        final String oldName = psiPackage.getQualifiedName();
        final String newName = super.getNewName();
        if (!Comparing.strEqual(StringUtil.getPackageName(oldName), StringUtil.getPackageName(newName))) {
          setToSearchInComments(psiPackage, isSearchInComments());
          if (isSearchForTextOccurrencesEnabled()) {
            setToSearchForTextOccurrences(psiPackage, isSearchInNonJavaFiles());
          }
          invokeRefactoring(createRenameMoveProcessor(newName, psiPackage, isSearchInComments(), isSearchInNonJavaFiles()));
        } else {
          super.doAction();
        }
      }
    };
  }
@NotNull
  @Override
  public RenameDialog createRenameDialog(@NotNull final Project project, @NotNull final PsiElement element, PsiElement nameSuggestionContext, Editor editor)