1 package org.simantics.scl.compiler.module.repository;
\r
3 import gnu.trove.procedure.TObjectProcedure;
\r
5 import java.util.ArrayList;
\r
6 import java.util.List;
\r
7 import java.util.regex.Pattern;
\r
9 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
\r
10 import org.simantics.scl.compiler.environment.filter.AcceptAllNamespaceFilter;
\r
11 import org.simantics.scl.compiler.errors.Failable;
\r
12 import org.simantics.scl.compiler.module.Module;
\r
14 public class ModuleRepositories {
\r
15 public static List<SCLValue> allValuesMatching(final ModuleRepository repository, String pattern) {
\r
16 final Pattern compiledPattern = pattern == null ? null
\r
17 : Pattern.compile(".*" + pattern + ".*", Pattern.CASE_INSENSITIVE);
\r
18 final ArrayList<SCLValue> results = new ArrayList<SCLValue>();
\r
19 repository.getSourceRepository().forAllModules(new TObjectProcedure<String>() {
\r
21 public boolean execute(String moduleName) {
\r
22 Failable<Module> failableModule = repository.getModule(moduleName);
\r
23 if(!failableModule.didSucceed())
\r
25 Module module = failableModule.getResult();
\r
26 module.findValuesForPrefix("", AcceptAllNamespaceFilter.INSTANCE, new TObjectProcedure<SCLValue>() {
\r
28 public boolean execute(SCLValue value) {
\r
29 String name = value.getName().name;
\r
30 if(!value.isPrivate() && !name.startsWith("_") && !(name.contains("$") &&
\r
31 Character.isLetter(name.charAt(0))) &&
\r
32 (compiledPattern == null || compiledPattern.matcher(name).matches())) {
\r
44 public static List<SCLValue> allValues(ModuleRepository repository) {
\r
45 return allValuesMatching(repository, null);
\r