src/main/java/ognl/SimpleNode.java
protected void flattenTree()
    {
        boolean shouldFlatten = false;
        int newSize = 0;

        for (int i = 0; i < _children.length; ++i)
            if (_children[i].getClass() == getClass())
            {
                shouldFlatten = true;
                newSize += _children[i].jjtGetNumChildren();
            } else
                ++newSize;

        if (shouldFlatten)
        {
            Node[] newChildren = new Node[newSize];
            int j = 0;

            for (int i = 0; i < _children.length; ++i)
            {
                Node c = _children[i];
                if (c.getClass() == getClass())
                {
                    for (int k = 0; k < c.jjtGetNumChildren(); ++k)
                        newChildren[j++] = c.jjtGetChild(k);

                } else
                    newChildren[j++] = c;
            }

            if (j != newSize)
                throw new Error("Assertion error: " + j + " != " + newSize);

            _children = newChildren;
        }
    }
protected void flattenTree()
    {
        boolean shouldFlatten = false;
        int newSize = 0;

        for (int i = 0; i < _children.length; ++i)
            if (_children[i].getClass() == getClass())
            {
                shouldFlatten = true;
                newSize += _children[i].jjtGetNumChildren();
            } else
                ++newSize;

        if (shouldFlatten)
        {
            Node[] newChildren = new Node[newSize];
            int j = 0;

            for (int i = 0; i < _children.length; ++i)
            {
                Node c = _children[i];
                if (c.getClass() == getClass())
                {
                    for (int k = 0; k < c.jjtGetNumChildren(); ++k)
                        newChildren[j++] = c.jjtGetChild(k);

                } else
                    newChildren[j++] = c;
            }

            if (j != newSize)
                throw new Error("Assertion error: " + j + " != " + newSize);

            _children = newChildren;
        }
    }
This method may be called from subclasses' jjtClose methods. It flattens the tree under this node by eliminating any children that are of the same class as this
node and copying their children to this node.