1 package org.simantics.scl.compiler.source.repository;
3 import gnu.trove.procedure.TObjectProcedure;
4 import gnu.trove.set.hash.THashSet;
6 import java.io.IOException;
9 import org.simantics.scl.compiler.module.ImportDeclaration;
10 import org.simantics.scl.compiler.module.repository.UpdateListener;
11 import org.simantics.scl.compiler.source.ClassModuleSource;
12 import org.simantics.scl.compiler.source.ModuleSource;
14 public class ClassModuleSourceRepository extends AbstractModuleSourceRepository {
16 private final Class<?> clazz;
17 private final String path;
18 private final ClassLoader classLoader;
19 private final THashSet<String> modules = new THashSet<String>();
21 public ClassModuleSourceRepository(Class<?> clazz, ClassLoader classLoader, String path) throws IOException {
24 this.classLoader = classLoader;
25 URL url = clazz.getResource(path);
27 throw new IOException("Didn't find a folder " + path + " relative to the class " + clazz.getName() + ".");
28 ModuleBrowsingUtil.collectModuleSourcesAt(modules, url);
32 public ModuleSource getModuleSource(String moduleName,
33 UpdateListener listener) {
34 if(!modules.contains(moduleName))
36 return new ClassModuleSource(moduleName, clazz, classLoader, path + "/" + moduleName + ".scl", getBuiltinImports());
40 public void forAllModules(TObjectProcedure<String> procedure) {
41 modules.forEach(procedure);
44 protected ImportDeclaration[] getBuiltinImports() {
45 return ClassModuleSource.DEFAULT_IMPORTS;