]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ModuleSourceRepository.java
c335a8aa1349d8bc4cf42c1c6ada90fd2961568e
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / source / repository / ModuleSourceRepository.java
1 package org.simantics.scl.compiler.source.repository;
2
3 import java.util.Collection;
4 import java.util.Collections;
5
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;
9
10 import gnu.trove.procedure.TObjectProcedure;
11
12 /**
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}.
15  * 
16  * @author Hannu Niemistö
17  */
18 public interface ModuleSourceRepository {
19     /**
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 
23      * works like this).
24      */
25     Collection<String> getModuleNames();
26     
27     /**
28      * Calls the given procedure with all module names returned by {@link #getModuleNames}
29      */
30     default void forAllModules(TObjectProcedure<String> procedure) {
31         for(String module : getModuleNames())
32             if(!procedure.execute(module))
33                 return;
34     }
35     
36     /**
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.
39      */
40     ModuleSource getModuleSource(String moduleName, UpdateListener listener);
41     
42     /**
43      * Returns all documentation names governed by this repository. Some implementations
44      * may return empty collection, even if the contain documentation.
45      */
46     default Collection<String> getDocumentationNames() {
47         return Collections.emptyList();
48     }
49     
50     /**
51      * Calls the given procedure with all documentation names eturned by {@link #getDocumentationNames}
52      */
53     default void forAllDocumentations(TObjectProcedure<String> procedure) {
54         for(String module : getDocumentationNames())
55             if(!procedure.execute(module))
56                 return;
57     }
58
59     /**
60      * Returns original markdown text for the given documentation name or null
61      * if the documentation does not exist.
62      */
63     default String getDocumentation(String documentationName) {
64         return null;
65     }
66     
67     /**
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.
70      */
71     default void checkUpdates() {
72     }
73
74     /**
75      * Resets the repository and removes listeners. This is only used during regression testing and shouldn't be called during normal operation.
76      */
77     default void clear() {
78     }
79 }