Search in sources :

Example 6 with SkylarkModule

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;
}
Also used : HashMap(java.util.HashMap) SkylarkModule(com.google.devtools.build.lib.skylarkinterface.SkylarkModule) TreeMap(java.util.TreeMap) SkylarkModuleDoc(com.google.devtools.build.docgen.skylark.SkylarkModuleDoc)

Example 7 with SkylarkModule

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);
}
Also used : SkylarkModule(com.google.devtools.build.lib.skylarkinterface.SkylarkModule) Test(org.junit.Test)

Example 8 with SkylarkModule

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);
}
Also used : SkylarkModule(com.google.devtools.build.lib.skylarkinterface.SkylarkModule) Test(org.junit.Test)

Aggregations

SkylarkModule (com.google.devtools.build.lib.skylarkinterface.SkylarkModule)8 Test (org.junit.Test)4 SkylarkModuleDoc (com.google.devtools.build.docgen.skylark.SkylarkModuleDoc)3 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 TreeMap (java.util.TreeMap)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 SkylarkBuiltinMethodDoc (com.google.devtools.build.docgen.skylark.SkylarkBuiltinMethodDoc)1 SkylarkJavaMethodDoc (com.google.devtools.build.docgen.skylark.SkylarkJavaMethodDoc)1 SkylarkCallable (com.google.devtools.build.lib.skylarkinterface.SkylarkCallable)1 SkylarkSignature (com.google.devtools.build.lib.skylarkinterface.SkylarkSignature)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1