use of com.google.devtools.build.docgen.skylark.SkylarkMethodDoc in project bazel by bazelbuild.
the class SkylarkDocumentationTest method testSkylarkCallableOverriding.
@Test
public void testSkylarkCallableOverriding() throws Exception {
Map<String, SkylarkModuleDoc> objects = collect(MockClassE.class);
assertThat(objects).hasSize(1);
assertThat(objects).containsKey("MockClassE");
SkylarkModuleDoc moduleDoc = objects.get("MockClassE");
assertThat(moduleDoc.getDocumentation()).isEqualTo("MockClassE");
assertThat(moduleDoc.getMethods()).hasSize(1);
SkylarkMethodDoc methodDoc = moduleDoc.getMethods().iterator().next();
assertThat(methodDoc.getDocumentation()).isEqualTo("MockClassA#get");
assertThat(methodDoc.getSignature()).isEqualTo("<a class=\"anchor\" href=\"int.html\">int</a> MockClassE.get()");
}
use of com.google.devtools.build.docgen.skylark.SkylarkMethodDoc in project bazel by bazelbuild.
the class SkylarkDocumentationTest method testSkylarkCallableParameters.
@Test
public void testSkylarkCallableParameters() throws Exception {
Map<String, SkylarkModuleDoc> objects = collect(MockClassD.class);
assertThat(objects).hasSize(1);
assertThat(objects).containsKey("MockClassD");
SkylarkModuleDoc moduleDoc = objects.get("MockClassD");
assertThat(moduleDoc.getDocumentation()).isEqualTo("MockClassD");
assertThat(moduleDoc.getMethods()).hasSize(1);
SkylarkMethodDoc methodDoc = moduleDoc.getMethods().iterator().next();
assertThat(methodDoc.getDocumentation()).isEqualTo("MockClassD#test");
assertThat(methodDoc.getSignature()).isEqualTo("<a class=\"anchor\" href=\"int.html\">int</a> " + "MockClassD.test(arg0:<a class=\"anchor\" href=\"int.html\">int</a>, " + "b, *, c, d=1)");
assertThat(methodDoc.getParams()).hasSize(3);
}
use of com.google.devtools.build.docgen.skylark.SkylarkMethodDoc in project bazel by bazelbuild.
the class SkylarkDocumentationProcessor method generateDocumentation.
/** Generates the Skylark documentation to the given output directory. */
public static void generateDocumentation(String outputDir, String... clazz) throws IOException, ClassPathException {
Map<String, SkylarkModuleDoc> modules = SkylarkDocumentationCollector.collectModules(clazz);
// Generate the top level module first in the doc
SkylarkModuleDoc topLevelModule = modules.remove(SkylarkDocumentationCollector.getTopLevelModule().name());
writePage(outputDir, topLevelModule);
Map<SkylarkModuleCategory, List<SkylarkModuleDoc>> modulesByCategory = new HashMap<>();
for (SkylarkModuleCategory c : SkylarkModuleCategory.values()) {
modulesByCategory.put(c, new ArrayList<SkylarkModuleDoc>());
}
modulesByCategory.get(topLevelModule.getAnnotation().category()).add(topLevelModule);
for (SkylarkModuleDoc module : modules.values()) {
if (module.getAnnotation().documented()) {
writePage(outputDir, module);
modulesByCategory.get(module.getAnnotation().category()).add(module);
}
}
writeCategoryPage(SkylarkModuleCategory.CONFIGURATION_FRAGMENT, outputDir, modulesByCategory);
writeCategoryPage(SkylarkModuleCategory.BUILTIN, outputDir, modulesByCategory);
writeCategoryPage(SkylarkModuleCategory.PROVIDER, outputDir, modulesByCategory);
writeNavPage(outputDir, modulesByCategory.get(SkylarkModuleCategory.TOP_LEVEL_TYPE));
// In the code, there are two SkylarkModuleCategory instances that have no heading:
// TOP_LEVEL_TYPE and NONE.
// TOP_LEVEL_TYPE also contains the "global" module.
// We remove both categories and the "global" module from the map and display them manually:
// - Methods in the "global" module are displayed under "Global Methods and Constants".
// - Modules in both categories are displayed under "Global Modules" (except for the global
// module itself).
List<String> globalFunctions = new ArrayList<>();
SkylarkModuleDoc globalModule = findGlobalModule(modulesByCategory);
for (SkylarkMethodDoc method : globalModule.getMethods()) {
if (method.documented()) {
globalFunctions.add(method.getName());
}
}
List<String> globalModules = new ArrayList<>();
for (SkylarkModuleCategory globalCategory : GLOBAL_CATEGORIES) {
List<SkylarkModuleDoc> allGlobalModules = modulesByCategory.remove(globalCategory);
for (SkylarkModuleDoc module : allGlobalModules) {
if (!module.getName().equals(globalModule.getName())) {
globalModules.add(module.getName());
}
}
}
Collections.sort(globalModules);
writeOverviewPage(outputDir, globalModule.getName(), globalFunctions, globalModules, modulesByCategory);
}
Aggregations