Search in sources :

Example 1 with SkylarkModuleCategory

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);
}
Also used : HashMap(java.util.HashMap) SkylarkModuleCategory(com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SkylarkModuleDoc(com.google.devtools.build.docgen.skylark.SkylarkModuleDoc) SkylarkMethodDoc(com.google.devtools.build.docgen.skylark.SkylarkMethodDoc)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 SkylarkMethodDoc (com.google.devtools.build.docgen.skylark.SkylarkMethodDoc)1 SkylarkModuleDoc (com.google.devtools.build.docgen.skylark.SkylarkModuleDoc)1 SkylarkModuleCategory (com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1