Java Code Examples for com.google.devtools.build.lib.syntax.Printer#repr()

The following examples show how to use com.google.devtools.build.lib.syntax.Printer#repr() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FakeStructApi.java    From bazel with Apache License 2.0 6 votes vote down vote up
/** Converts the object to string using Starlark syntax. */
@Override
public void repr(Printer printer) {
  boolean first = true;
  printer.append("struct(");
  for (String fieldName : Ordering.natural().sortedCopy(getFieldNames())) {
    if (!first) {
      printer.append(", ");
    }
    first = false;
    printer.append(fieldName);
    printer.append(" = ");
    printer.repr(getValueOrNull(fieldName));
  }

  printer.append(")");
}
 
Example 2
Source File: FilesetEntry.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public void repr(Printer printer) {
  printer.append("FilesetEntry(srcdir = ");
  printer.repr(getSrcLabel().toString());
  printer.append(", files = ");
  printer.repr(makeStringList(getFiles()));
  printer.append(", excludes = ");
  printer.repr(makeList(getExcludes()));
  printer.append(", destdir = ");
  printer.repr(getDestDir().getPathString());
  printer.append(", strip_prefix = ");
  printer.repr(getStripPrefix());
  printer.append(", symlinks = ");
  printer.repr(getSymlinkBehavior().toString());
  printer.append(")");
}
 
Example 3
Source File: StructImpl.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the object to string using Starlark syntax. The output tries to be reversible (but
 * there is no guarantee, it depends on the actual values).
 */
@Override
public void repr(Printer printer) {
  boolean first = true;
  printer.append("struct(");
  // Sort by key to ensure deterministic output.
  for (String fieldName : Ordering.natural().sortedCopy(getFieldNames())) {
    if (!first) {
      printer.append(", ");
    }
    first = false;
    printer.append(fieldName);
    printer.append(" = ");
    printer.repr(getValueOrNull(fieldName));
  }
  printer.append(")");
}
 
Example 4
Source File: StarlarkRuleContext.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public void repr(Printer printer) {
  if (isImmutable()) {
    printer.append("ctx.outputs(for ");
    printer.append(context.ruleLabelCanonicalName);
    printer.append(")");
    return;
  }
  boolean first = true;
  printer.append("ctx.outputs(");
  // Sort by field name to ensure deterministic output.
  try {
    for (String field : Ordering.natural().sortedCopy(getFieldNames())) {
      if (!first) {
        printer.append(", ");
      }
      first = false;
      printer.append(field);
      printer.append(" = ");
      printer.repr(getValue(field));
    }
    printer.append(")");
  } catch (EvalException e) {
    throw new AssertionError("mutable ctx.outputs should not throw", e);
  }
}
 
Example 5
Source File: Depset.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void repr(Printer printer) {
  printer.append("depset(");
  printer.printList(set.toList(), "[", ", ", "]", null);
  Order order = getOrder();
  if (order != Order.STABLE_ORDER) {
    printer.append(", order = ");
    printer.repr(order.getStarlarkName());
  }
  printer.append(")");
}
 
Example 6
Source File: BuildType.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void repr(Printer printer) {
  // Convert to a lib.syntax.SelectorList to guarantee consistency with callers that serialize
  // directly on that type.
  List<SelectorValue> selectorValueList = new ArrayList<>();
  for (Selector<T> element : elements) {
    selectorValueList.add(new SelectorValue(element.getEntries(), element.getNoMatchError()));
  }
  try {
    printer.repr(com.google.devtools.build.lib.packages.SelectorList.of(selectorValueList));
  } catch (EvalException e) {
    throw new IllegalStateException("this list should have been validated on creation");
  }
}
 
Example 7
Source File: Runfiles.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void repr(Printer printer) {
  printer.append("SymlinkEntry(path = ");
  printer.repr(getPathString());
  printer.append(", target_file = ");
  getArtifact().repr(printer);
  printer.append(")");
}
 
Example 8
Source File: Label.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void repr(Printer printer) {
  printer.append("Label(");
  printer.repr(getCanonicalForm());
  printer.append(")");
}