diff options
Diffstat (limited to 'Domains')
9 files changed, 279 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.yakinduModelExtractor/.classpath b/Domains/hu.bme.mit.inf.yakinduModelExtractor/.classpath new file mode 100644 index 00000000..1c96fe2f --- /dev/null +++ b/Domains/hu.bme.mit.inf.yakinduModelExtractor/.classpath | |||
@@ -0,0 +1,8 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <classpath> | ||
3 | <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
4 | <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
5 | <classpathentry kind="src" path="src"/> | ||
6 | <classpathentry kind="src" path="xtend-gen"/> | ||
7 | <classpathentry kind="output" path="bin"/> | ||
8 | </classpath> | ||
diff --git a/Domains/hu.bme.mit.inf.yakinduModelExtractor/.gitignore b/Domains/hu.bme.mit.inf.yakinduModelExtractor/.gitignore new file mode 100644 index 00000000..a9d27f1b --- /dev/null +++ b/Domains/hu.bme.mit.inf.yakinduModelExtractor/.gitignore | |||
@@ -0,0 +1,5 @@ | |||
1 | /bin/ | ||
2 | /src-gen/ | ||
3 | /vql-gen/ | ||
4 | /xtend-gen/ | ||
5 | /output/ \ No newline at end of file | ||
diff --git a/Domains/hu.bme.mit.inf.yakinduModelExtractor/.project b/Domains/hu.bme.mit.inf.yakinduModelExtractor/.project new file mode 100644 index 00000000..7ac6f61e --- /dev/null +++ b/Domains/hu.bme.mit.inf.yakinduModelExtractor/.project | |||
@@ -0,0 +1,34 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <projectDescription> | ||
3 | <name>hu.bme.mit.inf.yakinduModelExtractor</name> | ||
4 | <comment></comment> | ||
5 | <projects> | ||
6 | </projects> | ||
7 | <buildSpec> | ||
8 | <buildCommand> | ||
9 | <name>org.eclipse.xtext.ui.shared.xtextBuilder</name> | ||
10 | <arguments> | ||
11 | </arguments> | ||
12 | </buildCommand> | ||
13 | <buildCommand> | ||
14 | <name>org.eclipse.jdt.core.javabuilder</name> | ||
15 | <arguments> | ||
16 | </arguments> | ||
17 | </buildCommand> | ||
18 | <buildCommand> | ||
19 | <name>org.eclipse.pde.ManifestBuilder</name> | ||
20 | <arguments> | ||
21 | </arguments> | ||
22 | </buildCommand> | ||
23 | <buildCommand> | ||
24 | <name>org.eclipse.pde.SchemaBuilder</name> | ||
25 | <arguments> | ||
26 | </arguments> | ||
27 | </buildCommand> | ||
28 | </buildSpec> | ||
29 | <natures> | ||
30 | <nature>org.eclipse.pde.PluginNature</nature> | ||
31 | <nature>org.eclipse.jdt.core.javanature</nature> | ||
32 | <nature>org.eclipse.xtext.ui.shared.xtextNature</nature> | ||
33 | </natures> | ||
34 | </projectDescription> | ||
diff --git a/Domains/hu.bme.mit.inf.yakinduModelExtractor/.settings/org.eclipse.jdt.core.prefs b/Domains/hu.bme.mit.inf.yakinduModelExtractor/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..295926d9 --- /dev/null +++ b/Domains/hu.bme.mit.inf.yakinduModelExtractor/.settings/org.eclipse.jdt.core.prefs | |||
@@ -0,0 +1,7 @@ | |||
1 | eclipse.preferences.version=1 | ||
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
4 | org.eclipse.jdt.core.compiler.compliance=1.8 | ||
5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
7 | org.eclipse.jdt.core.compiler.source=1.8 | ||
diff --git a/Domains/hu.bme.mit.inf.yakinduModelExtractor/META-INF/MANIFEST.MF b/Domains/hu.bme.mit.inf.yakinduModelExtractor/META-INF/MANIFEST.MF new file mode 100644 index 00000000..c2535002 --- /dev/null +++ b/Domains/hu.bme.mit.inf.yakinduModelExtractor/META-INF/MANIFEST.MF | |||
@@ -0,0 +1,16 @@ | |||
1 | Manifest-Version: 1.0 | ||
2 | Bundle-ManifestVersion: 2 | ||
3 | Bundle-Name: YakinduModelExtractor | ||
4 | Bundle-SymbolicName: hu.bme.mit.inf.yakinduModelExtractor | ||
5 | Bundle-Version: 1.0.0.qualifier | ||
6 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 | ||
7 | Require-Bundle: hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph;bundle-version="1.0.0", | ||
8 | org.yakindu.sct.model.sgraph;bundle-version="2.9.2", | ||
9 | org.eclipse.core.runtime;bundle-version="3.12.0", | ||
10 | org.eclipse.gmf.runtime.notation;bundle-version="1.8.0", | ||
11 | org.eclipse.emf.ecore.xmi, | ||
12 | com.google.guava, | ||
13 | org.eclipse.xtext.xbase.lib, | ||
14 | org.eclipse.xtend.lib, | ||
15 | org.eclipse.xtend.lib.macro | ||
16 | |||
diff --git a/Domains/hu.bme.mit.inf.yakinduModelExtractor/build.properties b/Domains/hu.bme.mit.inf.yakinduModelExtractor/build.properties new file mode 100644 index 00000000..41eb6ade --- /dev/null +++ b/Domains/hu.bme.mit.inf.yakinduModelExtractor/build.properties | |||
@@ -0,0 +1,4 @@ | |||
1 | source.. = src/ | ||
2 | output.. = bin/ | ||
3 | bin.includes = META-INF/,\ | ||
4 | . | ||
diff --git a/Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/Main.java b/Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/Main.java new file mode 100644 index 00000000..ec525fd6 --- /dev/null +++ b/Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/Main.java | |||
@@ -0,0 +1,44 @@ | |||
1 | package hu.bme.mit.inf.yakinduModelExtractor; | ||
2 | |||
3 | import java.util.List; | ||
4 | |||
5 | import org.eclipse.emf.common.util.TreeIterator; | ||
6 | import org.eclipse.emf.ecore.EObject; | ||
7 | import org.yakindu.sct.model.sgraph.State; | ||
8 | import org.yakindu.sct.model.sgraph.Statechart; | ||
9 | |||
10 | public class Main { | ||
11 | |||
12 | public static void main(String[] args) { | ||
13 | ModelManager manager = new ModelManager(); | ||
14 | Yakindu2CommonModel converter = new Yakindu2CommonModel(); | ||
15 | |||
16 | String years[] = {"2015","2016","2017"}; | ||
17 | for(String year : years) { | ||
18 | String folderPath = "D:\\Eclipse\\GIT\\RemoHF\\"+year; | ||
19 | // Loading folder | ||
20 | List<String> paths = manager.loadAllModelPathsInDirectory(folderPath); | ||
21 | |||
22 | int index = 1; | ||
23 | for(String path : paths) { | ||
24 | Statechart s = null; | ||
25 | try{ | ||
26 | EObject root = manager.loadModel(path); | ||
27 | s = (Statechart) root; | ||
28 | } catch (Exception e) { | ||
29 | System.out.println("unable to load: "+ path); | ||
30 | } | ||
31 | |||
32 | if(s!=null) { | ||
33 | EObject s2 = converter.transform(s); | ||
34 | manager.saveModel(s2, "output/R"+year+index+".xmi"); | ||
35 | } | ||
36 | System.out.println(year + " Progress: " + 100.0*index/paths.size() + "%"); | ||
37 | index++; | ||
38 | } | ||
39 | |||
40 | System.out.println(year + " done."); | ||
41 | } | ||
42 | System.out.println("All done."); | ||
43 | } | ||
44 | } | ||
diff --git a/Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/ModelManager.java b/Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/ModelManager.java new file mode 100644 index 00000000..85fd208c --- /dev/null +++ b/Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/ModelManager.java | |||
@@ -0,0 +1,79 @@ | |||
1 | package hu.bme.mit.inf.yakinduModelExtractor; | ||
2 | |||
3 | import java.io.BufferedWriter; | ||
4 | import java.io.File; | ||
5 | import java.io.FileOutputStream; | ||
6 | import java.io.IOException; | ||
7 | import java.io.OutputStreamWriter; | ||
8 | import java.io.Writer; | ||
9 | import java.util.LinkedList; | ||
10 | import java.util.List; | ||
11 | |||
12 | import org.eclipse.emf.common.util.URI; | ||
13 | import org.eclipse.emf.ecore.EObject; | ||
14 | import org.eclipse.emf.ecore.resource.Resource; | ||
15 | import org.eclipse.emf.ecore.resource.ResourceSet; | ||
16 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; | ||
17 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
18 | import org.eclipse.gmf.runtime.notation.NotationPackage; | ||
19 | import org.yakindu.sct.model.sgraph.SGraphPackage; | ||
20 | |||
21 | public class ModelManager { | ||
22 | ResourceSet resourceSet; | ||
23 | |||
24 | public ModelManager() { | ||
25 | init(); | ||
26 | } | ||
27 | |||
28 | public void init() { | ||
29 | SGraphPackage.eINSTANCE.eClass(); | ||
30 | NotationPackage.eINSTANCE.eClass(); | ||
31 | resourceSet = new ResourceSetImpl(); | ||
32 | Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()); | ||
33 | } | ||
34 | |||
35 | public List<String> loadAllModelPathsInDirectory(String path) { | ||
36 | File directory = new File(path); | ||
37 | if(directory.exists() && directory.isDirectory()) { | ||
38 | List<String> filePaths = new LinkedList<>(); | ||
39 | for(File f : directory.listFiles()) { | ||
40 | if(f.isFile()) { | ||
41 | String filePath = f.getPath(); | ||
42 | if(filePath.endsWith("sct")) { | ||
43 | filePaths.add(filePath); | ||
44 | } | ||
45 | } | ||
46 | } | ||
47 | return filePaths; | ||
48 | } else { | ||
49 | throw new IllegalArgumentException("invalid path"); | ||
50 | } | ||
51 | } | ||
52 | |||
53 | public EObject loadModel(String path) { | ||
54 | Resource resource = this.resourceSet.getResource(URI.createFileURI(path), true); | ||
55 | return resource.getContents().get(0); | ||
56 | } | ||
57 | |||
58 | public boolean saveModel(EObject root, String path) { | ||
59 | Resource resource = this.resourceSet.createResource(URI.createURI(path)); | ||
60 | resource.getContents().add(root); | ||
61 | try { | ||
62 | resource.save(null); | ||
63 | return true; | ||
64 | } catch (IOException e) { | ||
65 | System.err.println("Unable to save file: "+path); | ||
66 | return false; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | public boolean saveFile(String path, String content) { | ||
71 | try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), "utf-8"))) { | ||
72 | writer.write(content.toString()); | ||
73 | return true; | ||
74 | } catch (IOException ex) { | ||
75 | System.err.println("Unable to save file: "+path); | ||
76 | return false; | ||
77 | } | ||
78 | } | ||
79 | } | ||
diff --git a/Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/Yakindu2CommonModel.xtend b/Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/Yakindu2CommonModel.xtend new file mode 100644 index 00000000..d9219d5a --- /dev/null +++ b/Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/Yakindu2CommonModel.xtend | |||
@@ -0,0 +1,82 @@ | |||
1 | package hu.bme.mit.inf.yakinduModelExtractor | ||
2 | |||
3 | import org.yakindu.sct.model.sgraph.Statechart | ||
4 | import org.yakindu.sct.model.sgraph.SGraphPackage | ||
5 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage | ||
6 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummFactory | ||
7 | import org.eclipse.emf.ecore.EObject | ||
8 | import org.eclipse.emf.ecore.EClass | ||
9 | import java.util.HashMap | ||
10 | import org.eclipse.emf.ecore.EReference | ||
11 | import java.util.List | ||
12 | |||
13 | class Yakindu2CommonModel { | ||
14 | val yakinduSGraphPackage = org.yakindu.sct.model.sgraph.SGraphPackage.eINSTANCE | ||
15 | val commonSGraphPackage = YakindummPackage.eINSTANCE | ||
16 | val extension YakindummFactory factory = YakindummFactory.eINSTANCE | ||
17 | |||
18 | def transform(Statechart s) { | ||
19 | val o2o = new HashMap | ||
20 | o2o.put(s,s.copyObject) | ||
21 | for(content: s.eAllContents.toIterable) { | ||
22 | val copied = content.copyObject | ||
23 | if(copied !== null) { | ||
24 | o2o.put(content,copied) | ||
25 | } | ||
26 | } | ||
27 | |||
28 | for(sourceObjectEntry : o2o.entrySet) { | ||
29 | val originalSource = sourceObjectEntry.key | ||
30 | val copiedSource = sourceObjectEntry.value | ||
31 | for(originalReference : originalSource.eClass.EAllReferences) { | ||
32 | if(originalReference.isMany) { | ||
33 | val originalTargets = originalSource.eGet(originalReference) as List<? extends EObject> | ||
34 | for(originalTarget : originalTargets) { | ||
35 | if(o2o.containsKey(originalTarget)) { | ||
36 | copyReference(originalReference,copiedSource,o2o.get(originalTarget)) | ||
37 | } | ||
38 | } | ||
39 | } else { | ||
40 | val originalTarget = originalSource.eGet(originalReference) as EObject | ||
41 | if(o2o.containsKey(originalTarget)) { | ||
42 | copyReference(originalReference,copiedSource,o2o.get(originalTarget)) | ||
43 | } | ||
44 | } | ||
45 | } | ||
46 | } | ||
47 | return o2o.get(s) | ||
48 | } | ||
49 | |||
50 | def private copyObject(EObject o) { | ||
51 | if(o.createCopy) { | ||
52 | val className = o.eClass.name | ||
53 | //if(className =="Exit") println("Exit") | ||
54 | val correspondingClass = commonSGraphPackage.EClassifiers.filter(EClass).filter[it.name == className].head | ||
55 | if(correspondingClass != null) { | ||
56 | return factory.create(correspondingClass) | ||
57 | } else { | ||
58 | println(className) | ||
59 | return null | ||
60 | } | ||
61 | } | ||
62 | else return null | ||
63 | } | ||
64 | |||
65 | def private copyReference(EReference reference, EObject source, EObject target) { | ||
66 | val correspondingSourceClass = commonSGraphPackage.EClassifiers.filter(EClass).filter[it.name == reference.EContainingClass.name].head | ||
67 | if(correspondingSourceClass !== null) { | ||
68 | val correspondingReference = correspondingSourceClass.EReferences.filter[it.name === reference.name].head | ||
69 | if(correspondingReference !== null) { | ||
70 | if(correspondingReference.isMany) { | ||
71 | (source.eGet(correspondingReference) as List<? super EObject>).add(target) | ||
72 | } else { | ||
73 | source.eSet(correspondingReference,target); | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | |||
79 | def private createCopy(EObject o) { | ||
80 | o.eClass.EPackage === yakinduSGraphPackage | ||
81 | } | ||
82 | } \ No newline at end of file | ||