private static @Nullable TreeElement findFirstLeafOrType(@NotNull TreeElement element,
                                                           IElementType searchedType,
                                                           CommonParentState commonParent,
                                                           boolean expandChameleons) {
    final class MyVisitor extends RecursiveTreeElementWalkingVisitor {
      private TreeElement result;

      private MyVisitor(boolean doTransform) {
        super(doTransform);
      }

      @Override
      protected void visitNode(TreeElement node) {
        if (result != null) return;

        if (commonParent != null) {
          initStrongWhitespaceHolder(commonParent, node, false);
        }
        if (!expandChameleons && isCollapsedChameleon(node) || node instanceof LeafElement || node.getElementType() == searchedType) {
          result = node;
          return;
        }

        super.visitNode(node);
      }
    }

    MyVisitor visitor = new MyVisitor(expandChameleons);
    element.acceptTree(visitor);
    return visitor.result;
  }
private static @Nullable TreeElement findFirstLeafOrType(@NotNull TreeElement element,
                                                           IElementType searchedType,
                                                           CommonParentState commonParent,
                                                           boolean expandChameleons)