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