private @Nullable E getElement(@NotNull ActionContext context) {
    if (myPointer != null) {
      E element = myPointer.getElement();
      return element != null && !BaseIntentionAction.canModify(element) ?
             null :
             element;
    }
    int offset = context.offset();
    PsiFile file = context.file();
    if (!BaseIntentionAction.canModify(file)) return null;
    if (context.element() != null && context.element().isValid()) {
      return getIfSatisfied(context.element(), context);
    }
    PsiElement right = file.findElementAt(offset);
    PsiElement left = offset > 0 ? file.findElementAt(offset - 1) : right;
    if (left == null && right == null) return null;
    if (left == null) left = right;
    if (right == null) right = left;
    PsiElement commonParent = PsiTreeUtil.findCommonParent(left, right);

    if (left != right) {
      while (right != commonParent) {
        E result = getIfSatisfied(right, context);
        if (result != null) return result;
        right = right.getParent();
      }
    }

    while (left != commonParent) {
      E result = getIfSatisfied(left, context);
      if (result != null) return result;
      left = left.getParent();
    }

    while (true) {
      if (commonParent == null) return null;
      E satisfied = getIfSatisfied(commonParent, context);
      if (satisfied != null) return satisfied;
      if (stopSearchAt(commonParent, context) || commonParent instanceof PsiFile) return null;
      commonParent = commonParent.getParent();
    }
  }
private @Nullable E getElement(@NotNull ActionContext context)