private static void doAction(@NotNull Editor editor, @NotNull PsiFile file) {
    if (!editor.getSelectionModel().hasSelection()) {
      return;
    }

    CharSequence text = editor.getDocument().getCharsSequence();

    int cursorOffset = editor.getCaretModel().getOffset();

    if (cursorOffset > 0 && cursorOffset < text.length() &&
       !Character.isJavaIdentifierPart(text.charAt(cursorOffset)) &&
       Character.isJavaIdentifierPart(text.charAt(cursorOffset - 1))) {
      cursorOffset--;
    }

    PsiElement element = file.findElementAt(cursorOffset);

    if (element instanceof PsiWhiteSpace && cursorOffset > 0) {
      PsiElement anotherElement = file.findElementAt(cursorOffset - 1);

      if (!(anotherElement instanceof PsiWhiteSpace)) {
        element = anotherElement;
      }
    }

    final TextRange selectionRange = new TextRange(editor.getSelectionModel().getSelectionStart(), editor.getSelectionModel().getSelectionEnd());
    MaxRangeProcessor rangeProcessor = new MaxRangeProcessor(selectionRange, editor, cursorOffset);
    if (element instanceof PsiWhiteSpace) {
      if (SelectWordUtil.canWhiteSpaceBeExpanded((PsiWhiteSpace) element, cursorOffset, null, editor)) {
        SelectWordUtil.processRanges(element, text, cursorOffset, editor, rangeProcessor);
      }
      PsiElement sibling = findNextSibling(element);
      if (sibling != null) {
        int siblingOffset = sibling.getTextRange().getStartOffset();
        rangeProcessor.setCursorOffset(siblingOffset);
        SelectWordUtil.processRanges(sibling, text, siblingOffset, editor, rangeProcessor);
      }
    } else {
      SelectWordUtil.processRanges(element, text, cursorOffset, editor, rangeProcessor);
    }

    TextRange range = rangeProcessor.getMaximumRange();
    if (range == null) {
      editor.getSelectionModel().setSelection(cursorOffset, cursorOffset);
    }
    else {
      editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
    }
  }
private static void doAction(@NotNull Editor editor, @NotNull PsiFile file)