diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2020-06-25 19:55:10 +0200 |
---|---|---|
committer | Kristóf Marussy <marussy@mit.bme.hu> | 2020-06-25 19:55:10 +0200 |
commit | c3a6d4b9cf3657070d180aa65ddbf0459e880329 (patch) | |
tree | 780c4fc61578dcb309af53fb0c164c7627e51676 /Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java | |
parent | New configuration language parser WIP (diff) | |
parent | Scope unsat benchmarks (diff) | |
download | VIATRA-Generator-c3a6d4b9cf3657070d180aa65ddbf0459e880329.tar.gz VIATRA-Generator-c3a6d4b9cf3657070d180aa65ddbf0459e880329.tar.zst VIATRA-Generator-c3a6d4b9cf3657070d180aa65ddbf0459e880329.zip |
Merge branch 'kris'
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java')
-rw-r--r-- | Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java | 597 |
1 files changed, 597 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java new file mode 100644 index 00000000..2a40ac57 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java | |||
@@ -0,0 +1,597 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql | ||
3 | */ | ||
4 | package hu.bme.mit.inf.dslreasoner.domains.cps.queries; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.Requirement; | ||
7 | import java.util.Arrays; | ||
8 | import java.util.Collection; | ||
9 | import java.util.LinkedHashSet; | ||
10 | import java.util.List; | ||
11 | import java.util.Objects; | ||
12 | import java.util.Optional; | ||
13 | import java.util.Set; | ||
14 | import java.util.function.Consumer; | ||
15 | import java.util.stream.Collectors; | ||
16 | import java.util.stream.Stream; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.emf.ecore.EClass; | ||
19 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
20 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
21 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
26 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
42 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
43 | |||
44 | /** | ||
45 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
46 | * | ||
47 | * <p>Original source: | ||
48 | * <code><pre> | ||
49 | * {@literal @}Constraint(severity = "error", key = {Req}, | ||
50 | * message = "Redundant instances must not be allocated to the same host.") | ||
51 | * pattern redundantInstancesOnSameHost(Req : Requirement) { | ||
52 | * Requirement.instances(Req, App1); | ||
53 | * Requirement.instances(Req, App2); | ||
54 | * App1 != App2; | ||
55 | * ApplicationInstance.allocatedTo(App1, Host); | ||
56 | * ApplicationInstance.allocatedTo(App2, Host); | ||
57 | * } | ||
58 | * </pre></code> | ||
59 | * | ||
60 | * @see Matcher | ||
61 | * @see Match | ||
62 | * | ||
63 | */ | ||
64 | @SuppressWarnings("all") | ||
65 | public final class RedundantInstancesOnSameHost extends BaseGeneratedEMFQuerySpecification<RedundantInstancesOnSameHost.Matcher> { | ||
66 | /** | ||
67 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost pattern, | ||
68 | * to be used in conjunction with {@link Matcher}. | ||
69 | * | ||
70 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
71 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
72 | * usable to represent a match of the pattern in the result of a query, | ||
73 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
74 | * | ||
75 | * @see Matcher | ||
76 | * | ||
77 | */ | ||
78 | public static abstract class Match extends BasePatternMatch { | ||
79 | private Requirement fReq; | ||
80 | |||
81 | private static List<String> parameterNames = makeImmutableList("Req"); | ||
82 | |||
83 | private Match(final Requirement pReq) { | ||
84 | this.fReq = pReq; | ||
85 | } | ||
86 | |||
87 | @Override | ||
88 | public Object get(final String parameterName) { | ||
89 | switch(parameterName) { | ||
90 | case "Req": return this.fReq; | ||
91 | default: return null; | ||
92 | } | ||
93 | } | ||
94 | |||
95 | @Override | ||
96 | public Object get(final int index) { | ||
97 | switch(index) { | ||
98 | case 0: return this.fReq; | ||
99 | default: return null; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | public Requirement getReq() { | ||
104 | return this.fReq; | ||
105 | } | ||
106 | |||
107 | @Override | ||
108 | public boolean set(final String parameterName, final Object newValue) { | ||
109 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
110 | if ("Req".equals(parameterName) ) { | ||
111 | this.fReq = (Requirement) newValue; | ||
112 | return true; | ||
113 | } | ||
114 | return false; | ||
115 | } | ||
116 | |||
117 | public void setReq(final Requirement pReq) { | ||
118 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
119 | this.fReq = pReq; | ||
120 | } | ||
121 | |||
122 | @Override | ||
123 | public String patternName() { | ||
124 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost"; | ||
125 | } | ||
126 | |||
127 | @Override | ||
128 | public List<String> parameterNames() { | ||
129 | return RedundantInstancesOnSameHost.Match.parameterNames; | ||
130 | } | ||
131 | |||
132 | @Override | ||
133 | public Object[] toArray() { | ||
134 | return new Object[]{fReq}; | ||
135 | } | ||
136 | |||
137 | @Override | ||
138 | public RedundantInstancesOnSameHost.Match toImmutable() { | ||
139 | return isMutable() ? newMatch(fReq) : this; | ||
140 | } | ||
141 | |||
142 | @Override | ||
143 | public String prettyPrint() { | ||
144 | StringBuilder result = new StringBuilder(); | ||
145 | result.append("\"Req\"=" + prettyPrintValue(fReq)); | ||
146 | return result.toString(); | ||
147 | } | ||
148 | |||
149 | @Override | ||
150 | public int hashCode() { | ||
151 | return Objects.hash(fReq); | ||
152 | } | ||
153 | |||
154 | @Override | ||
155 | public boolean equals(final Object obj) { | ||
156 | if (this == obj) | ||
157 | return true; | ||
158 | if (obj == null) { | ||
159 | return false; | ||
160 | } | ||
161 | if ((obj instanceof RedundantInstancesOnSameHost.Match)) { | ||
162 | RedundantInstancesOnSameHost.Match other = (RedundantInstancesOnSameHost.Match) obj; | ||
163 | return Objects.equals(fReq, other.fReq); | ||
164 | } else { | ||
165 | // this should be infrequent | ||
166 | if (!(obj instanceof IPatternMatch)) { | ||
167 | return false; | ||
168 | } | ||
169 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
170 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
171 | } | ||
172 | } | ||
173 | |||
174 | @Override | ||
175 | public RedundantInstancesOnSameHost specification() { | ||
176 | return RedundantInstancesOnSameHost.instance(); | ||
177 | } | ||
178 | |||
179 | /** | ||
180 | * Returns an empty, mutable match. | ||
181 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
182 | * | ||
183 | * @return the empty match. | ||
184 | * | ||
185 | */ | ||
186 | public static RedundantInstancesOnSameHost.Match newEmptyMatch() { | ||
187 | return new Mutable(null); | ||
188 | } | ||
189 | |||
190 | /** | ||
191 | * Returns a mutable (partial) match. | ||
192 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
193 | * | ||
194 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
195 | * @return the new, mutable (partial) match object. | ||
196 | * | ||
197 | */ | ||
198 | public static RedundantInstancesOnSameHost.Match newMutableMatch(final Requirement pReq) { | ||
199 | return new Mutable(pReq); | ||
200 | } | ||
201 | |||
202 | /** | ||
203 | * Returns a new (partial) match. | ||
204 | * This can be used e.g. to call the matcher with a partial match. | ||
205 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
206 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
207 | * @return the (partial) match object. | ||
208 | * | ||
209 | */ | ||
210 | public static RedundantInstancesOnSameHost.Match newMatch(final Requirement pReq) { | ||
211 | return new Immutable(pReq); | ||
212 | } | ||
213 | |||
214 | private static final class Mutable extends RedundantInstancesOnSameHost.Match { | ||
215 | Mutable(final Requirement pReq) { | ||
216 | super(pReq); | ||
217 | } | ||
218 | |||
219 | @Override | ||
220 | public boolean isMutable() { | ||
221 | return true; | ||
222 | } | ||
223 | } | ||
224 | |||
225 | private static final class Immutable extends RedundantInstancesOnSameHost.Match { | ||
226 | Immutable(final Requirement pReq) { | ||
227 | super(pReq); | ||
228 | } | ||
229 | |||
230 | @Override | ||
231 | public boolean isMutable() { | ||
232 | return false; | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | |||
237 | /** | ||
238 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost pattern, | ||
239 | * providing pattern-specific query methods. | ||
240 | * | ||
241 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
242 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
243 | * | ||
244 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
245 | * | ||
246 | * <p>Original source: | ||
247 | * <code><pre> | ||
248 | * {@literal @}Constraint(severity = "error", key = {Req}, | ||
249 | * message = "Redundant instances must not be allocated to the same host.") | ||
250 | * pattern redundantInstancesOnSameHost(Req : Requirement) { | ||
251 | * Requirement.instances(Req, App1); | ||
252 | * Requirement.instances(Req, App2); | ||
253 | * App1 != App2; | ||
254 | * ApplicationInstance.allocatedTo(App1, Host); | ||
255 | * ApplicationInstance.allocatedTo(App2, Host); | ||
256 | * } | ||
257 | * </pre></code> | ||
258 | * | ||
259 | * @see Match | ||
260 | * @see RedundantInstancesOnSameHost | ||
261 | * | ||
262 | */ | ||
263 | public static class Matcher extends BaseMatcher<RedundantInstancesOnSameHost.Match> { | ||
264 | /** | ||
265 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
266 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
267 | * | ||
268 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
269 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
270 | * | ||
271 | */ | ||
272 | public static RedundantInstancesOnSameHost.Matcher on(final ViatraQueryEngine engine) { | ||
273 | // check if matcher already exists | ||
274 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
275 | if (matcher == null) { | ||
276 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
277 | } | ||
278 | return matcher; | ||
279 | } | ||
280 | |||
281 | /** | ||
282 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
283 | * @return an initialized matcher | ||
284 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
285 | * | ||
286 | */ | ||
287 | public static RedundantInstancesOnSameHost.Matcher create() { | ||
288 | return new Matcher(); | ||
289 | } | ||
290 | |||
291 | private static final int POSITION_REQ = 0; | ||
292 | |||
293 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(RedundantInstancesOnSameHost.Matcher.class); | ||
294 | |||
295 | /** | ||
296 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
297 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
298 | * | ||
299 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
300 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
301 | * | ||
302 | */ | ||
303 | private Matcher() { | ||
304 | super(querySpecification()); | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
309 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
310 | * @return matches represented as a Match object. | ||
311 | * | ||
312 | */ | ||
313 | public Collection<RedundantInstancesOnSameHost.Match> getAllMatches(final Requirement pReq) { | ||
314 | return rawStreamAllMatches(new Object[]{pReq}).collect(Collectors.toSet()); | ||
315 | } | ||
316 | |||
317 | /** | ||
318 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
319 | * </p> | ||
320 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
321 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
322 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
323 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
324 | * @return a stream of matches represented as a Match object. | ||
325 | * | ||
326 | */ | ||
327 | public Stream<RedundantInstancesOnSameHost.Match> streamAllMatches(final Requirement pReq) { | ||
328 | return rawStreamAllMatches(new Object[]{pReq}); | ||
329 | } | ||
330 | |||
331 | /** | ||
332 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
333 | * Neither determinism nor randomness of selection is guaranteed. | ||
334 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
335 | * @return a match represented as a Match object, or null if no match is found. | ||
336 | * | ||
337 | */ | ||
338 | public Optional<RedundantInstancesOnSameHost.Match> getOneArbitraryMatch(final Requirement pReq) { | ||
339 | return rawGetOneArbitraryMatch(new Object[]{pReq}); | ||
340 | } | ||
341 | |||
342 | /** | ||
343 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
344 | * under any possible substitution of the unspecified parameters (if any). | ||
345 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
346 | * @return true if the input is a valid (partial) match of the pattern. | ||
347 | * | ||
348 | */ | ||
349 | public boolean hasMatch(final Requirement pReq) { | ||
350 | return rawHasMatch(new Object[]{pReq}); | ||
351 | } | ||
352 | |||
353 | /** | ||
354 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
355 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
356 | * @return the number of pattern matches found. | ||
357 | * | ||
358 | */ | ||
359 | public int countMatches(final Requirement pReq) { | ||
360 | return rawCountMatches(new Object[]{pReq}); | ||
361 | } | ||
362 | |||
363 | /** | ||
364 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
365 | * Neither determinism nor randomness of selection is guaranteed. | ||
366 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
367 | * @param processor the action that will process the selected match. | ||
368 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
369 | * | ||
370 | */ | ||
371 | public boolean forOneArbitraryMatch(final Requirement pReq, final Consumer<? super RedundantInstancesOnSameHost.Match> processor) { | ||
372 | return rawForOneArbitraryMatch(new Object[]{pReq}, processor); | ||
373 | } | ||
374 | |||
375 | /** | ||
376 | * Returns a new (partial) match. | ||
377 | * This can be used e.g. to call the matcher with a partial match. | ||
378 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
379 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
380 | * @return the (partial) match object. | ||
381 | * | ||
382 | */ | ||
383 | public RedundantInstancesOnSameHost.Match newMatch(final Requirement pReq) { | ||
384 | return RedundantInstancesOnSameHost.Match.newMatch(pReq); | ||
385 | } | ||
386 | |||
387 | /** | ||
388 | * Retrieve the set of values that occur in matches for Req. | ||
389 | * @return the Set of all values or empty set if there are no matches | ||
390 | * | ||
391 | */ | ||
392 | protected Stream<Requirement> rawStreamAllValuesOfReq(final Object[] parameters) { | ||
393 | return rawStreamAllValues(POSITION_REQ, parameters).map(Requirement.class::cast); | ||
394 | } | ||
395 | |||
396 | /** | ||
397 | * Retrieve the set of values that occur in matches for Req. | ||
398 | * @return the Set of all values or empty set if there are no matches | ||
399 | * | ||
400 | */ | ||
401 | public Set<Requirement> getAllValuesOfReq() { | ||
402 | return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet()); | ||
403 | } | ||
404 | |||
405 | /** | ||
406 | * Retrieve the set of values that occur in matches for Req. | ||
407 | * @return the Set of all values or empty set if there are no matches | ||
408 | * | ||
409 | */ | ||
410 | public Stream<Requirement> streamAllValuesOfReq() { | ||
411 | return rawStreamAllValuesOfReq(emptyArray()); | ||
412 | } | ||
413 | |||
414 | @Override | ||
415 | protected RedundantInstancesOnSameHost.Match tupleToMatch(final Tuple t) { | ||
416 | try { | ||
417 | return RedundantInstancesOnSameHost.Match.newMatch((Requirement) t.get(POSITION_REQ)); | ||
418 | } catch(ClassCastException e) { | ||
419 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
420 | return null; | ||
421 | } | ||
422 | } | ||
423 | |||
424 | @Override | ||
425 | protected RedundantInstancesOnSameHost.Match arrayToMatch(final Object[] match) { | ||
426 | try { | ||
427 | return RedundantInstancesOnSameHost.Match.newMatch((Requirement) match[POSITION_REQ]); | ||
428 | } catch(ClassCastException e) { | ||
429 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
430 | return null; | ||
431 | } | ||
432 | } | ||
433 | |||
434 | @Override | ||
435 | protected RedundantInstancesOnSameHost.Match arrayToMatchMutable(final Object[] match) { | ||
436 | try { | ||
437 | return RedundantInstancesOnSameHost.Match.newMutableMatch((Requirement) match[POSITION_REQ]); | ||
438 | } catch(ClassCastException e) { | ||
439 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
440 | return null; | ||
441 | } | ||
442 | } | ||
443 | |||
444 | /** | ||
445 | * @return the singleton instance of the query specification of this pattern | ||
446 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
447 | * | ||
448 | */ | ||
449 | public static IQuerySpecification<RedundantInstancesOnSameHost.Matcher> querySpecification() { | ||
450 | return RedundantInstancesOnSameHost.instance(); | ||
451 | } | ||
452 | } | ||
453 | |||
454 | private RedundantInstancesOnSameHost() { | ||
455 | super(GeneratedPQuery.INSTANCE); | ||
456 | } | ||
457 | |||
458 | /** | ||
459 | * @return the singleton instance of the query specification | ||
460 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
461 | * | ||
462 | */ | ||
463 | public static RedundantInstancesOnSameHost instance() { | ||
464 | try{ | ||
465 | return LazyHolder.INSTANCE; | ||
466 | } catch (ExceptionInInitializerError err) { | ||
467 | throw processInitializerError(err); | ||
468 | } | ||
469 | } | ||
470 | |||
471 | @Override | ||
472 | protected RedundantInstancesOnSameHost.Matcher instantiate(final ViatraQueryEngine engine) { | ||
473 | return RedundantInstancesOnSameHost.Matcher.on(engine); | ||
474 | } | ||
475 | |||
476 | @Override | ||
477 | public RedundantInstancesOnSameHost.Matcher instantiate() { | ||
478 | return RedundantInstancesOnSameHost.Matcher.create(); | ||
479 | } | ||
480 | |||
481 | @Override | ||
482 | public RedundantInstancesOnSameHost.Match newEmptyMatch() { | ||
483 | return RedundantInstancesOnSameHost.Match.newEmptyMatch(); | ||
484 | } | ||
485 | |||
486 | @Override | ||
487 | public RedundantInstancesOnSameHost.Match newMatch(final Object... parameters) { | ||
488 | return RedundantInstancesOnSameHost.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.Requirement) parameters[0]); | ||
489 | } | ||
490 | |||
491 | /** | ||
492 | * Inner class allowing the singleton instance of {@link RedundantInstancesOnSameHost} to be created | ||
493 | * <b>not</b> at the class load time of the outer class, | ||
494 | * but rather at the first call to {@link RedundantInstancesOnSameHost#instance()}. | ||
495 | * | ||
496 | * <p> This workaround is required e.g. to support recursion. | ||
497 | * | ||
498 | */ | ||
499 | private static class LazyHolder { | ||
500 | private static final RedundantInstancesOnSameHost INSTANCE = new RedundantInstancesOnSameHost(); | ||
501 | |||
502 | /** | ||
503 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
504 | * This initialization order is required to support indirect recursion. | ||
505 | * | ||
506 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
507 | * | ||
508 | */ | ||
509 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
510 | |||
511 | public static Object ensureInitialized() { | ||
512 | INSTANCE.ensureInitializedInternal(); | ||
513 | return null; | ||
514 | } | ||
515 | } | ||
516 | |||
517 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
518 | private static final RedundantInstancesOnSameHost.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
519 | |||
520 | private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.Requirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "Requirement")), PParameterDirection.INOUT); | ||
521 | |||
522 | private final List<PParameter> parameters = Arrays.asList(parameter_Req); | ||
523 | |||
524 | private GeneratedPQuery() { | ||
525 | super(PVisibility.PUBLIC); | ||
526 | } | ||
527 | |||
528 | @Override | ||
529 | public String getFullyQualifiedName() { | ||
530 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost"; | ||
531 | } | ||
532 | |||
533 | @Override | ||
534 | public List<String> getParameterNames() { | ||
535 | return Arrays.asList("Req"); | ||
536 | } | ||
537 | |||
538 | @Override | ||
539 | public List<PParameter> getParameters() { | ||
540 | return parameters; | ||
541 | } | ||
542 | |||
543 | @Override | ||
544 | public Set<PBody> doGetContainedBodies() { | ||
545 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
546 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
547 | { | ||
548 | PBody body = new PBody(this); | ||
549 | PVariable var_Req = body.getOrCreateVariableByName("Req"); | ||
550 | PVariable var_App1 = body.getOrCreateVariableByName("App1"); | ||
551 | PVariable var_App2 = body.getOrCreateVariableByName("App2"); | ||
552 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
553 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
554 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
555 | new ExportedParameter(body, var_Req, parameter_Req) | ||
556 | )); | ||
557 | // Requirement.instances(Req, App1) | ||
558 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
559 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
560 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances"))); | ||
561 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
562 | new Equality(body, var__virtual_0_, var_App1); | ||
563 | // Requirement.instances(Req, App2) | ||
564 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
565 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
566 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances"))); | ||
567 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
568 | new Equality(body, var__virtual_1_, var_App2); | ||
569 | // App1 != App2 | ||
570 | new Inequality(body, var_App1, var_App2); | ||
571 | // ApplicationInstance.allocatedTo(App1, Host) | ||
572 | new TypeConstraint(body, Tuples.flatTupleOf(var_App1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
573 | PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); | ||
574 | new TypeConstraint(body, Tuples.flatTupleOf(var_App1, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo"))); | ||
575 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
576 | new Equality(body, var__virtual_2_, var_Host); | ||
577 | // ApplicationInstance.allocatedTo(App2, Host) | ||
578 | new TypeConstraint(body, Tuples.flatTupleOf(var_App2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
579 | PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); | ||
580 | new TypeConstraint(body, Tuples.flatTupleOf(var_App2, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo"))); | ||
581 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
582 | new Equality(body, var__virtual_3_, var_Host); | ||
583 | bodies.add(body); | ||
584 | } | ||
585 | { | ||
586 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
587 | annotation.addAttribute("severity", "error"); | ||
588 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
589 | new ParameterReference("Req") | ||
590 | })); | ||
591 | annotation.addAttribute("message", "Redundant instances must not be allocated to the same host."); | ||
592 | addAnnotation(annotation); | ||
593 | } | ||
594 | return bodies; | ||
595 | } | ||
596 | } | ||
597 | } | ||