Search in sources :

Example 1 with Library

use of com.google.copybara.doc.annotations.Library in project copybara by google.

the class ModuleLoader method load.

public ImmutableList<DocModule> load(List<String> jarFiles) throws IOException {
    List<String> classes = loadClassList(jarFiles);
    List<DocModule> modules = new ArrayList<>();
    DocModule docModule = new DocModule("Globals", "Global functions available in Copybara");
    modules.add(docModule);
    for (String clsName : classes) {
        try {
            Class<?> cls = Generator.class.getClassLoader().loadClass(clsName);
            getAnnotation(cls, Library.class).ifPresent(library -> docModule.functions.addAll(processFunctions(cls, null)));
            getAnnotation(cls, StarlarkBuiltin.class).ifPresent(library -> {
                if (!library.documented()) {
                    return;
                }
                DocSignaturePrefix prefixAnn = cls.getAnnotation(DocSignaturePrefix.class);
                String prefix = prefixAnn != null ? prefixAnn.value() : library.name();
                DocModule mod = new DocModule(library.name(), library.doc());
                mod.functions.addAll(processFunctions(cls, prefix));
                mod.fields.addAll(processFields(cls));
                mod.flags.addAll(generateFlagsInfo(cls));
                modules.add(mod);
            });
        } catch (ClassNotFoundException e) {
            throw new IllegalStateException("Cannot generate documentation for " + clsName, e);
        }
    }
    return deduplicateAndSort(modules);
}
Also used : DocSignaturePrefix(com.google.copybara.doc.annotations.DocSignaturePrefix) StarlarkBuiltin(net.starlark.java.annot.StarlarkBuiltin) ArrayList(java.util.ArrayList) Library(com.google.copybara.doc.annotations.Library) DocModule(com.google.copybara.doc.DocBase.DocModule)

Aggregations

DocModule (com.google.copybara.doc.DocBase.DocModule)1 DocSignaturePrefix (com.google.copybara.doc.annotations.DocSignaturePrefix)1 Library (com.google.copybara.doc.annotations.Library)1 ArrayList (java.util.ArrayList)1 StarlarkBuiltin (net.starlark.java.annot.StarlarkBuiltin)1