]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ModuleSourceRepository.java
Fixing a deadlock. Some improvements to ModuleSourceRepository API
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / source / repository / ModuleSourceRepository.java
index 76698f5be6a44d9cea0db368d933b2e2d3251deb..c335a8aa1349d8bc4cf42c1c6ada90fd2961568e 100644 (file)
@@ -1,5 +1,8 @@
 package org.simantics.scl.compiler.source.repository;
 
+import java.util.Collection;
+import java.util.Collections;
+
 import org.simantics.scl.compiler.module.repository.ModuleRepository;
 import org.simantics.scl.compiler.module.repository.UpdateListener;
 import org.simantics.scl.compiler.source.ModuleSource;
@@ -13,10 +16,64 @@ import gnu.trove.procedure.TObjectProcedure;
  * @author Hannu Niemistö
  */
 public interface ModuleSourceRepository {
+    /**
+     * Returns all module names governed by this repository. Some implementations
+     * may return empty collection, even if the contain modules, if it is hard
+     * to discover all modules (for example file system based module repository 
+     * works like this).
+     */
+    Collection<String> getModuleNames();
+    
+    /**
+     * Calls the given procedure with all module names returned by {@link #getModuleNames}
+     */
+    default void forAllModules(TObjectProcedure<String> procedure) {
+        for(String module : getModuleNames())
+            if(!procedure.execute(module))
+                return;
+    }
+    
+    /**
+     * Returns the module source of the given module name or null, if the module does not exists.
+     * If {@code listener} is not null, it is called when the module contents change.
+     */
     ModuleSource getModuleSource(String moduleName, UpdateListener listener);
-    void forAllModules(TObjectProcedure<String> procedure);
-    String getDocumentation(String documentationName);
-    void forAllDocumentations(TObjectProcedure<String> procedure);
-    void checkUpdates();
-    void clear();
+    
+    /**
+     * Returns all documentation names governed by this repository. Some implementations
+     * may return empty collection, even if the contain documentation.
+     */
+    default Collection<String> getDocumentationNames() {
+        return Collections.emptyList();
+    }
+    
+    /**
+     * Calls the given procedure with all documentation names eturned by {@link #getDocumentationNames}
+     */
+    default void forAllDocumentations(TObjectProcedure<String> procedure) {
+        for(String module : getDocumentationNames())
+            if(!procedure.execute(module))
+                return;
+    }
+
+    /**
+     * Returns original markdown text for the given documentation name or null
+     * if the documentation does not exist.
+     */
+    default String getDocumentation(String documentationName) {
+        return null;
+    }
+    
+    /**
+     * Triggers repository to check if module contents have been changed. Some repositories listen
+     * changes and report them to update listeners even without manual triggering.
+     */
+    default void checkUpdates() {
+    }
+
+    /**
+     * Resets the repository and removes listeners. This is only used during regression testing and shouldn't be called during normal operation.
+     */
+    default void clear() {
+    }
 }