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();
}
Aggregations