use of com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory 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