aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2016-10-11 12:29:40 +0000
committerGravatar Yue Gan <yueg@google.com>2016-10-11 13:26:58 +0000
commitc79570cf340e158d5025ccdb1358c4e1548d2558 (patch)
tree5e343991a3b4c2b84d0e30af56fc8f139c5e019d /src/main/java/com/google/devtools/build
parent884ca5ccf3c3241402149a4262d8a71da8e2e70f (diff)
*** Reason for rollback *** Seems to break some parts of aspects. *** Original change description *** Make EvalUtils.getDataTypeNameFromClass() look for @SkylarkModules in parent classes This is needed to let subclasses of @SkylarkModules have the same type() string as their superclass, without requiring a second annotation for the subclass (which would lead to redundant documentation being generated). -- MOS_MIGRATED_REVID=135786137
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkInterfaceUtils.java59
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java7
2 files changed, 23 insertions, 43 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 348a9ccef4..95d4f4fcf5 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
@@ -23,59 +23,40 @@ import javax.annotation.Nullable;
public class SkylarkInterfaceUtils {
/**
- * Returns the {@link SkylarkModule} annotation for the given class, if it exists, and
- * null otherwise. The first annotation found will be returned, starting with {@code classObj}
- * and following its base classes and interfaces recursively.
- */
- @Nullable
- public static SkylarkModule getSkylarkModule(Class<?> classObj) {
- if (classObj.isAnnotationPresent(SkylarkModule.class)) {
- return classObj.getAnnotation(SkylarkModule.class);
- }
- Class<?> superclass = classObj.getSuperclass();
- if (superclass != null) {
- SkylarkModule annotation = getSkylarkModule(superclass);
- if (annotation != null) {
- return annotation;
- }
- }
- for (Class<?> interfaceObj : classObj.getInterfaces()) {
- SkylarkModule annotation = getSkylarkModule(interfaceObj);
- if (annotation != null) {
- return annotation;
- }
- }
- return null;
- }
-
- /**
* Returns the {@link SkylarkCallable} annotation for the given method, if it exists, and
- * null otherwise. The first annotation of an overridden version of the method that is found
+ * null otherwise. The method must be declared in {@code classObj} or one of its base classes
+ * or interfaces. The first annotation of an overridden version of the method that is found
* will be returned, starting with {@code classObj} and following its base classes and
- * interfaces recursively, skipping any annotation inside a class not marked
- * {@link SkylarkModule}.
+ * interfaces recursively.
*/
@Nullable
public static SkylarkCallable getSkylarkCallable(Class<?> classObj, Method method) {
+ boolean keepLooking = false;
try {
Method superMethod = classObj.getMethod(method.getName(), method.getParameterTypes());
if (classObj.isAnnotationPresent(SkylarkModule.class)
&& superMethod.isAnnotationPresent(SkylarkCallable.class)) {
return superMethod.getAnnotation(SkylarkCallable.class);
+ } else {
+ keepLooking = true;
}
} catch (NoSuchMethodException e) {
- // The class might not have the specified method, so an exception is OK.
+ // The class might not have the specified method, so an exceptions is OK.
+ keepLooking = true;
}
- if (classObj.getSuperclass() != null) {
- SkylarkCallable annotation = getSkylarkCallable(classObj.getSuperclass(), method);
- if (annotation != null) {
- return annotation;
+ if (keepLooking) {
+ if (classObj.getSuperclass() != null) {
+ SkylarkCallable annotation =
+ getSkylarkCallable(classObj.getSuperclass(), method);
+ if (annotation != null) {
+ return annotation;
+ }
}
- }
- for (Class<?> interfaceObj : classObj.getInterfaces()) {
- SkylarkCallable annotation = getSkylarkCallable(interfaceObj, method);
- if (annotation != null) {
- return annotation;
+ for (Class<?> interfaceObj : classObj.getInterfaces()) {
+ SkylarkCallable annotation = getSkylarkCallable(interfaceObj, method);
+ if (annotation != null) {
+ return annotation;
+ }
}
}
return null;
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 9609544e19..5b1834d868 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
@@ -21,7 +21,6 @@ import com.google.common.collect.Ordering;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.events.Location;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkInterfaceUtils;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.compiler.ByteCodeUtils;
@@ -256,9 +255,9 @@ public final class EvalUtils {
* when the given class identifies a Skylark name space.
*/
public static String getDataTypeNameFromClass(Class<?> c, boolean highlightNameSpaces) {
- SkylarkModule module = SkylarkInterfaceUtils.getSkylarkModule(c);
- if (module != null) {
- return module.name()
+ if (c.isAnnotationPresent(SkylarkModule.class)) {
+ SkylarkModule module = c.getAnnotation(SkylarkModule.class);
+ return c.getAnnotation(SkylarkModule.class).name()
+ ((module.namespace() && highlightNameSpaces) ? " (a language module)" : "");
} else if (c.equals(Object.class)) {
return "unknown";