1 package org.simantics.scl.compiler.source.repository;
3 import java.util.Collection;
5 import org.simantics.scl.compiler.module.Module;
6 import org.simantics.scl.compiler.module.repository.UpdateListener;
7 import org.simantics.scl.compiler.source.ModuleSource;
8 import org.simantics.scl.compiler.source.PrecompiledModuleSource;
10 import gnu.trove.map.hash.THashMap;
11 import gnu.trove.procedure.TObjectProcedure;
14 * An implementation of {@link ModuleSourceRepository} as a finite map.
15 * This implementation does not support listening module changes,
16 * so it should not be modified after it has been taken into use.
18 * @author Hannu Niemistö
20 public class MapModuleSourceRepository implements ModuleSourceRepository {
21 THashMap<String, ModuleSource> modules = new THashMap<String, ModuleSource>();
22 THashMap<String, String> documentations = new THashMap<String, String>();
24 public MapModuleSourceRepository() {
27 public MapModuleSourceRepository(ModuleSource ... descriptors) {
28 for(ModuleSource descriptor : descriptors)
29 addModuleDescriptor(descriptor);
32 public MapModuleSourceRepository(Module ... modules) {
33 for(Module module : modules)
37 public void addModuleDescriptor(ModuleSource descriptor) {
38 modules.put(descriptor.getModuleName(), descriptor);
41 public void addModule(Module module) {
42 addModuleDescriptor(new PrecompiledModuleSource(module));
45 public void addDocumentation(String documentationName, String documentation) {
46 documentations.put(documentationName, documentation);
50 public ModuleSource getModuleSource(String moduleName,
51 UpdateListener listener) {
52 return modules.get(moduleName);
56 public Collection<String> getModuleNames() {
57 return modules.keySet();
61 public void forAllModules(TObjectProcedure<String> procedure) {
62 modules.forEachKey(procedure);
66 public String getDocumentation(String documentationName) {
67 return documentations.get(documentationName);
71 public Collection<String> getDocumentationNames() {
72 return documentations.keySet();