Skip to content

Commit

Permalink
Improve the way a FuncallExpression is printed while debugging.
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=93908545
  • Loading branch information
fare authored and damienmg committed May 18, 2015
1 parent 88311f8 commit 9e3cc2e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ private static void printValueX(Object o, Appendable buffer)
}
}

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
Expand All @@ -418,7 +418,7 @@ private static void printList(Iterable<?> list,
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -254,10 +255,17 @@ public String toString() {
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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ public void testAugmentedAssign() throws Exception {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void testNoneIsAnyType() throws Exception {

@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():",
Expand Down

0 comments on commit 9e3cc2e

Please sign in to comment.