1 package org.simantics.scl.compiler.source.repository;
3 import gnu.trove.map.hash.THashMap;
4 import gnu.trove.procedure.TObjectProcedure;
6 import org.simantics.scl.compiler.module.Module;
7 import org.simantics.scl.compiler.module.repository.UpdateListener;
8 import org.simantics.scl.compiler.source.ModuleSource;
9 import org.simantics.scl.compiler.source.PrecompiledModuleSource;
12 * An implementation of {@link ModuleSourceRepository} as a finite map.
13 * This implementation does not support listening module changes,
14 * so it should not be modified after it has been taken into use.
16 * @author Hannu Niemistö
18 public class MapModuleSourceRepository implements ModuleSourceRepository {
19 THashMap<String, ModuleSource> modules = new THashMap<String, ModuleSource>();
20 THashMap<String, String> documentations = new THashMap<String, String>();
22 public MapModuleSourceRepository() {
25 public MapModuleSourceRepository(ModuleSource ... descriptors) {
26 for(ModuleSource descriptor : descriptors)
27 addModuleDescriptor(descriptor);
30 public MapModuleSourceRepository(Module ... modules) {
31 for(Module module : modules)
35 public void addModuleDescriptor(ModuleSource descriptor) {
36 modules.put(descriptor.getModuleName(), descriptor);
39 public void addModule(Module module) {
40 addModuleDescriptor(new PrecompiledModuleSource(module));
43 public void addDocumentation(String documentationName, String documentation) {
44 documentations.put(documentationName, documentation);
48 public ModuleSource getModuleSource(String moduleName,
49 UpdateListener listener) {
50 return modules.get(moduleName);
54 public void forAllModules(TObjectProcedure<String> procedure) {
55 modules.forEachKey(procedure);
59 public String getDocumentation(String documentationName) {
60 return documentations.get(documentationName);
64 public void forAllDocumentations(TObjectProcedure<String> procedure) {
65 for(String documentationName : documentations.keySet())
66 procedure.execute(documentationName);
70 public void checkUpdates() {