aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skylarkinterface
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2017-11-06 19:49:16 +0100
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-11-06 20:20:32 +0100
commit67c84b1036ad02ba2384fa75fb28e779a488f3d4 (patch)
treec70665241fab2a4947f0941659b8e6421eabb44c /src/main/java/com/google/devtools/build/lib/skylarkinterface
parent11517396816697ad1c48a71e47f37d9206225741 (diff)
Break dependency on vfs from the interface of syntax and cmdline.
These libs are exposed externally, implying that the vfs is also exposed externally. We break out PathFragment from vfs to still use this in their interface. This class is a much smaller dependency than the entire vfs. PiperOrigin-RevId: 174729373
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skylarkinterface')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkInterfaceUtils.java28
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkPrintable.java42
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkValue.java22
3 files changed, 61 insertions, 31 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkInterfaceUtils.java b/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkInterfaceUtils.java
index bee73efaf8..e3751a8494 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkInterfaceUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkInterfaceUtils.java
@@ -14,7 +14,6 @@
package com.google.devtools.build.lib.skylarkinterface;
-import com.google.devtools.build.lib.util.Pair;
import java.lang.reflect.Method;
import javax.annotation.Nullable;
@@ -23,21 +22,30 @@ import javax.annotation.Nullable;
*/
public class SkylarkInterfaceUtils {
+ private static final class ClassAndSkylarkModule {
+ final Class<?> klass;
+ final SkylarkModule skylarkModule;
+
+ ClassAndSkylarkModule(Class<?> klass, SkylarkModule skylarkModule) {
+ this.klass = klass;
+ this.skylarkModule = skylarkModule;
+ }
+ }
+
@Nullable
- private static Pair<Class<?>, SkylarkModule> searchForSkylarkModule(Class<?> classObj) {
+ private static ClassAndSkylarkModule searchForSkylarkModule(Class<?> classObj) {
if (classObj.isAnnotationPresent(SkylarkModule.class)) {
- return new Pair<Class<?>, SkylarkModule>(
- classObj, classObj.getAnnotation(SkylarkModule.class));
+ return new ClassAndSkylarkModule(classObj, classObj.getAnnotation(SkylarkModule.class));
}
Class<?> superclass = classObj.getSuperclass();
if (superclass != null) {
- Pair<Class<?>, SkylarkModule> result = searchForSkylarkModule(superclass);
+ ClassAndSkylarkModule result = searchForSkylarkModule(superclass);
if (result != null) {
return result;
}
}
for (Class<?> interfaceObj : classObj.getInterfaces()) {
- Pair<Class<?>, SkylarkModule> result = searchForSkylarkModule(interfaceObj);
+ ClassAndSkylarkModule result = searchForSkylarkModule(interfaceObj);
if (result != null) {
return result;
}
@@ -52,8 +60,8 @@ public class SkylarkInterfaceUtils {
*/
@Nullable
public static SkylarkModule getSkylarkModule(Class<?> classObj) {
- Pair<Class<?>, SkylarkModule> result = searchForSkylarkModule(classObj);
- return result == null ? null : result.second;
+ ClassAndSkylarkModule result = searchForSkylarkModule(classObj);
+ return result == null ? null : result.skylarkModule;
}
/**
@@ -63,8 +71,8 @@ public class SkylarkInterfaceUtils {
*/
@Nullable
public static Class<?> getParentWithSkylarkModule(Class<?> classObj) {
- Pair<Class<?>, SkylarkModule> result = searchForSkylarkModule(classObj);
- return result == null ? null : result.first;
+ ClassAndSkylarkModule result = searchForSkylarkModule(classObj);
+ return result == null ? null : result.klass;
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkPrintable.java b/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkPrintable.java
new file mode 100644
index 0000000000..39760c4108
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkPrintable.java
@@ -0,0 +1,42 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.skylarkinterface;
+
+/**
+ * Interface for types that aren't {@link SkylarkValue}s, but that we still want to support printing
+ * of.
+ */
+public interface SkylarkPrintable {
+
+ /**
+ * Print an official representation of object x.
+ *
+ * <p>For regular data structures, the value should be parsable back into an equal data structure.
+ *
+ * @param printer a printer to be used for formatting nested values.
+ */
+ void repr(SkylarkPrinter printer);
+
+ /**
+ * Print an informal, human-readable representation of the value.
+ *
+ * <p>By default dispatches to the {@code repr} method.
+ *
+ * @param printer a printer to be used for formatting nested values.
+ */
+ default void str(SkylarkPrinter printer) {
+ repr(printer);
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkValue.java b/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkValue.java
index 6d430ff4ab..b61da9b418 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkValue.java
@@ -19,7 +19,7 @@ package com.google.devtools.build.lib.skylarkinterface;
*
* <p>This is used for extending the Skylark interpreter with domain-specific values.
*/
-public interface SkylarkValue {
+public interface SkylarkValue extends SkylarkPrintable {
/**
* Returns if the value is immutable and thus suitable for being used as a dictionary key.
@@ -30,24 +30,4 @@ public interface SkylarkValue {
default boolean isImmutable() {
return false;
}
-
- /**
- * Print an official representation of object x.
- *
- * <p>For regular data structures, the value should be parsable back into an equal data structure.
- *
- * @param printer a printer to be used for formatting nested values.
- */
- void repr(SkylarkPrinter printer);
-
- /**
- * Print an informal, human-readable representation of the value.
- *
- * <p>By default dispatches to the {@code repr} method.
- *
- * @param printer a printer to be used for formatting nested values.
- */
- default void str(SkylarkPrinter printer) {
- repr(printer);
- }
}