diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2020-05-10 22:13:21 +0200 |
---|---|---|
committer | Kristóf Marussy <marussy@mit.bme.hu> | 2020-05-10 22:13:21 +0200 |
commit | 5a6eea9bd15597eab77bbcedb4b5116020f0a67d (patch) | |
tree | 6c86f7e5bd3d86fde29d3fee4fb4f912f35057bc /Tests/MODELS2020-CaseStudies/case.study.pledge.originalFiles/xtend-gen/converter/UML2TGF.java | |
parent | Add satellite case study (diff) | |
parent | Merge branch 'master' of https://github.com/viatra/VIATRA-Generator (diff) | |
download | VIATRA-Generator-5a6eea9bd15597eab77bbcedb4b5116020f0a67d.tar.gz VIATRA-Generator-5a6eea9bd15597eab77bbcedb4b5116020f0a67d.tar.zst VIATRA-Generator-5a6eea9bd15597eab77bbcedb4b5116020f0a67d.zip |
Merge branch 'master' of github.com:viatra/VIATRA-Generator
Diffstat (limited to 'Tests/MODELS2020-CaseStudies/case.study.pledge.originalFiles/xtend-gen/converter/UML2TGF.java')
-rw-r--r-- | Tests/MODELS2020-CaseStudies/case.study.pledge.originalFiles/xtend-gen/converter/UML2TGF.java | 234 |
1 files changed, 234 insertions, 0 deletions
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.originalFiles/xtend-gen/converter/UML2TGF.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.originalFiles/xtend-gen/converter/UML2TGF.java new file mode 100644 index 00000000..9081c3af --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.originalFiles/xtend-gen/converter/UML2TGF.java | |||
@@ -0,0 +1,234 @@ | |||
1 | package converter; | ||
2 | |||
3 | import java.io.PrintWriter; | ||
4 | import java.text.SimpleDateFormat; | ||
5 | import java.util.ArrayList; | ||
6 | import java.util.Collection; | ||
7 | import java.util.Date; | ||
8 | import java.util.HashMap; | ||
9 | import java.util.HashSet; | ||
10 | import org.eclipse.emf.common.util.EList; | ||
11 | import org.eclipse.emf.common.util.URI; | ||
12 | import org.eclipse.emf.ecore.EObject; | ||
13 | import org.eclipse.emf.ecore.resource.Resource; | ||
14 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; | ||
15 | import org.eclipse.uml2.uml.Element; | ||
16 | import org.eclipse.uml2.uml.EnumerationLiteral; | ||
17 | import org.eclipse.uml2.uml.InstanceSpecification; | ||
18 | import org.eclipse.uml2.uml.InstanceValue; | ||
19 | import org.eclipse.uml2.uml.Model; | ||
20 | import org.eclipse.uml2.uml.Slot; | ||
21 | import org.eclipse.uml2.uml.StructuralFeature; | ||
22 | import org.eclipse.uml2.uml.UMLPackage; | ||
23 | import org.eclipse.uml2.uml.ValueSpecification; | ||
24 | import org.eclipse.uml2.uml.resource.UMLResource; | ||
25 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
26 | import org.eclipse.xtext.xbase.lib.Conversions; | ||
27 | import org.eclipse.xtext.xbase.lib.Exceptions; | ||
28 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
29 | import org.eclipse.xtext.xbase.lib.InputOutput; | ||
30 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
31 | |||
32 | @SuppressWarnings("all") | ||
33 | public class UML2TGF { | ||
34 | public static void main(final String[] args) { | ||
35 | try { | ||
36 | final ResourceSetImpl resourceSet = new ResourceSetImpl(); | ||
37 | resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE); | ||
38 | resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, | ||
39 | UMLResource.Factory.INSTANCE); | ||
40 | final Resource res = resourceSet.getResource(URI.createFileURI("instance//Instance_model_A.uml"), true); | ||
41 | EObject _get = res.getContents().get(0); | ||
42 | final Model docRoot = ((Model) _get); | ||
43 | final Function1<Element, Boolean> _function = (Element it) -> { | ||
44 | return Boolean.valueOf((it instanceof InstanceSpecification)); | ||
45 | }; | ||
46 | final Iterable<Element> nodes = IterableExtensions.<Element>filter(docRoot.allOwnedElements(), _function); | ||
47 | final HashSet<Object> allTypes = new HashSet<Object>(); | ||
48 | for (final Element e : nodes) { | ||
49 | allTypes.add(e.getClass()); | ||
50 | } | ||
51 | long _currentTimeMillis = System.currentTimeMillis(); | ||
52 | final Date date = new Date(_currentTimeMillis); | ||
53 | final SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); | ||
54 | final String formattedDate = format.format(date); | ||
55 | final HashMap<InstanceSpecification, Integer> map = new HashMap<InstanceSpecification, Integer>(); | ||
56 | final HashSet<String> set = new HashSet<String>(); | ||
57 | final ArrayList<Object> unidentified = new ArrayList<Object>(); | ||
58 | final ArrayList<Object> enums = new ArrayList<Object>(); | ||
59 | final PrintWriter writer = new PrintWriter((("output//graph-" + formattedDate) + ".gml")); | ||
60 | InputOutput.<String>println("begin Writing"); | ||
61 | writer.append("graph\n[\n"); | ||
62 | int ind = 0; | ||
63 | int numNodes = ((Object[])Conversions.unwrapArray(nodes, Object.class)).length; | ||
64 | int numEdges = 0; | ||
65 | for (final Element node : nodes) { | ||
66 | { | ||
67 | final InstanceSpecification n = ((InstanceSpecification) node); | ||
68 | boolean _contains = map.keySet().contains(n); | ||
69 | if (_contains) { | ||
70 | System.err.println("contained"); | ||
71 | } | ||
72 | map.put(n, Integer.valueOf(ind)); | ||
73 | StringConcatenation _builder = new StringConcatenation(); | ||
74 | _builder.append(" "); | ||
75 | _builder.append("node"); | ||
76 | _builder.newLine(); | ||
77 | _builder.append(" "); | ||
78 | _builder.append("["); | ||
79 | _builder.newLine(); | ||
80 | _builder.append(" "); | ||
81 | _builder.append("id "); | ||
82 | _builder.append(ind, " "); | ||
83 | _builder.newLineIfNotEmpty(); | ||
84 | _builder.append(" "); | ||
85 | _builder.append("label \""); | ||
86 | { | ||
87 | String _name = n.getName(); | ||
88 | boolean _tripleNotEquals = (_name != null); | ||
89 | if (_tripleNotEquals) { | ||
90 | String _name_1 = n.getName(); | ||
91 | _builder.append(_name_1, " "); | ||
92 | } | ||
93 | } | ||
94 | _builder.append("\""); | ||
95 | _builder.newLineIfNotEmpty(); | ||
96 | { | ||
97 | if (((n.getName() != null) && (n.getName().contains("Household") || n.getName().contains("Household")))) { | ||
98 | _builder.append(" graphics"); | ||
99 | _builder.newLineIfNotEmpty(); | ||
100 | _builder.append(" "); | ||
101 | _builder.append("["); | ||
102 | _builder.newLine(); | ||
103 | _builder.append(" "); | ||
104 | _builder.append("fill\t\"#00FF00\""); | ||
105 | _builder.newLine(); | ||
106 | _builder.append(" "); | ||
107 | _builder.append("]"); | ||
108 | _builder.newLine(); | ||
109 | } | ||
110 | } | ||
111 | _builder.append(" "); | ||
112 | { | ||
113 | if ((node instanceof EnumerationLiteral)) { | ||
114 | _builder.append(" graphics"); | ||
115 | _builder.newLineIfNotEmpty(); | ||
116 | _builder.append(" "); | ||
117 | _builder.append(" "); | ||
118 | _builder.append("["); | ||
119 | _builder.newLine(); | ||
120 | _builder.append(" "); | ||
121 | _builder.append(" "); | ||
122 | _builder.append("fill\t\"#FF0000\""); | ||
123 | _builder.newLine(); | ||
124 | _builder.append(" "); | ||
125 | _builder.append(" "); | ||
126 | _builder.append("]"); | ||
127 | _builder.newLine(); | ||
128 | } | ||
129 | } | ||
130 | _builder.append(" "); | ||
131 | _builder.append("]"); | ||
132 | _builder.newLine(); | ||
133 | writer.append(_builder); | ||
134 | ind++; | ||
135 | } | ||
136 | } | ||
137 | Slot s = null; | ||
138 | try { | ||
139 | for (final Element node_1 : nodes) { | ||
140 | { | ||
141 | final InstanceSpecification n = ((InstanceSpecification) node_1); | ||
142 | final Integer nind = map.get(n); | ||
143 | EList<Slot> _slots = n.getSlots(); | ||
144 | for (final Slot slot : _slots) { | ||
145 | { | ||
146 | s = slot; | ||
147 | String fname = ""; | ||
148 | StructuralFeature _definingFeature = slot.getDefiningFeature(); | ||
149 | boolean _tripleNotEquals = (_definingFeature != null); | ||
150 | if (_tripleNotEquals) { | ||
151 | fname = slot.getDefiningFeature().getName(); | ||
152 | } | ||
153 | EList<ValueSpecification> _values = slot.getValues(); | ||
154 | for (final ValueSpecification v : _values) { | ||
155 | if ((v instanceof InstanceValue)) { | ||
156 | final InstanceValue value = ((InstanceValue) v); | ||
157 | boolean _containsKey = map.containsKey(value.getInstance()); | ||
158 | if (_containsKey) { | ||
159 | InstanceSpecification _instance = value.getInstance(); | ||
160 | boolean _notEquals = ((_instance instanceof EnumerationLiteral) != true); | ||
161 | if (_notEquals) { | ||
162 | final Integer vind = map.get(value.getInstance()); | ||
163 | StringConcatenation _builder = new StringConcatenation(); | ||
164 | _builder.append(" "); | ||
165 | _builder.append("edge"); | ||
166 | _builder.newLine(); | ||
167 | _builder.append(" "); | ||
168 | _builder.append("["); | ||
169 | _builder.newLine(); | ||
170 | _builder.append(" "); | ||
171 | _builder.append("source "); | ||
172 | _builder.append(nind, " "); | ||
173 | _builder.newLineIfNotEmpty(); | ||
174 | _builder.append(" "); | ||
175 | _builder.append("target "); | ||
176 | _builder.append(vind, " "); | ||
177 | _builder.newLineIfNotEmpty(); | ||
178 | _builder.append(" "); | ||
179 | _builder.append("label \""); | ||
180 | _builder.append(fname, " "); | ||
181 | _builder.append("\""); | ||
182 | _builder.newLineIfNotEmpty(); | ||
183 | _builder.append(" "); | ||
184 | _builder.append("]"); | ||
185 | _builder.newLine(); | ||
186 | writer.append(_builder); | ||
187 | numEdges++; | ||
188 | } else { | ||
189 | String _plus = (value + " -> "); | ||
190 | InstanceSpecification _instance_1 = value.getInstance(); | ||
191 | String _plus_1 = (_plus + _instance_1); | ||
192 | enums.add(_plus_1); | ||
193 | } | ||
194 | } else { | ||
195 | String _plus_2 = (value + " -> "); | ||
196 | InstanceSpecification _instance_2 = value.getInstance(); | ||
197 | String _plus_3 = (_plus_2 + _instance_2); | ||
198 | unidentified.add(_plus_3); | ||
199 | } | ||
200 | } else { | ||
201 | set.add(v.getClass().toString()); | ||
202 | } | ||
203 | } | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | } catch (final Throwable _t) { | ||
209 | if (_t instanceof Exception) { | ||
210 | InputOutput.<StructuralFeature>println(s.getDefiningFeature()); | ||
211 | } else { | ||
212 | throw Exceptions.sneakyThrow(_t); | ||
213 | } | ||
214 | } | ||
215 | UML2TGF.printset("Unhandled Edges", set); | ||
216 | UML2TGF.printset("Unidentified trgs", unidentified); | ||
217 | UML2TGF.printset("Enums:", enums); | ||
218 | writer.append("]"); | ||
219 | writer.close(); | ||
220 | InputOutput.<String>println("End"); | ||
221 | InputOutput.<String>println(((("#nodes:" + Integer.valueOf(numNodes)) + ", #edges:") + Integer.valueOf(numEdges))); | ||
222 | } catch (Throwable _e) { | ||
223 | throw Exceptions.sneakyThrow(_e); | ||
224 | } | ||
225 | } | ||
226 | |||
227 | public static void printset(final String name, final Collection s) { | ||
228 | InputOutput.<String>println((name + ":")); | ||
229 | for (final Object k : s) { | ||
230 | InputOutput.<String>println(("- " + k)); | ||
231 | } | ||
232 | InputOutput.println(); | ||
233 | } | ||
234 | } | ||