@@ -0,0 +1,2191 @@
+package rapanui.dsl;%0A%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.util.Arrays;%0Aimport java.util.Iterator;%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0Aimport java.util.Optional;%0A%0Aimport javax.inject.Inject;%0A%0Aimport org.eclipse.emf.common.util.URI;%0Aimport org.eclipse.emf.ecore.resource.Resource;%0Aimport org.eclipse.xtext.resource.XtextResource;%0Aimport org.eclipse.xtext.resource.XtextResourceSet;%0A%0Apublic class RuleSystemCollection implements Iterable%3CRuleSystem%3E %7B%0A%09private final List%3CRuleSystem%3E ruleSystems = new LinkedList%3CRuleSystem%3E();%0A%0A%09@Inject XtextResourceSet resourceSet;%0A%0A%09public RuleSystemCollection() %7B%0A%09%09new DslStandaloneSetup()%0A%09%09.createInjectorAndDoEMFRegistration()%0A%09%09.injectMembers(this);%0A%0A%09%09resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);%0A%09%7D%0A%0A%09public void load(String path) %7B%0A%09%09Resource resource = resourceSet.getResource(URI.createFileURI(path), true);%0A%09%09if (!resource.getErrors().isEmpty())%0A%09%09%09throw new IllegalArgumentException();%0A%09%09ruleSystems.add((RuleSystem)resource.getContents().get(0));%0A%09%7D%0A%0A%09public void load(InputStream data) throws IOException %7B%0A%09%09Resource resource = resourceSet.createResource(%0A%09%09%09%09URI.createURI(%22memory://inputstream/%22 + data.hashCode() + %22.raps%22));%0A%09%09resource.load(data, resourceSet.getLoadOptions());%0A%09%09if (!resource.getErrors().isEmpty())%0A%09%09%09throw new IllegalArgumentException();%0A%09%09ruleSystems.add((RuleSystem)resource.getContents().get(0));%0A%09%7D%0A%0A%09public String%5B%5D getDefinitionNames() %7B%0A%09%09return ruleSystems.stream()%0A%09%09%09.flatMap(system -%3E Arrays.stream(system.getDefinitionNames()))%0A%09%09%09.toArray(String%5B%5D::new);%0A%09%7D%0A%0A%09public Definition resolveDefinition(String name) %7B%0A%09%09// TODO: consider using scoping API / Xtext built-in reference resolving code%0A%09%09Optional%3CDefinition%3E definition = ruleSystems.stream()%0A%09%09%09.flatMap(ruleSystem -%3E ruleSystem.getDefinitions().stream())%0A%09%09%09.filter((def) -%3E def.getName().equals(name))%0A%09%09%09.findFirst();%0A%09%09return definition.get();%0A%09%7D%0A%0A%09public int size() %7B%0A%09%09return ruleSystems.size();%0A%09%7D%0A%0A%09public RuleSystem get(int index) %7B%0A%09%09return ruleSystems.get(index);%0A%09%7D%0A%0A%09@Override%0A%09public Iterator%3CRuleSystem%3E iterator() %7B%0A%09%09return ruleSystems.iterator();%0A%09%7D%0A%7D%0A

Add new RuleSystemCollection class (ref: #29)