diff options
author | 2016-10-11 12:29:40 +0000 | |
---|---|---|
committer | 2016-10-11 13:26:58 +0000 | |
commit | c79570cf340e158d5025ccdb1358c4e1548d2558 (patch) | |
tree | 5e343991a3b4c2b84d0e30af56fc8f139c5e019d /src/main/java/com/google/devtools/build/lib/skylarkinterface | |
parent | 884ca5ccf3c3241402149a4262d8a71da8e2e70f (diff) |
Rollback of commit 9c25afe750a937b2152c21a93effc8b9ba82c27b.
*** 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/lib/skylarkinterface')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skylarkinterface/SkylarkInterfaceUtils.java | 59 |
1 files changed, 20 insertions, 39 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; |