@Override
    public StreamStateElement visitStandard_stateful_source(
            @NotNull SiddhiQLParser.Standard_stateful_sourceContext ctx) {

//        standard_stateful_source
//        : (event '=')? basic_source
//        ;

        if (ctx.event() != null) {
            activeStreams.add(visitEvent(ctx.event()));
        }
        BasicSingleInputStream basicSingleInputStream = (BasicSingleInputStream) visit(ctx.basic_source());
        if (ctx.event() != null) {
            if (basicSingleInputStream.isInnerStream()) {
                activeStreams.remove("#" + basicSingleInputStream.getStreamId());
            } else if (basicSingleInputStream.isFaultStream()) {
                activeStreams.remove("!" + basicSingleInputStream.getStreamId());
            } else {
                activeStreams.remove(basicSingleInputStream.getStreamId());
            }
            StreamStateElement streamStateElement = new StreamStateElement(basicSingleInputStream.as((String)
                    visit(ctx.event())));
            populateQueryContext(streamStateElement, ctx);
            return streamStateElement;
        } else {
            StreamStateElement streamStateElement = new StreamStateElement(basicSingleInputStream);
            populateQueryContext(streamStateElement, ctx);
            return streamStateElement;
        }
    }
{@inheritDoc}
<p>The default implementation returns the result of calling
{@link #visitChildren} on {@code ctx}.</p>

@param ctx
modules/siddhi-query-compiler/src/main/java/io/siddhi/query/compiler/internal/SiddhiQLBaseVisitorImpl.java