aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
diff options
context:
space:
mode:
authorGravatar Francois-Rene Rideau <tunes@google.com>2015-02-25 15:48:30 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-02-25 15:48:30 +0000
commitb6091071623fe8c2800c7f9ddf4800c37cb2a8d1 (patch)
treee2aff38435dccf654ea051228804f114d7bb6900 /src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
parent53b15a4c104b7f8853ddef54a73d28aa9c695089 (diff)
Tweaks off of upcoming changes to SkylarkType.
-- MOS_MIGRATED_REVID=87154772
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java32
1 files changed, 27 insertions, 5 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 57aec07e56..02c10a26e1 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
@@ -139,6 +139,7 @@ public abstract class EvalUtils {
return null;
}
+ // TODO(bazel-team): move the following few type-related functions to SkylarkType
/**
* Returns the Skylark equivalent type of the parameter. Note that the Skylark
* language doesn't have inheritance.
@@ -168,16 +169,32 @@ public abstract class EvalUtils {
return c;
}
- // TODO(bazel-team): shouldn't we agree on Datatype vs DataType in the two methods below???
/**
* Returns a pretty name for the datatype of object 'o' in the Build language.
*/
public static String getDataTypeName(Object o) {
- Preconditions.checkNotNull(o);
- if (o instanceof SkylarkList) {
- return ((SkylarkList) o).isTuple() ? "tuple" : "list";
+ return getDataTypeName(o, false);
+ }
+
+ /**
+ * Returns a pretty name for the datatype of object {@code object} in Skylark
+ * or the BUILD language, with full details if the {@code full} boolean is true.
+ */
+ public static String getDataTypeName(Object object, boolean full) {
+ Preconditions.checkNotNull(object);
+ if (object instanceof SkylarkList) {
+ SkylarkList list = (SkylarkList) object;
+ if (list.isTuple()) {
+ return "tuple";
+ } else {
+ return "list" + (full ? " of " + list.getGenericType() + "s" : "");
+ }
+ } else if (object instanceof SkylarkNestedSet) {
+ SkylarkNestedSet set = (SkylarkNestedSet) object;
+ return "set" + (full ? " of " + set.getGenericType() + "s" : "");
+ } else {
+ return getDataTypeNameFromClass(object.getClass());
}
- return getDataTypeNameFromClass(o.getClass());
}
/**
@@ -280,6 +297,11 @@ public abstract class EvalUtils {
buffer.append(": ");
prettyPrintValue(entry.getValue(), buffer);
+ } else if (o instanceof SkylarkNestedSet) {
+ Iterable<?> seq = (Iterable<?>) o;
+ // TODO(bazel-team): preserve the order= flag when not the default "stable".
+ printList(seq, "set([", ", ", "])", buffer);
+
} else if (o instanceof Function) {
Function func = (Function) o;
buffer.append("<function " + func.getName() + ">");