@Override
    public Object visitTraversalTerminalMethod_next(final GremlinParser.TraversalTerminalMethod_nextContext ctx) {
        try {
            if (ctx.getChildCount() == 3) {
                return traversal.next();
            } else {
                // the 3rd child is integer value
                final int childIndexOfParamaterAmount = 2;
                return traversal.next(Integer.decode(ctx.getChild(childIndexOfParamaterAmount).getText()));
            }
        } finally {
            CloseableIterator.closeIterator(traversal);
        }
    }
{@inheritDoc}

Traversal terminal method next step
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalTerminalMethodVisitor.java