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