WorkspaceASTFunction returns a list of ASTs so we can split the AST before load statements
Issue #824 Step 2.
--
MOS_MIGRATED_REVID=113986176
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
index 1ff0883..3d324b2 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
@@ -59,6 +59,30 @@
setLocation(result.location);
}
+ private BuildFileAST(
+ ImmutableList<Statement> stmts,
+ boolean containsErrors,
+ String contentHashCode,
+ Location location) {
+ this.stmts = stmts;
+ this.containsErrors = containsErrors;
+ this.contentHashCode = contentHashCode;
+ this.comments = ImmutableList.of();
+ this.setLocation(location);
+ }
+
+ /**
+ * Extract a subtree containing only statements from {@code firstStatement} (included) up to
+ * {@code lastStatement} excluded.
+ */
+ public BuildFileAST subTree(int firstStatement, int lastStatement) {
+ return new BuildFileAST(
+ stmts.subList(firstStatement, lastStatement),
+ containsErrors,
+ null,
+ stmts.get(firstStatement).getLocation());
+ }
+
/** Collects all load statements */
private ImmutableList<SkylarkImport> fetchLoads(List<Statement> stmts) {
ImmutableList.Builder<SkylarkImport> imports = new ImmutableList.Builder<>();