aboutsummaryrefslogtreecommitdiffstats
path: root/Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam')
-rw-r--r--Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/.gitignore10
-rw-r--r--Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/TerminatorAndInformation.java747
-rw-r--r--Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/Type.java770
3 files changed, 1527 insertions, 0 deletions
diff --git a/Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/.gitignore b/Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/.gitignore
new file mode 100644
index 00000000..60f1891b
--- /dev/null
+++ b/Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/.gitignore
@@ -0,0 +1,10 @@
1/.FamPatterns.java._trace
2/.Model.java._trace
3/.Parent.java._trace
4/.RootElements.java._trace
5/.TerminatorAndInformation.java._trace
6/.Type.java._trace
7/FamPatterns.java
8/Model.java
9/Parent.java
10/RootElements.java
diff --git a/Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/TerminatorAndInformation.java b/Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/TerminatorAndInformation.java
new file mode 100644
index 00000000..69a6b9f4
--- /dev/null
+++ b/Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/TerminatorAndInformation.java
@@ -0,0 +1,747 @@
1/**
2 * Generated from platform:/resource/ca.mcgill.ecse.dslreasoner.standalone.test/queries/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/famPatterns.vql
3 */
4package ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries;
5
6import ca.mcgill.ecse.dslreasoner.standalone.test.fam.FAMTerminator;
7import ca.mcgill.ecse.dslreasoner.standalone.test.fam.InformationLink;
8import java.util.Arrays;
9import java.util.Collection;
10import java.util.LinkedHashSet;
11import java.util.List;
12import java.util.Objects;
13import java.util.Optional;
14import java.util.Set;
15import java.util.function.Consumer;
16import java.util.stream.Collectors;
17import java.util.stream.Stream;
18import org.apache.log4j.Logger;
19import org.eclipse.emf.ecore.EClass;
20import org.eclipse.viatra.query.runtime.api.IPatternMatch;
21import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
22import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
25import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
26import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
27import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
28import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
29import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
30import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
32import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
33import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
38import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
40import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
41import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
42import 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(message="terminatorAndInformation", severity="error", key={T})
50 * pattern terminatorAndInformation(T : FAMTerminator, I : InformationLink) = {
51 * FunctionalOutput.outgoingLinks(Out,I);
52 * FunctionalOutput.terminator(Out,T);
53 * } or {
54 * InformationLink.to(I,In);
55 * FunctionalInput.terminator(In,T);
56 * }
57 * </pre></code>
58 *
59 * @see Matcher
60 * @see Match
61 *
62 */
63@SuppressWarnings("all")
64public final class TerminatorAndInformation extends BaseGeneratedEMFQuerySpecification<TerminatorAndInformation.Matcher> {
65 /**
66 * Pattern-specific match representation of the ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.terminatorAndInformation pattern,
67 * to be used in conjunction with {@link Matcher}.
68 *
69 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
70 * Each instance is a (possibly partial) substitution of pattern parameters,
71 * usable to represent a match of the pattern in the result of a query,
72 * or to specify the bound (fixed) input parameters when issuing a query.
73 *
74 * @see Matcher
75 *
76 */
77 public static abstract class Match extends BasePatternMatch {
78 private FAMTerminator fT;
79
80 private InformationLink fI;
81
82 private static List<String> parameterNames = makeImmutableList("T", "I");
83
84 private Match(final FAMTerminator pT, final InformationLink pI) {
85 this.fT = pT;
86 this.fI = pI;
87 }
88
89 @Override
90 public Object get(final String parameterName) {
91 if ("T".equals(parameterName)) return this.fT;
92 if ("I".equals(parameterName)) return this.fI;
93 return null;
94 }
95
96 public FAMTerminator getT() {
97 return this.fT;
98 }
99
100 public InformationLink getI() {
101 return this.fI;
102 }
103
104 @Override
105 public boolean set(final String parameterName, final Object newValue) {
106 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
107 if ("T".equals(parameterName) ) {
108 this.fT = (FAMTerminator) newValue;
109 return true;
110 }
111 if ("I".equals(parameterName) ) {
112 this.fI = (InformationLink) newValue;
113 return true;
114 }
115 return false;
116 }
117
118 public void setT(final FAMTerminator pT) {
119 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
120 this.fT = pT;
121 }
122
123 public void setI(final InformationLink pI) {
124 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
125 this.fI = pI;
126 }
127
128 @Override
129 public String patternName() {
130 return "ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.terminatorAndInformation";
131 }
132
133 @Override
134 public List<String> parameterNames() {
135 return TerminatorAndInformation.Match.parameterNames;
136 }
137
138 @Override
139 public Object[] toArray() {
140 return new Object[]{fT, fI};
141 }
142
143 @Override
144 public TerminatorAndInformation.Match toImmutable() {
145 return isMutable() ? newMatch(fT, fI) : this;
146 }
147
148 @Override
149 public String prettyPrint() {
150 StringBuilder result = new StringBuilder();
151 result.append("\"T\"=" + prettyPrintValue(fT) + ", ");
152 result.append("\"I\"=" + prettyPrintValue(fI));
153 return result.toString();
154 }
155
156 @Override
157 public int hashCode() {
158 return Objects.hash(fT, fI);
159 }
160
161 @Override
162 public boolean equals(final Object obj) {
163 if (this == obj)
164 return true;
165 if (obj == null) {
166 return false;
167 }
168 if ((obj instanceof TerminatorAndInformation.Match)) {
169 TerminatorAndInformation.Match other = (TerminatorAndInformation.Match) obj;
170 return Objects.equals(fT, other.fT) && Objects.equals(fI, other.fI);
171 } else {
172 // this should be infrequent
173 if (!(obj instanceof IPatternMatch)) {
174 return false;
175 }
176 IPatternMatch otherSig = (IPatternMatch) obj;
177 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
178 }
179 }
180
181 @Override
182 public TerminatorAndInformation specification() {
183 return TerminatorAndInformation.instance();
184 }
185
186 /**
187 * Returns an empty, mutable match.
188 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
189 *
190 * @return the empty match.
191 *
192 */
193 public static TerminatorAndInformation.Match newEmptyMatch() {
194 return new Mutable(null, null);
195 }
196
197 /**
198 * Returns a mutable (partial) match.
199 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
200 *
201 * @param pT the fixed value of pattern parameter T, or null if not bound.
202 * @param pI the fixed value of pattern parameter I, or null if not bound.
203 * @return the new, mutable (partial) match object.
204 *
205 */
206 public static TerminatorAndInformation.Match newMutableMatch(final FAMTerminator pT, final InformationLink pI) {
207 return new Mutable(pT, pI);
208 }
209
210 /**
211 * Returns a new (partial) match.
212 * This can be used e.g. to call the matcher with a partial match.
213 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
214 * @param pT the fixed value of pattern parameter T, or null if not bound.
215 * @param pI the fixed value of pattern parameter I, or null if not bound.
216 * @return the (partial) match object.
217 *
218 */
219 public static TerminatorAndInformation.Match newMatch(final FAMTerminator pT, final InformationLink pI) {
220 return new Immutable(pT, pI);
221 }
222
223 private static final class Mutable extends TerminatorAndInformation.Match {
224 Mutable(final FAMTerminator pT, final InformationLink pI) {
225 super(pT, pI);
226 }
227
228 @Override
229 public boolean isMutable() {
230 return true;
231 }
232 }
233
234 private static final class Immutable extends TerminatorAndInformation.Match {
235 Immutable(final FAMTerminator pT, final InformationLink pI) {
236 super(pT, pI);
237 }
238
239 @Override
240 public boolean isMutable() {
241 return false;
242 }
243 }
244 }
245
246 /**
247 * Generated pattern matcher API of the ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.terminatorAndInformation pattern,
248 * providing pattern-specific query methods.
249 *
250 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
251 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
252 *
253 * <p>Matches of the pattern will be represented as {@link Match}.
254 *
255 * <p>Original source:
256 * <code><pre>
257 * {@literal @}Constraint(message="terminatorAndInformation", severity="error", key={T})
258 * pattern terminatorAndInformation(T : FAMTerminator, I : InformationLink) = {
259 * FunctionalOutput.outgoingLinks(Out,I);
260 * FunctionalOutput.terminator(Out,T);
261 * } or {
262 * InformationLink.to(I,In);
263 * FunctionalInput.terminator(In,T);
264 * }
265 * </pre></code>
266 *
267 * @see Match
268 * @see TerminatorAndInformation
269 *
270 */
271 public static class Matcher extends BaseMatcher<TerminatorAndInformation.Match> {
272 /**
273 * Initializes the pattern matcher within an existing VIATRA Query engine.
274 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
275 *
276 * @param engine the existing VIATRA Query engine in which this matcher will be created.
277 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
278 *
279 */
280 public static TerminatorAndInformation.Matcher on(final ViatraQueryEngine engine) {
281 // check if matcher already exists
282 Matcher matcher = engine.getExistingMatcher(querySpecification());
283 if (matcher == null) {
284 matcher = (Matcher)engine.getMatcher(querySpecification());
285 }
286 return matcher;
287 }
288
289 /**
290 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
291 * @return an initialized matcher
292 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
293 *
294 */
295 public static TerminatorAndInformation.Matcher create() {
296 return new Matcher();
297 }
298
299 private final static int POSITION_T = 0;
300
301 private final static int POSITION_I = 1;
302
303 private final static Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TerminatorAndInformation.Matcher.class);
304
305 /**
306 * Initializes the pattern matcher within an existing VIATRA Query engine.
307 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
308 *
309 * @param engine the existing VIATRA Query engine in which this matcher will be created.
310 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
311 *
312 */
313 private Matcher() {
314 super(querySpecification());
315 }
316
317 /**
318 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
319 * @param pT the fixed value of pattern parameter T, or null if not bound.
320 * @param pI the fixed value of pattern parameter I, or null if not bound.
321 * @return matches represented as a Match object.
322 *
323 */
324 public Collection<TerminatorAndInformation.Match> getAllMatches(final FAMTerminator pT, final InformationLink pI) {
325 return rawStreamAllMatches(new Object[]{pT, pI}).collect(Collectors.toSet());
326 }
327
328 /**
329 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
330 * </p>
331 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
332 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
333 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
334 * @param pT the fixed value of pattern parameter T, or null if not bound.
335 * @param pI the fixed value of pattern parameter I, or null if not bound.
336 * @return a stream of matches represented as a Match object.
337 *
338 */
339 public Stream<TerminatorAndInformation.Match> streamAllMatches(final FAMTerminator pT, final InformationLink pI) {
340 return rawStreamAllMatches(new Object[]{pT, pI});
341 }
342
343 /**
344 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
345 * Neither determinism nor randomness of selection is guaranteed.
346 * @param pT the fixed value of pattern parameter T, or null if not bound.
347 * @param pI the fixed value of pattern parameter I, or null if not bound.
348 * @return a match represented as a Match object, or null if no match is found.
349 *
350 */
351 public Optional<TerminatorAndInformation.Match> getOneArbitraryMatch(final FAMTerminator pT, final InformationLink pI) {
352 return rawGetOneArbitraryMatch(new Object[]{pT, pI});
353 }
354
355 /**
356 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
357 * under any possible substitution of the unspecified parameters (if any).
358 * @param pT the fixed value of pattern parameter T, or null if not bound.
359 * @param pI the fixed value of pattern parameter I, or null if not bound.
360 * @return true if the input is a valid (partial) match of the pattern.
361 *
362 */
363 public boolean hasMatch(final FAMTerminator pT, final InformationLink pI) {
364 return rawHasMatch(new Object[]{pT, pI});
365 }
366
367 /**
368 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
369 * @param pT the fixed value of pattern parameter T, or null if not bound.
370 * @param pI the fixed value of pattern parameter I, or null if not bound.
371 * @return the number of pattern matches found.
372 *
373 */
374 public int countMatches(final FAMTerminator pT, final InformationLink pI) {
375 return rawCountMatches(new Object[]{pT, pI});
376 }
377
378 /**
379 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
380 * Neither determinism nor randomness of selection is guaranteed.
381 * @param pT the fixed value of pattern parameter T, or null if not bound.
382 * @param pI the fixed value of pattern parameter I, or null if not bound.
383 * @param processor the action that will process the selected match.
384 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
385 *
386 */
387 public boolean forOneArbitraryMatch(final FAMTerminator pT, final InformationLink pI, final Consumer<? super TerminatorAndInformation.Match> processor) {
388 return rawForOneArbitraryMatch(new Object[]{pT, pI}, processor);
389 }
390
391 /**
392 * Returns a new (partial) match.
393 * This can be used e.g. to call the matcher with a partial match.
394 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
395 * @param pT the fixed value of pattern parameter T, or null if not bound.
396 * @param pI the fixed value of pattern parameter I, or null if not bound.
397 * @return the (partial) match object.
398 *
399 */
400 public TerminatorAndInformation.Match newMatch(final FAMTerminator pT, final InformationLink pI) {
401 return TerminatorAndInformation.Match.newMatch(pT, pI);
402 }
403
404 /**
405 * Retrieve the set of values that occur in matches for T.
406 * @return the Set of all values or empty set if there are no matches
407 *
408 */
409 protected Stream<FAMTerminator> rawStreamAllValuesOfT(final Object[] parameters) {
410 return rawStreamAllValues(POSITION_T, parameters).map(FAMTerminator.class::cast);
411 }
412
413 /**
414 * Retrieve the set of values that occur in matches for T.
415 * @return the Set of all values or empty set if there are no matches
416 *
417 */
418 public Set<FAMTerminator> getAllValuesOfT() {
419 return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet());
420 }
421
422 /**
423 * Retrieve the set of values that occur in matches for T.
424 * @return the Set of all values or empty set if there are no matches
425 *
426 */
427 public Stream<FAMTerminator> streamAllValuesOfT() {
428 return rawStreamAllValuesOfT(emptyArray());
429 }
430
431 /**
432 * Retrieve the set of values that occur in matches for T.
433 * </p>
434 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
435 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
436 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
437 *
438 * @return the Stream of all values or empty set if there are no matches
439 *
440 */
441 public Stream<FAMTerminator> streamAllValuesOfT(final TerminatorAndInformation.Match partialMatch) {
442 return rawStreamAllValuesOfT(partialMatch.toArray());
443 }
444
445 /**
446 * Retrieve the set of values that occur in matches for T.
447 * </p>
448 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
449 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
450 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
451 *
452 * @return the Stream of all values or empty set if there are no matches
453 *
454 */
455 public Stream<FAMTerminator> streamAllValuesOfT(final InformationLink pI) {
456 return rawStreamAllValuesOfT(new Object[]{null, pI});
457 }
458
459 /**
460 * Retrieve the set of values that occur in matches for T.
461 * @return the Set of all values or empty set if there are no matches
462 *
463 */
464 public Set<FAMTerminator> getAllValuesOfT(final TerminatorAndInformation.Match partialMatch) {
465 return rawStreamAllValuesOfT(partialMatch.toArray()).collect(Collectors.toSet());
466 }
467
468 /**
469 * Retrieve the set of values that occur in matches for T.
470 * @return the Set of all values or empty set if there are no matches
471 *
472 */
473 public Set<FAMTerminator> getAllValuesOfT(final InformationLink pI) {
474 return rawStreamAllValuesOfT(new Object[]{null, pI}).collect(Collectors.toSet());
475 }
476
477 /**
478 * Retrieve the set of values that occur in matches for I.
479 * @return the Set of all values or empty set if there are no matches
480 *
481 */
482 protected Stream<InformationLink> rawStreamAllValuesOfI(final Object[] parameters) {
483 return rawStreamAllValues(POSITION_I, parameters).map(InformationLink.class::cast);
484 }
485
486 /**
487 * Retrieve the set of values that occur in matches for I.
488 * @return the Set of all values or empty set if there are no matches
489 *
490 */
491 public Set<InformationLink> getAllValuesOfI() {
492 return rawStreamAllValuesOfI(emptyArray()).collect(Collectors.toSet());
493 }
494
495 /**
496 * Retrieve the set of values that occur in matches for I.
497 * @return the Set of all values or empty set if there are no matches
498 *
499 */
500 public Stream<InformationLink> streamAllValuesOfI() {
501 return rawStreamAllValuesOfI(emptyArray());
502 }
503
504 /**
505 * Retrieve the set of values that occur in matches for I.
506 * </p>
507 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
508 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
509 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
510 *
511 * @return the Stream of all values or empty set if there are no matches
512 *
513 */
514 public Stream<InformationLink> streamAllValuesOfI(final TerminatorAndInformation.Match partialMatch) {
515 return rawStreamAllValuesOfI(partialMatch.toArray());
516 }
517
518 /**
519 * Retrieve the set of values that occur in matches for I.
520 * </p>
521 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
522 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
523 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
524 *
525 * @return the Stream of all values or empty set if there are no matches
526 *
527 */
528 public Stream<InformationLink> streamAllValuesOfI(final FAMTerminator pT) {
529 return rawStreamAllValuesOfI(new Object[]{pT, null});
530 }
531
532 /**
533 * Retrieve the set of values that occur in matches for I.
534 * @return the Set of all values or empty set if there are no matches
535 *
536 */
537 public Set<InformationLink> getAllValuesOfI(final TerminatorAndInformation.Match partialMatch) {
538 return rawStreamAllValuesOfI(partialMatch.toArray()).collect(Collectors.toSet());
539 }
540
541 /**
542 * Retrieve the set of values that occur in matches for I.
543 * @return the Set of all values or empty set if there are no matches
544 *
545 */
546 public Set<InformationLink> getAllValuesOfI(final FAMTerminator pT) {
547 return rawStreamAllValuesOfI(new Object[]{pT, null}).collect(Collectors.toSet());
548 }
549
550 @Override
551 protected TerminatorAndInformation.Match tupleToMatch(final Tuple t) {
552 try {
553 return TerminatorAndInformation.Match.newMatch((FAMTerminator) t.get(POSITION_T), (InformationLink) t.get(POSITION_I));
554 } catch(ClassCastException e) {
555 LOGGER.error("Element(s) in tuple not properly typed!",e);
556 return null;
557 }
558 }
559
560 @Override
561 protected TerminatorAndInformation.Match arrayToMatch(final Object[] match) {
562 try {
563 return TerminatorAndInformation.Match.newMatch((FAMTerminator) match[POSITION_T], (InformationLink) match[POSITION_I]);
564 } catch(ClassCastException e) {
565 LOGGER.error("Element(s) in array not properly typed!",e);
566 return null;
567 }
568 }
569
570 @Override
571 protected TerminatorAndInformation.Match arrayToMatchMutable(final Object[] match) {
572 try {
573 return TerminatorAndInformation.Match.newMutableMatch((FAMTerminator) match[POSITION_T], (InformationLink) match[POSITION_I]);
574 } catch(ClassCastException e) {
575 LOGGER.error("Element(s) in array not properly typed!",e);
576 return null;
577 }
578 }
579
580 /**
581 * @return the singleton instance of the query specification of this pattern
582 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
583 *
584 */
585 public static IQuerySpecification<TerminatorAndInformation.Matcher> querySpecification() {
586 return TerminatorAndInformation.instance();
587 }
588 }
589
590 private TerminatorAndInformation() {
591 super(GeneratedPQuery.INSTANCE);
592 }
593
594 /**
595 * @return the singleton instance of the query specification
596 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
597 *
598 */
599 public static TerminatorAndInformation instance() {
600 try{
601 return LazyHolder.INSTANCE;
602 } catch (ExceptionInInitializerError err) {
603 throw processInitializerError(err);
604 }
605 }
606
607 @Override
608 protected TerminatorAndInformation.Matcher instantiate(final ViatraQueryEngine engine) {
609 return TerminatorAndInformation.Matcher.on(engine);
610 }
611
612 @Override
613 public TerminatorAndInformation.Matcher instantiate() {
614 return TerminatorAndInformation.Matcher.create();
615 }
616
617 @Override
618 public TerminatorAndInformation.Match newEmptyMatch() {
619 return TerminatorAndInformation.Match.newEmptyMatch();
620 }
621
622 @Override
623 public TerminatorAndInformation.Match newMatch(final Object... parameters) {
624 return TerminatorAndInformation.Match.newMatch((ca.mcgill.ecse.dslreasoner.standalone.test.fam.FAMTerminator) parameters[0], (ca.mcgill.ecse.dslreasoner.standalone.test.fam.InformationLink) parameters[1]);
625 }
626
627 /**
628 * Inner class allowing the singleton instance of {@link JvmGenericType: ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.TerminatorAndInformation (visibility: PUBLIC, simpleName: TerminatorAndInformation, identifier: ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.TerminatorAndInformation, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
629 * <b>not</b> at the class load time of the outer class,
630 * but rather at the first call to {@link JvmGenericType: ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.TerminatorAndInformation (visibility: PUBLIC, simpleName: TerminatorAndInformation, identifier: ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.TerminatorAndInformation, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
631 *
632 * <p> This workaround is required e.g. to support recursion.
633 *
634 */
635 private static class LazyHolder {
636 private final static TerminatorAndInformation INSTANCE = new TerminatorAndInformation();
637
638 /**
639 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
640 * This initialization order is required to support indirect recursion.
641 *
642 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
643 *
644 */
645 private final static Object STATIC_INITIALIZER = ensureInitialized();
646
647 public static Object ensureInitialized() {
648 INSTANCE.ensureInitializedInternal();
649 return null;
650 }
651 }
652
653 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
654 private final static TerminatorAndInformation.GeneratedPQuery INSTANCE = new GeneratedPQuery();
655
656 private final PParameter parameter_T = new PParameter("T", "ca.mcgill.ecse.dslreasoner.standalone.test.fam.FAMTerminator", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("FamMetamodel", "FAMTerminator")), PParameterDirection.INOUT);
657
658 private final PParameter parameter_I = new PParameter("I", "ca.mcgill.ecse.dslreasoner.standalone.test.fam.InformationLink", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("FamMetamodel", "InformationLink")), PParameterDirection.INOUT);
659
660 private final List<PParameter> parameters = Arrays.asList(parameter_T, parameter_I);
661
662 private GeneratedPQuery() {
663 super(PVisibility.PUBLIC);
664 }
665
666 @Override
667 public String getFullyQualifiedName() {
668 return "ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.terminatorAndInformation";
669 }
670
671 @Override
672 public List<String> getParameterNames() {
673 return Arrays.asList("T","I");
674 }
675
676 @Override
677 public List<PParameter> getParameters() {
678 return parameters;
679 }
680
681 @Override
682 public Set<PBody> doGetContainedBodies() {
683 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
684 Set<PBody> bodies = new LinkedHashSet<>();
685 {
686 PBody body = new PBody(this);
687 PVariable var_T = body.getOrCreateVariableByName("T");
688 PVariable var_I = body.getOrCreateVariableByName("I");
689 PVariable var_Out = body.getOrCreateVariableByName("Out");
690 new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "FAMTerminator")));
691 new TypeConstraint(body, Tuples.flatTupleOf(var_I), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "InformationLink")));
692 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
693 new ExportedParameter(body, var_T, parameter_T),
694 new ExportedParameter(body, var_I, parameter_I)
695 ));
696 // FunctionalOutput.outgoingLinks(Out,I)
697 new TypeConstraint(body, Tuples.flatTupleOf(var_Out), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "FunctionalOutput")));
698 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
699 new TypeConstraint(body, Tuples.flatTupleOf(var_Out, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("FamMetamodel", "FunctionalOutput", "outgoingLinks")));
700 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "InformationLink")));
701 new Equality(body, var__virtual_0_, var_I);
702 // FunctionalOutput.terminator(Out,T)
703 new TypeConstraint(body, Tuples.flatTupleOf(var_Out), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "FunctionalOutput")));
704 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
705 new TypeConstraint(body, Tuples.flatTupleOf(var_Out, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("FamMetamodel", "FunctionalData", "terminator")));
706 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "FAMTerminator")));
707 new Equality(body, var__virtual_1_, var_T);
708 bodies.add(body);
709 }
710 {
711 PBody body = new PBody(this);
712 PVariable var_T = body.getOrCreateVariableByName("T");
713 PVariable var_I = body.getOrCreateVariableByName("I");
714 PVariable var_In = body.getOrCreateVariableByName("In");
715 new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "FAMTerminator")));
716 new TypeConstraint(body, Tuples.flatTupleOf(var_I), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "InformationLink")));
717 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
718 new ExportedParameter(body, var_T, parameter_T),
719 new ExportedParameter(body, var_I, parameter_I)
720 ));
721 // InformationLink.to(I,In)
722 new TypeConstraint(body, Tuples.flatTupleOf(var_I), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "InformationLink")));
723 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
724 new TypeConstraint(body, Tuples.flatTupleOf(var_I, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("FamMetamodel", "InformationLink", "to")));
725 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "FunctionalInput")));
726 new Equality(body, var__virtual_0_, var_In);
727 // FunctionalInput.terminator(In,T)
728 new TypeConstraint(body, Tuples.flatTupleOf(var_In), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "FunctionalInput")));
729 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
730 new TypeConstraint(body, Tuples.flatTupleOf(var_In, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("FamMetamodel", "FunctionalData", "terminator")));
731 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "FAMTerminator")));
732 new Equality(body, var__virtual_1_, var_T);
733 bodies.add(body);
734 }
735 {
736 PAnnotation annotation = new PAnnotation("Constraint");
737 annotation.addAttribute("message", "terminatorAndInformation");
738 annotation.addAttribute("severity", "error");
739 annotation.addAttribute("key", Arrays.asList(new Object[] {
740 new ParameterReference("T")
741 }));
742 addAnnotation(annotation);
743 }
744 return bodies;
745 }
746 }
747}
diff --git a/Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/Type.java b/Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/Type.java
new file mode 100644
index 00000000..bc3230c5
--- /dev/null
+++ b/Tests/ca.mcgill.ecse.dslreasoner.standalone.test/src-gen/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/Type.java
@@ -0,0 +1,770 @@
1/**
2 * Generated from platform:/resource/ca.mcgill.ecse.dslreasoner.standalone.test/queries/ca/mcgill/ecse/dslreasoner/standalone/test/fam/queries/famPatterns.vql
3 */
4package ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries;
5
6import ca.mcgill.ecse.dslreasoner.standalone.test.fam.Function;
7import ca.mcgill.ecse.dslreasoner.standalone.test.fam.FunctionType;
8import ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.Parent;
9import ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.RootElements;
10import java.util.Arrays;
11import java.util.Collection;
12import java.util.LinkedHashSet;
13import java.util.List;
14import java.util.Objects;
15import java.util.Optional;
16import java.util.Set;
17import java.util.function.Consumer;
18import java.util.stream.Collectors;
19import java.util.stream.Stream;
20import org.apache.log4j.Logger;
21import org.eclipse.emf.ecore.EClass;
22import org.eclipse.emf.ecore.EDataType;
23import org.eclipse.viatra.query.runtime.api.IPatternMatch;
24import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
25import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
26import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
27import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
28import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
29import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
30import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
31import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey;
32import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
33import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
34import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
35import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
39import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue;
40import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
41import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
42import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
43import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
44import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
45import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
46import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
47import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
48
49/**
50 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
51 *
52 * <p>Original source:
53 * <code><pre>
54 * {@literal @}QueryBasedFeature
55 * pattern type(This : Function, Target : FunctionType) = {
56 * find rootElements(_Model, This);
57 * Target == FunctionType::Root;
58 * } or {
59 * neg find parent(_Child, This);
60 * neg find rootElements(_Model, This);
61 * Target == FunctionType::Leaf;
62 * } or {
63 * find parent(This, _Par);
64 * find parent(_Child, This);
65 * Target == FunctionType::Intermediate;
66 * }
67 * </pre></code>
68 *
69 * @see Matcher
70 * @see Match
71 *
72 */
73@SuppressWarnings("all")
74public final class Type extends BaseGeneratedEMFQuerySpecification<Type.Matcher> {
75 /**
76 * Pattern-specific match representation of the ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.type pattern,
77 * to be used in conjunction with {@link Matcher}.
78 *
79 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
80 * Each instance is a (possibly partial) substitution of pattern parameters,
81 * usable to represent a match of the pattern in the result of a query,
82 * or to specify the bound (fixed) input parameters when issuing a query.
83 *
84 * @see Matcher
85 *
86 */
87 public static abstract class Match extends BasePatternMatch {
88 private Function fThis;
89
90 private FunctionType fTarget;
91
92 private static List<String> parameterNames = makeImmutableList("This", "Target");
93
94 private Match(final Function pThis, final FunctionType pTarget) {
95 this.fThis = pThis;
96 this.fTarget = pTarget;
97 }
98
99 @Override
100 public Object get(final String parameterName) {
101 if ("This".equals(parameterName)) return this.fThis;
102 if ("Target".equals(parameterName)) return this.fTarget;
103 return null;
104 }
105
106 public Function getThis() {
107 return this.fThis;
108 }
109
110 public FunctionType getTarget() {
111 return this.fTarget;
112 }
113
114 @Override
115 public boolean set(final String parameterName, final Object newValue) {
116 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
117 if ("This".equals(parameterName) ) {
118 this.fThis = (Function) newValue;
119 return true;
120 }
121 if ("Target".equals(parameterName) ) {
122 this.fTarget = (FunctionType) newValue;
123 return true;
124 }
125 return false;
126 }
127
128 public void setThis(final Function pThis) {
129 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
130 this.fThis = pThis;
131 }
132
133 public void setTarget(final FunctionType pTarget) {
134 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
135 this.fTarget = pTarget;
136 }
137
138 @Override
139 public String patternName() {
140 return "ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.type";
141 }
142
143 @Override
144 public List<String> parameterNames() {
145 return Type.Match.parameterNames;
146 }
147
148 @Override
149 public Object[] toArray() {
150 return new Object[]{fThis, fTarget};
151 }
152
153 @Override
154 public Type.Match toImmutable() {
155 return isMutable() ? newMatch(fThis, fTarget) : this;
156 }
157
158 @Override
159 public String prettyPrint() {
160 StringBuilder result = new StringBuilder();
161 result.append("\"This\"=" + prettyPrintValue(fThis) + ", ");
162 result.append("\"Target\"=" + prettyPrintValue(fTarget));
163 return result.toString();
164 }
165
166 @Override
167 public int hashCode() {
168 return Objects.hash(fThis, fTarget);
169 }
170
171 @Override
172 public boolean equals(final Object obj) {
173 if (this == obj)
174 return true;
175 if (obj == null) {
176 return false;
177 }
178 if ((obj instanceof Type.Match)) {
179 Type.Match other = (Type.Match) obj;
180 return Objects.equals(fThis, other.fThis) && Objects.equals(fTarget, other.fTarget);
181 } else {
182 // this should be infrequent
183 if (!(obj instanceof IPatternMatch)) {
184 return false;
185 }
186 IPatternMatch otherSig = (IPatternMatch) obj;
187 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
188 }
189 }
190
191 @Override
192 public Type specification() {
193 return Type.instance();
194 }
195
196 /**
197 * Returns an empty, mutable match.
198 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
199 *
200 * @return the empty match.
201 *
202 */
203 public static Type.Match newEmptyMatch() {
204 return new Mutable(null, null);
205 }
206
207 /**
208 * Returns a mutable (partial) match.
209 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
210 *
211 * @param pThis the fixed value of pattern parameter This, or null if not bound.
212 * @param pTarget the fixed value of pattern parameter Target, or null if not bound.
213 * @return the new, mutable (partial) match object.
214 *
215 */
216 public static Type.Match newMutableMatch(final Function pThis, final FunctionType pTarget) {
217 return new Mutable(pThis, pTarget);
218 }
219
220 /**
221 * Returns a new (partial) match.
222 * This can be used e.g. to call the matcher with a partial match.
223 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
224 * @param pThis the fixed value of pattern parameter This, or null if not bound.
225 * @param pTarget the fixed value of pattern parameter Target, or null if not bound.
226 * @return the (partial) match object.
227 *
228 */
229 public static Type.Match newMatch(final Function pThis, final FunctionType pTarget) {
230 return new Immutable(pThis, pTarget);
231 }
232
233 private static final class Mutable extends Type.Match {
234 Mutable(final Function pThis, final FunctionType pTarget) {
235 super(pThis, pTarget);
236 }
237
238 @Override
239 public boolean isMutable() {
240 return true;
241 }
242 }
243
244 private static final class Immutable extends Type.Match {
245 Immutable(final Function pThis, final FunctionType pTarget) {
246 super(pThis, pTarget);
247 }
248
249 @Override
250 public boolean isMutable() {
251 return false;
252 }
253 }
254 }
255
256 /**
257 * Generated pattern matcher API of the ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.type pattern,
258 * providing pattern-specific query methods.
259 *
260 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
261 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
262 *
263 * <p>Matches of the pattern will be represented as {@link Match}.
264 *
265 * <p>Original source:
266 * <code><pre>
267 * {@literal @}QueryBasedFeature
268 * pattern type(This : Function, Target : FunctionType) = {
269 * find rootElements(_Model, This);
270 * Target == FunctionType::Root;
271 * } or {
272 * neg find parent(_Child, This);
273 * neg find rootElements(_Model, This);
274 * Target == FunctionType::Leaf;
275 * } or {
276 * find parent(This, _Par);
277 * find parent(_Child, This);
278 * Target == FunctionType::Intermediate;
279 * }
280 * </pre></code>
281 *
282 * @see Match
283 * @see Type
284 *
285 */
286 public static class Matcher extends BaseMatcher<Type.Match> {
287 /**
288 * Initializes the pattern matcher within an existing VIATRA Query engine.
289 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
290 *
291 * @param engine the existing VIATRA Query engine in which this matcher will be created.
292 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
293 *
294 */
295 public static Type.Matcher on(final ViatraQueryEngine engine) {
296 // check if matcher already exists
297 Matcher matcher = engine.getExistingMatcher(querySpecification());
298 if (matcher == null) {
299 matcher = (Matcher)engine.getMatcher(querySpecification());
300 }
301 return matcher;
302 }
303
304 /**
305 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
306 * @return an initialized matcher
307 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
308 *
309 */
310 public static Type.Matcher create() {
311 return new Matcher();
312 }
313
314 private final static int POSITION_THIS = 0;
315
316 private final static int POSITION_TARGET = 1;
317
318 private final static Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Type.Matcher.class);
319
320 /**
321 * Initializes the pattern matcher within an existing VIATRA Query engine.
322 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
323 *
324 * @param engine the existing VIATRA Query engine in which this matcher will be created.
325 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
326 *
327 */
328 private Matcher() {
329 super(querySpecification());
330 }
331
332 /**
333 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
334 * @param pThis the fixed value of pattern parameter This, or null if not bound.
335 * @param pTarget the fixed value of pattern parameter Target, or null if not bound.
336 * @return matches represented as a Match object.
337 *
338 */
339 public Collection<Type.Match> getAllMatches(final Function pThis, final FunctionType pTarget) {
340 return rawStreamAllMatches(new Object[]{pThis, pTarget}).collect(Collectors.toSet());
341 }
342
343 /**
344 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
345 * </p>
346 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
347 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
348 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
349 * @param pThis the fixed value of pattern parameter This, or null if not bound.
350 * @param pTarget the fixed value of pattern parameter Target, or null if not bound.
351 * @return a stream of matches represented as a Match object.
352 *
353 */
354 public Stream<Type.Match> streamAllMatches(final Function pThis, final FunctionType pTarget) {
355 return rawStreamAllMatches(new Object[]{pThis, pTarget});
356 }
357
358 /**
359 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
360 * Neither determinism nor randomness of selection is guaranteed.
361 * @param pThis the fixed value of pattern parameter This, or null if not bound.
362 * @param pTarget the fixed value of pattern parameter Target, or null if not bound.
363 * @return a match represented as a Match object, or null if no match is found.
364 *
365 */
366 public Optional<Type.Match> getOneArbitraryMatch(final Function pThis, final FunctionType pTarget) {
367 return rawGetOneArbitraryMatch(new Object[]{pThis, pTarget});
368 }
369
370 /**
371 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
372 * under any possible substitution of the unspecified parameters (if any).
373 * @param pThis the fixed value of pattern parameter This, or null if not bound.
374 * @param pTarget the fixed value of pattern parameter Target, or null if not bound.
375 * @return true if the input is a valid (partial) match of the pattern.
376 *
377 */
378 public boolean hasMatch(final Function pThis, final FunctionType pTarget) {
379 return rawHasMatch(new Object[]{pThis, pTarget});
380 }
381
382 /**
383 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
384 * @param pThis the fixed value of pattern parameter This, or null if not bound.
385 * @param pTarget the fixed value of pattern parameter Target, or null if not bound.
386 * @return the number of pattern matches found.
387 *
388 */
389 public int countMatches(final Function pThis, final FunctionType pTarget) {
390 return rawCountMatches(new Object[]{pThis, pTarget});
391 }
392
393 /**
394 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
395 * Neither determinism nor randomness of selection is guaranteed.
396 * @param pThis the fixed value of pattern parameter This, or null if not bound.
397 * @param pTarget the fixed value of pattern parameter Target, or null if not bound.
398 * @param processor the action that will process the selected match.
399 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
400 *
401 */
402 public boolean forOneArbitraryMatch(final Function pThis, final FunctionType pTarget, final Consumer<? super Type.Match> processor) {
403 return rawForOneArbitraryMatch(new Object[]{pThis, pTarget}, processor);
404 }
405
406 /**
407 * Returns a new (partial) match.
408 * This can be used e.g. to call the matcher with a partial match.
409 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
410 * @param pThis the fixed value of pattern parameter This, or null if not bound.
411 * @param pTarget the fixed value of pattern parameter Target, or null if not bound.
412 * @return the (partial) match object.
413 *
414 */
415 public Type.Match newMatch(final Function pThis, final FunctionType pTarget) {
416 return Type.Match.newMatch(pThis, pTarget);
417 }
418
419 /**
420 * Retrieve the set of values that occur in matches for This.
421 * @return the Set of all values or empty set if there are no matches
422 *
423 */
424 protected Stream<Function> rawStreamAllValuesOfThis(final Object[] parameters) {
425 return rawStreamAllValues(POSITION_THIS, parameters).map(Function.class::cast);
426 }
427
428 /**
429 * Retrieve the set of values that occur in matches for This.
430 * @return the Set of all values or empty set if there are no matches
431 *
432 */
433 public Set<Function> getAllValuesOfThis() {
434 return rawStreamAllValuesOfThis(emptyArray()).collect(Collectors.toSet());
435 }
436
437 /**
438 * Retrieve the set of values that occur in matches for This.
439 * @return the Set of all values or empty set if there are no matches
440 *
441 */
442 public Stream<Function> streamAllValuesOfThis() {
443 return rawStreamAllValuesOfThis(emptyArray());
444 }
445
446 /**
447 * Retrieve the set of values that occur in matches for This.
448 * </p>
449 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
450 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
451 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
452 *
453 * @return the Stream of all values or empty set if there are no matches
454 *
455 */
456 public Stream<Function> streamAllValuesOfThis(final Type.Match partialMatch) {
457 return rawStreamAllValuesOfThis(partialMatch.toArray());
458 }
459
460 /**
461 * Retrieve the set of values that occur in matches for This.
462 * </p>
463 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
464 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
465 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
466 *
467 * @return the Stream of all values or empty set if there are no matches
468 *
469 */
470 public Stream<Function> streamAllValuesOfThis(final FunctionType pTarget) {
471 return rawStreamAllValuesOfThis(new Object[]{null, pTarget});
472 }
473
474 /**
475 * Retrieve the set of values that occur in matches for This.
476 * @return the Set of all values or empty set if there are no matches
477 *
478 */
479 public Set<Function> getAllValuesOfThis(final Type.Match partialMatch) {
480 return rawStreamAllValuesOfThis(partialMatch.toArray()).collect(Collectors.toSet());
481 }
482
483 /**
484 * Retrieve the set of values that occur in matches for This.
485 * @return the Set of all values or empty set if there are no matches
486 *
487 */
488 public Set<Function> getAllValuesOfThis(final FunctionType pTarget) {
489 return rawStreamAllValuesOfThis(new Object[]{null, pTarget}).collect(Collectors.toSet());
490 }
491
492 /**
493 * Retrieve the set of values that occur in matches for Target.
494 * @return the Set of all values or empty set if there are no matches
495 *
496 */
497 protected Stream<FunctionType> rawStreamAllValuesOfTarget(final Object[] parameters) {
498 return rawStreamAllValues(POSITION_TARGET, parameters).map(FunctionType.class::cast);
499 }
500
501 /**
502 * Retrieve the set of values that occur in matches for Target.
503 * @return the Set of all values or empty set if there are no matches
504 *
505 */
506 public Set<FunctionType> getAllValuesOfTarget() {
507 return rawStreamAllValuesOfTarget(emptyArray()).collect(Collectors.toSet());
508 }
509
510 /**
511 * Retrieve the set of values that occur in matches for Target.
512 * @return the Set of all values or empty set if there are no matches
513 *
514 */
515 public Stream<FunctionType> streamAllValuesOfTarget() {
516 return rawStreamAllValuesOfTarget(emptyArray());
517 }
518
519 /**
520 * Retrieve the set of values that occur in matches for Target.
521 * </p>
522 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
523 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
524 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
525 *
526 * @return the Stream of all values or empty set if there are no matches
527 *
528 */
529 public Stream<FunctionType> streamAllValuesOfTarget(final Type.Match partialMatch) {
530 return rawStreamAllValuesOfTarget(partialMatch.toArray());
531 }
532
533 /**
534 * Retrieve the set of values that occur in matches for Target.
535 * </p>
536 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
537 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
538 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
539 *
540 * @return the Stream of all values or empty set if there are no matches
541 *
542 */
543 public Stream<FunctionType> streamAllValuesOfTarget(final Function pThis) {
544 return rawStreamAllValuesOfTarget(new Object[]{pThis, null});
545 }
546
547 /**
548 * Retrieve the set of values that occur in matches for Target.
549 * @return the Set of all values or empty set if there are no matches
550 *
551 */
552 public Set<FunctionType> getAllValuesOfTarget(final Type.Match partialMatch) {
553 return rawStreamAllValuesOfTarget(partialMatch.toArray()).collect(Collectors.toSet());
554 }
555
556 /**
557 * Retrieve the set of values that occur in matches for Target.
558 * @return the Set of all values or empty set if there are no matches
559 *
560 */
561 public Set<FunctionType> getAllValuesOfTarget(final Function pThis) {
562 return rawStreamAllValuesOfTarget(new Object[]{pThis, null}).collect(Collectors.toSet());
563 }
564
565 @Override
566 protected Type.Match tupleToMatch(final Tuple t) {
567 try {
568 return Type.Match.newMatch((Function) t.get(POSITION_THIS), (FunctionType) t.get(POSITION_TARGET));
569 } catch(ClassCastException e) {
570 LOGGER.error("Element(s) in tuple not properly typed!",e);
571 return null;
572 }
573 }
574
575 @Override
576 protected Type.Match arrayToMatch(final Object[] match) {
577 try {
578 return Type.Match.newMatch((Function) match[POSITION_THIS], (FunctionType) match[POSITION_TARGET]);
579 } catch(ClassCastException e) {
580 LOGGER.error("Element(s) in array not properly typed!",e);
581 return null;
582 }
583 }
584
585 @Override
586 protected Type.Match arrayToMatchMutable(final Object[] match) {
587 try {
588 return Type.Match.newMutableMatch((Function) match[POSITION_THIS], (FunctionType) match[POSITION_TARGET]);
589 } catch(ClassCastException e) {
590 LOGGER.error("Element(s) in array not properly typed!",e);
591 return null;
592 }
593 }
594
595 /**
596 * @return the singleton instance of the query specification of this pattern
597 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
598 *
599 */
600 public static IQuerySpecification<Type.Matcher> querySpecification() {
601 return Type.instance();
602 }
603 }
604
605 private Type() {
606 super(GeneratedPQuery.INSTANCE);
607 }
608
609 /**
610 * @return the singleton instance of the query specification
611 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
612 *
613 */
614 public static Type instance() {
615 try{
616 return LazyHolder.INSTANCE;
617 } catch (ExceptionInInitializerError err) {
618 throw processInitializerError(err);
619 }
620 }
621
622 @Override
623 protected Type.Matcher instantiate(final ViatraQueryEngine engine) {
624 return Type.Matcher.on(engine);
625 }
626
627 @Override
628 public Type.Matcher instantiate() {
629 return Type.Matcher.create();
630 }
631
632 @Override
633 public Type.Match newEmptyMatch() {
634 return Type.Match.newEmptyMatch();
635 }
636
637 @Override
638 public Type.Match newMatch(final Object... parameters) {
639 return Type.Match.newMatch((ca.mcgill.ecse.dslreasoner.standalone.test.fam.Function) parameters[0], (ca.mcgill.ecse.dslreasoner.standalone.test.fam.FunctionType) parameters[1]);
640 }
641
642 /**
643 * Inner class allowing the singleton instance of {@link JvmGenericType: ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.Type (visibility: PUBLIC, simpleName: Type, identifier: ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.Type, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
644 * <b>not</b> at the class load time of the outer class,
645 * but rather at the first call to {@link JvmGenericType: ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.Type (visibility: PUBLIC, simpleName: Type, identifier: ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.Type, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
646 *
647 * <p> This workaround is required e.g. to support recursion.
648 *
649 */
650 private static class LazyHolder {
651 private final static Type INSTANCE = new Type();
652
653 /**
654 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
655 * This initialization order is required to support indirect recursion.
656 *
657 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
658 *
659 */
660 private final static Object STATIC_INITIALIZER = ensureInitialized();
661
662 public static Object ensureInitialized() {
663 INSTANCE.ensureInitializedInternal();
664 return null;
665 }
666 }
667
668 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
669 private final static Type.GeneratedPQuery INSTANCE = new GeneratedPQuery();
670
671 private final PParameter parameter_This = new PParameter("This", "ca.mcgill.ecse.dslreasoner.standalone.test.fam.Function", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("FamMetamodel", "Function")), PParameterDirection.INOUT);
672
673 private final PParameter parameter_Target = new PParameter("Target", "ca.mcgill.ecse.dslreasoner.standalone.test.fam.FunctionType", new EDataTypeInSlotsKey((EDataType)getClassifierLiteralSafe("FamMetamodel", "FunctionType")), PParameterDirection.INOUT);
674
675 private final List<PParameter> parameters = Arrays.asList(parameter_This, parameter_Target);
676
677 private GeneratedPQuery() {
678 super(PVisibility.PUBLIC);
679 }
680
681 @Override
682 public String getFullyQualifiedName() {
683 return "ca.mcgill.ecse.dslreasoner.standalone.test.fam.queries.type";
684 }
685
686 @Override
687 public List<String> getParameterNames() {
688 return Arrays.asList("This","Target");
689 }
690
691 @Override
692 public List<PParameter> getParameters() {
693 return parameters;
694 }
695
696 @Override
697 public Set<PBody> doGetContainedBodies() {
698 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
699 Set<PBody> bodies = new LinkedHashSet<>();
700 {
701 PBody body = new PBody(this);
702 PVariable var_This = body.getOrCreateVariableByName("This");
703 PVariable var_Target = body.getOrCreateVariableByName("Target");
704 PVariable var__Model = body.getOrCreateVariableByName("_Model");
705 new TypeConstraint(body, Tuples.flatTupleOf(var_This), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "Function")));
706 new TypeConstraint(body, Tuples.flatTupleOf(var_Target), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("FamMetamodel", "FunctionType")));
707 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
708 new ExportedParameter(body, var_This, parameter_This),
709 new ExportedParameter(body, var_Target, parameter_Target)
710 ));
711 // find rootElements(_Model, This)
712 new PositivePatternCall(body, Tuples.flatTupleOf(var__Model, var_This), RootElements.instance().getInternalQueryRepresentation());
713 // Target == FunctionType::Root
714 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
715 new ConstantValue(body, var__virtual_0_, getEnumLiteral("FamMetamodel", "FunctionType", "Root").getInstance());
716 new Equality(body, var_Target, var__virtual_0_);
717 bodies.add(body);
718 }
719 {
720 PBody body = new PBody(this);
721 PVariable var_This = body.getOrCreateVariableByName("This");
722 PVariable var_Target = body.getOrCreateVariableByName("Target");
723 PVariable var__Child = body.getOrCreateVariableByName("_Child");
724 PVariable var__Model = body.getOrCreateVariableByName("_Model");
725 new TypeConstraint(body, Tuples.flatTupleOf(var_This), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "Function")));
726 new TypeConstraint(body, Tuples.flatTupleOf(var_Target), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("FamMetamodel", "FunctionType")));
727 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
728 new ExportedParameter(body, var_This, parameter_This),
729 new ExportedParameter(body, var_Target, parameter_Target)
730 ));
731 // neg find parent(_Child, This)
732 new NegativePatternCall(body, Tuples.flatTupleOf(var__Child, var_This), Parent.instance().getInternalQueryRepresentation());
733 // neg find rootElements(_Model, This)
734 new NegativePatternCall(body, Tuples.flatTupleOf(var__Model, var_This), RootElements.instance().getInternalQueryRepresentation());
735 // Target == FunctionType::Leaf
736 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
737 new ConstantValue(body, var__virtual_0_, getEnumLiteral("FamMetamodel", "FunctionType", "Leaf").getInstance());
738 new Equality(body, var_Target, var__virtual_0_);
739 bodies.add(body);
740 }
741 {
742 PBody body = new PBody(this);
743 PVariable var_This = body.getOrCreateVariableByName("This");
744 PVariable var_Target = body.getOrCreateVariableByName("Target");
745 PVariable var__Par = body.getOrCreateVariableByName("_Par");
746 PVariable var__Child = body.getOrCreateVariableByName("_Child");
747 new TypeConstraint(body, Tuples.flatTupleOf(var_This), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("FamMetamodel", "Function")));
748 new TypeConstraint(body, Tuples.flatTupleOf(var_Target), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("FamMetamodel", "FunctionType")));
749 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
750 new ExportedParameter(body, var_This, parameter_This),
751 new ExportedParameter(body, var_Target, parameter_Target)
752 ));
753 // find parent(This, _Par)
754 new PositivePatternCall(body, Tuples.flatTupleOf(var_This, var__Par), Parent.instance().getInternalQueryRepresentation());
755 // find parent(_Child, This)
756 new PositivePatternCall(body, Tuples.flatTupleOf(var__Child, var_This), Parent.instance().getInternalQueryRepresentation());
757 // Target == FunctionType::Intermediate
758 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
759 new ConstantValue(body, var__virtual_0_, getEnumLiteral("FamMetamodel", "FunctionType", "Intermediate").getInstance());
760 new Equality(body, var_Target, var__virtual_0_);
761 bodies.add(body);
762 }
763 {
764 PAnnotation annotation = new PAnnotation("QueryBasedFeature");
765 addAnnotation(annotation);
766 }
767 return bodies;
768 }
769 }
770}