Skip to content

Commit

Permalink
Fix pretty-printing of nested phase plans
Browse files Browse the repository at this point in the history
  • Loading branch information
gergo- committed Sep 20, 2022
1 parent 7da9a0d commit 265d8c1
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,24 @@ final class Printer {
* @return {@code buf}
*/
public <T> Formatter printTo(PhasePlan<T> plan, Formatter buf) {
return printPlan(Printer.CHILD, Printer.LAST_CHILD, plan, buf);
return printPlan("", plan, buf);
}

/**
* Prints {@code plan} to a string and returns it.
*/
public <T> String toString(PhasePlan<T> plan) {
return printPlan(Printer.CHILD, Printer.LAST_CHILD, plan, new Formatter()).toString();
return printPlan("", plan, new Formatter()).toString();
}

@SuppressWarnings("unchecked")
private <T> Formatter printPlan(String indent, String indentLast, PhasePlan<T> plan, Formatter buf) {
private <T> Formatter printPlan(String indent, PhasePlan<T> plan, Formatter buf) {
int index = 0;
for (Iterator<T> iter = plan.getPhases().iterator(); iter.hasNext();) {
T phase = iter.next();
String className = plan.getPhaseName(phase);
boolean hasNext = iter.hasNext();
buf.format("%s%s", hasNext ? indent : indentLast, abbreviate(className));
buf.format("%s%s%s", indent, hasNext ? Printer.CHILD : Printer.LAST_CHILD, abbreviate(className));

String graphState = plan.getGraphStateDiff(index);
if (graphState != null) {
Expand All @@ -120,8 +120,8 @@ private <T> Formatter printPlan(String indent, String indentLast, PhasePlan<T> p

if (phase instanceof PhasePlan) {
PhasePlan<T> subPlan = (PhasePlan<T>) phase;
String prefix = hasNext ? CONNECTING_INDENT : EMPTY_INDENT;
printPlan(prefix + indent, prefix + indentLast, subPlan, buf);
String nextLevel = hasNext ? CONNECTING_INDENT : EMPTY_INDENT;
printPlan(indent + nextLevel, subPlan, buf);
}

index++;
Expand Down

0 comments on commit 265d8c1

Please sign in to comment.