Skip to content

Instantly share code, notes, and snippets.

@manuelleduc
Created December 13, 2018 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelleduc/badb7e963d4b4763f6d58d6d460742a0 to your computer and use it in GitHub Desktop.
Save manuelleduc/badb7e963d4b4763f6d58d6d460742a0 to your computer and use it in GitHub Desktop.
package org.eclipse.emf.ecoretools.ale.compiler.generic;
import java.io.IOException;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
public class FindUsedConcepts {
private final static String program = "/home/manuel/dev/java/ale-lang/plzoo/benchmarks.scripts/fib30.xmi";
private final static String metamodel = "/home/manuel/dev/java/ale-lang/plzoo/boa.model/model/boa.ecore";
public static void main(final String[] args) throws IOException {
final ResourceSetImpl rs = new ResourceSetImpl();
final Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
final Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
m.put("ecore", new EcoreResourceFactoryImpl());
final Resource metares = rs.getResource(URI.createURI(metamodel), true);
EPackage metapackage = (EPackage) metares.getContents().get(0);
EPackage.Registry.INSTANCE.put("http://www.example.org/boa", metapackage);
final Resource res = rs.getResource(URI.createURI(program), true);
Set<EClass> distinctEClasses = new HashSet<>();
res.getAllContents().forEachRemaining(c -> {
distinctEClasses.add(c.eClass());
});
System.out.println(distinctEClasses.stream().map(x -> x.getEPackage().getName() + "." + x.getName())
.collect(Collectors.joining(System.lineSeparator())));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment