1 package org.simantics.scl.compiler.source.repository;
3 import java.util.Collection;
4 import java.util.Collections;
6 import org.simantics.scl.compiler.module.repository.ModuleRepository;
7 import org.simantics.scl.compiler.module.repository.UpdateListener;
8 import org.simantics.scl.compiler.source.ModuleSource;
10 import gnu.trove.procedure.TObjectProcedure;
13 * An interface for locating modules descriptors and listening if they change.
14 * An instance of this interface is used to create a {@link ModuleRepository}.
16 * @author Hannu Niemistö
18 public interface ModuleSourceRepository {
20 * Returns all module names governed by this repository. Some implementations
21 * may return empty collection, even if the contain modules, if it is hard
22 * to discover all modules (for example file system based module repository
25 Collection<String> getModuleNames();
28 * Calls the given procedure with all module names returned by {@link #getModuleNames}
30 default void forAllModules(TObjectProcedure<String> procedure) {
31 for(String module : getModuleNames())
32 if(!procedure.execute(module))
37 * Returns the module source of the given module name or null, if the module does not exists.
38 * If {@code listener} is not null, it is called when the module contents change.
40 ModuleSource getModuleSource(String moduleName, UpdateListener listener);
43 * Returns all documentation names governed by this repository. Some implementations
44 * may return empty collection, even if the contain documentation.
46 default Collection<String> getDocumentationNames() {
47 return Collections.emptyList();
51 * Calls the given procedure with all documentation names eturned by {@link #getDocumentationNames}
53 default void forAllDocumentations(TObjectProcedure<String> procedure) {
54 for(String module : getDocumentationNames())
55 if(!procedure.execute(module))
60 * Returns original markdown text for the given documentation name or null
61 * if the documentation does not exist.
63 default String getDocumentation(String documentationName) {
68 * Triggers repository to check if module contents have been changed. Some repositories listen
69 * changes and report them to update listeners even without manual triggering.
71 default void checkUpdates() {
75 * Resets the repository and removes listeners. This is only used during regression testing and shouldn't be called during normal operation.
77 default void clear() {