mirror of
https://github.com/Echtzeitsysteme/BioPMFramework.git
synced 2024-06-03 10:32:02 +00:00
now the framework can get Classes from the projects
This commit is contained in:
parent
9182335f33
commit
fb33d8e3e1
|
@ -10,7 +10,8 @@ Export-Package: de.tu.darmstadt.es.biochemicalSimulationFramework,
|
|||
de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.modification,
|
||||
de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.patternmatchingengine,
|
||||
de.tu.darmstadt.es.biochemicalSimulationFramework.persistence,
|
||||
de.tu.darmstadt.es.biochemicalSimulationFramework.splitter
|
||||
de.tu.darmstadt.es.biochemicalSimulationFramework.splitter,
|
||||
de.tu.darmstadt.es.biochemicalSimulationFramework.utils
|
||||
Require-Bundle: de.tu.darmstadt.es.geolibrary.MetaSpecification,
|
||||
de.tu.darmstadt.es.KappaRules,
|
||||
org.eclipse.emf.ecore
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package de.tu.darmstadt.es.biochemicalSimulationFramework.internal.utils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.patternmatchingengine.PatternMatchingEngine;
|
||||
|
||||
public class FrameworkFactory {
|
||||
private static FrameworkFactory instance;
|
||||
|
||||
private FrameworkFactory() {
|
||||
|
||||
}
|
||||
|
||||
public static FrameworkFactory instance() {
|
||||
if(instance == null)
|
||||
instance = new FrameworkFactory();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public <PM extends PatternMatchingEngine> PM createPatternMatchingEngine (String packageName, ResourceSet resourceSet, Class<PM> clazz) {
|
||||
|
||||
Optional<Constructor<?>> constructorMonad = Arrays.asList(clazz.getConstructors()).parallelStream().filter(this::findConstructor).findFirst();
|
||||
if(constructorMonad.isPresent()) {
|
||||
Constructor<?> constructor = constructorMonad.get();
|
||||
try {
|
||||
Object engine = constructor.newInstance(packageName,resourceSet);
|
||||
if(engine instanceof PatternMatchingEngine) {
|
||||
return clazz.cast(engine);
|
||||
}
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
||||
| InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private boolean findConstructor(Constructor<?> constructor) {
|
||||
if(constructor.getParameterCount() == 2) {
|
||||
List<Class<?>> parameterTypes = Arrays.asList(constructor.getParameterTypes());
|
||||
return parameterTypes.stream().anyMatch(String.class::isAssignableFrom) && parameterTypes.stream().anyMatch(ResourceSet.class::isAssignableFrom);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller;
|
||||
|
||||
public class NaivePatternMatchingController extends PatternMatchingController {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ package de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontrol
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.internal.utils.FrameworkFactory;
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.geolibrary.GeoLibrary;
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.modification.Modification;
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.patternmatchingengine.PatternMatchingEngine;
|
||||
|
@ -12,6 +15,10 @@ public abstract class PatternMatchingController {
|
|||
private List<Modification> modifications;
|
||||
|
||||
private PatternMatchingEngine patternMatchingEngine;
|
||||
|
||||
public void createPatternMatchingEngine (String packageName, ResourceSet resourceSet, Class<? extends PatternMatchingEngine> clazz) {
|
||||
patternMatchingEngine = FrameworkFactory.instance().createPatternMatchingEngine(packageName, resourceSet, clazz);
|
||||
}
|
||||
|
||||
public GeoLibrary getGeoLib() {
|
||||
return geoLib;
|
||||
|
@ -23,5 +30,6 @@ public abstract class PatternMatchingController {
|
|||
|
||||
public PatternMatchingEngine getPatternMatchingEngine() {
|
||||
return patternMatchingEngine;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.patternmatchingengine;
|
||||
|
||||
import de.tu.darmstadt.es.KappaRules.KappaRuleContainer;
|
||||
|
||||
public interface EnginePatternConverter {
|
||||
void convertToPatternModel(KappaRuleContainer container);
|
||||
PatternMatchingEngine getEngine();
|
||||
}
|
|
@ -3,6 +3,7 @@ package de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontrol
|
|||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
|
||||
import de.tu.darmstadt.es.KappaRules.KappaRuleContainer;
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.utils.FrameworkHelper;
|
||||
|
||||
public abstract class PatternMatchingEngine{
|
||||
|
||||
|
@ -14,9 +15,12 @@ public abstract class PatternMatchingEngine{
|
|||
public PatternMatchingEngine(String packageName, ResourceSet resourceSet) {
|
||||
this.packageName = packageName + PACKAGE_SUFFIX;
|
||||
this.resourceSet = resourceSet;
|
||||
FrameworkHelper.instance().addEngine(this);
|
||||
}
|
||||
|
||||
public abstract void convertToPatternModel(KappaRuleContainer container);
|
||||
public abstract void createController();
|
||||
|
||||
public abstract void run();
|
||||
public abstract EnginePatternConverter getConverter();
|
||||
|
||||
public abstract void run(Object... objects);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package de.tu.darmstadt.es.biochemicalSimulationFramework.utils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.internal.utils.FrameworkFactory;
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.patternmatchingengine.PatternMatchingEngine;
|
||||
|
||||
public class FrameworkHelper {
|
||||
|
||||
private static FrameworkHelper instance;
|
||||
|
||||
private Map<Class<? extends PatternMatchingEngine>,PatternMatchingEngine> engines;
|
||||
|
||||
private FrameworkHelper() {
|
||||
engines = new HashMap<>();
|
||||
}
|
||||
|
||||
public static FrameworkHelper instance() {
|
||||
if(instance == null)
|
||||
instance = new FrameworkHelper();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void addEngine(PatternMatchingEngine engine) {
|
||||
engines.put(engine.getClass(), engine);
|
||||
}
|
||||
|
||||
public Collection<PatternMatchingEngine> getEngines(){
|
||||
return engines.values();
|
||||
}
|
||||
|
||||
public <PM extends PatternMatchingEngine> PM getPatternMatcher (Class<PM> clazz) {
|
||||
PatternMatchingEngine engine = engines.get(clazz);
|
||||
if(engine != null) {
|
||||
return clazz.cast(engine);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public <PM extends PatternMatchingEngine> PM getOrCreatePatternMatcher (Class<PM> clazz, String packageName) {
|
||||
PatternMatchingEngine engine = engines.get(clazz);
|
||||
if(engine != null) {
|
||||
return clazz.cast(engine);
|
||||
}
|
||||
return FrameworkFactory.instance().createPatternMatchingEngine(packageName, new ResourceSetImpl(), clazz);
|
||||
}
|
||||
}
|
|
@ -25,4 +25,39 @@
|
|||
version="0.0.0"
|
||||
unpack="false"/>
|
||||
|
||||
<plugin
|
||||
id="de.tu.darmstadt.es.BiochemicalSimulationFramework"
|
||||
download-size="0"
|
||||
install-size="0"
|
||||
version="0.0.0"
|
||||
unpack="false"/>
|
||||
|
||||
<plugin
|
||||
id="de.tu.darmstadt.es.KappaRules"
|
||||
download-size="0"
|
||||
install-size="0"
|
||||
version="0.0.0"
|
||||
unpack="false"/>
|
||||
|
||||
<plugin
|
||||
id="de.tu.darmstadt.es.KappaStructure"
|
||||
download-size="0"
|
||||
install-size="0"
|
||||
version="0.0.0"
|
||||
unpack="false"/>
|
||||
|
||||
<plugin
|
||||
id="de.tu.darmstadt.es.geolibrary.MetaSpecification"
|
||||
download-size="0"
|
||||
install-size="0"
|
||||
version="0.0.0"
|
||||
unpack="false"/>
|
||||
|
||||
<plugin
|
||||
id="de.tu.darmstadt.es.xtext.utils"
|
||||
download-size="0"
|
||||
install-size="0"
|
||||
version="0.0.0"
|
||||
unpack="false"/>
|
||||
|
||||
</feature>
|
||||
|
|
|
@ -21,7 +21,8 @@ Require-Bundle: org.eclipse.xtext,
|
|||
de.tu.darmstadt.es.KappaRules,
|
||||
de.tu.darmstadt.es.PatternMatchingEngine.viatra,
|
||||
org.eclipse.viatra.query.patternlanguage,
|
||||
org.eclipse.viatra.query.patternlanguage.emf
|
||||
org.eclipse.viatra.query.patternlanguage.emf,
|
||||
de.tu.darmstadt.es.xtext.utils;bundle-version="1.0.0"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Export-Package: de.tu.darmstadt.es,
|
||||
de.tu.darmstadt.es.generator,
|
||||
|
|
|
@ -11,17 +11,23 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
|
|||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.viatra.query.patternlanguage.patternLanguage.PatternModel;
|
||||
import org.eclipse.xtext.generator.AbstractGenerator;
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess2;
|
||||
import org.eclipse.xtext.generator.IGeneratorContext;
|
||||
|
||||
import de.tu.darmstadt.es.KappaRules.KappaRuleContainer;
|
||||
import de.tu.darmstadt.es.PatternMatchingEngine.viatra.VIATRAEngine;
|
||||
import de.tu.darmstadt.es.PatternMatchingEngine.viatra.modelconverter.RuleToPatternConverter;
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.NaivePatternMatchingController;
|
||||
import de.tu.darmstadt.es.converter.KappaRuleConverter;
|
||||
import de.tu.darmstadt.es.converter.KappaStructureConverter;
|
||||
import de.tu.darmstadt.es.converter.NeoKappaExpressionSolver;
|
||||
import de.tu.darmstadt.es.kappaStructure.KappaContainer;
|
||||
import de.tu.darmstadt.es.neoKappa.NKAFile;
|
||||
import de.tu.darmstadt.es.utils.NeoKappaUtil;
|
||||
import de.tu.darmstadt.es.xtext.utils.utils.ResourceUtil;
|
||||
|
||||
|
||||
public abstract class AbstractNeoKappaGernerator extends AbstractGenerator{
|
||||
public class AbstractNeoKappaGernerator extends AbstractGenerator{
|
||||
|
||||
protected NeoKappaExpressionSolver neoKappaExpressionSolver;
|
||||
|
||||
|
@ -51,14 +57,15 @@ public abstract class AbstractNeoKappaGernerator extends AbstractGenerator{
|
|||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
try {
|
||||
VIATRAEngine engine = new VIATRAEngine(getProjectName(resource), new ResourceSetImpl());
|
||||
engine.convertToPatternModel(kappaRuleContainer);
|
||||
engine.run();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
NaivePatternMatchingController naivePatternMatchingController = new NaivePatternMatchingController();
|
||||
naivePatternMatchingController.createPatternMatchingEngine(getProjectName(resource), new ResourceSetImpl(), VIATRAEngine.class);
|
||||
|
||||
naivePatternMatchingController.getPatternMatchingEngine().getConverter().convertToPatternModel(kappaRuleContainer);
|
||||
|
||||
// VIATRAEngine engine = new VIATRAEngine(getProjectName(resource), new ResourceSetImpl());
|
||||
// engine.convertToPatternModel(kappaRuleContainer);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -66,15 +73,44 @@ public abstract class AbstractNeoKappaGernerator extends AbstractGenerator{
|
|||
return resource.getURI().toString().split("/")[2];
|
||||
}
|
||||
|
||||
protected URI createURIFromResource(Resource resource, String folder, String file){
|
||||
URI originUri = resource.getURI();
|
||||
List<String> segments = Arrays.asList(originUri.toString().split("/"));
|
||||
if(segments.size()>=3){
|
||||
String prefix = segments.get(0) + "/" + segments.get(1) + "/" + segments.get(2) +"/";
|
||||
String path = prefix+folder+"/" + file;
|
||||
return URI.createURI(path);
|
||||
// protected URI createURIFromResource(Resource resource, String folder, String file){
|
||||
// URI originUri = resource.getURI();
|
||||
// List<String> segments = Arrays.asList(originUri.toString().split("/"));
|
||||
// if(segments.size()>=3){
|
||||
// String prefix = segments.get(0) + "/" + segments.get(1) + "/" + segments.get(2) +"/";
|
||||
// String path = prefix+folder+"/" + file;
|
||||
// return URI.createURI(path);
|
||||
// }
|
||||
// return originUri;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
|
||||
try {
|
||||
List<EObject> contents = resource.getContents();
|
||||
|
||||
if (contents.size() > 0) {
|
||||
EObject file = contents.get(0);
|
||||
if (file instanceof NKAFile) {
|
||||
ResourceSet resSet = resource.getResourceSet();
|
||||
KappaRuleContainer rules = this.ruleConverter.convert(NKAFile.class.cast(file));
|
||||
URI rulesUri = ResourceUtil.getInstance().createURIFromResource(resource, "model", "ruleSet.xmi");
|
||||
|
||||
ResourceUtil.getInstance().saveToResource(rulesUri, resSet, rules);
|
||||
|
||||
generateTestViatra(rules,resource,resSet);
|
||||
|
||||
KappaContainer model = this.modelConverter.convert(NKAFile.class.cast(file));
|
||||
URI modelUri = ResourceUtil.getInstance().createURIFromResource(resource, "model", "kappaModel.xmi");
|
||||
ResourceUtil.getInstance().saveToResource(modelUri, resSet, model);
|
||||
|
||||
//NeoKappaUtil.instance.save(model, modelUri, resSet)
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
return originUri;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
*/
|
||||
package de.tu.darmstadt.es.generator
|
||||
|
||||
import org.eclipse.emf.ecore.resource.Resource
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess2
|
||||
import org.eclipse.xtext.generator.IGeneratorContext
|
||||
import de.tu.darmstadt.es.neoKappa.NKAFile
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import de.tu.darmstadt.es.utils.NeoKappaUtil
|
||||
|
||||
|
||||
/**
|
||||
* Generates code from your model files on save.
|
||||
*
|
||||
|
@ -18,26 +10,5 @@ import de.tu.darmstadt.es.utils.NeoKappaUtil
|
|||
*/
|
||||
class NeoKappaGenerator extends AbstractNeoKappaGernerator {
|
||||
|
||||
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
|
||||
val contents = resource.contents
|
||||
|
||||
if (contents.size > 0) {
|
||||
val file = contents.get(0)
|
||||
if (file instanceof NKAFile) {
|
||||
val resSet = resource.resourceSet
|
||||
val rules = this.ruleConverter.convert(file)
|
||||
val rulesUri = createURIFromResource(resource, "model", "ruleSet.xmi")
|
||||
NeoKappaUtil.getInstance.save(rules, rulesUri, resSet)
|
||||
|
||||
generateTestViatra(rules,resource,resSet)
|
||||
|
||||
val model = this.modelConverter.convert(file)
|
||||
val modelUri = createURIFromResource(resource, "model", "kappaModel.xmi")
|
||||
NeoKappaUtil.instance.save(model, modelUri, resSet)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.eclipse.emf.ecore.EObject;
|
|||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
|
||||
import de.tu.darmstadt.es.KappaRules.KappaRuleContainer;
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.patternmatchingengine.EnginePatternConverter;
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.patternmatchingengine.PatternMatchingEngine;
|
||||
|
||||
public class DemoclesEngine extends PatternMatchingEngine{
|
||||
|
@ -15,15 +16,23 @@ public class DemoclesEngine extends PatternMatchingEngine{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void convertToPatternModel(KappaRuleContainer container) {
|
||||
public EnginePatternConverter getConverter() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Object... objects) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public void createController() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -22,4 +22,6 @@ Require-Bundle: de.tu.darmstadt.es.BiochemicalSimulationFramework,
|
|||
org.eclipse.core.runtime;bundle-version="3.13.0",
|
||||
org.apache.log4j
|
||||
Export-Package: de.tu.darmstadt.es.PatternMatchingEngine.viatra,
|
||||
de.tu.darmstadt.es.PatternMatchingEngine.viatra.modelconverter
|
||||
de.tu.darmstadt.es.PatternMatchingEngine.viatra.modelconverter,
|
||||
de.tu.darmstadt.es.PatternMatchingEngine.viatra.runtime,
|
||||
de.tu.darmstadt.es.PatternMatchingEngine.viatra.utils
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package de.tu.darmstadt.es.PatternMatchingEngine.viatra;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.viatra.query.patternlanguage.emf.eMFPatternLanguage.PatternModel;
|
||||
|
||||
|
@ -8,34 +12,39 @@ import de.tu.darmstadt.es.PatternMatchingEngine.viatra.modelconverter.RuleToPatt
|
|||
import de.tu.darmstadt.es.PatternMatchingEngine.viatra.runtime.IRuleHandler;
|
||||
import de.tu.darmstadt.es.PatternMatchingEngine.viatra.runtime.RuleHandler;
|
||||
import de.tu.darmstadt.es.PatternMatchingEngine.viatra.runtime.ViatraRuntime;
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.patternmatchingengine.EnginePatternConverter;
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.patternmatchingengine.PatternMatchingEngine;
|
||||
|
||||
public class VIATRAEngine extends PatternMatchingEngine{
|
||||
|
||||
private RuleToPatternConverter ruleToPatternConverter;
|
||||
private PatternModel patternModel;
|
||||
private RuleHandler ruleHandler;
|
||||
private ViatraRuntime runtime;
|
||||
private boolean loaded = false;
|
||||
|
||||
|
||||
public VIATRAEngine(String packageName, ResourceSet resourceSet) {
|
||||
super(packageName, resourceSet);
|
||||
ruleToPatternConverter = new RuleToPatternConverter(this);
|
||||
ruleHandler = new RuleHandler(this.packageName, this);
|
||||
runtime = new ViatraRuntime(resourceSet, ruleHandler);
|
||||
super(packageName, resourceSet);
|
||||
ruleHandler = new RuleHandler(this.packageName, this);
|
||||
}
|
||||
|
||||
public void setLoaded(boolean load) {
|
||||
loaded=load;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertToPatternModel(KappaRuleContainer container) {
|
||||
patternModel = ruleToPatternConverter.createPatternModel(container, this.packageName);
|
||||
loaded = false;
|
||||
}
|
||||
// @Override
|
||||
// public void convertToPatternModel(KappaRuleContainer container) {
|
||||
// patternModel = ruleToPatternConverter.createPatternModel(container, this.packageName);
|
||||
// loaded = false;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public void run(Object... objects) {
|
||||
try {
|
||||
ruleHandler.loadMatches();
|
||||
List<Object> objectsList = Arrays.asList(objects);
|
||||
List<Class<?>> classes = objectsList.parallelStream().filter(Class.class::isInstance).map(Class.class::cast).collect(Collectors.toList());
|
||||
|
||||
ruleHandler.loadMatches(classes);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
@ -43,6 +52,13 @@ public class VIATRAEngine extends PatternMatchingEngine{
|
|||
loaded = true;
|
||||
}
|
||||
|
||||
public ViatraRuntime getRuntime() {
|
||||
if(runtime == null) {
|
||||
runtime = new ViatraRuntime(resourceSet, ruleHandler);
|
||||
}
|
||||
return this.runtime;
|
||||
}
|
||||
|
||||
public IRuleHandler getRuleHandler() {
|
||||
return this.ruleHandler;
|
||||
}
|
||||
|
@ -50,5 +66,17 @@ public class VIATRAEngine extends PatternMatchingEngine{
|
|||
public boolean isLoaded() {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnginePatternConverter getConverter() {
|
||||
if(ruleToPatternConverter == null)
|
||||
createController();
|
||||
return ruleToPatternConverter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createController() {
|
||||
ruleToPatternConverter = new RuleToPatternConverter(this, packageName, resourceSet);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,9 +7,11 @@ import java.util.Set;
|
|||
import java.util.Stack;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EClass;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.EPackage;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.viatra.query.patternlanguage.patternLanguage.CompareConstraint;
|
||||
import org.eclipse.viatra.query.patternlanguage.patternLanguage.CompareFeature;
|
||||
import org.eclipse.viatra.query.patternlanguage.patternLanguage.ExecutionType;
|
||||
|
@ -45,23 +47,44 @@ import de.tu.darmstadt.es.KappaRules.Source;
|
|||
import de.tu.darmstadt.es.KappaRules.SubRule;
|
||||
import de.tu.darmstadt.es.PatternMatchingEngine.viatra.VIATRAEngine;
|
||||
import de.tu.darmstadt.es.PatternMatchingEngine.viatra.utils.TypeCounter;
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.patternmatchingengine.EnginePatternConverter;
|
||||
import de.tu.darmstadt.es.biochemicalSimulationFramework.patternmatchingcontroller.patternmatchingengine.PatternMatchingEngine;
|
||||
import de.tu.darmstadt.es.kappaStructure.KappaContainer;
|
||||
import de.tu.darmstadt.es.xtext.utils.utils.BiMap;
|
||||
import de.tu.darmstadt.es.xtext.utils.utils.HashBiMap;
|
||||
import de.tu.darmstadt.es.xtext.utils.utils.ResourceUtil;
|
||||
|
||||
public class RuleToPatternConverter {
|
||||
public class RuleToPatternConverter implements EnginePatternConverter{
|
||||
|
||||
private PackageImport packageImport;
|
||||
private VIATRAEngine viatraEngine;
|
||||
private ResourceSet resourceSet;
|
||||
private String packageName;
|
||||
|
||||
public RuleToPatternConverter(VIATRAEngine viatraEngine) {
|
||||
public RuleToPatternConverter(VIATRAEngine viatraEngine, String packageName, ResourceSet resourceSet) {
|
||||
this.viatraEngine = viatraEngine;
|
||||
this.packageName = packageName;
|
||||
this.resourceSet = resourceSet;
|
||||
}
|
||||
|
||||
public PatternModel createPatternModel(KappaRuleContainer kappaRuleContainer, String packageName) {
|
||||
@Override
|
||||
public void convertToPatternModel(KappaRuleContainer container) {
|
||||
PatternModel patternModel = createPatternModel(container);
|
||||
URI uri = ResourceUtil.getInstance().createURIFromResource(container.eResource(), "src/" + packageName + "/patterns", "ViatraConvertion.vql");
|
||||
ResourceUtil.getInstance().saveToResource(uri, resourceSet, patternModel);
|
||||
viatraEngine.setLoaded(false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PatternMatchingEngine getEngine() {
|
||||
return this.viatraEngine;
|
||||
}
|
||||
|
||||
public PatternModel createPatternModel(KappaRuleContainer kappaRuleContainer) {
|
||||
//patternmodel creation
|
||||
PatternModel patternModel = EMFPatternLanguageFactory.eINSTANCE.createPatternModel();
|
||||
patternModel.setPackageName(packageName);
|
||||
patternModel.setPackageName(packageName + ".patterns");
|
||||
|
||||
// create imports
|
||||
patternModel.setImportPackages(createImport(kappaRuleContainer.eClass().getEPackage()));
|
||||
|
@ -282,4 +305,6 @@ public class RuleToPatternConverter {
|
|||
String name = eClass.getName();
|
||||
return Character.toLowerCase(name.charAt(0)) + name.substring(1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,11 @@ package de.tu.darmstadt.es.PatternMatchingEngine.viatra.runtime;
|
|||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.viatra.query.runtime.api.IPatternMatch;
|
||||
import org.osgi.framework.BundleException;
|
||||
|
||||
import de.tu.darmstadt.es.KappaRules.KappaRule;
|
||||
|
||||
|
@ -16,7 +18,7 @@ public interface IRuleHandler {
|
|||
int countMatchesForRule(String ruleName);
|
||||
int countAllMatches();
|
||||
|
||||
Collection<Class<? extends IPatternMatch>> loadMatches() throws ClassNotFoundException, CoreException, MalformedURLException;
|
||||
|
||||
void loadMatches(List<Class<?>> clases) throws ClassNotFoundException, CoreException, MalformedURLException, BundleException;
|
||||
Collection<Class<? extends IPatternMatch>> getMatches();
|
||||
void addKappaRule(String ruleName, KappaRule kappaRule);
|
||||
}
|
||||
|
|
|
@ -4,24 +4,40 @@ import java.io.File;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import org.eclipse.osgi.internal.loader.BundleLoader;
|
||||
import org.eclipse.osgi.internal.loader.EquinoxClassLoader;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.ToolProvider;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
import org.eclipse.viatra.query.runtime.api.IPatternMatch;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.BundleException;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.osgi.framework.launch.Framework;
|
||||
import org.osgi.framework.launch.FrameworkFactory;
|
||||
|
||||
import de.tu.darmstadt.es.xtext.utils.utils.WorkspaceHelper;
|
||||
|
||||
public class MatchLoader {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Class<? extends IPatternMatch>> loadMatches(IFolder patternPackageFolder, String packageName, Collection<String> ruleNames) throws ClassNotFoundException, CoreException, MalformedURLException {
|
||||
public Map<String, Class<? extends IPatternMatch>> loadMatches(IFolder patternPackageFolder, String packageName, Collection<String> ruleNames) throws ClassNotFoundException, CoreException, MalformedURLException, BundleException {
|
||||
Map<String, Class<? extends IPatternMatch>> matchClasses = new HashMap<>();
|
||||
for(String ruleName : ruleNames) {
|
||||
Package package1 = Package.getPackage(packageName);
|
||||
|
@ -41,15 +57,32 @@ public class MatchLoader {
|
|||
return matchClasses;
|
||||
}
|
||||
|
||||
private Class<?> getClassFromFile(IFile iFile, String className) throws CoreException, MalformedURLException, ClassNotFoundException{
|
||||
private Class<?> getClassFromFile(IFile iFile, String className) throws CoreException, MalformedURLException, ClassNotFoundException, BundleException{
|
||||
//String str = convertStreamToString(iFile.getContents());
|
||||
IProject project = iFile.getProject();
|
||||
|
||||
File javaFile = iFile.getFullPath().toFile().getAbsoluteFile();
|
||||
|
||||
IFolder binFolder = WorkspaceHelper.INSTANCE.getBinFolder(iFile.getProject());
|
||||
URL binFolderAsFile = binFolder.getRawLocationURI().toURL();
|
||||
ClassLoader innerClassLoader = this.getClass().getClassLoader();
|
||||
String projectName = project.getName();
|
||||
// File file = project.getRawLocation().toFile();
|
||||
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
|
||||
Map<String,String> config = new HashMap<String,String>();
|
||||
Framework framework = frameworkFactory.newFramework(config);
|
||||
framework.start();
|
||||
BundleContext context = framework.getBundleContext();
|
||||
Bundle bundle = context.installBundle("reference:file:"+project.getLocation().toString());
|
||||
bundle.start();
|
||||
|
||||
URLClassLoader classLoader = new URLClassLoader(new URL[] {binFolderAsFile});
|
||||
Class<?> clazz = Class.forName(className, true, classLoader);//classLoader.loadClass(className);
|
||||
//Bundle bundle = Platform.getBundle(projectName);
|
||||
|
||||
// List<Bundle> bundles = Arrays.asList(Platform.getBundles(projectName, ""));
|
||||
|
||||
|
||||
//ClassLoader classLoader = new EquinoxClassLoader(parent, configuration, delegate, generation); //;new URLClassLoader(new URL[] {binFolderAsFile});
|
||||
Class<?> clazz = bundle.loadClass(className);//Class.forName(className, true, classLoader);//classLoader.loadClass(className);
|
||||
//JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
|
||||
return clazz;
|
||||
|
|
|
@ -5,12 +5,15 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.viatra.query.runtime.api.IPatternMatch;
|
||||
import org.osgi.framework.BundleException;
|
||||
|
||||
import de.tu.darmstadt.es.KappaRules.KappaRule;
|
||||
import de.tu.darmstadt.es.PatternMatchingEngine.viatra.VIATRAEngine;
|
||||
|
@ -64,20 +67,32 @@ public class RuleHandler implements IRuleHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends IPatternMatch>> loadMatches() throws ClassNotFoundException, CoreException, MalformedURLException {
|
||||
public void loadMatches(List<Class<?>> classes) throws ClassNotFoundException, CoreException, MalformedURLException, BundleException {
|
||||
if (!engine.isLoaded() || matchClasses == null) {
|
||||
String packageRealName = packageName.substring(0, packageName.length() - 9);
|
||||
IProject project = WorkspaceHelper.INSTANCE.getProjectByName(packageRealName);
|
||||
IFolder srcGen = WorkspaceHelper.INSTANCE.getSrcGenFolder(project);
|
||||
IFolder projectNameFolder = WorkspaceHelper.INSTANCE.getSubFolderFromQualifiedName(srcGen, packageName);
|
||||
matchClasses = matchLoader.loadMatches(projectNameFolder, packageName, ruleCache.keySet());
|
||||
}
|
||||
return matchClasses.values();
|
||||
if(matchClasses == null)
|
||||
matchClasses = new HashMap<>();
|
||||
List<Class<IPatternMatch>> matchClassList = classes.parallelStream().filter(IPatternMatch.class::isAssignableFrom).map(this::convertAnyClassToIPatternMatchClass).collect(Collectors.toList());
|
||||
for(Class<IPatternMatch> clazz : matchClassList) {
|
||||
matchClasses.put(clazz.getName(), clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Class<IPatternMatch> convertAnyClassToIPatternMatchClass(Class<?> anyClass) {
|
||||
return (Class<IPatternMatch>) anyClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countAllMatches() {
|
||||
return matchCache.entrySet().parallelStream().mapToInt(entry -> entry.getValue().size()).reduce(0, (a,b) -> a + b);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends IPatternMatch>> getMatches() {
|
||||
return matchClasses.values();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public class ViatraRuntime {
|
|||
|
||||
public EventDrivenTransformation createTransformation() {
|
||||
try {
|
||||
Collection<Class<? extends IPatternMatch> > classes = ruleHandler.loadMatches();
|
||||
Collection<Class<? extends IPatternMatch> > classes = ruleHandler.getMatches();
|
||||
List<EventDrivenTransformationRule<?, ?>> rules = classes.parallelStream().map(this::createRule).collect(Collectors.toList());
|
||||
EventDrivenTransformation.EventDrivenTransformationBuilder forEngine = EventDrivenTransformation.forEngine(this.engine);
|
||||
EventDrivenTransformationRuleGroup transformationRuleGroup = createEventDrivenTransformationRuleGroup(rules);
|
||||
|
|
|
@ -12,7 +12,6 @@ Require-Bundle: org.eclipse.xtext,
|
|||
org.eclipse.core.resources
|
||||
Export-Package: de.tu.darmstadt.es.xtext.utils.exceptions,
|
||||
de.tu.darmstadt.es.xtext.utils.scoping,
|
||||
de.tu.darmstadt.es.xtext.utils.scoping.utils,
|
||||
de.tu.darmstadt.es.xtext.utils.ui.highlighting,
|
||||
de.tu.darmstadt.es.xtext.utils.ui.highlighting.exceptions,
|
||||
de.tu.darmstadt.es.xtext.utils.ui.highlighting.rules,
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.eclipse.xtext.scoping.IScope;
|
|||
import org.eclipse.xtext.scoping.Scopes;
|
||||
|
||||
import de.tu.darmstadt.es.xtext.utils.exceptions.CannotFindScopeException;
|
||||
import de.tu.darmstadt.es.xtext.utils.scoping.utils.ScopeUtil;
|
||||
import de.tu.darmstadt.es.xtext.utils.utils.ResourceUtil;
|
||||
|
||||
public class ScopeProviderHelper <E extends EObject> {
|
||||
private Map<URI, E> existingScopingRoots;
|
||||
|
@ -30,7 +30,7 @@ public class ScopeProviderHelper <E extends EObject> {
|
|||
|
||||
public ScopeProviderHelper() {
|
||||
init();
|
||||
resourceSet = ScopeUtil.getInstance().getResourceSet("ecore");
|
||||
resourceSet = ResourceUtil.getInstance().getResourceSet("ecore");
|
||||
}
|
||||
|
||||
private void init(){
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package de.tu.darmstadt.es.xtext.utils.scoping.utils;
|
||||
package de.tu.darmstadt.es.xtext.utils.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
@ -14,18 +14,18 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
|
|||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
|
||||
|
||||
public class ScopeUtil
|
||||
public class ResourceUtil
|
||||
{
|
||||
private static ScopeUtil instance;
|
||||
private static ResourceUtil instance;
|
||||
|
||||
private ScopeUtil()
|
||||
private ResourceUtil()
|
||||
{
|
||||
}
|
||||
|
||||
public static ScopeUtil getInstance()
|
||||
public static ResourceUtil getInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = new ScopeUtil();
|
||||
instance = new ResourceUtil();
|
||||
return instance;
|
||||
}
|
||||
|
Loading…
Reference in a new issue