X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fsource%2Frepository%2FModuleSourceRepository.java;h=c335a8aa1349d8bc4cf42c1c6ada90fd2961568e;hp=76698f5be6a44d9cea0db368d933b2e2d3251deb;hb=8d60995e2ff936c9a360c7fdb69cc4ed44666bc5;hpb=5c111109af1939b28b1ff68539208652664ced27 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ModuleSourceRepository.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ModuleSourceRepository.java index 76698f5be..c335a8aa1 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ModuleSourceRepository.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ModuleSourceRepository.java @@ -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 getModuleNames(); + + /** + * Calls the given procedure with all module names returned by {@link #getModuleNames} + */ + default void forAllModules(TObjectProcedure 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 procedure); - String getDocumentation(String documentationName); - void forAllDocumentations(TObjectProcedure 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 getDocumentationNames() { + return Collections.emptyList(); + } + + /** + * Calls the given procedure with all documentation names eturned by {@link #getDocumentationNames} + */ + default void forAllDocumentations(TObjectProcedure 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() { + } }