Search in sources :

Example 1 with LoadStatement

use of com.google.devtools.build.lib.syntax.LoadStatement in project bazel by bazelbuild.

the class WorkspaceASTFunction method splitAST.

/**
   * Cut {@code ast} into a list of AST separated by load statements. We cut right before each load
   * statement series.
   */
private static ImmutableList<BuildFileAST> splitAST(BuildFileAST ast) {
    ImmutableList.Builder<BuildFileAST> asts = ImmutableList.builder();
    int prevIdx = 0;
    // don't cut if the first statement is a load.
    boolean lastIsLoad = true;
    List<Statement> statements = ast.getStatements();
    for (int idx = 0; idx < statements.size(); idx++) {
        Statement st = statements.get(idx);
        if (st instanceof LoadStatement) {
            if (!lastIsLoad) {
                asts.add(ast.subTree(prevIdx, idx));
                prevIdx = idx;
            }
            lastIsLoad = true;
        } else {
            lastIsLoad = false;
        }
    }
    if (!statements.isEmpty()) {
        asts.add(ast.subTree(prevIdx, statements.size()));
    }
    return asts.build();
}
Also used : LoadStatement(com.google.devtools.build.lib.syntax.LoadStatement) ImmutableList(com.google.common.collect.ImmutableList) Statement(com.google.devtools.build.lib.syntax.Statement) LoadStatement(com.google.devtools.build.lib.syntax.LoadStatement) BuildFileAST(com.google.devtools.build.lib.syntax.BuildFileAST)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 BuildFileAST (com.google.devtools.build.lib.syntax.BuildFileAST)1 LoadStatement (com.google.devtools.build.lib.syntax.LoadStatement)1 Statement (com.google.devtools.build.lib.syntax.Statement)1