aboutsummaryrefslogtreecommitdiffstats
path: root/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/CpsStateCoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/CpsStateCoder.java')
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/CpsStateCoder.java316
1 files changed, 0 insertions, 316 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/CpsStateCoder.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/CpsStateCoder.java
deleted file mode 100644
index 3ae8e828..00000000
--- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/CpsStateCoder.java
+++ /dev/null
@@ -1,316 +0,0 @@
1package hu.bme.mit.inf.dslreasoner.domains.cps.dse;
2
3import com.google.common.base.Objects;
4import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance;
5import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem;
6import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance;
7import hu.bme.mit.inf.dslreasoner.domains.cps.HostType;
8import hu.bme.mit.inf.dslreasoner.domains.cps.Request;
9import hu.bme.mit.inf.dslreasoner.domains.cps.Requirement;
10import java.util.Arrays;
11import org.eclipse.emf.common.notify.Notifier;
12import org.eclipse.emf.common.util.EList;
13import org.eclipse.emf.ecore.EObject;
14import org.eclipse.emf.ecore.resource.Resource;
15import org.eclipse.emf.ecore.resource.ResourceSet;
16import org.eclipse.viatra.dse.statecode.IStateCoder;
17import org.eclipse.viatra.dse.statecode.IStateCoderFactory;
18import org.eclipse.viatra.query.runtime.api.IPatternMatch;
19import org.eclipse.xtend2.lib.StringConcatenation;
20import org.eclipse.xtend2.lib.StringConcatenationClient;
21import org.eclipse.xtext.xbase.lib.IterableExtensions;
22
23@SuppressWarnings("all")
24public class CpsStateCoder implements IStateCoder {
25 public static class Factory implements IStateCoderFactory {
26 @Override
27 public IStateCoder createStateCoder() {
28 return new CpsStateCoder();
29 }
30 }
31
32 private CyberPhysicalSystem cps;
33
34 protected CpsStateCoder() {
35 }
36
37 @Override
38 public void init(final Notifier notifier) {
39 CyberPhysicalSystem _switchResult = null;
40 boolean _matched = false;
41 if (notifier instanceof ResourceSet) {
42 _matched=true;
43 _switchResult = this.getCpsFromResourceSet(((ResourceSet)notifier));
44 }
45 if (!_matched) {
46 if (notifier instanceof Resource) {
47 _matched=true;
48 _switchResult = this.getCpsFromResource(((Resource)notifier));
49 }
50 }
51 if (!_matched) {
52 if (notifier instanceof CyberPhysicalSystem) {
53 _matched=true;
54 _switchResult = ((CyberPhysicalSystem)notifier);
55 }
56 }
57 if (!_matched) {
58 throw new IllegalArgumentException("notifier is not a CyberPhysicalSystem");
59 }
60 this.cps = _switchResult;
61 }
62
63 private CyberPhysicalSystem getCpsFromResourceSet(final ResourceSet resourceSet) {
64 CyberPhysicalSystem _xblockexpression = null;
65 {
66 boolean _isEmpty = resourceSet.getResources().isEmpty();
67 if (_isEmpty) {
68 throw new IllegalArgumentException("No Resource in ResourceSet");
69 }
70 final Resource resource = IterableExtensions.<Resource>head(resourceSet.getResources());
71 _xblockexpression = this.getCpsFromResource(resource);
72 }
73 return _xblockexpression;
74 }
75
76 private CyberPhysicalSystem getCpsFromResource(final Resource resource) {
77 CyberPhysicalSystem _xblockexpression = null;
78 {
79 boolean _isEmpty = resource.getContents().isEmpty();
80 if (_isEmpty) {
81 throw new IllegalArgumentException("No EObject in Resource");
82 }
83 final EObject cps = IterableExtensions.<EObject>head(resource.getContents());
84 CyberPhysicalSystem _xifexpression = null;
85 if ((cps instanceof CyberPhysicalSystem)) {
86 _xifexpression = ((CyberPhysicalSystem)cps);
87 } else {
88 throw new IllegalArgumentException("EObject in Resource is not a CyberPhysicalSystem");
89 }
90 _xblockexpression = _xifexpression;
91 }
92 return _xblockexpression;
93 }
94
95 @Override
96 public String createStateCode() {
97 StringConcatenation _builder = new StringConcatenation();
98 StringConcatenationClient _createRequestsCode = this.createRequestsCode();
99 _builder.append(_createRequestsCode);
100 CharSequence _createHostTypesCode = this.createHostTypesCode();
101 _builder.append(_createHostTypesCode);
102 return _builder.toString();
103 }
104
105 private StringConcatenationClient createRequestsCode() {
106 StringConcatenationClient _client = new StringConcatenationClient() {
107 @Override
108 protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
109 {
110 EList<Request> _requests = CpsStateCoder.this.cps.getRequests();
111 for(final Request request : _requests) {
112 StringConcatenationClient _createRequestCode = CpsStateCoder.this.createRequestCode(request);
113 _builder.append(_createRequestCode);
114 }
115 }
116 }
117 };
118 return _client;
119 }
120
121 private StringConcatenationClient createRequestCode(final Request request) {
122 StringConcatenationClient _client = new StringConcatenationClient() {
123 @Override
124 protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
125 _builder.append("[");
126 {
127 EList<Requirement> _requirements = request.getRequirements();
128 for(final Requirement requirement : _requirements) {
129 StringConcatenationClient _createRequirementCode = CpsStateCoder.this.createRequirementCode(requirement);
130 _builder.append(_createRequirementCode);
131 }
132 }
133 _builder.append("]");
134 }
135 };
136 return _client;
137 }
138
139 private StringConcatenationClient createRequirementCode(final Requirement requirement) {
140 StringConcatenationClient _client = new StringConcatenationClient() {
141 @Override
142 protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
143 _builder.append("[");
144 {
145 EList<ApplicationInstance> _instances = requirement.getInstances();
146 boolean _hasElements = false;
147 for(final ApplicationInstance app : _instances) {
148 if (!_hasElements) {
149 _hasElements = true;
150 } else {
151 _builder.appendImmediate(",", "");
152 }
153 String _createAppCode = CpsStateCoder.this.createAppCode(app);
154 _builder.append(_createAppCode);
155 }
156 }
157 _builder.append("]");
158 }
159 };
160 return _client;
161 }
162
163 private String createAppCode(final ApplicationInstance app) {
164 String _xifexpression = null;
165 HostInstance _allocatedTo = app.getAllocatedTo();
166 boolean _tripleEquals = (_allocatedTo == null);
167 if (_tripleEquals) {
168 _xifexpression = "-";
169 } else {
170 _xifexpression = this.createMatchArgumentCode(app.getAllocatedTo());
171 }
172 return _xifexpression;
173 }
174
175 private CharSequence createHostTypesCode() {
176 StringConcatenation _builder = new StringConcatenation();
177 _builder.append("(");
178 {
179 EList<HostType> _hostTypes = this.cps.getHostTypes();
180 boolean _hasElements = false;
181 for(final HostType hostType : _hostTypes) {
182 if (!_hasElements) {
183 _hasElements = true;
184 } else {
185 _builder.appendImmediate(",", "");
186 }
187 int _size = hostType.getInstances().size();
188 _builder.append(_size);
189 }
190 }
191 _builder.append(")");
192 return _builder;
193 }
194
195 @Override
196 public String createActivationCode(final IPatternMatch match) {
197 StringConcatenation _builder = new StringConcatenation();
198 String _simpleName = match.specification().getSimpleName();
199 _builder.append(_simpleName);
200 _builder.append("(");
201 {
202 Object[] _array = match.toArray();
203 boolean _hasElements = false;
204 for(final Object arg : _array) {
205 if (!_hasElements) {
206 _hasElements = true;
207 } else {
208 _builder.appendImmediate(",", "");
209 }
210 String _createMatchArgumentCode = this.createMatchArgumentCode(arg);
211 _builder.append(_createMatchArgumentCode);
212 }
213 }
214 _builder.append(")");
215 return _builder.toString();
216 }
217
218 protected String _createMatchArgumentCode(final Requirement requirement) {
219 String _xblockexpression = null;
220 {
221 final EObject request = requirement.eContainer();
222 String _xifexpression = null;
223 if ((request instanceof Request)) {
224 String _xblockexpression_1 = null;
225 {
226 EObject _eContainer = ((Request)request).eContainer();
227 boolean _notEquals = (!Objects.equal(_eContainer, this.cps));
228 if (_notEquals) {
229 throw new IllegalArgumentException("Request is not contained in the CPS");
230 }
231 final int requestIndex = this.cps.getRequests().indexOf(request);
232 final int requirementIndex = ((Request)request).getRequirements().indexOf(requirement);
233 String _plus = (Integer.valueOf(requestIndex) + ".");
234 _xblockexpression_1 = (_plus + Integer.valueOf(requirementIndex));
235 }
236 _xifexpression = _xblockexpression_1;
237 } else {
238 throw new IllegalArgumentException("Requirement is not contained in a request");
239 }
240 _xblockexpression = _xifexpression;
241 }
242 return _xblockexpression;
243 }
244
245 protected String _createMatchArgumentCode(final ApplicationInstance app) {
246 String _xblockexpression = null;
247 {
248 final Requirement requirement = app.getRequirement();
249 if ((requirement == null)) {
250 throw new IllegalArgumentException("Application instance is not associated with a requirement");
251 }
252 final int instanceIndex = requirement.getInstances().indexOf(app);
253 String _createMatchArgumentCode = this.createMatchArgumentCode(requirement);
254 String _plus = (_createMatchArgumentCode + ".");
255 _xblockexpression = (_plus + Integer.valueOf(instanceIndex));
256 }
257 return _xblockexpression;
258 }
259
260 protected String _createMatchArgumentCode(final HostInstance host) {
261 String _xblockexpression = null;
262 {
263 final EObject hostType = host.eContainer();
264 String _xifexpression = null;
265 if ((hostType instanceof HostType)) {
266 String _xblockexpression_1 = null;
267 {
268 final int hostIndex = ((HostType)hostType).getInstances().indexOf(host);
269 String _createMatchArgumentCode = this.createMatchArgumentCode(hostType);
270 String _plus = (_createMatchArgumentCode + ".");
271 _xblockexpression_1 = (_plus + Integer.valueOf(hostIndex));
272 }
273 _xifexpression = _xblockexpression_1;
274 } else {
275 throw new IllegalArgumentException("Host is not contained in a host type");
276 }
277 _xblockexpression = _xifexpression;
278 }
279 return _xblockexpression;
280 }
281
282 protected String _createMatchArgumentCode(final HostType hostType) {
283 String _xblockexpression = null;
284 {
285 EObject _eContainer = hostType.eContainer();
286 boolean _notEquals = (!Objects.equal(_eContainer, this.cps));
287 if (_notEquals) {
288 throw new IllegalArgumentException("Host type is not contained in the CPS");
289 }
290 final int hostTypeIndex = this.cps.getHostTypes().indexOf(hostType);
291 _xblockexpression = Integer.valueOf(hostTypeIndex).toString();
292 }
293 return _xblockexpression;
294 }
295
296 protected String _createMatchArgumentCode(final Object object) {
297 throw new IllegalArgumentException("Unknown match argument: ");
298 }
299
300 protected String createMatchArgumentCode(final Object app) {
301 if (app instanceof ApplicationInstance) {
302 return _createMatchArgumentCode((ApplicationInstance)app);
303 } else if (app instanceof HostInstance) {
304 return _createMatchArgumentCode((HostInstance)app);
305 } else if (app instanceof HostType) {
306 return _createMatchArgumentCode((HostType)app);
307 } else if (app instanceof Requirement) {
308 return _createMatchArgumentCode((Requirement)app);
309 } else if (app != null) {
310 return _createMatchArgumentCode(app);
311 } else {
312 throw new IllegalArgumentException("Unhandled parameter types: " +
313 Arrays.<Object>asList(app).toString());
314 }
315 }
316}