use of com.google.devtools.build.lib.skylarkinterface.SkylarkModule in project bazel by bazelbuild.
the class SkylarkDocumentationCollector method collectModules.
/**
* Collects the documentation for all Skylark modules and returns a map that maps Skylark module
* name to the module documentation.
*
* <p>WARNING: This method no longer supports the specification of additional module classes via
* parameters. Instead, all module classes are being picked up automatically.
*
* @param clazz DEPRECATED.
*/
public static Map<String, SkylarkModuleDoc> collectModules(@Deprecated String... clazz) throws ClassPathException {
Map<String, SkylarkModuleDoc> modules = new TreeMap<>();
Map<SkylarkModule, Class<?>> builtinModules = new HashMap<>();
for (Class<?> candidateClass : Classpath.findClasses(MODULES_PACKAGE_PREFIX)) {
SkylarkModule annotation = candidateClass.getAnnotation(SkylarkModule.class);
if (annotation != null) {
collectBuiltinModule(builtinModules, candidateClass);
collectJavaObjects(annotation, candidateClass, modules);
}
collectBuiltinDoc(modules, candidateClass.getDeclaredFields());
}
return modules;
}
use of com.google.devtools.build.lib.skylarkinterface.SkylarkModule in project bazel by bazelbuild.
the class SkylarkInterfaceUtilsTest method testGetSkylarkModuleSubclass.
@Test
public void testGetSkylarkModuleSubclass() throws Exception {
// Subclass's annotation is used.
SkylarkModule ann = SkylarkInterfaceUtils.getSkylarkModule(MockClassC.class);
Class<?> cls = SkylarkInterfaceUtils.getParentWithSkylarkModule(MockClassC.class);
assertThat(ann).isNotNull();
assertThat(ann.doc()).isEqualTo("MockClassC");
assertThat(cls).isNotNull();
assertThat(cls).isEqualTo(MockClassC.class);
}
use of com.google.devtools.build.lib.skylarkinterface.SkylarkModule in project bazel by bazelbuild.
the class SkylarkInterfaceUtilsTest method testGetSkylarkModuleBasic.
// The tests for getSkylarkModule() double as tests for getParentWithSkylarkModule(),
// since they share an implementation.
@Test
public void testGetSkylarkModuleBasic() throws Exception {
// Normal case.
SkylarkModule ann = SkylarkInterfaceUtils.getSkylarkModule(MockClassA.class);
Class<?> cls = SkylarkInterfaceUtils.getParentWithSkylarkModule(MockClassA.class);
assertThat(ann).isNotNull();
assertThat(ann.doc()).isEqualTo("MockClassA");
assertThat(cls).isNotNull();
assertThat(cls).isEqualTo(MockClassA.class);
}
Aggregations