@Override
  public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
    CodeFloatingToolbar floatingToolbar = CodeFloatingToolbar.getToolbar(editor);
    if (floatingToolbar != null && (floatingToolbar.isShown() || floatingToolbar.canBeShownAtCurrentSelection())) return false;
    if (file instanceof PsiCodeFragment || !file.getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
      return false;
    }
    SelectionModel model = editor.getSelectionModel();
    if (!model.hasSelection()) return false;
    PsiElement[] elements = ExtractMethodHandler.getElements(project, editor, file);
    if (elements == null || elements.length == 0) return false;
    if (PsiTreeUtil.getParentOfType(elements[0], PsiClass.class) == null) return false;
    ExtractMethodProcessor processor = ExtractMethodHandler.getProcessor(project, elements, file, false);
    if (processor == null) return false;
    try {
      return processor.prepare(null);
    }
    catch (PrepareFailedException e) {
      return false;
    }
  }
@Override
  public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file)