public Statement buildStatement(final ParserRuleContext parseTree) {
    return build(Optional.of(getSources(parseTree)), parseTree);
  }
@Test
  public void shouldGetCorrectLocationsSimpleCtasMultiLine() {
    // Given:
    final String query =
        "CREATE TABLE X AS\n" +
        "  SELECT COUNT(1)\n" +
        "  FROM TEST1\n" +
        "  GROUP BY ROWKEY;";
    final SingleStatementContext stmt = givenQuery(query);

    // When:
    final CreateTableAsSelect result = (CreateTableAsSelect) builder.buildStatement(stmt);

    // Then:
    final NodeLocation loc = result.getLocation().get();
    final TokenLocation start = loc.getStartTokenLocation();
    final TokenLocation stop = loc.getStopTokenLocation().get();

    assertThat(start.getLine(), is(1));
    assertThat(start.getCharPositionInLine(), is(0));
    assertThat(start.getStartIndex(), is(0));
    assertThat(start.getStopIndex(),
        is("CREATE TABLE X AS".indexOf("E TABLE"))); // ends at the E of CREATE


    assertThat(stop.getLine(), is(4));

    // last token is ROWKEY
    assertThat(stop.getCharPositionInLine(),
        is("  GROUP BY ROWKEY;".indexOf("ROWKEY")));
    assertThat(stop.getStartIndex(),
        is("CREATE TABLE X AS\n  SELECT COUNT(1)\n  FROM TEST1\n  GROUP BY ROWKEY;".indexOf("ROWKEY")));
    assertThat(stop.getStopIndex(),
        is("CREATE TABLE X AS\n  SELECT COUNT(1)\n  FROM TEST1\n  GROUP BY ROWKEY;".indexOf("Y;")));

    assertThat(loc.getLength(), is(OptionalInt.of(query.length() - 1))); // subtracting 1 as the last ';' is not counted
  }