Add a pretty printer for Skylark ASTs
This can be used to canonically compare ASTs for equality, e.g. in tests.
RELNOTES: None
PiperOrigin-RevId: 160283160
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/FunctionDefStatement.java b/src/main/java/com/google/devtools/build/lib/syntax/FunctionDefStatement.java
index e6ef1ba..881368b 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/FunctionDefStatement.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/FunctionDefStatement.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.syntax;
import com.google.common.collect.ImmutableList;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -69,8 +70,24 @@
}
@Override
+ public void prettyPrint(Appendable buffer, int indentLevel) throws IOException {
+ printIndent(buffer, indentLevel);
+ buffer.append("def ");
+ ident.prettyPrint(buffer);
+ buffer.append('(');
+ String sep = "";
+ for (Parameter<?, ?> param : parameters) {
+ buffer.append(sep);
+ param.prettyPrint(buffer);
+ sep = ", ";
+ }
+ buffer.append("):\n");
+ printSuite(buffer, statements, indentLevel);
+ }
+
+ @Override
public String toString() {
- return "def " + ident + "(" + signature + "):\n";
+ return "def " + ident + "(" + signature + "): ...\n";
}
public Identifier getIdent() {