diff options
author | 2015-05-18 18:35:36 +0000 | |
---|---|---|
committer | 2015-05-18 20:02:33 +0000 | |
commit | 9e3cc2e608184e9f3ff9eea5a97116e61c6cee23 (patch) | |
tree | d3aadca80dda9142a25531162de6bba03237496d /src | |
parent | 88311f87c5b7c1b70499b03093b6088429144cbe (diff) |
Improve the way a FuncallExpression is printed while debugging.
--
MOS_MIGRATED_REVID=93908545
Diffstat (limited to 'src')
4 files changed, 15 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java index bdc0fb625e..1287fc70bc 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java @@ -398,7 +398,7 @@ public abstract class EvalUtils { } } - private static void printList(Iterable<?> list, + public static void printList(Iterable<?> list, String before, String separator, String after, String singletonTerminator, Appendable buffer) throws IOException { boolean printSeparator = false; // don't print the separator before the first element @@ -418,7 +418,7 @@ public abstract class EvalUtils { buffer.append(after); } - private static void printList(Iterable<?> list, boolean isTuple, Appendable buffer) + public static void printList(Iterable<?> list, boolean isTuple, Appendable buffer) throws IOException { if (isTuple) { printList(list, "(", ", ", ")", ",", buffer); diff --git a/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java b/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java index b996588822..5a04ba1935 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java @@ -26,6 +26,7 @@ import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.syntax.EvalException.EvalExceptionWithJavaCause; import com.google.devtools.build.lib.util.StringUtilities; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -254,10 +255,17 @@ public final class FuncallExpression extends Expression { if (func.getName().equals("$index")) { return obj + "[" + args.get(0) + "]"; } + StringBuilder sb = new StringBuilder(); if (obj != null) { - return obj + "." + func + "(" + args + ")"; + sb.append(obj).append("."); + } + sb.append(func); + try { + EvalUtils.printList(args, "(", ", ", ")", null, sb); + } catch (IOException x) { + throw new RuntimeException("Error while printing", x); } - return func + "(" + args + ")"; + return sb.toString(); } /** diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java index e5d481533b..ef1b9f9fda 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java @@ -392,8 +392,8 @@ public class ParserTest extends EvaluationTestCase { public void testPrettyPrintFunctions() throws Exception { assertEquals("[x[1:3]\n]", parseFile("x[1:3]").toString()); assertEquals("[str[42]\n]", parseFile("str[42]").toString()); - assertEquals("[ctx.new_file(['hello'])\n]", parseFile("ctx.new_file('hello')").toString()); - assertEquals("[new_file(['hello'])\n]", parseFile("new_file('hello')").toString()); + assertEquals("[ctx.new_file('hello')\n]", parseFile("ctx.new_file('hello')").toString()); + assertEquals("[new_file('hello')\n]", parseFile("new_file('hello')").toString()); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java b/src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java index fbbdbcc82a..3326fec778 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java @@ -180,7 +180,7 @@ public class ValidationTests extends EvaluationTestCase { @Test public void testFuncReturningDictAssignmentAsLValue() throws Exception { - checkError("can only assign to variables and tuples, not to 'dict([])['b']'", + checkError("can only assign to variables and tuples, not to 'dict()['b']'", "def dict():", " return {'a': 1}", "def func():", |