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/ConditionalExpression.java b/src/main/java/com/google/devtools/build/lib/syntax/ConditionalExpression.java
index a891022..4abc12a 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/ConditionalExpression.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/ConditionalExpression.java
@@ -13,6 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.syntax;
+import java.io.IOException;
/**
* Syntax node for an if/else expression.
@@ -43,8 +44,12 @@
* Constructs a string representation of the if expression
*/
@Override
- public String toString() {
- return thenCase + " if " + condition + " else " + elseCase;
+ public void prettyPrint(Appendable buffer) throws IOException {
+ thenCase.prettyPrint(buffer);
+ buffer.append(" if ");
+ condition.prettyPrint(buffer);
+ buffer.append(" else ");
+ elseCase.prettyPrint(buffer);
}
@Override