aboutsummaryrefslogtreecommitdiffstats
path: root/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen')
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/.gitignore75
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Case_study_A.java438
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv03.java652
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv05.java701
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv06.java509
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv07.java455
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv08.java705
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv10.java616
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv11.java566
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv12.java589
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv13.java591
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv15.java567
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv17.java643
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv20.java587
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv33.java665
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv34.java639
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv35.java639
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv47.java636
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv48.java566
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv49.java561
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_eligAll.java606
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_hasAll.java551
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv05_inRange.java628
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_inRange.java630
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_noType.java551
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_notEI.java544
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incNotOver100.java610
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incOver100.java629
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notNonRes.java543
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notZZ.java555
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv13.java544
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv15.java637
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv47.java569
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_3.java555
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_Dis.java610
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_notDis.java569
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_1.java579
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_2.java544
38 files changed, 21854 insertions, 0 deletions
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/.gitignore b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/.gitignore
new file mode 100644
index 00000000..16afa8c0
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/.gitignore
@@ -0,0 +1,75 @@
1/.Inv17.java._trace
2/.Inv20.java._trace
3/.Inv33_con.java._trace
4/.Inv34.java._trace
5/.Inv35.java._trace
6/.Inv47.java._trace
7/.Inv48.java._trace
8/.Inv48_helper.java._trace
9/.Case_study_A.java._trace
10/.Inv49.java._trace
11/.Inv49_con.java._trace
12/.Inv49_helper.java._trace
13/.H_inv49.java._trace
14/.Ocl_inv49.java._trace
15/.Vql_inv49.java._trace
16/.Vql_inv492.java._trace
17/.H1_inv48.java._trace
18/.H2_inv48.java._trace
19/.Vql_inv48.java._trace
20/.H3_inv48.java._trace
21/.H1_inv49.java._trace
22/.H2_inv49.java._trace
23/.H_inv47.java._trace
24/.Inv35test.java._trace
25/.Inv33.java._trace
26/.X.java._trace
27/.H_inv16_moreThan1.java._trace
28/.H_inv48_1.java._trace
29/.H_inv48_2.java._trace
30/.H_inv48_3.java._trace
31/.H_inv49_1.java._trace
32/.H_inv49_2.java._trace
33/.Inv16.java._trace
34/.Inv15.java._trace
35/.H_inv13.java._trace
36/.Inv13.java._trace
37/.Inv12.java._trace
38/.H_inv12_notNonRes.java._trace
39/.H_inv12_notZZ.java._trace
40/.H_inv11_incOver100.java._trace
41/.Inv11.java._trace
42/.H_inv11_incNotOver100.java._trace
43/.H_inv8_notEI.java._trace
44/.Inv8.java._trace
45/.H_inv08_notEI.java._trace
46/.Inv08.java._trace
47/.H_inv08_inRange.java._trace
48/.X_inv08_inRange.java._trace
49/.X_inv08_notEI.java._trace
50/.X_inv11_incNotOver100.java._trace
51/.X_inv11_incOver100.java._trace
52/.X_inv12_notNonRes.java._trace
53/.X_inv12_notZZ.java._trace
54/.X_inv13.java._trace
55/.X_inv47.java._trace
56/.X_inv48_1.java._trace
57/.X_inv48_2.java._trace
58/.X_inv48_3.java._trace
59/.X_inv49_1.java._trace
60/.X_inv49_2.java._trace
61/.X_inv48_Dis.java._trace
62/.X_inv48_notDis.java._trace
63/.X_inv08_noType.java._trace
64/.X_inv08_invalidType.java._trace
65/.Inv06.java._trace
66/.X_inv06_inRange.java._trace
67/.Inv05.java._trace
68/.X_inv05_inRange.java._trace
69/.Inv03.java._trace
70/.X_inv03_noAll.java._trace
71/.X_inv03_eligAll.java._trace
72/.X_inv03_hasAll.java._trace
73/.Inv07.java._trace
74/.Inv10.java._trace
75/.X_inv15.java._trace
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Case_study_A.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Case_study_A.java
new file mode 100644
index 00000000..a8ab2996
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Case_study_A.java
@@ -0,0 +1,438 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
7import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup;
8import queries.Inv03;
9import queries.Inv05;
10import queries.Inv06;
11import queries.Inv07;
12import queries.Inv08;
13import queries.Inv10;
14import queries.Inv11;
15import queries.Inv12;
16import queries.Inv13;
17import queries.Inv15;
18import queries.Inv17;
19import queries.Inv20;
20import queries.Inv33;
21import queries.Inv34;
22import queries.Inv35;
23import queries.Inv47;
24import queries.Inv48;
25import queries.Inv49;
26import queries.X_inv03_eligAll;
27import queries.X_inv03_hasAll;
28import queries.X_inv05_inRange;
29import queries.X_inv08_inRange;
30import queries.X_inv08_noType;
31import queries.X_inv08_notEI;
32import queries.X_inv11_incNotOver100;
33import queries.X_inv11_incOver100;
34import queries.X_inv12_notNonRes;
35import queries.X_inv12_notZZ;
36import queries.X_inv13;
37import queries.X_inv15;
38import queries.X_inv47;
39import queries.X_inv48_3;
40import queries.X_inv48_Dis;
41import queries.X_inv48_notDis;
42import queries.X_inv49_1;
43import queries.X_inv49_2;
44
45/**
46 * A pattern group formed of all public patterns defined in case_study_A.vql.
47 *
48 * <p>Use the static instance as any {@link interface org.eclipse.viatra.query.runtime.api.IQueryGroup}, to conveniently prepare
49 * a VIATRA Query engine for matching all patterns originally defined in file case_study_A.vql,
50 * in order to achieve better performance than one-by-one on-demand matcher initialization.
51 *
52 * <p> From package queries, the group contains the definition of the following patterns: <ul>
53 * <li>inv03</li>
54 * <li>x_inv03_eligAll</li>
55 * <li>x_inv03_hasAll</li>
56 * <li>inv05</li>
57 * <li>x_inv05_inRange</li>
58 * <li>inv06</li>
59 * <li>inv07</li>
60 * <li>inv08</li>
61 * <li>x_inv08_notEI</li>
62 * <li>x_inv08_noType</li>
63 * <li>x_inv08_inRange</li>
64 * <li>inv10</li>
65 * <li>inv11</li>
66 * <li>x_inv11_incOver100</li>
67 * <li>x_inv11_incNotOver100</li>
68 * <li>inv12</li>
69 * <li>x_inv12_notNonRes</li>
70 * <li>x_inv12_notZZ</li>
71 * <li>inv13</li>
72 * <li>x_inv13</li>
73 * <li>inv15</li>
74 * <li>x_inv15</li>
75 * <li>inv17</li>
76 * <li>inv20</li>
77 * <li>inv33</li>
78 * <li>inv34</li>
79 * <li>inv35</li>
80 * <li>inv47</li>
81 * <li>x_inv47</li>
82 * <li>inv48</li>
83 * <li>x_inv48_notDis</li>
84 * <li>x_inv48_Dis</li>
85 * <li>x_inv48_3</li>
86 * <li>inv49</li>
87 * <li>x_inv49_1</li>
88 * <li>x_inv49_2</li>
89 * </ul>
90 *
91 * @see IQueryGroup
92 *
93 */
94@SuppressWarnings("all")
95public final class Case_study_A extends BaseGeneratedPatternGroup {
96 /**
97 * Access the pattern group.
98 *
99 * @return the singleton instance of the group
100 * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications
101 *
102 */
103 public static Case_study_A instance() {
104 if (INSTANCE == null) {
105 INSTANCE = new Case_study_A();
106 }
107 return INSTANCE;
108 }
109
110 private static Case_study_A INSTANCE;
111
112 private Case_study_A() {
113 querySpecifications.add(Inv03.instance());
114 querySpecifications.add(X_inv03_eligAll.instance());
115 querySpecifications.add(X_inv03_hasAll.instance());
116 querySpecifications.add(Inv05.instance());
117 querySpecifications.add(X_inv05_inRange.instance());
118 querySpecifications.add(Inv06.instance());
119 querySpecifications.add(Inv07.instance());
120 querySpecifications.add(Inv08.instance());
121 querySpecifications.add(X_inv08_notEI.instance());
122 querySpecifications.add(X_inv08_noType.instance());
123 querySpecifications.add(X_inv08_inRange.instance());
124 querySpecifications.add(Inv10.instance());
125 querySpecifications.add(Inv11.instance());
126 querySpecifications.add(X_inv11_incOver100.instance());
127 querySpecifications.add(X_inv11_incNotOver100.instance());
128 querySpecifications.add(Inv12.instance());
129 querySpecifications.add(X_inv12_notNonRes.instance());
130 querySpecifications.add(X_inv12_notZZ.instance());
131 querySpecifications.add(Inv13.instance());
132 querySpecifications.add(X_inv13.instance());
133 querySpecifications.add(Inv15.instance());
134 querySpecifications.add(X_inv15.instance());
135 querySpecifications.add(Inv17.instance());
136 querySpecifications.add(Inv20.instance());
137 querySpecifications.add(Inv33.instance());
138 querySpecifications.add(Inv34.instance());
139 querySpecifications.add(Inv35.instance());
140 querySpecifications.add(Inv47.instance());
141 querySpecifications.add(X_inv47.instance());
142 querySpecifications.add(Inv48.instance());
143 querySpecifications.add(X_inv48_notDis.instance());
144 querySpecifications.add(X_inv48_Dis.instance());
145 querySpecifications.add(X_inv48_3.instance());
146 querySpecifications.add(Inv49.instance());
147 querySpecifications.add(X_inv49_1.instance());
148 querySpecifications.add(X_inv49_2.instance());
149 }
150
151 public Inv03 getInv03() {
152 return Inv03.instance();
153 }
154
155 public Inv03.Matcher getInv03(final ViatraQueryEngine engine) {
156 return Inv03.Matcher.on(engine);
157 }
158
159 public X_inv03_eligAll getX_inv03_eligAll() {
160 return X_inv03_eligAll.instance();
161 }
162
163 public X_inv03_eligAll.Matcher getX_inv03_eligAll(final ViatraQueryEngine engine) {
164 return X_inv03_eligAll.Matcher.on(engine);
165 }
166
167 public X_inv03_hasAll getX_inv03_hasAll() {
168 return X_inv03_hasAll.instance();
169 }
170
171 public X_inv03_hasAll.Matcher getX_inv03_hasAll(final ViatraQueryEngine engine) {
172 return X_inv03_hasAll.Matcher.on(engine);
173 }
174
175 public Inv05 getInv05() {
176 return Inv05.instance();
177 }
178
179 public Inv05.Matcher getInv05(final ViatraQueryEngine engine) {
180 return Inv05.Matcher.on(engine);
181 }
182
183 public X_inv05_inRange getX_inv05_inRange() {
184 return X_inv05_inRange.instance();
185 }
186
187 public X_inv05_inRange.Matcher getX_inv05_inRange(final ViatraQueryEngine engine) {
188 return X_inv05_inRange.Matcher.on(engine);
189 }
190
191 public Inv06 getInv06() {
192 return Inv06.instance();
193 }
194
195 public Inv06.Matcher getInv06(final ViatraQueryEngine engine) {
196 return Inv06.Matcher.on(engine);
197 }
198
199 public Inv07 getInv07() {
200 return Inv07.instance();
201 }
202
203 public Inv07.Matcher getInv07(final ViatraQueryEngine engine) {
204 return Inv07.Matcher.on(engine);
205 }
206
207 public Inv08 getInv08() {
208 return Inv08.instance();
209 }
210
211 public Inv08.Matcher getInv08(final ViatraQueryEngine engine) {
212 return Inv08.Matcher.on(engine);
213 }
214
215 public X_inv08_notEI getX_inv08_notEI() {
216 return X_inv08_notEI.instance();
217 }
218
219 public X_inv08_notEI.Matcher getX_inv08_notEI(final ViatraQueryEngine engine) {
220 return X_inv08_notEI.Matcher.on(engine);
221 }
222
223 public X_inv08_noType getX_inv08_noType() {
224 return X_inv08_noType.instance();
225 }
226
227 public X_inv08_noType.Matcher getX_inv08_noType(final ViatraQueryEngine engine) {
228 return X_inv08_noType.Matcher.on(engine);
229 }
230
231 public X_inv08_inRange getX_inv08_inRange() {
232 return X_inv08_inRange.instance();
233 }
234
235 public X_inv08_inRange.Matcher getX_inv08_inRange(final ViatraQueryEngine engine) {
236 return X_inv08_inRange.Matcher.on(engine);
237 }
238
239 public Inv10 getInv10() {
240 return Inv10.instance();
241 }
242
243 public Inv10.Matcher getInv10(final ViatraQueryEngine engine) {
244 return Inv10.Matcher.on(engine);
245 }
246
247 public Inv11 getInv11() {
248 return Inv11.instance();
249 }
250
251 public Inv11.Matcher getInv11(final ViatraQueryEngine engine) {
252 return Inv11.Matcher.on(engine);
253 }
254
255 public X_inv11_incOver100 getX_inv11_incOver100() {
256 return X_inv11_incOver100.instance();
257 }
258
259 public X_inv11_incOver100.Matcher getX_inv11_incOver100(final ViatraQueryEngine engine) {
260 return X_inv11_incOver100.Matcher.on(engine);
261 }
262
263 public X_inv11_incNotOver100 getX_inv11_incNotOver100() {
264 return X_inv11_incNotOver100.instance();
265 }
266
267 public X_inv11_incNotOver100.Matcher getX_inv11_incNotOver100(final ViatraQueryEngine engine) {
268 return X_inv11_incNotOver100.Matcher.on(engine);
269 }
270
271 public Inv12 getInv12() {
272 return Inv12.instance();
273 }
274
275 public Inv12.Matcher getInv12(final ViatraQueryEngine engine) {
276 return Inv12.Matcher.on(engine);
277 }
278
279 public X_inv12_notNonRes getX_inv12_notNonRes() {
280 return X_inv12_notNonRes.instance();
281 }
282
283 public X_inv12_notNonRes.Matcher getX_inv12_notNonRes(final ViatraQueryEngine engine) {
284 return X_inv12_notNonRes.Matcher.on(engine);
285 }
286
287 public X_inv12_notZZ getX_inv12_notZZ() {
288 return X_inv12_notZZ.instance();
289 }
290
291 public X_inv12_notZZ.Matcher getX_inv12_notZZ(final ViatraQueryEngine engine) {
292 return X_inv12_notZZ.Matcher.on(engine);
293 }
294
295 public Inv13 getInv13() {
296 return Inv13.instance();
297 }
298
299 public Inv13.Matcher getInv13(final ViatraQueryEngine engine) {
300 return Inv13.Matcher.on(engine);
301 }
302
303 public X_inv13 getX_inv13() {
304 return X_inv13.instance();
305 }
306
307 public X_inv13.Matcher getX_inv13(final ViatraQueryEngine engine) {
308 return X_inv13.Matcher.on(engine);
309 }
310
311 public Inv15 getInv15() {
312 return Inv15.instance();
313 }
314
315 public Inv15.Matcher getInv15(final ViatraQueryEngine engine) {
316 return Inv15.Matcher.on(engine);
317 }
318
319 public X_inv15 getX_inv15() {
320 return X_inv15.instance();
321 }
322
323 public X_inv15.Matcher getX_inv15(final ViatraQueryEngine engine) {
324 return X_inv15.Matcher.on(engine);
325 }
326
327 public Inv17 getInv17() {
328 return Inv17.instance();
329 }
330
331 public Inv17.Matcher getInv17(final ViatraQueryEngine engine) {
332 return Inv17.Matcher.on(engine);
333 }
334
335 public Inv20 getInv20() {
336 return Inv20.instance();
337 }
338
339 public Inv20.Matcher getInv20(final ViatraQueryEngine engine) {
340 return Inv20.Matcher.on(engine);
341 }
342
343 public Inv33 getInv33() {
344 return Inv33.instance();
345 }
346
347 public Inv33.Matcher getInv33(final ViatraQueryEngine engine) {
348 return Inv33.Matcher.on(engine);
349 }
350
351 public Inv34 getInv34() {
352 return Inv34.instance();
353 }
354
355 public Inv34.Matcher getInv34(final ViatraQueryEngine engine) {
356 return Inv34.Matcher.on(engine);
357 }
358
359 public Inv35 getInv35() {
360 return Inv35.instance();
361 }
362
363 public Inv35.Matcher getInv35(final ViatraQueryEngine engine) {
364 return Inv35.Matcher.on(engine);
365 }
366
367 public Inv47 getInv47() {
368 return Inv47.instance();
369 }
370
371 public Inv47.Matcher getInv47(final ViatraQueryEngine engine) {
372 return Inv47.Matcher.on(engine);
373 }
374
375 public X_inv47 getX_inv47() {
376 return X_inv47.instance();
377 }
378
379 public X_inv47.Matcher getX_inv47(final ViatraQueryEngine engine) {
380 return X_inv47.Matcher.on(engine);
381 }
382
383 public Inv48 getInv48() {
384 return Inv48.instance();
385 }
386
387 public Inv48.Matcher getInv48(final ViatraQueryEngine engine) {
388 return Inv48.Matcher.on(engine);
389 }
390
391 public X_inv48_notDis getX_inv48_notDis() {
392 return X_inv48_notDis.instance();
393 }
394
395 public X_inv48_notDis.Matcher getX_inv48_notDis(final ViatraQueryEngine engine) {
396 return X_inv48_notDis.Matcher.on(engine);
397 }
398
399 public X_inv48_Dis getX_inv48_Dis() {
400 return X_inv48_Dis.instance();
401 }
402
403 public X_inv48_Dis.Matcher getX_inv48_Dis(final ViatraQueryEngine engine) {
404 return X_inv48_Dis.Matcher.on(engine);
405 }
406
407 public X_inv48_3 getX_inv48_3() {
408 return X_inv48_3.instance();
409 }
410
411 public X_inv48_3.Matcher getX_inv48_3(final ViatraQueryEngine engine) {
412 return X_inv48_3.Matcher.on(engine);
413 }
414
415 public Inv49 getInv49() {
416 return Inv49.instance();
417 }
418
419 public Inv49.Matcher getInv49(final ViatraQueryEngine engine) {
420 return Inv49.Matcher.on(engine);
421 }
422
423 public X_inv49_1 getX_inv49_1() {
424 return X_inv49_1.instance();
425 }
426
427 public X_inv49_1.Matcher getX_inv49_1(final ViatraQueryEngine engine) {
428 return X_inv49_1.Matcher.on(engine);
429 }
430
431 public X_inv49_2 getX_inv49_2() {
432 return X_inv49_2.instance();
433 }
434
435 public X_inv49_2.Matcher getX_inv49_2(final ViatraQueryEngine engine) {
436 return X_inv49_2.Matcher.on(engine);
437 }
438}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv03.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv03.java
new file mode 100644
index 00000000..cfe496bd
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv03.java
@@ -0,0 +1,652 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Dependent;
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.basicdeferred.NegativePatternCall;
41import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue;
42import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
43import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
44import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
45import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
46import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
47import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
48import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
49import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
50import queries.X_inv03_eligAll;
51import queries.X_inv03_hasAll;
52
53/**
54 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
55 *
56 * <p>Original source:
57 * <code><pre>
58 * //AttributeRemoved -{@literal >} DF
59 *
60 * //inv1-External_Allowance.amount is a derived feature (TODOcheck)
61 * //inv2-Tax_Card.income.taxPayer.taxesDue is a derived feature (TODOcheck)
62 *
63 * //inv3-multiplicity adjusted
64 * {@literal @}Constraint(message = "inv03", severity = "error", key = {dep})
65 * pattern inv03(dep : Dependent) {
66 * find x_inv03_eligAll(dep);
67 * neg find x_inv03_hasAll(dep);
68 * } or {
69 * Dependent.birth_year(dep, by);
70 * check(2018-by {@literal >} 21);
71 * Dependent.continued_studies(dep, false);
72 * Dependent.allowances(dep, _);
73 * }
74 * </pre></code>
75 *
76 * @see Matcher
77 * @see Match
78 *
79 */
80@SuppressWarnings("all")
81public final class Inv03 extends BaseGeneratedEMFQuerySpecification<Inv03.Matcher> {
82 /**
83 * Pattern-specific match representation of the queries.inv03 pattern,
84 * to be used in conjunction with {@link Matcher}.
85 *
86 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
87 * Each instance is a (possibly partial) substitution of pattern parameters,
88 * usable to represent a match of the pattern in the result of a query,
89 * or to specify the bound (fixed) input parameters when issuing a query.
90 *
91 * @see Matcher
92 *
93 */
94 public static abstract class Match extends BasePatternMatch {
95 private Dependent fDep;
96
97 private static List<String> parameterNames = makeImmutableList("dep");
98
99 private Match(final Dependent pDep) {
100 this.fDep = pDep;
101 }
102
103 @Override
104 public Object get(final String parameterName) {
105 switch(parameterName) {
106 case "dep": return this.fDep;
107 default: return null;
108 }
109 }
110
111 @Override
112 public Object get(final int index) {
113 switch(index) {
114 case 0: return this.fDep;
115 default: return null;
116 }
117 }
118
119 public Dependent getDep() {
120 return this.fDep;
121 }
122
123 @Override
124 public boolean set(final String parameterName, final Object newValue) {
125 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
126 if ("dep".equals(parameterName) ) {
127 this.fDep = (Dependent) newValue;
128 return true;
129 }
130 return false;
131 }
132
133 public void setDep(final Dependent pDep) {
134 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
135 this.fDep = pDep;
136 }
137
138 @Override
139 public String patternName() {
140 return "queries.inv03";
141 }
142
143 @Override
144 public List<String> parameterNames() {
145 return Inv03.Match.parameterNames;
146 }
147
148 @Override
149 public Object[] toArray() {
150 return new Object[]{fDep};
151 }
152
153 @Override
154 public Inv03.Match toImmutable() {
155 return isMutable() ? newMatch(fDep) : this;
156 }
157
158 @Override
159 public String prettyPrint() {
160 StringBuilder result = new StringBuilder();
161 result.append("\"dep\"=" + prettyPrintValue(fDep));
162 return result.toString();
163 }
164
165 @Override
166 public int hashCode() {
167 return Objects.hash(fDep);
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 Inv03.Match)) {
178 Inv03.Match other = (Inv03.Match) obj;
179 return Objects.equals(fDep, other.fDep);
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 Inv03 specification() {
192 return Inv03.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 Inv03.Match newEmptyMatch() {
203 return new Mutable(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 pDep the fixed value of pattern parameter dep, or null if not bound.
211 * @return the new, mutable (partial) match object.
212 *
213 */
214 public static Inv03.Match newMutableMatch(final Dependent pDep) {
215 return new Mutable(pDep);
216 }
217
218 /**
219 * Returns a new (partial) match.
220 * This can be used e.g. to call the matcher with a partial match.
221 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
222 * @param pDep the fixed value of pattern parameter dep, or null if not bound.
223 * @return the (partial) match object.
224 *
225 */
226 public static Inv03.Match newMatch(final Dependent pDep) {
227 return new Immutable(pDep);
228 }
229
230 private static final class Mutable extends Inv03.Match {
231 Mutable(final Dependent pDep) {
232 super(pDep);
233 }
234
235 @Override
236 public boolean isMutable() {
237 return true;
238 }
239 }
240
241 private static final class Immutable extends Inv03.Match {
242 Immutable(final Dependent pDep) {
243 super(pDep);
244 }
245
246 @Override
247 public boolean isMutable() {
248 return false;
249 }
250 }
251 }
252
253 /**
254 * Generated pattern matcher API of the queries.inv03 pattern,
255 * providing pattern-specific query methods.
256 *
257 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
258 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
259 *
260 * <p>Matches of the pattern will be represented as {@link Match}.
261 *
262 * <p>Original source:
263 * <code><pre>
264 * //AttributeRemoved -{@literal >} DF
265 *
266 * //inv1-External_Allowance.amount is a derived feature (TODOcheck)
267 * //inv2-Tax_Card.income.taxPayer.taxesDue is a derived feature (TODOcheck)
268 *
269 * //inv3-multiplicity adjusted
270 * {@literal @}Constraint(message = "inv03", severity = "error", key = {dep})
271 * pattern inv03(dep : Dependent) {
272 * find x_inv03_eligAll(dep);
273 * neg find x_inv03_hasAll(dep);
274 * } or {
275 * Dependent.birth_year(dep, by);
276 * check(2018-by {@literal >} 21);
277 * Dependent.continued_studies(dep, false);
278 * Dependent.allowances(dep, _);
279 * }
280 * </pre></code>
281 *
282 * @see Match
283 * @see Inv03
284 *
285 */
286 public static class Matcher extends BaseMatcher<Inv03.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 Inv03.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 Inv03.Matcher create() {
311 return new Matcher();
312 }
313
314 private static final int POSITION_DEP = 0;
315
316 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv03.Matcher.class);
317
318 /**
319 * Initializes the pattern matcher within an existing VIATRA Query engine.
320 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
321 *
322 * @param engine the existing VIATRA Query engine in which this matcher will be created.
323 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
324 *
325 */
326 private Matcher() {
327 super(querySpecification());
328 }
329
330 /**
331 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
332 * @param pDep the fixed value of pattern parameter dep, or null if not bound.
333 * @return matches represented as a Match object.
334 *
335 */
336 public Collection<Inv03.Match> getAllMatches(final Dependent pDep) {
337 return rawStreamAllMatches(new Object[]{pDep}).collect(Collectors.toSet());
338 }
339
340 /**
341 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
342 * </p>
343 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
344 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
345 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
346 * @param pDep the fixed value of pattern parameter dep, or null if not bound.
347 * @return a stream of matches represented as a Match object.
348 *
349 */
350 public Stream<Inv03.Match> streamAllMatches(final Dependent pDep) {
351 return rawStreamAllMatches(new Object[]{pDep});
352 }
353
354 /**
355 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
356 * Neither determinism nor randomness of selection is guaranteed.
357 * @param pDep the fixed value of pattern parameter dep, or null if not bound.
358 * @return a match represented as a Match object, or null if no match is found.
359 *
360 */
361 public Optional<Inv03.Match> getOneArbitraryMatch(final Dependent pDep) {
362 return rawGetOneArbitraryMatch(new Object[]{pDep});
363 }
364
365 /**
366 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
367 * under any possible substitution of the unspecified parameters (if any).
368 * @param pDep the fixed value of pattern parameter dep, or null if not bound.
369 * @return true if the input is a valid (partial) match of the pattern.
370 *
371 */
372 public boolean hasMatch(final Dependent pDep) {
373 return rawHasMatch(new Object[]{pDep});
374 }
375
376 /**
377 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
378 * @param pDep the fixed value of pattern parameter dep, or null if not bound.
379 * @return the number of pattern matches found.
380 *
381 */
382 public int countMatches(final Dependent pDep) {
383 return rawCountMatches(new Object[]{pDep});
384 }
385
386 /**
387 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
388 * Neither determinism nor randomness of selection is guaranteed.
389 * @param pDep the fixed value of pattern parameter dep, 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 Dependent pDep, final Consumer<? super Inv03.Match> processor) {
395 return rawForOneArbitraryMatch(new Object[]{pDep}, 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 pDep the fixed value of pattern parameter dep, or null if not bound.
403 * @return the (partial) match object.
404 *
405 */
406 public Inv03.Match newMatch(final Dependent pDep) {
407 return Inv03.Match.newMatch(pDep);
408 }
409
410 /**
411 * Retrieve the set of values that occur in matches for dep.
412 * @return the Set of all values or empty set if there are no matches
413 *
414 */
415 protected Stream<Dependent> rawStreamAllValuesOfdep(final Object[] parameters) {
416 return rawStreamAllValues(POSITION_DEP, parameters).map(Dependent.class::cast);
417 }
418
419 /**
420 * Retrieve the set of values that occur in matches for dep.
421 * @return the Set of all values or empty set if there are no matches
422 *
423 */
424 public Set<Dependent> getAllValuesOfdep() {
425 return rawStreamAllValuesOfdep(emptyArray()).collect(Collectors.toSet());
426 }
427
428 /**
429 * Retrieve the set of values that occur in matches for dep.
430 * @return the Set of all values or empty set if there are no matches
431 *
432 */
433 public Stream<Dependent> streamAllValuesOfdep() {
434 return rawStreamAllValuesOfdep(emptyArray());
435 }
436
437 @Override
438 protected Inv03.Match tupleToMatch(final Tuple t) {
439 try {
440 return Inv03.Match.newMatch((Dependent) t.get(POSITION_DEP));
441 } catch(ClassCastException e) {
442 LOGGER.error("Element(s) in tuple not properly typed!",e);
443 return null;
444 }
445 }
446
447 @Override
448 protected Inv03.Match arrayToMatch(final Object[] match) {
449 try {
450 return Inv03.Match.newMatch((Dependent) match[POSITION_DEP]);
451 } catch(ClassCastException e) {
452 LOGGER.error("Element(s) in array not properly typed!",e);
453 return null;
454 }
455 }
456
457 @Override
458 protected Inv03.Match arrayToMatchMutable(final Object[] match) {
459 try {
460 return Inv03.Match.newMutableMatch((Dependent) match[POSITION_DEP]);
461 } catch(ClassCastException e) {
462 LOGGER.error("Element(s) in array not properly typed!",e);
463 return null;
464 }
465 }
466
467 /**
468 * @return the singleton instance of the query specification of this pattern
469 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
470 *
471 */
472 public static IQuerySpecification<Inv03.Matcher> querySpecification() {
473 return Inv03.instance();
474 }
475 }
476
477 private Inv03() {
478 super(GeneratedPQuery.INSTANCE);
479 }
480
481 /**
482 * @return the singleton instance of the query specification
483 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
484 *
485 */
486 public static Inv03 instance() {
487 try{
488 return LazyHolder.INSTANCE;
489 } catch (ExceptionInInitializerError err) {
490 throw processInitializerError(err);
491 }
492 }
493
494 @Override
495 protected Inv03.Matcher instantiate(final ViatraQueryEngine engine) {
496 return Inv03.Matcher.on(engine);
497 }
498
499 @Override
500 public Inv03.Matcher instantiate() {
501 return Inv03.Matcher.create();
502 }
503
504 @Override
505 public Inv03.Match newEmptyMatch() {
506 return Inv03.Match.newEmptyMatch();
507 }
508
509 @Override
510 public Inv03.Match newMatch(final Object... parameters) {
511 return Inv03.Match.newMatch((Taxation.Dependent) parameters[0]);
512 }
513
514 /**
515 * Inner class allowing the singleton instance of {@link Inv03} to be created
516 * <b>not</b> at the class load time of the outer class,
517 * but rather at the first call to {@link Inv03#instance()}.
518 *
519 * <p> This workaround is required e.g. to support recursion.
520 *
521 */
522 private static class LazyHolder {
523 private static final Inv03 INSTANCE = new Inv03();
524
525 /**
526 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
527 * This initialization order is required to support indirect recursion.
528 *
529 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
530 *
531 */
532 private static final Object STATIC_INITIALIZER = ensureInitialized();
533
534 public static Object ensureInitialized() {
535 INSTANCE.ensureInitializedInternal();
536 return null;
537 }
538 }
539
540 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
541 private static final Inv03.GeneratedPQuery INSTANCE = new GeneratedPQuery();
542
543 private final PParameter parameter_dep = new PParameter("dep", "Taxation.Dependent", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Dependent")), PParameterDirection.INOUT);
544
545 private final List<PParameter> parameters = Arrays.asList(parameter_dep);
546
547 private GeneratedPQuery() {
548 super(PVisibility.PUBLIC);
549 }
550
551 @Override
552 public String getFullyQualifiedName() {
553 return "queries.inv03";
554 }
555
556 @Override
557 public List<String> getParameterNames() {
558 return Arrays.asList("dep");
559 }
560
561 @Override
562 public List<PParameter> getParameters() {
563 return parameters;
564 }
565
566 @Override
567 public Set<PBody> doGetContainedBodies() {
568 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
569 Set<PBody> bodies = new LinkedHashSet<>();
570 {
571 PBody body = new PBody(this);
572 PVariable var_dep = body.getOrCreateVariableByName("dep");
573 new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
574 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
575 new ExportedParameter(body, var_dep, parameter_dep)
576 ));
577 // find x_inv03_eligAll(dep)
578 new PositivePatternCall(body, Tuples.flatTupleOf(var_dep), X_inv03_eligAll.instance().getInternalQueryRepresentation());
579 // neg find x_inv03_hasAll(dep)
580 new NegativePatternCall(body, Tuples.flatTupleOf(var_dep), X_inv03_hasAll.instance().getInternalQueryRepresentation());
581 bodies.add(body);
582 }
583 {
584 PBody body = new PBody(this);
585 PVariable var_dep = body.getOrCreateVariableByName("dep");
586 PVariable var_by = body.getOrCreateVariableByName("by");
587 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
588 new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
589 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
590 new ExportedParameter(body, var_dep, parameter_dep)
591 ));
592 // Dependent.birth_year(dep, by)
593 new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
594 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
595 new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year")));
596 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
597 new Equality(body, var__virtual_0_, var_by);
598 // check(2018-by > 21)
599 new ExpressionEvaluation(body, new IExpressionEvaluator() {
600
601 @Override
602 public String getShortDescription() {
603 return "Expression evaluation from pattern inv03";
604 }
605
606 @Override
607 public Iterable<String> getInputParameterNames() {
608 return Arrays.asList("by");}
609
610 @Override
611 public Object evaluateExpression(IValueProvider provider) throws Exception {
612 Integer by = (Integer) provider.getValue("by");
613 return evaluateExpression_2_1(by);
614 }
615 }, null);
616 // Dependent.continued_studies(dep, false)
617 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
618 new ConstantValue(body, var__virtual_1_, false);
619 new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
620 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
621 new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Dependent", "continued_studies")));
622 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EBoolean")));
623 new Equality(body, var__virtual_2_, var__virtual_1_);
624 // Dependent.allowances(dep, _)
625 new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
626 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
627 new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Dependent", "allowances")));
628 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance")));
629 new Equality(body, var__virtual_3_, var___0_);
630 bodies.add(body);
631 }
632 {
633 PAnnotation annotation = new PAnnotation("Constraint");
634 annotation.addAttribute("message", "inv03");
635 annotation.addAttribute("severity", "error");
636 annotation.addAttribute("key", Arrays.asList(new Object[] {
637 new ParameterReference("dep")
638 }));
639 addAnnotation(annotation);
640 }
641 return bodies;
642 }
643 }
644
645 private static boolean evaluateExpression_2_1(final Integer by) {
646 return ((2018 - (by).intValue()) > 21);
647 }
648
649 private static boolean evaluateExpression_2_2() {
650 return false;
651 }
652}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv05.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv05.java
new file mode 100644
index 00000000..ba1f8552
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv05.java
@@ -0,0 +1,701 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Income;
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.basicdeferred.NegativePatternCall;
41import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
42import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
43import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
44import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
45import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
46import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
47import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
48import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
49import queries.X_inv05_inRange;
50import queries.X_inv08_noType;
51import queries.X_inv08_notEI;
52
53/**
54 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
55 *
56 * <p>Original source:
57 * <code><pre>
58 * //inv5 - oclIsTypeOf - handled here
59 * {@literal @}Constraint(message = "inv05", severity = "error", key = {inc})
60 * pattern inv05(inc : Income) {
61 * //income_type: None
62 * neg find x_inv08_noType(inc);
63 * Income.details.worked_days(inc, wd);
64 * check(wd != 0);
65 * } or {
66 * //income_type: Not Employment_Income
67 * Income.income_type(inc, type);
68 * neg find x_inv08_notEI(type);
69 * Income.details.worked_days(inc, wd);
70 * check(wd != 0);
71 * } or {
72 * //income_type: Employment Income
73 * Income.income_type(inc, type);
74 * Employment_Income(type);
75 * find x_inv05_inRange(inc);
76 * }
77 * </pre></code>
78 *
79 * @see Matcher
80 * @see Match
81 *
82 */
83@SuppressWarnings("all")
84public final class Inv05 extends BaseGeneratedEMFQuerySpecification<Inv05.Matcher> {
85 /**
86 * Pattern-specific match representation of the queries.inv05 pattern,
87 * to be used in conjunction with {@link Matcher}.
88 *
89 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
90 * Each instance is a (possibly partial) substitution of pattern parameters,
91 * usable to represent a match of the pattern in the result of a query,
92 * or to specify the bound (fixed) input parameters when issuing a query.
93 *
94 * @see Matcher
95 *
96 */
97 public static abstract class Match extends BasePatternMatch {
98 private Income fInc;
99
100 private static List<String> parameterNames = makeImmutableList("inc");
101
102 private Match(final Income pInc) {
103 this.fInc = pInc;
104 }
105
106 @Override
107 public Object get(final String parameterName) {
108 switch(parameterName) {
109 case "inc": return this.fInc;
110 default: return null;
111 }
112 }
113
114 @Override
115 public Object get(final int index) {
116 switch(index) {
117 case 0: return this.fInc;
118 default: return null;
119 }
120 }
121
122 public Income getInc() {
123 return this.fInc;
124 }
125
126 @Override
127 public boolean set(final String parameterName, final Object newValue) {
128 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
129 if ("inc".equals(parameterName) ) {
130 this.fInc = (Income) newValue;
131 return true;
132 }
133 return false;
134 }
135
136 public void setInc(final Income pInc) {
137 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
138 this.fInc = pInc;
139 }
140
141 @Override
142 public String patternName() {
143 return "queries.inv05";
144 }
145
146 @Override
147 public List<String> parameterNames() {
148 return Inv05.Match.parameterNames;
149 }
150
151 @Override
152 public Object[] toArray() {
153 return new Object[]{fInc};
154 }
155
156 @Override
157 public Inv05.Match toImmutable() {
158 return isMutable() ? newMatch(fInc) : this;
159 }
160
161 @Override
162 public String prettyPrint() {
163 StringBuilder result = new StringBuilder();
164 result.append("\"inc\"=" + prettyPrintValue(fInc));
165 return result.toString();
166 }
167
168 @Override
169 public int hashCode() {
170 return Objects.hash(fInc);
171 }
172
173 @Override
174 public boolean equals(final Object obj) {
175 if (this == obj)
176 return true;
177 if (obj == null) {
178 return false;
179 }
180 if ((obj instanceof Inv05.Match)) {
181 Inv05.Match other = (Inv05.Match) obj;
182 return Objects.equals(fInc, other.fInc);
183 } else {
184 // this should be infrequent
185 if (!(obj instanceof IPatternMatch)) {
186 return false;
187 }
188 IPatternMatch otherSig = (IPatternMatch) obj;
189 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
190 }
191 }
192
193 @Override
194 public Inv05 specification() {
195 return Inv05.instance();
196 }
197
198 /**
199 * Returns an empty, mutable match.
200 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
201 *
202 * @return the empty match.
203 *
204 */
205 public static Inv05.Match newEmptyMatch() {
206 return new Mutable(null);
207 }
208
209 /**
210 * Returns a mutable (partial) match.
211 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
212 *
213 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
214 * @return the new, mutable (partial) match object.
215 *
216 */
217 public static Inv05.Match newMutableMatch(final Income pInc) {
218 return new Mutable(pInc);
219 }
220
221 /**
222 * Returns a new (partial) match.
223 * This can be used e.g. to call the matcher with a partial match.
224 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
225 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
226 * @return the (partial) match object.
227 *
228 */
229 public static Inv05.Match newMatch(final Income pInc) {
230 return new Immutable(pInc);
231 }
232
233 private static final class Mutable extends Inv05.Match {
234 Mutable(final Income pInc) {
235 super(pInc);
236 }
237
238 @Override
239 public boolean isMutable() {
240 return true;
241 }
242 }
243
244 private static final class Immutable extends Inv05.Match {
245 Immutable(final Income pInc) {
246 super(pInc);
247 }
248
249 @Override
250 public boolean isMutable() {
251 return false;
252 }
253 }
254 }
255
256 /**
257 * Generated pattern matcher API of the queries.inv05 pattern,
258 * providing pattern-specific query methods.
259 *
260 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
261 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
262 *
263 * <p>Matches of the pattern will be represented as {@link Match}.
264 *
265 * <p>Original source:
266 * <code><pre>
267 * //inv5 - oclIsTypeOf - handled here
268 * {@literal @}Constraint(message = "inv05", severity = "error", key = {inc})
269 * pattern inv05(inc : Income) {
270 * //income_type: None
271 * neg find x_inv08_noType(inc);
272 * Income.details.worked_days(inc, wd);
273 * check(wd != 0);
274 * } or {
275 * //income_type: Not Employment_Income
276 * Income.income_type(inc, type);
277 * neg find x_inv08_notEI(type);
278 * Income.details.worked_days(inc, wd);
279 * check(wd != 0);
280 * } or {
281 * //income_type: Employment Income
282 * Income.income_type(inc, type);
283 * Employment_Income(type);
284 * find x_inv05_inRange(inc);
285 * }
286 * </pre></code>
287 *
288 * @see Match
289 * @see Inv05
290 *
291 */
292 public static class Matcher extends BaseMatcher<Inv05.Match> {
293 /**
294 * Initializes the pattern matcher within an existing VIATRA Query engine.
295 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
296 *
297 * @param engine the existing VIATRA Query engine in which this matcher will be created.
298 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
299 *
300 */
301 public static Inv05.Matcher on(final ViatraQueryEngine engine) {
302 // check if matcher already exists
303 Matcher matcher = engine.getExistingMatcher(querySpecification());
304 if (matcher == null) {
305 matcher = (Matcher)engine.getMatcher(querySpecification());
306 }
307 return matcher;
308 }
309
310 /**
311 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
312 * @return an initialized matcher
313 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
314 *
315 */
316 public static Inv05.Matcher create() {
317 return new Matcher();
318 }
319
320 private static final int POSITION_INC = 0;
321
322 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv05.Matcher.class);
323
324 /**
325 * Initializes the pattern matcher within an existing VIATRA Query engine.
326 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
327 *
328 * @param engine the existing VIATRA Query engine in which this matcher will be created.
329 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
330 *
331 */
332 private Matcher() {
333 super(querySpecification());
334 }
335
336 /**
337 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
338 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
339 * @return matches represented as a Match object.
340 *
341 */
342 public Collection<Inv05.Match> getAllMatches(final Income pInc) {
343 return rawStreamAllMatches(new Object[]{pInc}).collect(Collectors.toSet());
344 }
345
346 /**
347 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
348 * </p>
349 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
350 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
351 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
352 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
353 * @return a stream of matches represented as a Match object.
354 *
355 */
356 public Stream<Inv05.Match> streamAllMatches(final Income pInc) {
357 return rawStreamAllMatches(new Object[]{pInc});
358 }
359
360 /**
361 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
362 * Neither determinism nor randomness of selection is guaranteed.
363 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
364 * @return a match represented as a Match object, or null if no match is found.
365 *
366 */
367 public Optional<Inv05.Match> getOneArbitraryMatch(final Income pInc) {
368 return rawGetOneArbitraryMatch(new Object[]{pInc});
369 }
370
371 /**
372 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
373 * under any possible substitution of the unspecified parameters (if any).
374 * @param pInc the fixed value of pattern parameter inc, 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 Income pInc) {
379 return rawHasMatch(new Object[]{pInc});
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 pInc the fixed value of pattern parameter inc, or null if not bound.
385 * @return the number of pattern matches found.
386 *
387 */
388 public int countMatches(final Income pInc) {
389 return rawCountMatches(new Object[]{pInc});
390 }
391
392 /**
393 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
394 * Neither determinism nor randomness of selection is guaranteed.
395 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
396 * @param processor the action that will process the selected match.
397 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
398 *
399 */
400 public boolean forOneArbitraryMatch(final Income pInc, final Consumer<? super Inv05.Match> processor) {
401 return rawForOneArbitraryMatch(new Object[]{pInc}, processor);
402 }
403
404 /**
405 * Returns a new (partial) match.
406 * This can be used e.g. to call the matcher with a partial match.
407 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
408 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
409 * @return the (partial) match object.
410 *
411 */
412 public Inv05.Match newMatch(final Income pInc) {
413 return Inv05.Match.newMatch(pInc);
414 }
415
416 /**
417 * Retrieve the set of values that occur in matches for inc.
418 * @return the Set of all values or empty set if there are no matches
419 *
420 */
421 protected Stream<Income> rawStreamAllValuesOfinc(final Object[] parameters) {
422 return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast);
423 }
424
425 /**
426 * Retrieve the set of values that occur in matches for inc.
427 * @return the Set of all values or empty set if there are no matches
428 *
429 */
430 public Set<Income> getAllValuesOfinc() {
431 return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet());
432 }
433
434 /**
435 * Retrieve the set of values that occur in matches for inc.
436 * @return the Set of all values or empty set if there are no matches
437 *
438 */
439 public Stream<Income> streamAllValuesOfinc() {
440 return rawStreamAllValuesOfinc(emptyArray());
441 }
442
443 @Override
444 protected Inv05.Match tupleToMatch(final Tuple t) {
445 try {
446 return Inv05.Match.newMatch((Income) t.get(POSITION_INC));
447 } catch(ClassCastException e) {
448 LOGGER.error("Element(s) in tuple not properly typed!",e);
449 return null;
450 }
451 }
452
453 @Override
454 protected Inv05.Match arrayToMatch(final Object[] match) {
455 try {
456 return Inv05.Match.newMatch((Income) match[POSITION_INC]);
457 } catch(ClassCastException e) {
458 LOGGER.error("Element(s) in array not properly typed!",e);
459 return null;
460 }
461 }
462
463 @Override
464 protected Inv05.Match arrayToMatchMutable(final Object[] match) {
465 try {
466 return Inv05.Match.newMutableMatch((Income) match[POSITION_INC]);
467 } catch(ClassCastException e) {
468 LOGGER.error("Element(s) in array not properly typed!",e);
469 return null;
470 }
471 }
472
473 /**
474 * @return the singleton instance of the query specification of this pattern
475 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
476 *
477 */
478 public static IQuerySpecification<Inv05.Matcher> querySpecification() {
479 return Inv05.instance();
480 }
481 }
482
483 private Inv05() {
484 super(GeneratedPQuery.INSTANCE);
485 }
486
487 /**
488 * @return the singleton instance of the query specification
489 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
490 *
491 */
492 public static Inv05 instance() {
493 try{
494 return LazyHolder.INSTANCE;
495 } catch (ExceptionInInitializerError err) {
496 throw processInitializerError(err);
497 }
498 }
499
500 @Override
501 protected Inv05.Matcher instantiate(final ViatraQueryEngine engine) {
502 return Inv05.Matcher.on(engine);
503 }
504
505 @Override
506 public Inv05.Matcher instantiate() {
507 return Inv05.Matcher.create();
508 }
509
510 @Override
511 public Inv05.Match newEmptyMatch() {
512 return Inv05.Match.newEmptyMatch();
513 }
514
515 @Override
516 public Inv05.Match newMatch(final Object... parameters) {
517 return Inv05.Match.newMatch((Taxation.Income) parameters[0]);
518 }
519
520 /**
521 * Inner class allowing the singleton instance of {@link Inv05} to be created
522 * <b>not</b> at the class load time of the outer class,
523 * but rather at the first call to {@link Inv05#instance()}.
524 *
525 * <p> This workaround is required e.g. to support recursion.
526 *
527 */
528 private static class LazyHolder {
529 private static final Inv05 INSTANCE = new Inv05();
530
531 /**
532 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
533 * This initialization order is required to support indirect recursion.
534 *
535 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
536 *
537 */
538 private static final Object STATIC_INITIALIZER = ensureInitialized();
539
540 public static Object ensureInitialized() {
541 INSTANCE.ensureInitializedInternal();
542 return null;
543 }
544 }
545
546 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
547 private static final Inv05.GeneratedPQuery INSTANCE = new GeneratedPQuery();
548
549 private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT);
550
551 private final List<PParameter> parameters = Arrays.asList(parameter_inc);
552
553 private GeneratedPQuery() {
554 super(PVisibility.PUBLIC);
555 }
556
557 @Override
558 public String getFullyQualifiedName() {
559 return "queries.inv05";
560 }
561
562 @Override
563 public List<String> getParameterNames() {
564 return Arrays.asList("inc");
565 }
566
567 @Override
568 public List<PParameter> getParameters() {
569 return parameters;
570 }
571
572 @Override
573 public Set<PBody> doGetContainedBodies() {
574 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
575 Set<PBody> bodies = new LinkedHashSet<>();
576 {
577 PBody body = new PBody(this);
578 PVariable var_inc = body.getOrCreateVariableByName("inc");
579 PVariable var_wd = body.getOrCreateVariableByName("wd");
580 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
581 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
582 new ExportedParameter(body, var_inc, parameter_inc)
583 ));
584 // //income_type: None neg find x_inv08_noType(inc)
585 new NegativePatternCall(body, Tuples.flatTupleOf(var_inc), X_inv08_noType.instance().getInternalQueryRepresentation());
586 // Income.details.worked_days(inc, wd)
587 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
588 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
589 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details")));
590 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail")));
591 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
592 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "worked_days")));
593 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
594 new Equality(body, var__virtual_1_, var_wd);
595 // check(wd != 0)
596 new ExpressionEvaluation(body, new IExpressionEvaluator() {
597
598 @Override
599 public String getShortDescription() {
600 return "Expression evaluation from pattern inv05";
601 }
602
603 @Override
604 public Iterable<String> getInputParameterNames() {
605 return Arrays.asList("wd");}
606
607 @Override
608 public Object evaluateExpression(IValueProvider provider) throws Exception {
609 Integer wd = (Integer) provider.getValue("wd");
610 return evaluateExpression_1_1(wd);
611 }
612 }, null);
613 bodies.add(body);
614 }
615 {
616 PBody body = new PBody(this);
617 PVariable var_inc = body.getOrCreateVariableByName("inc");
618 PVariable var_type = body.getOrCreateVariableByName("type");
619 PVariable var_wd = body.getOrCreateVariableByName("wd");
620 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
621 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
622 new ExportedParameter(body, var_inc, parameter_inc)
623 ));
624 // //income_type: Not Employment_Income Income.income_type(inc, type)
625 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
626 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
627 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_type")));
628 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Type")));
629 new Equality(body, var__virtual_0_, var_type);
630 // neg find x_inv08_notEI(type)
631 new NegativePatternCall(body, Tuples.flatTupleOf(var_type), X_inv08_notEI.instance().getInternalQueryRepresentation());
632 // Income.details.worked_days(inc, wd)
633 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
634 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
635 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details")));
636 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail")));
637 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
638 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "worked_days")));
639 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
640 new Equality(body, var__virtual_2_, var_wd);
641 // check(wd != 0)
642 new ExpressionEvaluation(body, new IExpressionEvaluator() {
643
644 @Override
645 public String getShortDescription() {
646 return "Expression evaluation from pattern inv05";
647 }
648
649 @Override
650 public Iterable<String> getInputParameterNames() {
651 return Arrays.asList("wd");}
652
653 @Override
654 public Object evaluateExpression(IValueProvider provider) throws Exception {
655 Integer wd = (Integer) provider.getValue("wd");
656 return evaluateExpression_2_1(wd);
657 }
658 }, null);
659 bodies.add(body);
660 }
661 {
662 PBody body = new PBody(this);
663 PVariable var_inc = body.getOrCreateVariableByName("inc");
664 PVariable var_type = body.getOrCreateVariableByName("type");
665 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
666 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
667 new ExportedParameter(body, var_inc, parameter_inc)
668 ));
669 // //income_type: Employment Income Income.income_type(inc, type)
670 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
671 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
672 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_type")));
673 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Type")));
674 new Equality(body, var__virtual_0_, var_type);
675 // Employment_Income(type)
676 new TypeConstraint(body, Tuples.flatTupleOf(var_type), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Employment_Income")));
677 // find x_inv05_inRange(inc)
678 new PositivePatternCall(body, Tuples.flatTupleOf(var_inc), X_inv05_inRange.instance().getInternalQueryRepresentation());
679 bodies.add(body);
680 }
681 {
682 PAnnotation annotation = new PAnnotation("Constraint");
683 annotation.addAttribute("message", "inv05");
684 annotation.addAttribute("severity", "error");
685 annotation.addAttribute("key", Arrays.asList(new Object[] {
686 new ParameterReference("inc")
687 }));
688 addAnnotation(annotation);
689 }
690 return bodies;
691 }
692 }
693
694 private static boolean evaluateExpression_1_1(final Integer wd) {
695 return ((wd).intValue() != 0);
696 }
697
698 private static boolean evaluateExpression_2_1(final Integer wd) {
699 return ((wd).intValue() != 0);
700 }
701}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv06.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv06.java
new file mode 100644
index 00000000..fcf7ac89
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv06.java
@@ -0,0 +1,509 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Tax_Payer;
7import java.util.Arrays;
8import java.util.Collection;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Optional;
12import java.util.Set;
13import java.util.function.Consumer;
14import java.util.stream.Collectors;
15import java.util.stream.Stream;
16import org.apache.log4j.Logger;
17import org.eclipse.emf.ecore.EClass;
18import org.eclipse.emf.ecore.EDataType;
19import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
20import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
21import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
22import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
23import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
24import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
25import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
26import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey;
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.IExpressionEvaluator;
30import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
32import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
33import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
34import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
42import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
43import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
44import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
45
46/**
47 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
48 *
49 * <p>Original source:
50 * <code><pre>
51 * //inv6-Does not make sens, but directly from OCL
52 * //first part of or from definition of getAge()
53 * {@literal @}Constraint(message = "inv06", severity = "error", key = {tp})
54 * pattern inv06(tp : Tax_Payer) {
55 * Tax_Payer.dependents(tp, _);
56 * Tax_Payer.birth_year(tp, TPBy);
57 * check(2018 - TPBy {@literal >} 2018-16);
58 * } or {
59 * Tax_Payer.birth_year(tp, TPBy);
60 * Tax_Payer.dependents(tp, dep);
61 * Dependent.birth_year(dep, DepBy);
62 * check(2018-DepBy {@literal <}= 2018-TPBy-16);
63 * }
64 * </pre></code>
65 *
66 * @see Matcher
67 * @see Match
68 *
69 */
70@SuppressWarnings("all")
71public final class Inv06 extends BaseGeneratedEMFQuerySpecification<Inv06.Matcher> {
72 /**
73 * Pattern-specific match representation of the queries.inv06 pattern,
74 * to be used in conjunction with {@link Matcher}.
75 *
76 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
77 * Each instance is a (possibly partial) substitution of pattern parameters,
78 * usable to represent a match of the pattern in the result of a query,
79 * or to specify the bound (fixed) input parameters when issuing a query.
80 *
81 * @see Matcher
82 *
83 */
84 public static abstract class Match extends BasePatternMatch {
85 }
86
87 /**
88 * Generated pattern matcher API of the queries.inv06 pattern,
89 * providing pattern-specific query methods.
90 *
91 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
92 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
93 *
94 * <p>Matches of the pattern will be represented as {@link Match}.
95 *
96 * <p>Original source:
97 * <code><pre>
98 * //inv6-Does not make sens, but directly from OCL
99 * //first part of or from definition of getAge()
100 * {@literal @}Constraint(message = "inv06", severity = "error", key = {tp})
101 * pattern inv06(tp : Tax_Payer) {
102 * Tax_Payer.dependents(tp, _);
103 * Tax_Payer.birth_year(tp, TPBy);
104 * check(2018 - TPBy {@literal >} 2018-16);
105 * } or {
106 * Tax_Payer.birth_year(tp, TPBy);
107 * Tax_Payer.dependents(tp, dep);
108 * Dependent.birth_year(dep, DepBy);
109 * check(2018-DepBy {@literal <}= 2018-TPBy-16);
110 * }
111 * </pre></code>
112 *
113 * @see Match
114 * @see Inv06
115 *
116 */
117 public static class Matcher extends BaseMatcher<Inv06.Match> {
118 /**
119 * Initializes the pattern matcher within an existing VIATRA Query engine.
120 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
121 *
122 * @param engine the existing VIATRA Query engine in which this matcher will be created.
123 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
124 *
125 */
126 public static Inv06.Matcher on(final ViatraQueryEngine engine) {
127 // check if matcher already exists
128 Matcher matcher = engine.getExistingMatcher(querySpecification());
129 if (matcher == null) {
130 matcher = (Matcher)engine.getMatcher(querySpecification());
131 }
132 return matcher;
133 }
134
135 /**
136 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
137 * @return an initialized matcher
138 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
139 *
140 */
141 public static Inv06.Matcher create() {
142 return new Matcher();
143 }
144
145 private static final int POSITION_TP = 0;
146
147 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv06.Matcher.class);
148
149 /**
150 * Initializes the pattern matcher within an existing VIATRA Query engine.
151 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
152 *
153 * @param engine the existing VIATRA Query engine in which this matcher will be created.
154 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
155 *
156 */
157 private Matcher() {
158 super(querySpecification());
159 }
160
161 /**
162 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
163 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
164 * @return matches represented as a Match object.
165 *
166 */
167 public Collection<Inv06.Match> getAllMatches(final Tax_Payer pTp) {
168 return rawStreamAllMatches(new Object[]{pTp}).collect(Collectors.toSet());
169 }
170
171 /**
172 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
173 * </p>
174 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
175 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
176 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
177 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
178 * @return a stream of matches represented as a Match object.
179 *
180 */
181 public Stream<Inv06.Match> streamAllMatches(final Tax_Payer pTp) {
182 return rawStreamAllMatches(new Object[]{pTp});
183 }
184
185 /**
186 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
187 * Neither determinism nor randomness of selection is guaranteed.
188 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
189 * @return a match represented as a Match object, or null if no match is found.
190 *
191 */
192 public Optional<Inv06.Match> getOneArbitraryMatch();
193
194 /**
195 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
196 * under any possible substitution of the unspecified parameters (if any).
197 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
198 * @return true if the input is a valid (partial) match of the pattern.
199 *
200 */
201 public boolean hasMatch(final Tax_Payer pTp) {
202 return rawHasMatch(new Object[]{pTp});
203 }
204
205 /**
206 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
207 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
208 * @return the number of pattern matches found.
209 *
210 */
211 public int countMatches(final Tax_Payer pTp) {
212 return rawCountMatches(new Object[]{pTp});
213 }
214
215 /**
216 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
217 * Neither determinism nor randomness of selection is guaranteed.
218 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
219 * @param processor the action that will process the selected match.
220 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
221 *
222 */
223 public boolean forOneArbitraryMatch(final Tax_Payer pTp, final Consumer<? super Inv06.Match> processor) {
224 return rawForOneArbitraryMatch(new Object[]{pTp}, processor);
225 }
226
227 /**
228 * Returns a new (partial) match.
229 * This can be used e.g. to call the matcher with a partial match.
230 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
231 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
232 * @return the (partial) match object.
233 *
234 */
235 public Inv06.Match newMatch(final Tax_Payer pTp) {
236 return Inv06.Match.newMatch(pTp);
237 }
238
239 /**
240 * Retrieve the set of values that occur in matches for tp.
241 * @return the Set of all values or empty set if there are no matches
242 *
243 */
244 protected Stream<Tax_Payer> rawStreamAllValuesOftp(final Object[] parameters) {
245 return rawStreamAllValues(POSITION_TP, parameters).map(Tax_Payer.class::cast);
246 }
247
248 /**
249 * Retrieve the set of values that occur in matches for tp.
250 * @return the Set of all values or empty set if there are no matches
251 *
252 */
253 public Set<Tax_Payer> getAllValuesOftp() {
254 return rawStreamAllValuesOftp(emptyArray()).collect(Collectors.toSet());
255 }
256
257 /**
258 * Retrieve the set of values that occur in matches for tp.
259 * @return the Set of all values or empty set if there are no matches
260 *
261 */
262 public Stream<Tax_Payer> streamAllValuesOftp() {
263 return rawStreamAllValuesOftp(emptyArray());
264 }
265
266 @Override
267 protected Inv06.Match tupleToMatch(final Tuple t) {
268 try {
269 return Inv06.Match.newMatch((Tax_Payer) t.get(POSITION_TP));
270 } catch(ClassCastException e) {
271 LOGGER.error("Element(s) in tuple not properly typed!",e);
272 return null;
273 }
274 }
275
276 @Override
277 protected Inv06.Match arrayToMatch(final Object[] match) {
278 try {
279 return Inv06.Match.newMatch((Tax_Payer) match[POSITION_TP]);
280 } catch(ClassCastException e) {
281 LOGGER.error("Element(s) in array not properly typed!",e);
282 return null;
283 }
284 }
285
286 @Override
287 protected Inv06.Match arrayToMatchMutable(final Object[] match) {
288 try {
289 return Inv06.Match.newMutableMatch((Tax_Payer) match[POSITION_TP]);
290 } catch(ClassCastException e) {
291 LOGGER.error("Element(s) in array not properly typed!",e);
292 return null;
293 }
294 }
295
296 /**
297 * @return the singleton instance of the query specification of this pattern
298 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
299 *
300 */
301 public static IQuerySpecification<Inv06.Matcher> querySpecification() {
302 return Inv06.instance();
303 }
304 }
305
306 private Inv06() {
307 super(GeneratedPQuery.INSTANCE);
308 }
309
310 /**
311 * @return the singleton instance of the query specification
312 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
313 *
314 */
315 public static Inv06 instance() {
316 try{
317 return LazyHolder.INSTANCE;
318 } catch (ExceptionInInitializerError err) {
319 throw processInitializerError(err);
320 }
321 }
322
323 @Override
324 protected Inv06.Matcher instantiate(final ViatraQueryEngine engine) {
325 return Inv06.Matcher.on(engine);
326 }
327
328 @Override
329 public Inv06.Matcher instantiate() {
330 return Inv06.Matcher.create();
331 }
332
333 @Override
334 public Inv06.Match newEmptyMatch() {
335 return Inv06.Match.newEmptyMatch();
336 }
337
338 @Override
339 public Inv06.Match newMatch(final Object... parameters) {
340 return Inv06.Match.newMatch((Taxation.Tax_Payer) parameters[0]);
341 }
342
343 /**
344 * Inner class allowing the singleton instance of {@link Inv06} to be created
345 * <b>not</b> at the class load time of the outer class,
346 * but rather at the first call to {@link Inv06#instance()}.
347 *
348 * <p> This workaround is required e.g. to support recursion.
349 *
350 */
351 private static class LazyHolder {
352 private static final Inv06 INSTANCE = new Inv06();
353
354 /**
355 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
356 * This initialization order is required to support indirect recursion.
357 *
358 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
359 *
360 */
361 private static final Object STATIC_INITIALIZER = ensureInitialized();
362
363 public static Object ensureInitialized() {
364 INSTANCE.ensureInitializedInternal();
365 return null;
366 }
367 }
368
369 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
370 private static final Inv06.GeneratedPQuery INSTANCE = new GeneratedPQuery();
371
372 private final PParameter parameter_tp = new PParameter("tp", "Taxation.Tax_Payer", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Tax_Payer")), PParameterDirection.INOUT);
373
374 private final List<PParameter> parameters = Arrays.asList(parameter_tp);
375
376 private GeneratedPQuery() {
377 super(PVisibility.PUBLIC);
378 }
379
380 @Override
381 public String getFullyQualifiedName() {
382 return "queries.inv06";
383 }
384
385 @Override
386 public List<String> getParameterNames() {
387 return Arrays.asList("tp");
388 }
389
390 @Override
391 public List<PParameter> getParameters() {
392 return parameters;
393 }
394
395 @Override
396 public Set<PBody> doGetContainedBodies() {
397 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
398 Set<PBody> bodies = new LinkedHashSet<>();
399 {
400 PBody body = new PBody(this);
401 PVariable var_tp = body.getOrCreateVariableByName("tp");
402 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
403 PVariable var_TPBy = body.getOrCreateVariableByName("TPBy");
404 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
405 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
406 new ExportedParameter(body, var_tp, parameter_tp)
407 ));
408 // Tax_Payer.dependents(tp, _)
409 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
410 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
411 new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Tax_Payer", "dependents")));
412 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
413 new Equality(body, var__virtual_0_, var___0_);
414 // Tax_Payer.birth_year(tp, TPBy)
415 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
416 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
417 new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year")));
418 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
419 new Equality(body, var__virtual_1_, var_TPBy);
420 // check(2018 - TPBy > 2018-16)
421 new ExpressionEvaluation(body, new IExpressionEvaluator() {
422
423 @Override
424 public String getShortDescription() {
425 return "Expression evaluation from pattern inv06";
426 }
427
428 @Override
429 public Iterable<String> getInputParameterNames() {
430 return Arrays.asList("TPBy");}
431
432 @Override
433 public Object evaluateExpression(IValueProvider provider) throws Exception {
434 Integer TPBy = (Integer) provider.getValue("TPBy");
435 return evaluateExpression_1_1(TPBy);
436 }
437 }, null);
438 bodies.add(body);
439 }
440 {
441 PBody body = new PBody(this);
442 PVariable var_tp = body.getOrCreateVariableByName("tp");
443 PVariable var_TPBy = body.getOrCreateVariableByName("TPBy");
444 PVariable var_dep = body.getOrCreateVariableByName("dep");
445 PVariable var_DepBy = body.getOrCreateVariableByName("DepBy");
446 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
447 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
448 new ExportedParameter(body, var_tp, parameter_tp)
449 ));
450 // Tax_Payer.birth_year(tp, TPBy)
451 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
452 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
453 new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year")));
454 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
455 new Equality(body, var__virtual_0_, var_TPBy);
456 // Tax_Payer.dependents(tp, dep)
457 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
458 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
459 new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Tax_Payer", "dependents")));
460 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
461 new Equality(body, var__virtual_1_, var_dep);
462 // Dependent.birth_year(dep, DepBy)
463 new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
464 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
465 new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year")));
466 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
467 new Equality(body, var__virtual_2_, var_DepBy);
468 // check(2018-DepBy <= 2018-TPBy-16)
469 new ExpressionEvaluation(body, new IExpressionEvaluator() {
470
471 @Override
472 public String getShortDescription() {
473 return "Expression evaluation from pattern inv06";
474 }
475
476 @Override
477 public Iterable<String> getInputParameterNames() {
478 return Arrays.asList("DepBy", "TPBy");}
479
480 @Override
481 public Object evaluateExpression(IValueProvider provider) throws Exception {
482 Integer DepBy = (Integer) provider.getValue("DepBy");
483 Integer TPBy = (Integer) provider.getValue("TPBy");
484 return evaluateExpression_2_1(DepBy, TPBy);
485 }
486 }, null);
487 bodies.add(body);
488 }
489 {
490 PAnnotation annotation = new PAnnotation("Constraint");
491 annotation.addAttribute("message", "inv06");
492 annotation.addAttribute("severity", "error");
493 annotation.addAttribute("key", Arrays.asList(new Object[] {
494 new ParameterReference("tp")
495 }));
496 addAnnotation(annotation);
497 }
498 return bodies;
499 }
500 }
501
502 private static boolean evaluateExpression_1_1(final Integer TPBy) {
503 return ((2018 - (TPBy).intValue()) > (2018 - 16));
504 }
505
506 private static boolean evaluateExpression_2_1(final Integer DepBy, final Integer TPBy) {
507 return ((2018 - (DepBy).intValue()) <= ((2018 - (TPBy).intValue()) - 16));
508 }
509}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv07.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv07.java
new file mode 100644
index 00000000..d9fed653
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv07.java
@@ -0,0 +1,455 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Income;
7import com.google.common.base.Objects;
8import java.util.Arrays;
9import java.util.Collection;
10import java.util.LinkedHashSet;
11import java.util.List;
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.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.EDataTypeInSlotsKey;
28import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
29import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
30import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
31import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
32import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
33import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
34import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
35import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
39import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
42import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
43import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
44import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
45import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
46
47/**
48 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
49 *
50 * <p>Original source:
51 * <code><pre>
52 * //inv7-OrderedSet
53 * {@literal @}Constraint(message = "inv07", severity = "error", key = {inc})
54 * pattern inv07(inc : Income) {
55 * Income.details.distance(inc, d1);
56 * Income.details.distance(inc, d2);
57 * check(d1 != d2);//compare values
58 * }
59 * </pre></code>
60 *
61 * @see Matcher
62 * @see Match
63 *
64 */
65@SuppressWarnings("all")
66public final class Inv07 extends BaseGeneratedEMFQuerySpecification<Inv07.Matcher> {
67 /**
68 * Pattern-specific match representation of the queries.inv07 pattern,
69 * to be used in conjunction with {@link Matcher}.
70 *
71 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
72 * Each instance is a (possibly partial) substitution of pattern parameters,
73 * usable to represent a match of the pattern in the result of a query,
74 * or to specify the bound (fixed) input parameters when issuing a query.
75 *
76 * @see Matcher
77 *
78 */
79 public static abstract class Match extends BasePatternMatch {
80 }
81
82 /**
83 * Generated pattern matcher API of the queries.inv07 pattern,
84 * providing pattern-specific query methods.
85 *
86 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
87 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
88 *
89 * <p>Matches of the pattern will be represented as {@link Match}.
90 *
91 * <p>Original source:
92 * <code><pre>
93 * //inv7-OrderedSet
94 * {@literal @}Constraint(message = "inv07", severity = "error", key = {inc})
95 * pattern inv07(inc : Income) {
96 * Income.details.distance(inc, d1);
97 * Income.details.distance(inc, d2);
98 * check(d1 != d2);//compare values
99 * }
100 * </pre></code>
101 *
102 * @see Match
103 * @see Inv07
104 *
105 */
106 public static class Matcher extends BaseMatcher<Inv07.Match> {
107 /**
108 * Initializes the pattern matcher within an existing VIATRA Query engine.
109 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
110 *
111 * @param engine the existing VIATRA Query engine in which this matcher will be created.
112 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
113 *
114 */
115 public static Inv07.Matcher on(final ViatraQueryEngine engine) {
116 // check if matcher already exists
117 Matcher matcher = engine.getExistingMatcher(querySpecification());
118 if (matcher == null) {
119 matcher = (Matcher)engine.getMatcher(querySpecification());
120 }
121 return matcher;
122 }
123
124 /**
125 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
126 * @return an initialized matcher
127 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
128 *
129 */
130 public static Inv07.Matcher create() {
131 return new Matcher();
132 }
133
134 private static final int POSITION_INC = 0;
135
136 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv07.Matcher.class);
137
138 /**
139 * Initializes the pattern matcher within an existing VIATRA Query engine.
140 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
141 *
142 * @param engine the existing VIATRA Query engine in which this matcher will be created.
143 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
144 *
145 */
146 private Matcher() {
147 super(querySpecification());
148 }
149
150 /**
151 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
152 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
153 * @return matches represented as a Match object.
154 *
155 */
156 public Collection<Inv07.Match> getAllMatches(final Income pInc) {
157 return rawStreamAllMatches(new Object[]{pInc}).collect(Collectors.toSet());
158 }
159
160 /**
161 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
162 * </p>
163 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
164 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
165 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
166 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
167 * @return a stream of matches represented as a Match object.
168 *
169 */
170 public Stream<Inv07.Match> streamAllMatches(final Income pInc) {
171 return rawStreamAllMatches(new Object[]{pInc});
172 }
173
174 /**
175 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
176 * Neither determinism nor randomness of selection is guaranteed.
177 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
178 * @return a match represented as a Match object, or null if no match is found.
179 *
180 */
181 public Optional<Inv07.Match> getOneArbitraryMatch(final Income pInc) {
182 return rawGetOneArbitraryMatch(new Object[]{pInc});
183 }
184
185 /**
186 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
187 * under any possible substitution of the unspecified parameters (if any).
188 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
189 * @return true if the input is a valid (partial) match of the pattern.
190 *
191 */
192 public boolean hasMatch(final Income pInc) {
193 return rawHasMatch(new Object[]{pInc});
194 }
195
196 /**
197 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
198 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
199 * @return the number of pattern matches found.
200 *
201 */
202 public int countMatches(final Income pInc) {
203 return rawCountMatches(new Object[]{pInc});
204 }
205
206 /**
207 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
208 * Neither determinism nor randomness of selection is guaranteed.
209 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
210 * @param processor the action that will process the selected match.
211 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
212 *
213 */
214 public boolean forOneArbitraryMatch(final Income pInc, final Consumer<? super Inv07.Match> processor) {
215 return rawForOneArbitraryMatch(new Object[]{pInc}, processor);
216 }
217
218 /**
219 * Returns a new (partial) match.
220 * This can be used e.g. to call the matcher with a partial match.
221 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
222 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
223 * @return the (partial) match object.
224 *
225 */
226 public Inv07.Match newMatch(final Income pInc) {
227 return Inv07.Match.newMatch(pInc);
228 }
229
230 /**
231 * Retrieve the set of values that occur in matches for inc.
232 * @return the Set of all values or empty set if there are no matches
233 *
234 */
235 protected Stream<Income> rawStreamAllValuesOfinc(final Object[] parameters) {
236 return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast);
237 }
238
239 /**
240 * Retrieve the set of values that occur in matches for inc.
241 * @return the Set of all values or empty set if there are no matches
242 *
243 */
244 public Set<Income> getAllValuesOfinc() {
245 return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet());
246 }
247
248 /**
249 * Retrieve the set of values that occur in matches for inc.
250 * @return the Set of all values or empty set if there are no matches
251 *
252 */
253 public Stream<Income> streamAllValuesOfinc() {
254 return rawStreamAllValuesOfinc(emptyArray());
255 }
256
257 @Override
258 protected Inv07.Match tupleToMatch(final Tuple t) {
259 try {
260 return Inv07.Match.newMatch((Income) t.get(POSITION_INC));
261 } catch(ClassCastException e) {
262 LOGGER.error("Element(s) in tuple not properly typed!",e);
263 return null;
264 }
265 }
266
267 @Override
268 protected Inv07.Match arrayToMatch(final Object[] match) {
269 try {
270 return Inv07.Match.newMatch((Income) match[POSITION_INC]);
271 } catch(ClassCastException e) {
272 LOGGER.error("Element(s) in array not properly typed!",e);
273 return null;
274 }
275 }
276
277 @Override
278 protected Inv07.Match arrayToMatchMutable(final Object[] match) {
279 try {
280 return Inv07.Match.newMutableMatch((Income) match[POSITION_INC]);
281 } catch(ClassCastException e) {
282 LOGGER.error("Element(s) in array not properly typed!",e);
283 return null;
284 }
285 }
286
287 /**
288 * @return the singleton instance of the query specification of this pattern
289 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
290 *
291 */
292 public static IQuerySpecification<Inv07.Matcher> querySpecification() {
293 return Inv07.instance();
294 }
295 }
296
297 private Inv07() {
298 super(GeneratedPQuery.INSTANCE);
299 }
300
301 /**
302 * @return the singleton instance of the query specification
303 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
304 *
305 */
306 public static Inv07 instance() {
307 try{
308 return LazyHolder.INSTANCE;
309 } catch (ExceptionInInitializerError err) {
310 throw processInitializerError(err);
311 }
312 }
313
314 @Override
315 protected Inv07.Matcher instantiate(final ViatraQueryEngine engine) {
316 return Inv07.Matcher.on(engine);
317 }
318
319 @Override
320 public Inv07.Matcher instantiate() {
321 return Inv07.Matcher.create();
322 }
323
324 @Override
325 public Inv07.Match newEmptyMatch() {
326 return Inv07.Match.newEmptyMatch();
327 }
328
329 @Override
330 public Inv07.Match newMatch(final Object... parameters) {
331 return Inv07.Match.newMatch((Taxation.Income) parameters[0]);
332 }
333
334 /**
335 * Inner class allowing the singleton instance of {@link Inv07} to be created
336 * <b>not</b> at the class load time of the outer class,
337 * but rather at the first call to {@link Inv07#instance()}.
338 *
339 * <p> This workaround is required e.g. to support recursion.
340 *
341 */
342 private static class LazyHolder {
343 private static final Inv07 INSTANCE = new Inv07();
344
345 /**
346 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
347 * This initialization order is required to support indirect recursion.
348 *
349 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
350 *
351 */
352 private static final Object STATIC_INITIALIZER = ensureInitialized();
353
354 public static Object ensureInitialized() {
355 INSTANCE.ensureInitializedInternal();
356 return null;
357 }
358 }
359
360 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
361 private static final Inv07.GeneratedPQuery INSTANCE = new GeneratedPQuery();
362
363 private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT);
364
365 private final List<PParameter> parameters = Arrays.asList(parameter_inc);
366
367 private GeneratedPQuery() {
368 super(PVisibility.PUBLIC);
369 }
370
371 @Override
372 public String getFullyQualifiedName() {
373 return "queries.inv07";
374 }
375
376 @Override
377 public List<String> getParameterNames() {
378 return Arrays.asList("inc");
379 }
380
381 @Override
382 public List<PParameter> getParameters() {
383 return parameters;
384 }
385
386 @Override
387 public Set<PBody> doGetContainedBodies() {
388 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
389 Set<PBody> bodies = new LinkedHashSet<>();
390 {
391 PBody body = new PBody(this);
392 PVariable var_inc = body.getOrCreateVariableByName("inc");
393 PVariable var_d1 = body.getOrCreateVariableByName("d1");
394 PVariable var_d2 = body.getOrCreateVariableByName("d2");
395 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
396 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
397 new ExportedParameter(body, var_inc, parameter_inc)
398 ));
399 // Income.details.distance(inc, d1)
400 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
401 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
402 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details")));
403 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail")));
404 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
405 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "distance")));
406 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
407 new Equality(body, var__virtual_1_, var_d1);
408 // Income.details.distance(inc, d2)
409 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
410 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
411 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details")));
412 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail")));
413 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
414 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "distance")));
415 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
416 new Equality(body, var__virtual_3_, var_d2);
417 // check(d1 != d2)
418 new ExpressionEvaluation(body, new IExpressionEvaluator() {
419
420 @Override
421 public String getShortDescription() {
422 return "Expression evaluation from pattern inv07";
423 }
424
425 @Override
426 public Iterable<String> getInputParameterNames() {
427 return Arrays.asList("d1", "d2");}
428
429 @Override
430 public Object evaluateExpression(IValueProvider provider) throws Exception {
431 Double d1 = (Double) provider.getValue("d1");
432 Double d2 = (Double) provider.getValue("d2");
433 return evaluateExpression_1_1(d1, d2);
434 }
435 }, null);
436 bodies.add(body);
437 }
438 {
439 PAnnotation annotation = new PAnnotation("Constraint");
440 annotation.addAttribute("message", "inv07");
441 annotation.addAttribute("severity", "error");
442 annotation.addAttribute("key", Arrays.asList(new Object[] {
443 new ParameterReference("inc")
444 }));
445 addAnnotation(annotation);
446 }
447 return bodies;
448 }
449 }
450
451 private static boolean evaluateExpression_1_1(final Double d1, final Double d2) {
452 boolean _notEquals = (!Objects.equal(d1, d2));
453 return _notEquals;
454 }
455}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv08.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv08.java
new file mode 100644
index 00000000..d2f869c6
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv08.java
@@ -0,0 +1,705 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Income;
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.basicdeferred.NegativePatternCall;
41import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
42import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
43import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
44import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
45import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
46import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
47import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
48import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
49import queries.X_inv08_inRange;
50import queries.X_inv08_noType;
51import queries.X_inv08_notEI;
52
53/**
54 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
55 *
56 * <p>Original source:
57 * <code><pre>
58 * //user_complete_details-AttributeRemoved
59 *
60 * //inv8 - oclIsTypeOf - handled here
61 * {@literal @}Constraint(message = "inv08", severity = "error", key = {inc})
62 * pattern inv08(inc : Income) {
63 * //income_type: None
64 * neg find x_inv08_noType(inc);
65 * Income.details.distance(inc, dist);
66 * check(dist != 0);
67 * } or {
68 * //income_type: Not Employment_Income
69 * Income.income_type(inc, type);
70 * neg find x_inv08_notEI(type);
71 * Income.details.distance(inc, dist);
72 * check(dist != 0);
73 * } or {
74 * //income_type: Employment Income
75 * Income.income_type(inc, type);
76 * Employment_Income(type);
77 * find x_inv08_inRange(inc);
78 * }
79 * </pre></code>
80 *
81 * @see Matcher
82 * @see Match
83 *
84 */
85@SuppressWarnings("all")
86public final class Inv08 extends BaseGeneratedEMFQuerySpecification<Inv08.Matcher> {
87 /**
88 * Pattern-specific match representation of the queries.inv08 pattern,
89 * to be used in conjunction with {@link Matcher}.
90 *
91 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
92 * Each instance is a (possibly partial) substitution of pattern parameters,
93 * usable to represent a match of the pattern in the result of a query,
94 * or to specify the bound (fixed) input parameters when issuing a query.
95 *
96 * @see Matcher
97 *
98 */
99 public static abstract class Match extends BasePatternMatch {
100 private Income fInc;
101
102 private static List<String> parameterNames = makeImmutableList("inc");
103
104 private Match(final Income pInc) {
105 this.fInc = pInc;
106 }
107
108 @Override
109 public Object get(final String parameterName) {
110 switch(parameterName) {
111 case "inc": return this.fInc;
112 default: return null;
113 }
114 }
115
116 @Override
117 public Object get(final int index) {
118 switch(index) {
119 case 0: return this.fInc;
120 default: return null;
121 }
122 }
123
124 public Income getInc() {
125 return this.fInc;
126 }
127
128 @Override
129 public boolean set(final String parameterName, final Object newValue) {
130 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
131 if ("inc".equals(parameterName) ) {
132 this.fInc = (Income) newValue;
133 return true;
134 }
135 return false;
136 }
137
138 public void setInc(final Income pInc) {
139 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
140 this.fInc = pInc;
141 }
142
143 @Override
144 public String patternName() {
145 return "queries.inv08";
146 }
147
148 @Override
149 public List<String> parameterNames() {
150 return Inv08.Match.parameterNames;
151 }
152
153 @Override
154 public Object[] toArray() {
155 return new Object[]{fInc};
156 }
157
158 @Override
159 public Inv08.Match toImmutable() {
160 return isMutable() ? newMatch(fInc) : this;
161 }
162
163 @Override
164 public String prettyPrint() {
165 StringBuilder result = new StringBuilder();
166 result.append("\"inc\"=" + prettyPrintValue(fInc));
167 return result.toString();
168 }
169
170 @Override
171 public int hashCode() {
172 return Objects.hash(fInc);
173 }
174
175 @Override
176 public boolean equals(final Object obj) {
177 if (this == obj)
178 return true;
179 if (obj == null) {
180 return false;
181 }
182 if ((obj instanceof Inv08.Match)) {
183 Inv08.Match other = (Inv08.Match) obj;
184 return Objects.equals(fInc, other.fInc);
185 } else {
186 // this should be infrequent
187 if (!(obj instanceof IPatternMatch)) {
188 return false;
189 }
190 IPatternMatch otherSig = (IPatternMatch) obj;
191 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
192 }
193 }
194
195 @Override
196 public Inv08 specification() {
197 return Inv08.instance();
198 }
199
200 /**
201 * Returns an empty, mutable match.
202 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
203 *
204 * @return the empty match.
205 *
206 */
207 public static Inv08.Match newEmptyMatch() {
208 return new Mutable(null);
209 }
210
211 /**
212 * Returns a mutable (partial) match.
213 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
214 *
215 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
216 * @return the new, mutable (partial) match object.
217 *
218 */
219 public static Inv08.Match newMutableMatch(final Income pInc) {
220 return new Mutable(pInc);
221 }
222
223 /**
224 * Returns a new (partial) match.
225 * This can be used e.g. to call the matcher with a partial match.
226 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
227 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
228 * @return the (partial) match object.
229 *
230 */
231 public static Inv08.Match newMatch(final Income pInc) {
232 return new Immutable(pInc);
233 }
234
235 private static final class Mutable extends Inv08.Match {
236 Mutable(final Income pInc) {
237 super(pInc);
238 }
239
240 @Override
241 public boolean isMutable() {
242 return true;
243 }
244 }
245
246 private static final class Immutable extends Inv08.Match {
247 Immutable(final Income pInc) {
248 super(pInc);
249 }
250
251 @Override
252 public boolean isMutable() {
253 return false;
254 }
255 }
256 }
257
258 /**
259 * Generated pattern matcher API of the queries.inv08 pattern,
260 * providing pattern-specific query methods.
261 *
262 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
263 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
264 *
265 * <p>Matches of the pattern will be represented as {@link Match}.
266 *
267 * <p>Original source:
268 * <code><pre>
269 * //user_complete_details-AttributeRemoved
270 *
271 * //inv8 - oclIsTypeOf - handled here
272 * {@literal @}Constraint(message = "inv08", severity = "error", key = {inc})
273 * pattern inv08(inc : Income) {
274 * //income_type: None
275 * neg find x_inv08_noType(inc);
276 * Income.details.distance(inc, dist);
277 * check(dist != 0);
278 * } or {
279 * //income_type: Not Employment_Income
280 * Income.income_type(inc, type);
281 * neg find x_inv08_notEI(type);
282 * Income.details.distance(inc, dist);
283 * check(dist != 0);
284 * } or {
285 * //income_type: Employment Income
286 * Income.income_type(inc, type);
287 * Employment_Income(type);
288 * find x_inv08_inRange(inc);
289 * }
290 * </pre></code>
291 *
292 * @see Match
293 * @see Inv08
294 *
295 */
296 public static class Matcher extends BaseMatcher<Inv08.Match> {
297 /**
298 * Initializes the pattern matcher within an existing VIATRA Query engine.
299 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
300 *
301 * @param engine the existing VIATRA Query engine in which this matcher will be created.
302 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
303 *
304 */
305 public static Inv08.Matcher on(final ViatraQueryEngine engine) {
306 // check if matcher already exists
307 Matcher matcher = engine.getExistingMatcher(querySpecification());
308 if (matcher == null) {
309 matcher = (Matcher)engine.getMatcher(querySpecification());
310 }
311 return matcher;
312 }
313
314 /**
315 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
316 * @return an initialized matcher
317 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
318 *
319 */
320 public static Inv08.Matcher create() {
321 return new Matcher();
322 }
323
324 private static final int POSITION_INC = 0;
325
326 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv08.Matcher.class);
327
328 /**
329 * Initializes the pattern matcher within an existing VIATRA Query engine.
330 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
331 *
332 * @param engine the existing VIATRA Query engine in which this matcher will be created.
333 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
334 *
335 */
336 private Matcher() {
337 super(querySpecification());
338 }
339
340 /**
341 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
342 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
343 * @return matches represented as a Match object.
344 *
345 */
346 public Collection<Inv08.Match> getAllMatches(final Income pInc) {
347 return rawStreamAllMatches(new Object[]{pInc}).collect(Collectors.toSet());
348 }
349
350 /**
351 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
352 * </p>
353 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
354 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
355 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
356 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
357 * @return a stream of matches represented as a Match object.
358 *
359 */
360 public Stream<Inv08.Match> streamAllMatches(final Income pInc) {
361 return rawStreamAllMatches(new Object[]{pInc});
362 }
363
364 /**
365 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
366 * Neither determinism nor randomness of selection is guaranteed.
367 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
368 * @return a match represented as a Match object, or null if no match is found.
369 *
370 */
371 public Optional<Inv08.Match> getOneArbitraryMatch(final Income pInc) {
372 return rawGetOneArbitraryMatch(new Object[]{pInc});
373 }
374
375 /**
376 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
377 * under any possible substitution of the unspecified parameters (if any).
378 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
379 * @return true if the input is a valid (partial) match of the pattern.
380 *
381 */
382 public boolean hasMatch(final Income pInc) {
383 return rawHasMatch(new Object[]{pInc});
384 }
385
386 /**
387 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
388 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
389 * @return the number of pattern matches found.
390 *
391 */
392 public int countMatches(final Income pInc) {
393 return rawCountMatches(new Object[]{pInc});
394 }
395
396 /**
397 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
398 * Neither determinism nor randomness of selection is guaranteed.
399 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
400 * @param processor the action that will process the selected match.
401 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
402 *
403 */
404 public boolean forOneArbitraryMatch(final Income pInc, final Consumer<? super Inv08.Match> processor) {
405 return rawForOneArbitraryMatch(new Object[]{pInc}, processor);
406 }
407
408 /**
409 * Returns a new (partial) match.
410 * This can be used e.g. to call the matcher with a partial match.
411 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
412 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
413 * @return the (partial) match object.
414 *
415 */
416 public Inv08.Match newMatch(final Income pInc) {
417 return Inv08.Match.newMatch(pInc);
418 }
419
420 /**
421 * Retrieve the set of values that occur in matches for inc.
422 * @return the Set of all values or empty set if there are no matches
423 *
424 */
425 protected Stream<Income> rawStreamAllValuesOfinc(final Object[] parameters) {
426 return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast);
427 }
428
429 /**
430 * Retrieve the set of values that occur in matches for inc.
431 * @return the Set of all values or empty set if there are no matches
432 *
433 */
434 public Set<Income> getAllValuesOfinc() {
435 return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet());
436 }
437
438 /**
439 * Retrieve the set of values that occur in matches for inc.
440 * @return the Set of all values or empty set if there are no matches
441 *
442 */
443 public Stream<Income> streamAllValuesOfinc() {
444 return rawStreamAllValuesOfinc(emptyArray());
445 }
446
447 @Override
448 protected Inv08.Match tupleToMatch(final Tuple t) {
449 try {
450 return Inv08.Match.newMatch((Income) t.get(POSITION_INC));
451 } catch(ClassCastException e) {
452 LOGGER.error("Element(s) in tuple not properly typed!",e);
453 return null;
454 }
455 }
456
457 @Override
458 protected Inv08.Match arrayToMatch(final Object[] match) {
459 try {
460 return Inv08.Match.newMatch((Income) match[POSITION_INC]);
461 } catch(ClassCastException e) {
462 LOGGER.error("Element(s) in array not properly typed!",e);
463 return null;
464 }
465 }
466
467 @Override
468 protected Inv08.Match arrayToMatchMutable(final Object[] match) {
469 try {
470 return Inv08.Match.newMutableMatch((Income) match[POSITION_INC]);
471 } catch(ClassCastException e) {
472 LOGGER.error("Element(s) in array not properly typed!",e);
473 return null;
474 }
475 }
476
477 /**
478 * @return the singleton instance of the query specification of this pattern
479 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
480 *
481 */
482 public static IQuerySpecification<Inv08.Matcher> querySpecification() {
483 return Inv08.instance();
484 }
485 }
486
487 private Inv08() {
488 super(GeneratedPQuery.INSTANCE);
489 }
490
491 /**
492 * @return the singleton instance of the query specification
493 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
494 *
495 */
496 public static Inv08 instance() {
497 try{
498 return LazyHolder.INSTANCE;
499 } catch (ExceptionInInitializerError err) {
500 throw processInitializerError(err);
501 }
502 }
503
504 @Override
505 protected Inv08.Matcher instantiate(final ViatraQueryEngine engine) {
506 return Inv08.Matcher.on(engine);
507 }
508
509 @Override
510 public Inv08.Matcher instantiate() {
511 return Inv08.Matcher.create();
512 }
513
514 @Override
515 public Inv08.Match newEmptyMatch() {
516 return Inv08.Match.newEmptyMatch();
517 }
518
519 @Override
520 public Inv08.Match newMatch(final Object... parameters) {
521 return Inv08.Match.newMatch((Taxation.Income) parameters[0]);
522 }
523
524 /**
525 * Inner class allowing the singleton instance of {@link Inv08} to be created
526 * <b>not</b> at the class load time of the outer class,
527 * but rather at the first call to {@link Inv08#instance()}.
528 *
529 * <p> This workaround is required e.g. to support recursion.
530 *
531 */
532 private static class LazyHolder {
533 private static final Inv08 INSTANCE = new Inv08();
534
535 /**
536 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
537 * This initialization order is required to support indirect recursion.
538 *
539 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
540 *
541 */
542 private static final Object STATIC_INITIALIZER = ensureInitialized();
543
544 public static Object ensureInitialized() {
545 INSTANCE.ensureInitializedInternal();
546 return null;
547 }
548 }
549
550 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
551 private static final Inv08.GeneratedPQuery INSTANCE = new GeneratedPQuery();
552
553 private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT);
554
555 private final List<PParameter> parameters = Arrays.asList(parameter_inc);
556
557 private GeneratedPQuery() {
558 super(PVisibility.PUBLIC);
559 }
560
561 @Override
562 public String getFullyQualifiedName() {
563 return "queries.inv08";
564 }
565
566 @Override
567 public List<String> getParameterNames() {
568 return Arrays.asList("inc");
569 }
570
571 @Override
572 public List<PParameter> getParameters() {
573 return parameters;
574 }
575
576 @Override
577 public Set<PBody> doGetContainedBodies() {
578 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
579 Set<PBody> bodies = new LinkedHashSet<>();
580 {
581 PBody body = new PBody(this);
582 PVariable var_inc = body.getOrCreateVariableByName("inc");
583 PVariable var_dist = body.getOrCreateVariableByName("dist");
584 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
585 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
586 new ExportedParameter(body, var_inc, parameter_inc)
587 ));
588 // //income_type: None neg find x_inv08_noType(inc)
589 new NegativePatternCall(body, Tuples.flatTupleOf(var_inc), X_inv08_noType.instance().getInternalQueryRepresentation());
590 // Income.details.distance(inc, dist)
591 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
592 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
593 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details")));
594 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail")));
595 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
596 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "distance")));
597 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
598 new Equality(body, var__virtual_1_, var_dist);
599 // check(dist != 0)
600 new ExpressionEvaluation(body, new IExpressionEvaluator() {
601
602 @Override
603 public String getShortDescription() {
604 return "Expression evaluation from pattern inv08";
605 }
606
607 @Override
608 public Iterable<String> getInputParameterNames() {
609 return Arrays.asList("dist");}
610
611 @Override
612 public Object evaluateExpression(IValueProvider provider) throws Exception {
613 Double dist = (Double) provider.getValue("dist");
614 return evaluateExpression_1_1(dist);
615 }
616 }, null);
617 bodies.add(body);
618 }
619 {
620 PBody body = new PBody(this);
621 PVariable var_inc = body.getOrCreateVariableByName("inc");
622 PVariable var_type = body.getOrCreateVariableByName("type");
623 PVariable var_dist = body.getOrCreateVariableByName("dist");
624 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
625 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
626 new ExportedParameter(body, var_inc, parameter_inc)
627 ));
628 // //income_type: Not Employment_Income Income.income_type(inc, type)
629 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
630 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
631 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_type")));
632 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Type")));
633 new Equality(body, var__virtual_0_, var_type);
634 // neg find x_inv08_notEI(type)
635 new NegativePatternCall(body, Tuples.flatTupleOf(var_type), X_inv08_notEI.instance().getInternalQueryRepresentation());
636 // Income.details.distance(inc, dist)
637 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
638 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
639 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details")));
640 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail")));
641 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
642 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "distance")));
643 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
644 new Equality(body, var__virtual_2_, var_dist);
645 // check(dist != 0)
646 new ExpressionEvaluation(body, new IExpressionEvaluator() {
647
648 @Override
649 public String getShortDescription() {
650 return "Expression evaluation from pattern inv08";
651 }
652
653 @Override
654 public Iterable<String> getInputParameterNames() {
655 return Arrays.asList("dist");}
656
657 @Override
658 public Object evaluateExpression(IValueProvider provider) throws Exception {
659 Double dist = (Double) provider.getValue("dist");
660 return evaluateExpression_2_1(dist);
661 }
662 }, null);
663 bodies.add(body);
664 }
665 {
666 PBody body = new PBody(this);
667 PVariable var_inc = body.getOrCreateVariableByName("inc");
668 PVariable var_type = body.getOrCreateVariableByName("type");
669 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
670 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
671 new ExportedParameter(body, var_inc, parameter_inc)
672 ));
673 // //income_type: Employment Income Income.income_type(inc, type)
674 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
675 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
676 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_type")));
677 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Type")));
678 new Equality(body, var__virtual_0_, var_type);
679 // Employment_Income(type)
680 new TypeConstraint(body, Tuples.flatTupleOf(var_type), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Employment_Income")));
681 // find x_inv08_inRange(inc)
682 new PositivePatternCall(body, Tuples.flatTupleOf(var_inc), X_inv08_inRange.instance().getInternalQueryRepresentation());
683 bodies.add(body);
684 }
685 {
686 PAnnotation annotation = new PAnnotation("Constraint");
687 annotation.addAttribute("message", "inv08");
688 annotation.addAttribute("severity", "error");
689 annotation.addAttribute("key", Arrays.asList(new Object[] {
690 new ParameterReference("inc")
691 }));
692 addAnnotation(annotation);
693 }
694 return bodies;
695 }
696 }
697
698 private static boolean evaluateExpression_1_1(final Double dist) {
699 return ((dist).doubleValue() != 0);
700 }
701
702 private static boolean evaluateExpression_2_1(final Double dist) {
703 return ((dist).doubleValue() != 0);
704 }
705}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv10.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv10.java
new file mode 100644
index 00000000..3c36b831
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv10.java
@@ -0,0 +1,616 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Income;
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 * //inv9-DerivedFeature
54 *
55 * //inv10-Ordered Sets
56 * {@literal @}Constraint(message = "inv10", severity = "error", key = {inc})
57 * pattern inv10(inc : Income) {
58 * Income.details.amount(inc, a1);
59 * Income.details.amount(inc, a2);
60 * check(a1 != a2);//compare values
61 * }
62 * </pre></code>
63 *
64 * @see Matcher
65 * @see Match
66 *
67 */
68@SuppressWarnings("all")
69public final class Inv10 extends BaseGeneratedEMFQuerySpecification<Inv10.Matcher> {
70 /**
71 * Pattern-specific match representation of the queries.inv10 pattern,
72 * to be used in conjunction with {@link Matcher}.
73 *
74 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
75 * Each instance is a (possibly partial) substitution of pattern parameters,
76 * usable to represent a match of the pattern in the result of a query,
77 * or to specify the bound (fixed) input parameters when issuing a query.
78 *
79 * @see Matcher
80 *
81 */
82 public static abstract class Match extends BasePatternMatch {
83 private Income fInc;
84
85 private static List<String> parameterNames = makeImmutableList("inc");
86
87 private Match(final Income pInc) {
88 this.fInc = pInc;
89 }
90
91 @Override
92 public Object get(final String parameterName) {
93 switch(parameterName) {
94 case "inc": return this.fInc;
95 default: return null;
96 }
97 }
98
99 @Override
100 public Object get(final int index) {
101 switch(index) {
102 case 0: return this.fInc;
103 default: return null;
104 }
105 }
106
107 public Income getInc() {
108 return this.fInc;
109 }
110
111 @Override
112 public boolean set(final String parameterName, final Object newValue) {
113 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
114 if ("inc".equals(parameterName) ) {
115 this.fInc = (Income) newValue;
116 return true;
117 }
118 return false;
119 }
120
121 public void setInc(final Income pInc) {
122 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
123 this.fInc = pInc;
124 }
125
126 @Override
127 public String patternName() {
128 return "queries.inv10";
129 }
130
131 @Override
132 public List<String> parameterNames() {
133 return Inv10.Match.parameterNames;
134 }
135
136 @Override
137 public Object[] toArray() {
138 return new Object[]{fInc};
139 }
140
141 @Override
142 public Inv10.Match toImmutable() {
143 return isMutable() ? newMatch(fInc) : this;
144 }
145
146 @Override
147 public String prettyPrint() {
148 StringBuilder result = new StringBuilder();
149 result.append("\"inc\"=" + prettyPrintValue(fInc));
150 return result.toString();
151 }
152
153 @Override
154 public int hashCode() {
155 return Objects.hash(fInc);
156 }
157
158 @Override
159 public boolean equals(final Object obj) {
160 if (this == obj)
161 return true;
162 if (obj == null) {
163 return false;
164 }
165 if ((obj instanceof Inv10.Match)) {
166 Inv10.Match other = (Inv10.Match) obj;
167 return Objects.equals(fInc, other.fInc);
168 } else {
169 // this should be infrequent
170 if (!(obj instanceof IPatternMatch)) {
171 return false;
172 }
173 IPatternMatch otherSig = (IPatternMatch) obj;
174 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
175 }
176 }
177
178 @Override
179 public Inv10 specification() {
180 return Inv10.instance();
181 }
182
183 /**
184 * Returns an empty, mutable match.
185 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
186 *
187 * @return the empty match.
188 *
189 */
190 public static Inv10.Match newEmptyMatch() {
191 return new Mutable(null);
192 }
193
194 /**
195 * Returns a mutable (partial) match.
196 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
197 *
198 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
199 * @return the new, mutable (partial) match object.
200 *
201 */
202 public static Inv10.Match newMutableMatch(final Income pInc) {
203 return new Mutable(pInc);
204 }
205
206 /**
207 * Returns a new (partial) match.
208 * This can be used e.g. to call the matcher with a partial match.
209 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
210 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
211 * @return the (partial) match object.
212 *
213 */
214 public static Inv10.Match newMatch(final Income pInc) {
215 return new Immutable(pInc);
216 }
217
218 private static final class Mutable extends Inv10.Match {
219 Mutable(final Income pInc) {
220 super(pInc);
221 }
222
223 @Override
224 public boolean isMutable() {
225 return true;
226 }
227 }
228
229 private static final class Immutable extends Inv10.Match {
230 Immutable(final Income pInc) {
231 super(pInc);
232 }
233
234 @Override
235 public boolean isMutable() {
236 return false;
237 }
238 }
239 }
240
241 /**
242 * Generated pattern matcher API of the queries.inv10 pattern,
243 * providing pattern-specific query methods.
244 *
245 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
246 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
247 *
248 * <p>Matches of the pattern will be represented as {@link Match}.
249 *
250 * <p>Original source:
251 * <code><pre>
252 * //inv9-DerivedFeature
253 *
254 * //inv10-Ordered Sets
255 * {@literal @}Constraint(message = "inv10", severity = "error", key = {inc})
256 * pattern inv10(inc : Income) {
257 * Income.details.amount(inc, a1);
258 * Income.details.amount(inc, a2);
259 * check(a1 != a2);//compare values
260 * }
261 * </pre></code>
262 *
263 * @see Match
264 * @see Inv10
265 *
266 */
267 public static class Matcher extends BaseMatcher<Inv10.Match> {
268 /**
269 * Initializes the pattern matcher within an existing VIATRA Query engine.
270 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
271 *
272 * @param engine the existing VIATRA Query engine in which this matcher will be created.
273 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
274 *
275 */
276 public static Inv10.Matcher on(final ViatraQueryEngine engine) {
277 // check if matcher already exists
278 Matcher matcher = engine.getExistingMatcher(querySpecification());
279 if (matcher == null) {
280 matcher = (Matcher)engine.getMatcher(querySpecification());
281 }
282 return matcher;
283 }
284
285 /**
286 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
287 * @return an initialized matcher
288 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
289 *
290 */
291 public static Inv10.Matcher create() {
292 return new Matcher();
293 }
294
295 private static final int POSITION_INC = 0;
296
297 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv10.Matcher.class);
298
299 /**
300 * Initializes the pattern matcher within an existing VIATRA Query engine.
301 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
302 *
303 * @param engine the existing VIATRA Query engine in which this matcher will be created.
304 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
305 *
306 */
307 private Matcher() {
308 super(querySpecification());
309 }
310
311 /**
312 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
313 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
314 * @return matches represented as a Match object.
315 *
316 */
317 public Collection<Inv10.Match> getAllMatches(final Income pInc) {
318 return rawStreamAllMatches(new Object[]{pInc}).collect(Collectors.toSet());
319 }
320
321 /**
322 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
323 * </p>
324 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
325 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
326 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
327 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
328 * @return a stream of matches represented as a Match object.
329 *
330 */
331 public Stream<Inv10.Match> streamAllMatches(final Income pInc) {
332 return rawStreamAllMatches(new Object[]{pInc});
333 }
334
335 /**
336 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
337 * Neither determinism nor randomness of selection is guaranteed.
338 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
339 * @return a match represented as a Match object, or null if no match is found.
340 *
341 */
342 public Optional<Inv10.Match> getOneArbitraryMatch(final Income pInc) {
343 return rawGetOneArbitraryMatch(new Object[]{pInc});
344 }
345
346 /**
347 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
348 * under any possible substitution of the unspecified parameters (if any).
349 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
350 * @return true if the input is a valid (partial) match of the pattern.
351 *
352 */
353 public boolean hasMatch(final Income pInc) {
354 return rawHasMatch(new Object[]{pInc});
355 }
356
357 /**
358 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
359 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
360 * @return the number of pattern matches found.
361 *
362 */
363 public int countMatches(final Income pInc) {
364 return rawCountMatches(new Object[]{pInc});
365 }
366
367 /**
368 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
369 * Neither determinism nor randomness of selection is guaranteed.
370 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
371 * @param processor the action that will process the selected match.
372 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
373 *
374 */
375 public boolean forOneArbitraryMatch(final Income pInc, final Consumer<? super Inv10.Match> processor) {
376 return rawForOneArbitraryMatch(new Object[]{pInc}, processor);
377 }
378
379 /**
380 * Returns a new (partial) match.
381 * This can be used e.g. to call the matcher with a partial match.
382 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
383 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
384 * @return the (partial) match object.
385 *
386 */
387 public Inv10.Match newMatch(final Income pInc) {
388 return Inv10.Match.newMatch(pInc);
389 }
390
391 /**
392 * Retrieve the set of values that occur in matches for inc.
393 * @return the Set of all values or empty set if there are no matches
394 *
395 */
396 protected Stream<Income> rawStreamAllValuesOfinc(final Object[] parameters) {
397 return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast);
398 }
399
400 /**
401 * Retrieve the set of values that occur in matches for inc.
402 * @return the Set of all values or empty set if there are no matches
403 *
404 */
405 public Set<Income> getAllValuesOfinc() {
406 return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet());
407 }
408
409 /**
410 * Retrieve the set of values that occur in matches for inc.
411 * @return the Set of all values or empty set if there are no matches
412 *
413 */
414 public Stream<Income> streamAllValuesOfinc() {
415 return rawStreamAllValuesOfinc(emptyArray());
416 }
417
418 @Override
419 protected Inv10.Match tupleToMatch(final Tuple t) {
420 try {
421 return Inv10.Match.newMatch((Income) t.get(POSITION_INC));
422 } catch(ClassCastException e) {
423 LOGGER.error("Element(s) in tuple not properly typed!",e);
424 return null;
425 }
426 }
427
428 @Override
429 protected Inv10.Match arrayToMatch(final Object[] match) {
430 try {
431 return Inv10.Match.newMatch((Income) match[POSITION_INC]);
432 } catch(ClassCastException e) {
433 LOGGER.error("Element(s) in array not properly typed!",e);
434 return null;
435 }
436 }
437
438 @Override
439 protected Inv10.Match arrayToMatchMutable(final Object[] match) {
440 try {
441 return Inv10.Match.newMutableMatch((Income) match[POSITION_INC]);
442 } catch(ClassCastException e) {
443 LOGGER.error("Element(s) in array not properly typed!",e);
444 return null;
445 }
446 }
447
448 /**
449 * @return the singleton instance of the query specification of this pattern
450 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
451 *
452 */
453 public static IQuerySpecification<Inv10.Matcher> querySpecification() {
454 return Inv10.instance();
455 }
456 }
457
458 private Inv10() {
459 super(GeneratedPQuery.INSTANCE);
460 }
461
462 /**
463 * @return the singleton instance of the query specification
464 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
465 *
466 */
467 public static Inv10 instance() {
468 try{
469 return LazyHolder.INSTANCE;
470 } catch (ExceptionInInitializerError err) {
471 throw processInitializerError(err);
472 }
473 }
474
475 @Override
476 protected Inv10.Matcher instantiate(final ViatraQueryEngine engine) {
477 return Inv10.Matcher.on(engine);
478 }
479
480 @Override
481 public Inv10.Matcher instantiate() {
482 return Inv10.Matcher.create();
483 }
484
485 @Override
486 public Inv10.Match newEmptyMatch() {
487 return Inv10.Match.newEmptyMatch();
488 }
489
490 @Override
491 public Inv10.Match newMatch(final Object... parameters) {
492 return Inv10.Match.newMatch((Taxation.Income) parameters[0]);
493 }
494
495 /**
496 * Inner class allowing the singleton instance of {@link Inv10} to be created
497 * <b>not</b> at the class load time of the outer class,
498 * but rather at the first call to {@link Inv10#instance()}.
499 *
500 * <p> This workaround is required e.g. to support recursion.
501 *
502 */
503 private static class LazyHolder {
504 private static final Inv10 INSTANCE = new Inv10();
505
506 /**
507 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
508 * This initialization order is required to support indirect recursion.
509 *
510 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
511 *
512 */
513 private static final Object STATIC_INITIALIZER = ensureInitialized();
514
515 public static Object ensureInitialized() {
516 INSTANCE.ensureInitializedInternal();
517 return null;
518 }
519 }
520
521 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
522 private static final Inv10.GeneratedPQuery INSTANCE = new GeneratedPQuery();
523
524 private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT);
525
526 private final List<PParameter> parameters = Arrays.asList(parameter_inc);
527
528 private GeneratedPQuery() {
529 super(PVisibility.PUBLIC);
530 }
531
532 @Override
533 public String getFullyQualifiedName() {
534 return "queries.inv10";
535 }
536
537 @Override
538 public List<String> getParameterNames() {
539 return Arrays.asList("inc");
540 }
541
542 @Override
543 public List<PParameter> getParameters() {
544 return parameters;
545 }
546
547 @Override
548 public Set<PBody> doGetContainedBodies() {
549 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
550 Set<PBody> bodies = new LinkedHashSet<>();
551 {
552 PBody body = new PBody(this);
553 PVariable var_inc = body.getOrCreateVariableByName("inc");
554 PVariable var_a1 = body.getOrCreateVariableByName("a1");
555 PVariable var_a2 = body.getOrCreateVariableByName("a2");
556 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
557 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
558 new ExportedParameter(body, var_inc, parameter_inc)
559 ));
560 // Income.details.amount(inc, a1)
561 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
562 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
563 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details")));
564 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail")));
565 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
566 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "amount")));
567 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
568 new Equality(body, var__virtual_1_, var_a1);
569 // Income.details.amount(inc, a2)
570 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
571 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
572 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details")));
573 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail")));
574 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
575 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "amount")));
576 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
577 new Equality(body, var__virtual_3_, var_a2);
578 // check(a1 != a2)
579 new ExpressionEvaluation(body, new IExpressionEvaluator() {
580
581 @Override
582 public String getShortDescription() {
583 return "Expression evaluation from pattern inv10";
584 }
585
586 @Override
587 public Iterable<String> getInputParameterNames() {
588 return Arrays.asList("a1", "a2");}
589
590 @Override
591 public Object evaluateExpression(IValueProvider provider) throws Exception {
592 Double a1 = (Double) provider.getValue("a1");
593 Double a2 = (Double) provider.getValue("a2");
594 return evaluateExpression_1_1(a1, a2);
595 }
596 }, null);
597 bodies.add(body);
598 }
599 {
600 PAnnotation annotation = new PAnnotation("Constraint");
601 annotation.addAttribute("message", "inv10");
602 annotation.addAttribute("severity", "error");
603 annotation.addAttribute("key", Arrays.asList(new Object[] {
604 new ParameterReference("inc")
605 }));
606 addAnnotation(annotation);
607 }
608 return bodies;
609 }
610 }
611
612 private static boolean evaluateExpression_1_1(final Double a1, final Double a2) {
613 boolean _notEquals = (!com.google.common.base.Objects.equal(a1, a2));
614 return _notEquals;
615 }
616}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv11.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv11.java
new file mode 100644
index 00000000..a64ef7ff
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv11.java
@@ -0,0 +1,566 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Expense;
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.basicenumerables.PositivePatternCall;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
39import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
40import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
41import queries.X_inv11_incNotOver100;
42import queries.X_inv11_incOver100;
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 * //inv11-attributes-handled by multiplicity
50 * {@literal @}Constraint(message = "inv11", severity = "error", key = {exp})
51 * pattern inv11(exp : Expense) {
52 * find x_inv11_incOver100(exp);
53 * find x_inv11_incNotOver100(exp);
54 * }
55 * </pre></code>
56 *
57 * @see Matcher
58 * @see Match
59 *
60 */
61@SuppressWarnings("all")
62public final class Inv11 extends BaseGeneratedEMFQuerySpecification<Inv11.Matcher> {
63 /**
64 * Pattern-specific match representation of the queries.inv11 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 Expense fExp;
77
78 private static List<String> parameterNames = makeImmutableList("exp");
79
80 private Match(final Expense pExp) {
81 this.fExp = pExp;
82 }
83
84 @Override
85 public Object get(final String parameterName) {
86 switch(parameterName) {
87 case "exp": return this.fExp;
88 default: return null;
89 }
90 }
91
92 @Override
93 public Object get(final int index) {
94 switch(index) {
95 case 0: return this.fExp;
96 default: return null;
97 }
98 }
99
100 public Expense getExp() {
101 return this.fExp;
102 }
103
104 @Override
105 public boolean set(final String parameterName, final Object newValue) {
106 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
107 if ("exp".equals(parameterName) ) {
108 this.fExp = (Expense) newValue;
109 return true;
110 }
111 return false;
112 }
113
114 public void setExp(final Expense pExp) {
115 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
116 this.fExp = pExp;
117 }
118
119 @Override
120 public String patternName() {
121 return "queries.inv11";
122 }
123
124 @Override
125 public List<String> parameterNames() {
126 return Inv11.Match.parameterNames;
127 }
128
129 @Override
130 public Object[] toArray() {
131 return new Object[]{fExp};
132 }
133
134 @Override
135 public Inv11.Match toImmutable() {
136 return isMutable() ? newMatch(fExp) : this;
137 }
138
139 @Override
140 public String prettyPrint() {
141 StringBuilder result = new StringBuilder();
142 result.append("\"exp\"=" + prettyPrintValue(fExp));
143 return result.toString();
144 }
145
146 @Override
147 public int hashCode() {
148 return Objects.hash(fExp);
149 }
150
151 @Override
152 public boolean equals(final Object obj) {
153 if (this == obj)
154 return true;
155 if (obj == null) {
156 return false;
157 }
158 if ((obj instanceof Inv11.Match)) {
159 Inv11.Match other = (Inv11.Match) obj;
160 return Objects.equals(fExp, other.fExp);
161 } else {
162 // this should be infrequent
163 if (!(obj instanceof IPatternMatch)) {
164 return false;
165 }
166 IPatternMatch otherSig = (IPatternMatch) obj;
167 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
168 }
169 }
170
171 @Override
172 public Inv11 specification() {
173 return Inv11.instance();
174 }
175
176 /**
177 * Returns an empty, mutable match.
178 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
179 *
180 * @return the empty match.
181 *
182 */
183 public static Inv11.Match newEmptyMatch() {
184 return new Mutable(null);
185 }
186
187 /**
188 * Returns a mutable (partial) match.
189 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
190 *
191 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
192 * @return the new, mutable (partial) match object.
193 *
194 */
195 public static Inv11.Match newMutableMatch(final Expense pExp) {
196 return new Mutable(pExp);
197 }
198
199 /**
200 * Returns a new (partial) match.
201 * This can be used e.g. to call the matcher with a partial match.
202 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
203 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
204 * @return the (partial) match object.
205 *
206 */
207 public static Inv11.Match newMatch(final Expense pExp) {
208 return new Immutable(pExp);
209 }
210
211 private static final class Mutable extends Inv11.Match {
212 Mutable(final Expense pExp) {
213 super(pExp);
214 }
215
216 @Override
217 public boolean isMutable() {
218 return true;
219 }
220 }
221
222 private static final class Immutable extends Inv11.Match {
223 Immutable(final Expense pExp) {
224 super(pExp);
225 }
226
227 @Override
228 public boolean isMutable() {
229 return false;
230 }
231 }
232 }
233
234 /**
235 * Generated pattern matcher API of the queries.inv11 pattern,
236 * providing pattern-specific query methods.
237 *
238 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
239 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
240 *
241 * <p>Matches of the pattern will be represented as {@link Match}.
242 *
243 * <p>Original source:
244 * <code><pre>
245 * //inv11-attributes-handled by multiplicity
246 * {@literal @}Constraint(message = "inv11", severity = "error", key = {exp})
247 * pattern inv11(exp : Expense) {
248 * find x_inv11_incOver100(exp);
249 * find x_inv11_incNotOver100(exp);
250 * }
251 * </pre></code>
252 *
253 * @see Match
254 * @see Inv11
255 *
256 */
257 public static class Matcher extends BaseMatcher<Inv11.Match> {
258 /**
259 * Initializes the pattern matcher within an existing VIATRA Query engine.
260 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
261 *
262 * @param engine the existing VIATRA Query engine in which this matcher will be created.
263 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
264 *
265 */
266 public static Inv11.Matcher on(final ViatraQueryEngine engine) {
267 // check if matcher already exists
268 Matcher matcher = engine.getExistingMatcher(querySpecification());
269 if (matcher == null) {
270 matcher = (Matcher)engine.getMatcher(querySpecification());
271 }
272 return matcher;
273 }
274
275 /**
276 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
277 * @return an initialized matcher
278 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
279 *
280 */
281 public static Inv11.Matcher create() {
282 return new Matcher();
283 }
284
285 private static final int POSITION_EXP = 0;
286
287 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv11.Matcher.class);
288
289 /**
290 * Initializes the pattern matcher within an existing VIATRA Query engine.
291 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
292 *
293 * @param engine the existing VIATRA Query engine in which this matcher will be created.
294 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
295 *
296 */
297 private Matcher() {
298 super(querySpecification());
299 }
300
301 /**
302 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
303 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
304 * @return matches represented as a Match object.
305 *
306 */
307 public Collection<Inv11.Match> getAllMatches(final Expense pExp) {
308 return rawStreamAllMatches(new Object[]{pExp}).collect(Collectors.toSet());
309 }
310
311 /**
312 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
313 * </p>
314 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
315 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
316 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
317 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
318 * @return a stream of matches represented as a Match object.
319 *
320 */
321 public Stream<Inv11.Match> streamAllMatches(final Expense pExp) {
322 return rawStreamAllMatches(new Object[]{pExp});
323 }
324
325 /**
326 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
327 * Neither determinism nor randomness of selection is guaranteed.
328 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
329 * @return a match represented as a Match object, or null if no match is found.
330 *
331 */
332 public Optional<Inv11.Match> getOneArbitraryMatch(final Expense pExp) {
333 return rawGetOneArbitraryMatch(new Object[]{pExp});
334 }
335
336 /**
337 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
338 * under any possible substitution of the unspecified parameters (if any).
339 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
340 * @return true if the input is a valid (partial) match of the pattern.
341 *
342 */
343 public boolean hasMatch(final Expense pExp) {
344 return rawHasMatch(new Object[]{pExp});
345 }
346
347 /**
348 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
349 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
350 * @return the number of pattern matches found.
351 *
352 */
353 public int countMatches(final Expense pExp) {
354 return rawCountMatches(new Object[]{pExp});
355 }
356
357 /**
358 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
359 * Neither determinism nor randomness of selection is guaranteed.
360 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
361 * @param processor the action that will process the selected match.
362 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
363 *
364 */
365 public boolean forOneArbitraryMatch(final Expense pExp, final Consumer<? super Inv11.Match> processor) {
366 return rawForOneArbitraryMatch(new Object[]{pExp}, processor);
367 }
368
369 /**
370 * Returns a new (partial) match.
371 * This can be used e.g. to call the matcher with a partial match.
372 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
373 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
374 * @return the (partial) match object.
375 *
376 */
377 public Inv11.Match newMatch(final Expense pExp) {
378 return Inv11.Match.newMatch(pExp);
379 }
380
381 /**
382 * Retrieve the set of values that occur in matches for exp.
383 * @return the Set of all values or empty set if there are no matches
384 *
385 */
386 protected Stream<Expense> rawStreamAllValuesOfexp(final Object[] parameters) {
387 return rawStreamAllValues(POSITION_EXP, parameters).map(Expense.class::cast);
388 }
389
390 /**
391 * Retrieve the set of values that occur in matches for exp.
392 * @return the Set of all values or empty set if there are no matches
393 *
394 */
395 public Set<Expense> getAllValuesOfexp() {
396 return rawStreamAllValuesOfexp(emptyArray()).collect(Collectors.toSet());
397 }
398
399 /**
400 * Retrieve the set of values that occur in matches for exp.
401 * @return the Set of all values or empty set if there are no matches
402 *
403 */
404 public Stream<Expense> streamAllValuesOfexp() {
405 return rawStreamAllValuesOfexp(emptyArray());
406 }
407
408 @Override
409 protected Inv11.Match tupleToMatch(final Tuple t) {
410 try {
411 return Inv11.Match.newMatch((Expense) t.get(POSITION_EXP));
412 } catch(ClassCastException e) {
413 LOGGER.error("Element(s) in tuple not properly typed!",e);
414 return null;
415 }
416 }
417
418 @Override
419 protected Inv11.Match arrayToMatch(final Object[] match) {
420 try {
421 return Inv11.Match.newMatch((Expense) match[POSITION_EXP]);
422 } catch(ClassCastException e) {
423 LOGGER.error("Element(s) in array not properly typed!",e);
424 return null;
425 }
426 }
427
428 @Override
429 protected Inv11.Match arrayToMatchMutable(final Object[] match) {
430 try {
431 return Inv11.Match.newMutableMatch((Expense) match[POSITION_EXP]);
432 } catch(ClassCastException e) {
433 LOGGER.error("Element(s) in array not properly typed!",e);
434 return null;
435 }
436 }
437
438 /**
439 * @return the singleton instance of the query specification of this pattern
440 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
441 *
442 */
443 public static IQuerySpecification<Inv11.Matcher> querySpecification() {
444 return Inv11.instance();
445 }
446 }
447
448 private Inv11() {
449 super(GeneratedPQuery.INSTANCE);
450 }
451
452 /**
453 * @return the singleton instance of the query specification
454 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
455 *
456 */
457 public static Inv11 instance() {
458 try{
459 return LazyHolder.INSTANCE;
460 } catch (ExceptionInInitializerError err) {
461 throw processInitializerError(err);
462 }
463 }
464
465 @Override
466 protected Inv11.Matcher instantiate(final ViatraQueryEngine engine) {
467 return Inv11.Matcher.on(engine);
468 }
469
470 @Override
471 public Inv11.Matcher instantiate() {
472 return Inv11.Matcher.create();
473 }
474
475 @Override
476 public Inv11.Match newEmptyMatch() {
477 return Inv11.Match.newEmptyMatch();
478 }
479
480 @Override
481 public Inv11.Match newMatch(final Object... parameters) {
482 return Inv11.Match.newMatch((Taxation.Expense) parameters[0]);
483 }
484
485 /**
486 * Inner class allowing the singleton instance of {@link Inv11} to be created
487 * <b>not</b> at the class load time of the outer class,
488 * but rather at the first call to {@link Inv11#instance()}.
489 *
490 * <p> This workaround is required e.g. to support recursion.
491 *
492 */
493 private static class LazyHolder {
494 private static final Inv11 INSTANCE = new Inv11();
495
496 /**
497 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
498 * This initialization order is required to support indirect recursion.
499 *
500 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
501 *
502 */
503 private static final Object STATIC_INITIALIZER = ensureInitialized();
504
505 public static Object ensureInitialized() {
506 INSTANCE.ensureInitializedInternal();
507 return null;
508 }
509 }
510
511 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
512 private static final Inv11.GeneratedPQuery INSTANCE = new GeneratedPQuery();
513
514 private final PParameter parameter_exp = new PParameter("exp", "Taxation.Expense", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Expense")), PParameterDirection.INOUT);
515
516 private final List<PParameter> parameters = Arrays.asList(parameter_exp);
517
518 private GeneratedPQuery() {
519 super(PVisibility.PUBLIC);
520 }
521
522 @Override
523 public String getFullyQualifiedName() {
524 return "queries.inv11";
525 }
526
527 @Override
528 public List<String> getParameterNames() {
529 return Arrays.asList("exp");
530 }
531
532 @Override
533 public List<PParameter> getParameters() {
534 return parameters;
535 }
536
537 @Override
538 public Set<PBody> doGetContainedBodies() {
539 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
540 Set<PBody> bodies = new LinkedHashSet<>();
541 {
542 PBody body = new PBody(this);
543 PVariable var_exp = body.getOrCreateVariableByName("exp");
544 new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense")));
545 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
546 new ExportedParameter(body, var_exp, parameter_exp)
547 ));
548 // find x_inv11_incOver100(exp)
549 new PositivePatternCall(body, Tuples.flatTupleOf(var_exp), X_inv11_incOver100.instance().getInternalQueryRepresentation());
550 // find x_inv11_incNotOver100(exp)
551 new PositivePatternCall(body, Tuples.flatTupleOf(var_exp), X_inv11_incNotOver100.instance().getInternalQueryRepresentation());
552 bodies.add(body);
553 }
554 {
555 PAnnotation annotation = new PAnnotation("Constraint");
556 annotation.addAttribute("message", "inv11");
557 annotation.addAttribute("severity", "error");
558 annotation.addAttribute("key", Arrays.asList(new Object[] {
559 new ParameterReference("exp")
560 }));
561 addAnnotation(annotation);
562 }
563 return bodies;
564 }
565 }
566}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv12.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv12.java
new file mode 100644
index 00000000..2a539a1d
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv12.java
@@ -0,0 +1,589 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Tax_Payer;
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.basicdeferred.NegativePatternCall;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
38import org.eclipse.viatra.query.runtime.matchers.psystem.queries.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.X_inv12_notNonRes;
43import queries.X_inv12_notZZ;
44
45/**
46 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
47 *
48 * <p>Original source:
49 * <code><pre>
50 * //inv12
51 * //exists - handled logically
52 * {@literal @}Constraint(message = "inv12", severity = "error", key = {tp})
53 * pattern inv12(tp : Tax_Payer) {
54 * Tax_Payer.addresses(tp, hab_add);
55 * Habitual_Address(hab_add);
56 * neg find x_inv12_notZZ(hab_add);
57 * Tax_Payer.incomes(tp, inc);
58 * Local_Income(inc);
59 * neg find x_inv12_notNonRes(tp);
60 * }
61 * </pre></code>
62 *
63 * @see Matcher
64 * @see Match
65 *
66 */
67@SuppressWarnings("all")
68public final class Inv12 extends BaseGeneratedEMFQuerySpecification<Inv12.Matcher> {
69 /**
70 * Pattern-specific match representation of the queries.inv12 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 Tax_Payer fTp;
83
84 private static List<String> parameterNames = makeImmutableList("tp");
85
86 private Match(final Tax_Payer pTp) {
87 this.fTp = pTp;
88 }
89
90 @Override
91 public Object get(final String parameterName) {
92 switch(parameterName) {
93 case "tp": return this.fTp;
94 default: return null;
95 }
96 }
97
98 @Override
99 public Object get(final int index) {
100 switch(index) {
101 case 0: return this.fTp;
102 default: return null;
103 }
104 }
105
106 public Tax_Payer getTp() {
107 return this.fTp;
108 }
109
110 @Override
111 public boolean set(final String parameterName, final Object newValue) {
112 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
113 if ("tp".equals(parameterName) ) {
114 this.fTp = (Tax_Payer) newValue;
115 return true;
116 }
117 return false;
118 }
119
120 public void setTp(final Tax_Payer pTp) {
121 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
122 this.fTp = pTp;
123 }
124
125 @Override
126 public String patternName() {
127 return "queries.inv12";
128 }
129
130 @Override
131 public List<String> parameterNames() {
132 return Inv12.Match.parameterNames;
133 }
134
135 @Override
136 public Object[] toArray() {
137 return new Object[]{fTp};
138 }
139
140 @Override
141 public Inv12.Match toImmutable() {
142 return isMutable() ? newMatch(fTp) : this;
143 }
144
145 @Override
146 public String prettyPrint() {
147 StringBuilder result = new StringBuilder();
148 result.append("\"tp\"=" + prettyPrintValue(fTp));
149 return result.toString();
150 }
151
152 @Override
153 public int hashCode() {
154 return Objects.hash(fTp);
155 }
156
157 @Override
158 public boolean equals(final Object obj) {
159 if (this == obj)
160 return true;
161 if (obj == null) {
162 return false;
163 }
164 if ((obj instanceof Inv12.Match)) {
165 Inv12.Match other = (Inv12.Match) obj;
166 return Objects.equals(fTp, other.fTp);
167 } else {
168 // this should be infrequent
169 if (!(obj instanceof IPatternMatch)) {
170 return false;
171 }
172 IPatternMatch otherSig = (IPatternMatch) obj;
173 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
174 }
175 }
176
177 @Override
178 public Inv12 specification() {
179 return Inv12.instance();
180 }
181
182 /**
183 * Returns an empty, mutable match.
184 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
185 *
186 * @return the empty match.
187 *
188 */
189 public static Inv12.Match newEmptyMatch() {
190 return new Mutable(null);
191 }
192
193 /**
194 * Returns a mutable (partial) match.
195 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
196 *
197 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
198 * @return the new, mutable (partial) match object.
199 *
200 */
201 public static Inv12.Match newMutableMatch(final Tax_Payer pTp) {
202 return new Mutable(pTp);
203 }
204
205 /**
206 * Returns a new (partial) match.
207 * This can be used e.g. to call the matcher with a partial match.
208 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
209 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
210 * @return the (partial) match object.
211 *
212 */
213 public static Inv12.Match newMatch(final Tax_Payer pTp) {
214 return new Immutable(pTp);
215 }
216
217 private static final class Mutable extends Inv12.Match {
218 @Override
219 public boolean isMutable() {
220 return true;
221 }
222 }
223
224 private static final class Immutable extends Inv12.Match {
225 Immutable(final Tax_Payer pTp) {
226 super(pTp);
227 }
228
229 @Override
230 public boolean isMutable() {
231 return false;
232 }
233 }
234 }
235
236 /**
237 * Generated pattern matcher API of the queries.inv12 pattern,
238 * providing pattern-specific query methods.
239 *
240 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
241 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
242 *
243 * <p>Matches of the pattern will be represented as {@link Match}.
244 *
245 * <p>Original source:
246 * <code><pre>
247 * //inv12
248 * //exists - handled logically
249 * {@literal @}Constraint(message = "inv12", severity = "error", key = {tp})
250 * pattern inv12(tp : Tax_Payer) {
251 * Tax_Payer.addresses(tp, hab_add);
252 * Habitual_Address(hab_add);
253 * neg find x_inv12_notZZ(hab_add);
254 * Tax_Payer.incomes(tp, inc);
255 * Local_Income(inc);
256 * neg find x_inv12_notNonRes(tp);
257 * }
258 * </pre></code>
259 *
260 * @see Match
261 * @see Inv12
262 *
263 */
264 public static class Matcher extends BaseMatcher<Inv12.Match> {
265 /**
266 * Initializes the pattern matcher within an existing VIATRA Query engine.
267 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
268 *
269 * @param engine the existing VIATRA Query engine in which this matcher will be created.
270 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
271 *
272 */
273 public static Inv12.Matcher on(final ViatraQueryEngine engine) {
274 // check if matcher already exists
275 Matcher matcher = engine.getExistingMatcher(querySpecification());
276 if (matcher == null) {
277 matcher = (Matcher)engine.getMatcher(querySpecification());
278 }
279 return matcher;
280 }
281
282 /**
283 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
284 * @return an initialized matcher
285 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
286 *
287 */
288 public static Inv12.Matcher create() {
289 return new Matcher();
290 }
291
292 private static final int POSITION_TP = 0;
293
294 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv12.Matcher.class);
295
296 /**
297 * Initializes the pattern matcher within an existing VIATRA Query engine.
298 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
299 *
300 * @param engine the existing VIATRA Query engine in which this matcher will be created.
301 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
302 *
303 */
304 private Matcher() {
305 super(querySpecification());
306 }
307
308 /**
309 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
310 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
311 * @return matches represented as a Match object.
312 *
313 */
314 public Collection<Inv12.Match> getAllMatches(final Tax_Payer pTp) {
315 return rawStreamAllMatches(new Object[]{pTp}).collect(Collectors.toSet());
316 }
317
318 /**
319 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
320 * </p>
321 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
322 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
323 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
324 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
325 * @return a stream of matches represented as a Match object.
326 *
327 */
328 public Stream<Inv12.Match> streamAllMatches(final Tax_Payer pTp) {
329 return rawStreamAllMatches(new Object[]{pTp});
330 }
331
332 /**
333 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
334 * Neither determinism nor randomness of selection is guaranteed.
335 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
336 * @return a match represented as a Match object, or null if no match is found.
337 *
338 */
339 public Optional<Inv12.Match> getOneArbitraryMatch(final Tax_Payer pTp) {
340 return rawGetOneArbitraryMatch(new Object[]{pTp});
341 }
342
343 /**
344 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
345 * under any possible substitution of the unspecified parameters (if any).
346 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
347 * @return true if the input is a valid (partial) match of the pattern.
348 *
349 */
350 public boolean hasMatch(final Tax_Payer pTp) {
351 return rawHasMatch(new Object[]{pTp});
352 }
353
354 /**
355 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
356 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
357 * @return the number of pattern matches found.
358 *
359 */
360 public int countMatches(final Tax_Payer pTp) {
361 return rawCountMatches(new Object[]{pTp});
362 }
363
364 /**
365 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
366 * Neither determinism nor randomness of selection is guaranteed.
367 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
368 * @param processor the action that will process the selected match.
369 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
370 *
371 */
372 public boolean forOneArbitraryMatch(final Tax_Payer pTp, final Consumer<? super Inv12.Match> processor) {
373 return rawForOneArbitraryMatch(new Object[]{pTp}, processor);
374 }
375
376 /**
377 * Returns a new (partial) match.
378 * This can be used e.g. to call the matcher with a partial match.
379 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
380 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
381 * @return the (partial) match object.
382 *
383 */
384 public Inv12.Match newMatch();
385
386 /**
387 * Retrieve the set of values that occur in matches for tp.
388 * @return the Set of all values or empty set if there are no matches
389 *
390 */
391 protected Stream<Tax_Payer> rawStreamAllValuesOftp(final Object[] parameters) {
392 return rawStreamAllValues(POSITION_TP, parameters).map(Tax_Payer.class::cast);
393 }
394
395 /**
396 * Retrieve the set of values that occur in matches for tp.
397 * @return the Set of all values or empty set if there are no matches
398 *
399 */
400 public Set<Tax_Payer> getAllValuesOftp() {
401 return rawStreamAllValuesOftp(emptyArray()).collect(Collectors.toSet());
402 }
403
404 /**
405 * Retrieve the set of values that occur in matches for tp.
406 * @return the Set of all values or empty set if there are no matches
407 *
408 */
409 public Stream<Tax_Payer> streamAllValuesOftp() {
410 return rawStreamAllValuesOftp(emptyArray());
411 }
412
413 @Override
414 protected Inv12.Match tupleToMatch(final Tuple t) {
415 try {
416 return Inv12.Match.newMatch((Tax_Payer) t.get(POSITION_TP));
417 } catch(ClassCastException e) {
418 LOGGER.error("Element(s) in tuple not properly typed!",e);
419 return null;
420 }
421 }
422
423 @Override
424 protected Inv12.Match arrayToMatch(final Object[] match) {
425 try {
426 return Inv12.Match.newMatch((Tax_Payer) match[POSITION_TP]);
427 } catch(ClassCastException e) {
428 LOGGER.error("Element(s) in array not properly typed!",e);
429 return null;
430 }
431 }
432
433 @Override
434 protected Inv12.Match arrayToMatchMutable(final Object[] match) {
435 try {
436 return Inv12.Match.newMutableMatch((Tax_Payer) match[POSITION_TP]);
437 } catch(ClassCastException e) {
438 LOGGER.error("Element(s) in array not properly typed!",e);
439 return null;
440 }
441 }
442
443 /**
444 * @return the singleton instance of the query specification of this pattern
445 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
446 *
447 */
448 public static IQuerySpecification<Inv12.Matcher> querySpecification() {
449 return Inv12.instance();
450 }
451 }
452
453 private Inv12() {
454 super(GeneratedPQuery.INSTANCE);
455 }
456
457 /**
458 * @return the singleton instance of the query specification
459 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
460 *
461 */
462 public static Inv12 instance() {
463 try{
464 return LazyHolder.INSTANCE;
465 } catch (ExceptionInInitializerError err) {
466 throw processInitializerError(err);
467 }
468 }
469
470 @Override
471 protected Inv12.Matcher instantiate(final ViatraQueryEngine engine) {
472 return Inv12.Matcher.on(engine);
473 }
474
475 @Override
476 public Inv12.Matcher instantiate() {
477 return Inv12.Matcher.create();
478 }
479
480 @Override
481 public Inv12.Match newEmptyMatch() {
482 return Inv12.Match.newEmptyMatch();
483 }
484
485 @Override
486 public Inv12.Match newMatch(final Object... parameters) {
487 return Inv12.Match.newMatch((Taxation.Tax_Payer) parameters[0]);
488 }
489
490 /**
491 * Inner class allowing the singleton instance of {@link Inv12} to be created
492 * <b>not</b> at the class load time of the outer class,
493 * but rather at the first call to {@link Inv12#instance()}.
494 *
495 * <p> This workaround is required e.g. to support recursion.
496 *
497 */
498 private static class LazyHolder {
499 private static final Inv12 INSTANCE = new Inv12();
500
501 /**
502 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
503 * This initialization order is required to support indirect recursion.
504 *
505 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
506 *
507 */
508 private static final Object STATIC_INITIALIZER = ensureInitialized();
509
510 public static Object ensureInitialized() {
511 INSTANCE.ensureInitializedInternal();
512 return null;
513 }
514 }
515
516 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
517 private static final Inv12.GeneratedPQuery INSTANCE = new GeneratedPQuery();
518
519 private final PParameter parameter_tp;
520
521 private final List<PParameter> parameters = Arrays.asList(parameter_tp);
522
523 private GeneratedPQuery() {
524 super(PVisibility.PUBLIC);
525 }
526
527 @Override
528 public String getFullyQualifiedName() {
529 return "queries.inv12";
530 }
531
532 @Override
533 public List<String> getParameterNames() {
534 return Arrays.asList("tp");
535 }
536
537 @Override
538 public List<PParameter> getParameters() {
539 return parameters;
540 }
541
542 @Override
543 public Set<PBody> doGetContainedBodies() {
544 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
545 Set<PBody> bodies = new LinkedHashSet<>();
546 {
547 PBody body = new PBody(this);
548 PVariable var_tp = body.getOrCreateVariableByName("tp");
549 PVariable var_hab_add = body.getOrCreateVariableByName("hab_add");
550 PVariable var_inc = body.getOrCreateVariableByName("inc");
551 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
552 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
553 new ExportedParameter(body, var_tp, parameter_tp)
554 ));
555 // Tax_Payer.addresses(tp, hab_add)
556 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
557 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
558 new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "addresses")));
559 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Address")));
560 new Equality(body, var__virtual_0_, var_hab_add);
561 // Habitual_Address(hab_add)
562 new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Habitual_Address")));
563 // neg find x_inv12_notZZ(hab_add)
564 new NegativePatternCall(body, Tuples.flatTupleOf(var_hab_add), X_inv12_notZZ.instance().getInternalQueryRepresentation());
565 // Tax_Payer.incomes(tp, inc)
566 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
567 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
568 new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Tax_Payer", "incomes")));
569 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
570 new Equality(body, var__virtual_1_, var_inc);
571 // Local_Income(inc)
572 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Local_Income")));
573 // neg find x_inv12_notNonRes(tp)
574 new NegativePatternCall(body, Tuples.flatTupleOf(var_tp), X_inv12_notNonRes.instance().getInternalQueryRepresentation());
575 bodies.add(body);
576 }
577 {
578 PAnnotation annotation = new PAnnotation("Constraint");
579 annotation.addAttribute("message", "inv12");
580 annotation.addAttribute("severity", "error");
581 annotation.addAttribute("key", Arrays.asList(new Object[] {
582 new ParameterReference("tp")
583 }));
584 addAnnotation(annotation);
585 }
586 return bodies;
587 }
588 }
589}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv13.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv13.java
new file mode 100644
index 00000000..c162969f
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv13.java
@@ -0,0 +1,591 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Tax_Payer;
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.PBody;
32import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
33import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
34import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue;
39import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
42import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
43import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
44import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
45import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
46import queries.X_inv13;
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 * //inv13 - Added new containment rel Phys_Pers-{@literal >}Address
54 * //exists - handled logically
55 * {@literal @}Constraint(message = "inv13", severity = "error", key = {tp})
56 * pattern inv13(tp : Tax_Payer) {
57 * Tax_Payer.addresses(tp, hab_add);
58 * Habitual_Address(hab_add);
59 * Address.country(hab_add, ::ZZ);
60 * neg find x_inv13(tp);
61 * }
62 * </pre></code>
63 *
64 * @see Matcher
65 * @see Match
66 *
67 */
68@SuppressWarnings("all")
69public final class Inv13 extends BaseGeneratedEMFQuerySpecification<Inv13.Matcher> {
70 /**
71 * Pattern-specific match representation of the queries.inv13 pattern,
72 * to be used in conjunction with {@link Matcher}.
73 *
74 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
75 * Each instance is a (possibly partial) substitution of pattern parameters,
76 * usable to represent a match of the pattern in the result of a query,
77 * or to specify the bound (fixed) input parameters when issuing a query.
78 *
79 * @see Matcher
80 *
81 */
82 public static abstract class Match extends BasePatternMatch {
83 private Tax_Payer fTp;
84
85 private static List<String> parameterNames = makeImmutableList("tp");
86
87 private Match(final Tax_Payer pTp) {
88 this.fTp = pTp;
89 }
90
91 @Override
92 public Object get(final String parameterName) {
93 switch(parameterName) {
94 case "tp": return this.fTp;
95 default: return null;
96 }
97 }
98
99 @Override
100 public Object get(final int index) {
101 switch(index) {
102 case 0: return this.fTp;
103 default: return null;
104 }
105 }
106
107 public Tax_Payer getTp() {
108 return this.fTp;
109 }
110
111 @Override
112 public boolean set(final String parameterName, final Object newValue) {
113 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
114 if ("tp".equals(parameterName) ) {
115 this.fTp = (Tax_Payer) newValue;
116 return true;
117 }
118 return false;
119 }
120
121 public void setTp(final Tax_Payer pTp) {
122 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
123 this.fTp = pTp;
124 }
125
126 @Override
127 public String patternName() {
128 return "queries.inv13";
129 }
130
131 @Override
132 public List<String> parameterNames() {
133 return Inv13.Match.parameterNames;
134 }
135
136 @Override
137 public Object[] toArray() {
138 return new Object[]{fTp};
139 }
140
141 @Override
142 public Inv13.Match toImmutable() {
143 return isMutable() ? newMatch(fTp) : this;
144 }
145
146 @Override
147 public String prettyPrint() {
148 StringBuilder result = new StringBuilder();
149 result.append("\"tp\"=" + prettyPrintValue(fTp));
150 return result.toString();
151 }
152
153 @Override
154 public int hashCode() {
155 return Objects.hash(fTp);
156 }
157
158 @Override
159 public boolean equals(final Object obj) {
160 if (this == obj)
161 return true;
162 if (obj == null) {
163 return false;
164 }
165 if ((obj instanceof Inv13.Match)) {
166 Inv13.Match other = (Inv13.Match) obj;
167 return Objects.equals(fTp, other.fTp);
168 } else {
169 // this should be infrequent
170 if (!(obj instanceof IPatternMatch)) {
171 return false;
172 }
173 IPatternMatch otherSig = (IPatternMatch) obj;
174 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
175 }
176 }
177
178 @Override
179 public Inv13 specification() {
180 return Inv13.instance();
181 }
182
183 /**
184 * Returns an empty, mutable match.
185 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
186 *
187 * @return the empty match.
188 *
189 */
190 public static Inv13.Match newEmptyMatch() {
191 return new Mutable(null);
192 }
193
194 /**
195 * Returns a mutable (partial) match.
196 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
197 *
198 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
199 * @return the new, mutable (partial) match object.
200 *
201 */
202 public static Inv13.Match newMutableMatch(final Tax_Payer pTp) {
203 return new Mutable(pTp);
204 }
205
206 /**
207 * Returns a new (partial) match.
208 * This can be used e.g. to call the matcher with a partial match.
209 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
210 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
211 * @return the (partial) match object.
212 *
213 */
214 public static Inv13.Match newMatch(final Tax_Payer pTp) {
215 return new Immutable(pTp);
216 }
217
218 private static final class Mutable extends Inv13.Match {
219 Mutable(final Tax_Payer pTp) {
220 super(pTp);
221 }
222
223 @Override
224 public boolean isMutable() {
225 return true;
226 }
227 }
228
229 private static final class Immutable extends Inv13.Match {
230 Immutable(final Tax_Payer pTp) {
231 super(pTp);
232 }
233
234 @Override
235 public boolean isMutable() {
236 return false;
237 }
238 }
239 }
240
241 /**
242 * Generated pattern matcher API of the queries.inv13 pattern,
243 * providing pattern-specific query methods.
244 *
245 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
246 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
247 *
248 * <p>Matches of the pattern will be represented as {@link Match}.
249 *
250 * <p>Original source:
251 * <code><pre>
252 * //inv13 - Added new containment rel Phys_Pers-{@literal >}Address
253 * //exists - handled logically
254 * {@literal @}Constraint(message = "inv13", severity = "error", key = {tp})
255 * pattern inv13(tp : Tax_Payer) {
256 * Tax_Payer.addresses(tp, hab_add);
257 * Habitual_Address(hab_add);
258 * Address.country(hab_add, ::ZZ);
259 * neg find x_inv13(tp);
260 * }
261 * </pre></code>
262 *
263 * @see Match
264 * @see Inv13
265 *
266 */
267 public static class Matcher extends BaseMatcher<Inv13.Match> {
268 /**
269 * Initializes the pattern matcher within an existing VIATRA Query engine.
270 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
271 *
272 * @param engine the existing VIATRA Query engine in which this matcher will be created.
273 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
274 *
275 */
276 public static Inv13.Matcher on(final ViatraQueryEngine engine) {
277 // check if matcher already exists
278 Matcher matcher = engine.getExistingMatcher(querySpecification());
279 if (matcher == null) {
280 matcher = (Matcher)engine.getMatcher(querySpecification());
281 }
282 return matcher;
283 }
284
285 /**
286 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
287 * @return an initialized matcher
288 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
289 *
290 */
291 public static Inv13.Matcher create() {
292 return new Matcher();
293 }
294
295 private static final int POSITION_TP = 0;
296
297 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv13.Matcher.class);
298
299 /**
300 * Initializes the pattern matcher within an existing VIATRA Query engine.
301 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
302 *
303 * @param engine the existing VIATRA Query engine in which this matcher will be created.
304 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
305 *
306 */
307 private Matcher() {
308 super(querySpecification());
309 }
310
311 /**
312 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
313 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
314 * @return matches represented as a Match object.
315 *
316 */
317 public Collection<Inv13.Match> getAllMatches(final Tax_Payer pTp) {
318 return rawStreamAllMatches(new Object[]{pTp}).collect(Collectors.toSet());
319 }
320
321 /**
322 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
323 * </p>
324 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
325 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
326 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
327 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
328 * @return a stream of matches represented as a Match object.
329 *
330 */
331 public Stream<Inv13.Match> streamAllMatches(final Tax_Payer pTp) {
332 return rawStreamAllMatches(new Object[]{pTp});
333 }
334
335 /**
336 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
337 * Neither determinism nor randomness of selection is guaranteed.
338 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
339 * @return a match represented as a Match object, or null if no match is found.
340 *
341 */
342 public Optional<Inv13.Match> getOneArbitraryMatch(final Tax_Payer pTp) {
343 return rawGetOneArbitraryMatch(new Object[]{pTp});
344 }
345
346 /**
347 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
348 * under any possible substitution of the unspecified parameters (if any).
349 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
350 * @return true if the input is a valid (partial) match of the pattern.
351 *
352 */
353 public boolean hasMatch(final Tax_Payer pTp) {
354 return rawHasMatch(new Object[]{pTp});
355 }
356
357 /**
358 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
359 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
360 * @return the number of pattern matches found.
361 *
362 */
363 public int countMatches(final Tax_Payer pTp) {
364 return rawCountMatches(new Object[]{pTp});
365 }
366
367 /**
368 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
369 * Neither determinism nor randomness of selection is guaranteed.
370 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
371 * @param processor the action that will process the selected match.
372 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
373 *
374 */
375 public boolean forOneArbitraryMatch(final Tax_Payer pTp, final Consumer<? super Inv13.Match> processor) {
376 return rawForOneArbitraryMatch(new Object[]{pTp}, processor);
377 }
378
379 /**
380 * Returns a new (partial) match.
381 * This can be used e.g. to call the matcher with a partial match.
382 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
383 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
384 * @return the (partial) match object.
385 *
386 */
387 public Inv13.Match newMatch(final Tax_Payer pTp) {
388 return Inv13.Match.newMatch(pTp);
389 }
390
391 /**
392 * Retrieve the set of values that occur in matches for tp.
393 * @return the Set of all values or empty set if there are no matches
394 *
395 */
396 protected Stream<Tax_Payer> rawStreamAllValuesOftp(final Object[] parameters) {
397 return rawStreamAllValues(POSITION_TP, parameters).map(Tax_Payer.class::cast);
398 }
399
400 /**
401 * Retrieve the set of values that occur in matches for tp.
402 * @return the Set of all values or empty set if there are no matches
403 *
404 */
405 public Set<Tax_Payer> getAllValuesOftp() {
406 return rawStreamAllValuesOftp(emptyArray()).collect(Collectors.toSet());
407 }
408
409 /**
410 * Retrieve the set of values that occur in matches for tp.
411 * @return the Set of all values or empty set if there are no matches
412 *
413 */
414 public Stream<Tax_Payer> streamAllValuesOftp() {
415 return rawStreamAllValuesOftp(emptyArray());
416 }
417
418 @Override
419 protected Inv13.Match tupleToMatch(final Tuple t) {
420 try {
421 return Inv13.Match.newMatch((Tax_Payer) t.get(POSITION_TP));
422 } catch(ClassCastException e) {
423 LOGGER.error("Element(s) in tuple not properly typed!",e);
424 return null;
425 }
426 }
427
428 @Override
429 protected Inv13.Match arrayToMatch(final Object[] match) {
430 try {
431 return Inv13.Match.newMatch((Tax_Payer) match[POSITION_TP]);
432 } catch(ClassCastException e) {
433 LOGGER.error("Element(s) in array not properly typed!",e);
434 return null;
435 }
436 }
437
438 @Override
439 protected Inv13.Match arrayToMatchMutable(final Object[] match) {
440 try {
441 return Inv13.Match.newMutableMatch((Tax_Payer) match[POSITION_TP]);
442 } catch(ClassCastException e) {
443 LOGGER.error("Element(s) in array not properly typed!",e);
444 return null;
445 }
446 }
447
448 /**
449 * @return the singleton instance of the query specification of this pattern
450 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
451 *
452 */
453 public static IQuerySpecification<Inv13.Matcher> querySpecification() {
454 return Inv13.instance();
455 }
456 }
457
458 private Inv13() {
459 super(GeneratedPQuery.INSTANCE);
460 }
461
462 /**
463 * @return the singleton instance of the query specification
464 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
465 *
466 */
467 public static Inv13 instance() {
468 try{
469 return LazyHolder.INSTANCE;
470 } catch (ExceptionInInitializerError err) {
471 throw processInitializerError(err);
472 }
473 }
474
475 @Override
476 protected Inv13.Matcher instantiate(final ViatraQueryEngine engine) {
477 return Inv13.Matcher.on(engine);
478 }
479
480 @Override
481 public Inv13.Matcher instantiate() {
482 return Inv13.Matcher.create();
483 }
484
485 @Override
486 public Inv13.Match newEmptyMatch() {
487 return Inv13.Match.newEmptyMatch();
488 }
489
490 @Override
491 public Inv13.Match newMatch(final Object... parameters) {
492 return Inv13.Match.newMatch((Taxation.Tax_Payer) parameters[0]);
493 }
494
495 /**
496 * Inner class allowing the singleton instance of {@link Inv13} to be created
497 * <b>not</b> at the class load time of the outer class,
498 * but rather at the first call to {@link Inv13#instance()}.
499 *
500 * <p> This workaround is required e.g. to support recursion.
501 *
502 */
503 private static class LazyHolder {
504 private static final Inv13 INSTANCE = new Inv13();
505
506 /**
507 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
508 * This initialization order is required to support indirect recursion.
509 *
510 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
511 *
512 */
513 private static final Object STATIC_INITIALIZER = ensureInitialized();
514
515 public static Object ensureInitialized() {
516 INSTANCE.ensureInitializedInternal();
517 return null;
518 }
519 }
520
521 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
522 private static final Inv13.GeneratedPQuery INSTANCE = new GeneratedPQuery();
523
524 private final PParameter parameter_tp = new PParameter("tp", "Taxation.Tax_Payer", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Tax_Payer")), PParameterDirection.INOUT);
525
526 private final List<PParameter> parameters = Arrays.asList(parameter_tp);
527
528 private GeneratedPQuery() {
529 super(PVisibility.PUBLIC);
530 }
531
532 @Override
533 public String getFullyQualifiedName() {
534 return "queries.inv13";
535 }
536
537 @Override
538 public List<String> getParameterNames() {
539 return Arrays.asList("tp");
540 }
541
542 @Override
543 public List<PParameter> getParameters() {
544 return parameters;
545 }
546
547 @Override
548 public Set<PBody> doGetContainedBodies() {
549 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
550 Set<PBody> bodies = new LinkedHashSet<>();
551 {
552 PBody body = new PBody(this);
553 PVariable var_tp = body.getOrCreateVariableByName("tp");
554 PVariable var_hab_add = body.getOrCreateVariableByName("hab_add");
555 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
556 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
557 new ExportedParameter(body, var_tp, parameter_tp)
558 ));
559 // Tax_Payer.addresses(tp, hab_add)
560 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
561 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
562 new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "addresses")));
563 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Address")));
564 new Equality(body, var__virtual_0_, var_hab_add);
565 // Habitual_Address(hab_add)
566 new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Habitual_Address")));
567 // Address.country(hab_add, ::ZZ)
568 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
569 new ConstantValue(body, var__virtual_1_, getEnumLiteral("http:///TaxCard.ecore", "Country", "ZZ").getInstance());
570 new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Address")));
571 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
572 new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Address", "country")));
573 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http:///TaxCard.ecore", "Country")));
574 new Equality(body, var__virtual_2_, var__virtual_1_);
575 // neg find x_inv13(tp)
576 new NegativePatternCall(body, Tuples.flatTupleOf(var_tp), X_inv13.instance().getInternalQueryRepresentation());
577 bodies.add(body);
578 }
579 {
580 PAnnotation annotation = new PAnnotation("Constraint");
581 annotation.addAttribute("message", "inv13");
582 annotation.addAttribute("severity", "error");
583 annotation.addAttribute("key", Arrays.asList(new Object[] {
584 new ParameterReference("tp")
585 }));
586 addAnnotation(annotation);
587 }
588 return bodies;
589 }
590 }
591}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv15.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv15.java
new file mode 100644
index 00000000..50799179
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv15.java
@@ -0,0 +1,567 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.External_Allowance;
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.NegativePatternCall;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
39import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
40import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
41import queries.X_inv15;
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 * //inv14-MultiplicityChanged
49 *
50 * //inv15-Ordered Sets in assignment if block
51 * //ERROR if no household object
52 * {@literal @}Constraint(message = "inv15", severity = "error", key = {ea})
53 * pattern inv15(ea : External_Allowance) {
54 * neg find x_inv15(ea);
55 * }
56 * </pre></code>
57 *
58 * @see Matcher
59 * @see Match
60 *
61 */
62@SuppressWarnings("all")
63public final class Inv15 extends BaseGeneratedEMFQuerySpecification<Inv15.Matcher> {
64 /**
65 * Pattern-specific match representation of the queries.inv15 pattern,
66 * to be used in conjunction with {@link Matcher}.
67 *
68 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
69 * Each instance is a (possibly partial) substitution of pattern parameters,
70 * usable to represent a match of the pattern in the result of a query,
71 * or to specify the bound (fixed) input parameters when issuing a query.
72 *
73 * @see Matcher
74 *
75 */
76 public static abstract class Match extends BasePatternMatch {
77 private External_Allowance fEa;
78
79 private static List<String> parameterNames = makeImmutableList("ea");
80
81 private Match(final External_Allowance pEa) {
82 this.fEa = pEa;
83 }
84
85 @Override
86 public Object get(final String parameterName) {
87 switch(parameterName) {
88 case "ea": return this.fEa;
89 default: return null;
90 }
91 }
92
93 @Override
94 public Object get(final int index) {
95 switch(index) {
96 case 0: return this.fEa;
97 default: return null;
98 }
99 }
100
101 public External_Allowance getEa() {
102 return this.fEa;
103 }
104
105 @Override
106 public boolean set(final String parameterName, final Object newValue) {
107 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
108 if ("ea".equals(parameterName) ) {
109 this.fEa = (External_Allowance) newValue;
110 return true;
111 }
112 return false;
113 }
114
115 public void setEa(final External_Allowance pEa) {
116 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
117 this.fEa = pEa;
118 }
119
120 @Override
121 public String patternName() {
122 return "queries.inv15";
123 }
124
125 @Override
126 public List<String> parameterNames() {
127 return Inv15.Match.parameterNames;
128 }
129
130 @Override
131 public Object[] toArray() {
132 return new Object[]{fEa};
133 }
134
135 @Override
136 public Inv15.Match toImmutable() {
137 return isMutable() ? newMatch(fEa) : this;
138 }
139
140 @Override
141 public String prettyPrint() {
142 StringBuilder result = new StringBuilder();
143 result.append("\"ea\"=" + prettyPrintValue(fEa));
144 return result.toString();
145 }
146
147 @Override
148 public int hashCode() {
149 return Objects.hash(fEa);
150 }
151
152 @Override
153 public boolean equals(final Object obj) {
154 if (this == obj)
155 return true;
156 if (obj == null) {
157 return false;
158 }
159 if ((obj instanceof Inv15.Match)) {
160 Inv15.Match other = (Inv15.Match) obj;
161 return Objects.equals(fEa, other.fEa);
162 } else {
163 // this should be infrequent
164 if (!(obj instanceof IPatternMatch)) {
165 return false;
166 }
167 IPatternMatch otherSig = (IPatternMatch) obj;
168 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
169 }
170 }
171
172 @Override
173 public Inv15 specification() {
174 return Inv15.instance();
175 }
176
177 /**
178 * Returns an empty, mutable match.
179 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
180 *
181 * @return the empty match.
182 *
183 */
184 public static Inv15.Match newEmptyMatch() {
185 return new Mutable(null);
186 }
187
188 /**
189 * Returns a mutable (partial) match.
190 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
191 *
192 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
193 * @return the new, mutable (partial) match object.
194 *
195 */
196 public static Inv15.Match newMutableMatch(final External_Allowance pEa) {
197 return new Mutable(pEa);
198 }
199
200 /**
201 * Returns a new (partial) match.
202 * This can be used e.g. to call the matcher with a partial match.
203 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
204 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
205 * @return the (partial) match object.
206 *
207 */
208 public static Inv15.Match newMatch(final External_Allowance pEa) {
209 return new Immutable(pEa);
210 }
211
212 private static final class Mutable extends Inv15.Match {
213 Mutable(final External_Allowance pEa) {
214 super(pEa);
215 }
216
217 @Override
218 public boolean isMutable() {
219 return true;
220 }
221 }
222
223 private static final class Immutable extends Inv15.Match {
224 Immutable(final External_Allowance pEa) {
225 super(pEa);
226 }
227
228 @Override
229 public boolean isMutable() {
230 return false;
231 }
232 }
233 }
234
235 /**
236 * Generated pattern matcher API of the queries.inv15 pattern,
237 * providing pattern-specific query methods.
238 *
239 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
240 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
241 *
242 * <p>Matches of the pattern will be represented as {@link Match}.
243 *
244 * <p>Original source:
245 * <code><pre>
246 * //inv14-MultiplicityChanged
247 *
248 * //inv15-Ordered Sets in assignment if block
249 * //ERROR if no household object
250 * {@literal @}Constraint(message = "inv15", severity = "error", key = {ea})
251 * pattern inv15(ea : External_Allowance) {
252 * neg find x_inv15(ea);
253 * }
254 * </pre></code>
255 *
256 * @see Match
257 * @see Inv15
258 *
259 */
260 public static class Matcher extends BaseMatcher<Inv15.Match> {
261 /**
262 * Initializes the pattern matcher within an existing VIATRA Query engine.
263 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
264 *
265 * @param engine the existing VIATRA Query engine in which this matcher will be created.
266 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
267 *
268 */
269 public static Inv15.Matcher on(final ViatraQueryEngine engine) {
270 // check if matcher already exists
271 Matcher matcher = engine.getExistingMatcher(querySpecification());
272 if (matcher == null) {
273 matcher = (Matcher)engine.getMatcher(querySpecification());
274 }
275 return matcher;
276 }
277
278 /**
279 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
280 * @return an initialized matcher
281 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
282 *
283 */
284 public static Inv15.Matcher create() {
285 return new Matcher();
286 }
287
288 private static final int POSITION_EA = 0;
289
290 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv15.Matcher.class);
291
292 /**
293 * Initializes the pattern matcher within an existing VIATRA Query engine.
294 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
295 *
296 * @param engine the existing VIATRA Query engine in which this matcher will be created.
297 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
298 *
299 */
300 private Matcher() {
301 super(querySpecification());
302 }
303
304 /**
305 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
306 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
307 * @return matches represented as a Match object.
308 *
309 */
310 public Collection<Inv15.Match> getAllMatches(final External_Allowance pEa) {
311 return rawStreamAllMatches(new Object[]{pEa}).collect(Collectors.toSet());
312 }
313
314 /**
315 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
316 * </p>
317 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
318 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
319 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
320 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
321 * @return a stream of matches represented as a Match object.
322 *
323 */
324 public Stream<Inv15.Match> streamAllMatches(final External_Allowance pEa) {
325 return rawStreamAllMatches(new Object[]{pEa});
326 }
327
328 /**
329 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
330 * Neither determinism nor randomness of selection is guaranteed.
331 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
332 * @return a match represented as a Match object, or null if no match is found.
333 *
334 */
335 public Optional<Inv15.Match> getOneArbitraryMatch(final External_Allowance pEa) {
336 return rawGetOneArbitraryMatch(new Object[]{pEa});
337 }
338
339 /**
340 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
341 * under any possible substitution of the unspecified parameters (if any).
342 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
343 * @return true if the input is a valid (partial) match of the pattern.
344 *
345 */
346 public boolean hasMatch(final External_Allowance pEa) {
347 return rawHasMatch(new Object[]{pEa});
348 }
349
350 /**
351 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
352 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
353 * @return the number of pattern matches found.
354 *
355 */
356 public int countMatches(final External_Allowance pEa) {
357 return rawCountMatches(new Object[]{pEa});
358 }
359
360 /**
361 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
362 * Neither determinism nor randomness of selection is guaranteed.
363 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
364 * @param processor the action that will process the selected match.
365 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
366 *
367 */
368 public boolean forOneArbitraryMatch(final External_Allowance pEa, final Consumer<? super Inv15.Match> processor) {
369 return rawForOneArbitraryMatch(new Object[]{pEa}, processor);
370 }
371
372 /**
373 * Returns a new (partial) match.
374 * This can be used e.g. to call the matcher with a partial match.
375 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
376 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
377 * @return the (partial) match object.
378 *
379 */
380 public Inv15.Match newMatch(final External_Allowance pEa) {
381 return Inv15.Match.newMatch(pEa);
382 }
383
384 /**
385 * Retrieve the set of values that occur in matches for ea.
386 * @return the Set of all values or empty set if there are no matches
387 *
388 */
389 protected Stream<External_Allowance> rawStreamAllValuesOfea(final Object[] parameters) {
390 return rawStreamAllValues(POSITION_EA, parameters).map(External_Allowance.class::cast);
391 }
392
393 /**
394 * Retrieve the set of values that occur in matches for ea.
395 * @return the Set of all values or empty set if there are no matches
396 *
397 */
398 public Set<External_Allowance> getAllValuesOfea() {
399 return rawStreamAllValuesOfea(emptyArray()).collect(Collectors.toSet());
400 }
401
402 /**
403 * Retrieve the set of values that occur in matches for ea.
404 * @return the Set of all values or empty set if there are no matches
405 *
406 */
407 public Stream<External_Allowance> streamAllValuesOfea() {
408 return rawStreamAllValuesOfea(emptyArray());
409 }
410
411 @Override
412 protected Inv15.Match tupleToMatch(final Tuple t) {
413 try {
414 return Inv15.Match.newMatch((External_Allowance) t.get(POSITION_EA));
415 } catch(ClassCastException e) {
416 LOGGER.error("Element(s) in tuple not properly typed!",e);
417 return null;
418 }
419 }
420
421 @Override
422 protected Inv15.Match arrayToMatch(final Object[] match) {
423 try {
424 return Inv15.Match.newMatch((External_Allowance) match[POSITION_EA]);
425 } catch(ClassCastException e) {
426 LOGGER.error("Element(s) in array not properly typed!",e);
427 return null;
428 }
429 }
430
431 @Override
432 protected Inv15.Match arrayToMatchMutable(final Object[] match) {
433 try {
434 return Inv15.Match.newMutableMatch((External_Allowance) match[POSITION_EA]);
435 } catch(ClassCastException e) {
436 LOGGER.error("Element(s) in array not properly typed!",e);
437 return null;
438 }
439 }
440
441 /**
442 * @return the singleton instance of the query specification of this pattern
443 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
444 *
445 */
446 public static IQuerySpecification<Inv15.Matcher> querySpecification() {
447 return Inv15.instance();
448 }
449 }
450
451 private Inv15() {
452 super(GeneratedPQuery.INSTANCE);
453 }
454
455 /**
456 * @return the singleton instance of the query specification
457 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
458 *
459 */
460 public static Inv15 instance() {
461 try{
462 return LazyHolder.INSTANCE;
463 } catch (ExceptionInInitializerError err) {
464 throw processInitializerError(err);
465 }
466 }
467
468 @Override
469 protected Inv15.Matcher instantiate(final ViatraQueryEngine engine) {
470 return Inv15.Matcher.on(engine);
471 }
472
473 @Override
474 public Inv15.Matcher instantiate() {
475 return Inv15.Matcher.create();
476 }
477
478 @Override
479 public Inv15.Match newEmptyMatch() {
480 return Inv15.Match.newEmptyMatch();
481 }
482
483 @Override
484 public Inv15.Match newMatch(final Object... parameters) {
485 return Inv15.Match.newMatch((Taxation.External_Allowance) parameters[0]);
486 }
487
488 /**
489 * Inner class allowing the singleton instance of {@link Inv15} to be created
490 * <b>not</b> at the class load time of the outer class,
491 * but rather at the first call to {@link Inv15#instance()}.
492 *
493 * <p> This workaround is required e.g. to support recursion.
494 *
495 */
496 private static class LazyHolder {
497 private static final Inv15 INSTANCE = new Inv15();
498
499 /**
500 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
501 * This initialization order is required to support indirect recursion.
502 *
503 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
504 *
505 */
506 private static final Object STATIC_INITIALIZER = ensureInitialized();
507
508 public static Object ensureInitialized() {
509 INSTANCE.ensureInitializedInternal();
510 return null;
511 }
512 }
513
514 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
515 private static final Inv15.GeneratedPQuery INSTANCE = new GeneratedPQuery();
516
517 private final PParameter parameter_ea = new PParameter("ea", "Taxation.External_Allowance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "External_Allowance")), PParameterDirection.INOUT);
518
519 private final List<PParameter> parameters = Arrays.asList(parameter_ea);
520
521 private GeneratedPQuery() {
522 super(PVisibility.PUBLIC);
523 }
524
525 @Override
526 public String getFullyQualifiedName() {
527 return "queries.inv15";
528 }
529
530 @Override
531 public List<String> getParameterNames() {
532 return Arrays.asList("ea");
533 }
534
535 @Override
536 public List<PParameter> getParameters() {
537 return parameters;
538 }
539
540 @Override
541 public Set<PBody> doGetContainedBodies() {
542 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
543 Set<PBody> bodies = new LinkedHashSet<>();
544 {
545 PBody body = new PBody(this);
546 PVariable var_ea = body.getOrCreateVariableByName("ea");
547 new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance")));
548 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
549 new ExportedParameter(body, var_ea, parameter_ea)
550 ));
551 // neg find x_inv15(ea)
552 new NegativePatternCall(body, Tuples.flatTupleOf(var_ea), X_inv15.instance().getInternalQueryRepresentation());
553 bodies.add(body);
554 }
555 {
556 PAnnotation annotation = new PAnnotation("Constraint");
557 annotation.addAttribute("message", "inv15");
558 annotation.addAttribute("severity", "error");
559 annotation.addAttribute("key", Arrays.asList(new Object[] {
560 new ParameterReference("ea")
561 }));
562 addAnnotation(annotation);
563 }
564 return bodies;
565 }
566 }
567}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv17.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv17.java
new file mode 100644
index 00000000..8019db8c
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv17.java
@@ -0,0 +1,643 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Legal_Union_Record;
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 * //inv16-Tax_Card.tax_card_type is a derived feature
54 *
55 * //inv17-attribute-handled by multiplicity
56 * {@literal @}Constraint(message = "inv17", severity = "error", key = {lur})
57 * pattern inv17(lur : Legal_Union_Record) {
58 * Legal_Union_Record.start_year(lur, sy);
59 * check(sy {@literal <} 1950);
60 * } or {
61 * Legal_Union_Record.start_year(lur, sy);
62 * check(sy {@literal >} 2018);
63 * }
64 * </pre></code>
65 *
66 * @see Matcher
67 * @see Match
68 *
69 */
70@SuppressWarnings("all")
71public final class Inv17 extends BaseGeneratedEMFQuerySpecification<Inv17.Matcher> {
72 /**
73 * Pattern-specific match representation of the queries.inv17 pattern,
74 * to be used in conjunction with {@link Matcher}.
75 *
76 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
77 * Each instance is a (possibly partial) substitution of pattern parameters,
78 * usable to represent a match of the pattern in the result of a query,
79 * or to specify the bound (fixed) input parameters when issuing a query.
80 *
81 * @see Matcher
82 *
83 */
84 public static abstract class Match extends BasePatternMatch {
85 private Legal_Union_Record fLur;
86
87 private static List<String> parameterNames = makeImmutableList("lur");
88
89 private Match(final Legal_Union_Record pLur) {
90 this.fLur = pLur;
91 }
92
93 @Override
94 public Object get(final String parameterName) {
95 switch(parameterName) {
96 case "lur": return this.fLur;
97 default: return null;
98 }
99 }
100
101 @Override
102 public Object get(final int index) {
103 switch(index) {
104 case 0: return this.fLur;
105 default: return null;
106 }
107 }
108
109 public Legal_Union_Record getLur() {
110 return this.fLur;
111 }
112
113 @Override
114 public boolean set(final String parameterName, final Object newValue) {
115 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
116 if ("lur".equals(parameterName) ) {
117 this.fLur = (Legal_Union_Record) newValue;
118 return true;
119 }
120 return false;
121 }
122
123 public void setLur(final Legal_Union_Record pLur) {
124 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
125 this.fLur = pLur;
126 }
127
128 @Override
129 public String patternName() {
130 return "queries.inv17";
131 }
132
133 @Override
134 public List<String> parameterNames() {
135 return Inv17.Match.parameterNames;
136 }
137
138 @Override
139 public Object[] toArray() {
140 return new Object[]{fLur};
141 }
142
143 @Override
144 public Inv17.Match toImmutable() {
145 return isMutable() ? newMatch(fLur) : this;
146 }
147
148 @Override
149 public String prettyPrint() {
150 StringBuilder result = new StringBuilder();
151 result.append("\"lur\"=" + prettyPrintValue(fLur));
152 return result.toString();
153 }
154
155 @Override
156 public int hashCode() {
157 return Objects.hash(fLur);
158 }
159
160 @Override
161 public boolean equals(final Object obj) {
162 if (this == obj)
163 return true;
164 if (obj == null) {
165 return false;
166 }
167 if ((obj instanceof Inv17.Match)) {
168 Inv17.Match other = (Inv17.Match) obj;
169 return Objects.equals(fLur, other.fLur);
170 } else {
171 // this should be infrequent
172 if (!(obj instanceof IPatternMatch)) {
173 return false;
174 }
175 IPatternMatch otherSig = (IPatternMatch) obj;
176 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
177 }
178 }
179
180 @Override
181 public Inv17 specification() {
182 return Inv17.instance();
183 }
184
185 /**
186 * Returns an empty, mutable match.
187 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
188 *
189 * @return the empty match.
190 *
191 */
192 public static Inv17.Match newEmptyMatch() {
193 return new Mutable(null);
194 }
195
196 /**
197 * Returns a mutable (partial) match.
198 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
199 *
200 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
201 * @return the new, mutable (partial) match object.
202 *
203 */
204 public static Inv17.Match newMutableMatch(final Legal_Union_Record pLur) {
205 return new Mutable(pLur);
206 }
207
208 /**
209 * Returns a new (partial) match.
210 * This can be used e.g. to call the matcher with a partial match.
211 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
212 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
213 * @return the (partial) match object.
214 *
215 */
216 public static Inv17.Match newMatch(final Legal_Union_Record pLur) {
217 return new Immutable(pLur);
218 }
219
220 private static final class Mutable extends Inv17.Match {
221 Mutable(final Legal_Union_Record pLur) {
222 super(pLur);
223 }
224
225 @Override
226 public boolean isMutable() {
227 return true;
228 }
229 }
230
231 private static final class Immutable extends Inv17.Match {
232 Immutable(final Legal_Union_Record pLur) {
233 super(pLur);
234 }
235
236 @Override
237 public boolean isMutable() {
238 return false;
239 }
240 }
241 }
242
243 /**
244 * Generated pattern matcher API of the queries.inv17 pattern,
245 * providing pattern-specific query methods.
246 *
247 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
248 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
249 *
250 * <p>Matches of the pattern will be represented as {@link Match}.
251 *
252 * <p>Original source:
253 * <code><pre>
254 * //inv16-Tax_Card.tax_card_type is a derived feature
255 *
256 * //inv17-attribute-handled by multiplicity
257 * {@literal @}Constraint(message = "inv17", severity = "error", key = {lur})
258 * pattern inv17(lur : Legal_Union_Record) {
259 * Legal_Union_Record.start_year(lur, sy);
260 * check(sy {@literal <} 1950);
261 * } or {
262 * Legal_Union_Record.start_year(lur, sy);
263 * check(sy {@literal >} 2018);
264 * }
265 * </pre></code>
266 *
267 * @see Match
268 * @see Inv17
269 *
270 */
271 public static class Matcher extends BaseMatcher<Inv17.Match> {
272 /**
273 * Initializes the pattern matcher within an existing VIATRA Query engine.
274 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
275 *
276 * @param engine the existing VIATRA Query engine in which this matcher will be created.
277 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
278 *
279 */
280 public static Inv17.Matcher on(final ViatraQueryEngine engine) {
281 // check if matcher already exists
282 Matcher matcher = engine.getExistingMatcher(querySpecification());
283 if (matcher == null) {
284 matcher = (Matcher)engine.getMatcher(querySpecification());
285 }
286 return matcher;
287 }
288
289 /**
290 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
291 * @return an initialized matcher
292 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
293 *
294 */
295 public static Inv17.Matcher create() {
296 return new Matcher();
297 }
298
299 private static final int POSITION_LUR = 0;
300
301 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv17.Matcher.class);
302
303 /**
304 * Initializes the pattern matcher within an existing VIATRA Query engine.
305 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
306 *
307 * @param engine the existing VIATRA Query engine in which this matcher will be created.
308 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
309 *
310 */
311 private Matcher() {
312 super(querySpecification());
313 }
314
315 /**
316 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
317 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
318 * @return matches represented as a Match object.
319 *
320 */
321 public Collection<Inv17.Match> getAllMatches(final Legal_Union_Record pLur) {
322 return rawStreamAllMatches(new Object[]{pLur}).collect(Collectors.toSet());
323 }
324
325 /**
326 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
327 * </p>
328 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
329 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
330 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
331 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
332 * @return a stream of matches represented as a Match object.
333 *
334 */
335 public Stream<Inv17.Match> streamAllMatches(final Legal_Union_Record pLur) {
336 return rawStreamAllMatches(new Object[]{pLur});
337 }
338
339 /**
340 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
341 * Neither determinism nor randomness of selection is guaranteed.
342 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
343 * @return a match represented as a Match object, or null if no match is found.
344 *
345 */
346 public Optional<Inv17.Match> getOneArbitraryMatch(final Legal_Union_Record pLur) {
347 return rawGetOneArbitraryMatch(new Object[]{pLur});
348 }
349
350 /**
351 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
352 * under any possible substitution of the unspecified parameters (if any).
353 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
354 * @return true if the input is a valid (partial) match of the pattern.
355 *
356 */
357 public boolean hasMatch(final Legal_Union_Record pLur) {
358 return rawHasMatch(new Object[]{pLur});
359 }
360
361 /**
362 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
363 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
364 * @return the number of pattern matches found.
365 *
366 */
367 public int countMatches(final Legal_Union_Record pLur) {
368 return rawCountMatches(new Object[]{pLur});
369 }
370
371 /**
372 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
373 * Neither determinism nor randomness of selection is guaranteed.
374 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
375 * @param processor the action that will process the selected match.
376 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
377 *
378 */
379 public boolean forOneArbitraryMatch(final Legal_Union_Record pLur, final Consumer<? super Inv17.Match> processor) {
380 return rawForOneArbitraryMatch(new Object[]{pLur}, processor);
381 }
382
383 /**
384 * Returns a new (partial) match.
385 * This can be used e.g. to call the matcher with a partial match.
386 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
387 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
388 * @return the (partial) match object.
389 *
390 */
391 public Inv17.Match newMatch(final Legal_Union_Record pLur) {
392 return Inv17.Match.newMatch(pLur);
393 }
394
395 /**
396 * Retrieve the set of values that occur in matches for lur.
397 * @return the Set of all values or empty set if there are no matches
398 *
399 */
400 protected Stream<Legal_Union_Record> rawStreamAllValuesOflur(final Object[] parameters) {
401 return rawStreamAllValues(POSITION_LUR, parameters).map(Legal_Union_Record.class::cast);
402 }
403
404 /**
405 * Retrieve the set of values that occur in matches for lur.
406 * @return the Set of all values or empty set if there are no matches
407 *
408 */
409 public Set<Legal_Union_Record> getAllValuesOflur() {
410 return rawStreamAllValuesOflur(emptyArray()).collect(Collectors.toSet());
411 }
412
413 /**
414 * Retrieve the set of values that occur in matches for lur.
415 * @return the Set of all values or empty set if there are no matches
416 *
417 */
418 public Stream<Legal_Union_Record> streamAllValuesOflur() {
419 return rawStreamAllValuesOflur(emptyArray());
420 }
421
422 @Override
423 protected Inv17.Match tupleToMatch(final Tuple t) {
424 try {
425 return Inv17.Match.newMatch((Legal_Union_Record) t.get(POSITION_LUR));
426 } catch(ClassCastException e) {
427 LOGGER.error("Element(s) in tuple not properly typed!",e);
428 return null;
429 }
430 }
431
432 @Override
433 protected Inv17.Match arrayToMatch(final Object[] match) {
434 try {
435 return Inv17.Match.newMatch((Legal_Union_Record) match[POSITION_LUR]);
436 } catch(ClassCastException e) {
437 LOGGER.error("Element(s) in array not properly typed!",e);
438 return null;
439 }
440 }
441
442 @Override
443 protected Inv17.Match arrayToMatchMutable(final Object[] match) {
444 try {
445 return Inv17.Match.newMutableMatch((Legal_Union_Record) match[POSITION_LUR]);
446 } catch(ClassCastException e) {
447 LOGGER.error("Element(s) in array not properly typed!",e);
448 return null;
449 }
450 }
451
452 /**
453 * @return the singleton instance of the query specification of this pattern
454 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
455 *
456 */
457 public static IQuerySpecification<Inv17.Matcher> querySpecification() {
458 return Inv17.instance();
459 }
460 }
461
462 private Inv17() {
463 super(GeneratedPQuery.INSTANCE);
464 }
465
466 /**
467 * @return the singleton instance of the query specification
468 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
469 *
470 */
471 public static Inv17 instance() {
472 try{
473 return LazyHolder.INSTANCE;
474 } catch (ExceptionInInitializerError err) {
475 throw processInitializerError(err);
476 }
477 }
478
479 @Override
480 protected Inv17.Matcher instantiate(final ViatraQueryEngine engine) {
481 return Inv17.Matcher.on(engine);
482 }
483
484 @Override
485 public Inv17.Matcher instantiate() {
486 return Inv17.Matcher.create();
487 }
488
489 @Override
490 public Inv17.Match newEmptyMatch() {
491 return Inv17.Match.newEmptyMatch();
492 }
493
494 @Override
495 public Inv17.Match newMatch(final Object... parameters) {
496 return Inv17.Match.newMatch((Taxation.Legal_Union_Record) parameters[0]);
497 }
498
499 /**
500 * Inner class allowing the singleton instance of {@link Inv17} to be created
501 * <b>not</b> at the class load time of the outer class,
502 * but rather at the first call to {@link Inv17#instance()}.
503 *
504 * <p> This workaround is required e.g. to support recursion.
505 *
506 */
507 private static class LazyHolder {
508 private static final Inv17 INSTANCE = new Inv17();
509
510 /**
511 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
512 * This initialization order is required to support indirect recursion.
513 *
514 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
515 *
516 */
517 private static final Object STATIC_INITIALIZER = ensureInitialized();
518
519 public static Object ensureInitialized() {
520 INSTANCE.ensureInitializedInternal();
521 return null;
522 }
523 }
524
525 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
526 private static final Inv17.GeneratedPQuery INSTANCE = new GeneratedPQuery();
527
528 private final PParameter parameter_lur = new PParameter("lur", "Taxation.Legal_Union_Record", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Legal_Union_Record")), PParameterDirection.INOUT);
529
530 private final List<PParameter> parameters = Arrays.asList(parameter_lur);
531
532 private GeneratedPQuery() {
533 super(PVisibility.PUBLIC);
534 }
535
536 @Override
537 public String getFullyQualifiedName() {
538 return "queries.inv17";
539 }
540
541 @Override
542 public List<String> getParameterNames() {
543 return Arrays.asList("lur");
544 }
545
546 @Override
547 public List<PParameter> getParameters() {
548 return parameters;
549 }
550
551 @Override
552 public Set<PBody> doGetContainedBodies() {
553 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
554 Set<PBody> bodies = new LinkedHashSet<>();
555 {
556 PBody body = new PBody(this);
557 PVariable var_lur = body.getOrCreateVariableByName("lur");
558 PVariable var_sy = body.getOrCreateVariableByName("sy");
559 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
560 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
561 new ExportedParameter(body, var_lur, parameter_lur)
562 ));
563 // Legal_Union_Record.start_year(lur, sy)
564 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
565 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
566 new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "start_year")));
567 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
568 new Equality(body, var__virtual_0_, var_sy);
569 // check(sy < 1950)
570 new ExpressionEvaluation(body, new IExpressionEvaluator() {
571
572 @Override
573 public String getShortDescription() {
574 return "Expression evaluation from pattern inv17";
575 }
576
577 @Override
578 public Iterable<String> getInputParameterNames() {
579 return Arrays.asList("sy");}
580
581 @Override
582 public Object evaluateExpression(IValueProvider provider) throws Exception {
583 Integer sy = (Integer) provider.getValue("sy");
584 return evaluateExpression_1_1(sy);
585 }
586 }, null);
587 bodies.add(body);
588 }
589 {
590 PBody body = new PBody(this);
591 PVariable var_lur = body.getOrCreateVariableByName("lur");
592 PVariable var_sy = body.getOrCreateVariableByName("sy");
593 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
594 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
595 new ExportedParameter(body, var_lur, parameter_lur)
596 ));
597 // Legal_Union_Record.start_year(lur, sy)
598 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
599 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
600 new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "start_year")));
601 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
602 new Equality(body, var__virtual_0_, var_sy);
603 // check(sy > 2018)
604 new ExpressionEvaluation(body, new IExpressionEvaluator() {
605
606 @Override
607 public String getShortDescription() {
608 return "Expression evaluation from pattern inv17";
609 }
610
611 @Override
612 public Iterable<String> getInputParameterNames() {
613 return Arrays.asList("sy");}
614
615 @Override
616 public Object evaluateExpression(IValueProvider provider) throws Exception {
617 Integer sy = (Integer) provider.getValue("sy");
618 return evaluateExpression_2_1(sy);
619 }
620 }, null);
621 bodies.add(body);
622 }
623 {
624 PAnnotation annotation = new PAnnotation("Constraint");
625 annotation.addAttribute("message", "inv17");
626 annotation.addAttribute("severity", "error");
627 annotation.addAttribute("key", Arrays.asList(new Object[] {
628 new ParameterReference("lur")
629 }));
630 addAnnotation(annotation);
631 }
632 return bodies;
633 }
634 }
635
636 private static boolean evaluateExpression_1_1(final Integer sy) {
637 return ((sy).intValue() < 1950);
638 }
639
640 private static boolean evaluateExpression_2_1(final Integer sy) {
641 return ((sy).intValue() > 2018);
642 }
643}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv20.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv20.java
new file mode 100644
index 00000000..2d5bd266
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv20.java
@@ -0,0 +1,587 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Legal_Union_Record;
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 * //inv18-MultiplicityChecked
49 * //inv19-MultiplicityChecked
50 *
51 * //inv20-Useless constraint since both edges are containment (TODOCheck)
52 * //OclIsUndefined-Handled by multiplicity
53 * {@literal @}Constraint(message = "inv20", severity = "error", key = {lur})
54 * pattern inv20(lur : Legal_Union_Record) {
55 * Legal_Union_Record.individual_A(lur, iA);
56 * Legal_Union_Record.individual_B(lur, iB);
57 * iA == iB;
58 * }
59 * </pre></code>
60 *
61 * @see Matcher
62 * @see Match
63 *
64 */
65@SuppressWarnings("all")
66public final class Inv20 extends BaseGeneratedEMFQuerySpecification<Inv20.Matcher> {
67 /**
68 * Pattern-specific match representation of the queries.inv20 pattern,
69 * to be used in conjunction with {@link Matcher}.
70 *
71 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
72 * Each instance is a (possibly partial) substitution of pattern parameters,
73 * usable to represent a match of the pattern in the result of a query,
74 * or to specify the bound (fixed) input parameters when issuing a query.
75 *
76 * @see Matcher
77 *
78 */
79 public static abstract class Match extends BasePatternMatch {
80 private Legal_Union_Record fLur;
81
82 private static List<String> parameterNames = makeImmutableList("lur");
83
84 private Match(final Legal_Union_Record pLur) {
85 this.fLur = pLur;
86 }
87
88 @Override
89 public Object get(final String parameterName) {
90 switch(parameterName) {
91 case "lur": return this.fLur;
92 default: return null;
93 }
94 }
95
96 @Override
97 public Object get(final int index) {
98 switch(index) {
99 case 0: return this.fLur;
100 default: return null;
101 }
102 }
103
104 public Legal_Union_Record getLur() {
105 return this.fLur;
106 }
107
108 @Override
109 public boolean set(final String parameterName, final Object newValue) {
110 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
111 if ("lur".equals(parameterName) ) {
112 this.fLur = (Legal_Union_Record) newValue;
113 return true;
114 }
115 return false;
116 }
117
118 public void setLur(final Legal_Union_Record pLur) {
119 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
120 this.fLur = pLur;
121 }
122
123 @Override
124 public String patternName() {
125 return "queries.inv20";
126 }
127
128 @Override
129 public List<String> parameterNames() {
130 return Inv20.Match.parameterNames;
131 }
132
133 @Override
134 public Object[] toArray() {
135 return new Object[]{fLur};
136 }
137
138 @Override
139 public Inv20.Match toImmutable() {
140 return isMutable() ? newMatch(fLur) : this;
141 }
142
143 @Override
144 public String prettyPrint() {
145 StringBuilder result = new StringBuilder();
146 result.append("\"lur\"=" + prettyPrintValue(fLur));
147 return result.toString();
148 }
149
150 @Override
151 public int hashCode() {
152 return Objects.hash(fLur);
153 }
154
155 @Override
156 public boolean equals(final Object obj) {
157 if (this == obj)
158 return true;
159 if (obj == null) {
160 return false;
161 }
162 if ((obj instanceof Inv20.Match)) {
163 Inv20.Match other = (Inv20.Match) obj;
164 return Objects.equals(fLur, other.fLur);
165 } else {
166 // this should be infrequent
167 if (!(obj instanceof IPatternMatch)) {
168 return false;
169 }
170 IPatternMatch otherSig = (IPatternMatch) obj;
171 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
172 }
173 }
174
175 @Override
176 public Inv20 specification() {
177 return Inv20.instance();
178 }
179
180 /**
181 * Returns an empty, mutable match.
182 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
183 *
184 * @return the empty match.
185 *
186 */
187 public static Inv20.Match newEmptyMatch() {
188 return new Mutable(null);
189 }
190
191 /**
192 * Returns a mutable (partial) match.
193 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
194 *
195 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
196 * @return the new, mutable (partial) match object.
197 *
198 */
199 public static Inv20.Match newMutableMatch(final Legal_Union_Record pLur) {
200 return new Mutable(pLur);
201 }
202
203 /**
204 * Returns a new (partial) match.
205 * This can be used e.g. to call the matcher with a partial match.
206 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
207 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
208 * @return the (partial) match object.
209 *
210 */
211 public static Inv20.Match newMatch(final Legal_Union_Record pLur) {
212 return new Immutable(pLur);
213 }
214
215 private static final class Mutable extends Inv20.Match {
216 Mutable(final Legal_Union_Record pLur) {
217 super(pLur);
218 }
219
220 @Override
221 public boolean isMutable() {
222 return true;
223 }
224 }
225
226 private static final class Immutable extends Inv20.Match {
227 Immutable(final Legal_Union_Record pLur) {
228 super(pLur);
229 }
230
231 @Override
232 public boolean isMutable() {
233 return false;
234 }
235 }
236 }
237
238 /**
239 * Generated pattern matcher API of the queries.inv20 pattern,
240 * providing pattern-specific query methods.
241 *
242 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
243 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
244 *
245 * <p>Matches of the pattern will be represented as {@link Match}.
246 *
247 * <p>Original source:
248 * <code><pre>
249 * //inv18-MultiplicityChecked
250 * //inv19-MultiplicityChecked
251 *
252 * //inv20-Useless constraint since both edges are containment (TODOCheck)
253 * //OclIsUndefined-Handled by multiplicity
254 * {@literal @}Constraint(message = "inv20", severity = "error", key = {lur})
255 * pattern inv20(lur : Legal_Union_Record) {
256 * Legal_Union_Record.individual_A(lur, iA);
257 * Legal_Union_Record.individual_B(lur, iB);
258 * iA == iB;
259 * }
260 * </pre></code>
261 *
262 * @see Match
263 * @see Inv20
264 *
265 */
266 public static class Matcher extends BaseMatcher<Inv20.Match> {
267 /**
268 * Initializes the pattern matcher within an existing VIATRA Query engine.
269 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
270 *
271 * @param engine the existing VIATRA Query engine in which this matcher will be created.
272 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
273 *
274 */
275 public static Inv20.Matcher on(final ViatraQueryEngine engine) {
276 // check if matcher already exists
277 Matcher matcher = engine.getExistingMatcher(querySpecification());
278 if (matcher == null) {
279 matcher = (Matcher)engine.getMatcher(querySpecification());
280 }
281 return matcher;
282 }
283
284 /**
285 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
286 * @return an initialized matcher
287 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
288 *
289 */
290 public static Inv20.Matcher create() {
291 return new Matcher();
292 }
293
294 private static final int POSITION_LUR = 0;
295
296 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv20.Matcher.class);
297
298 /**
299 * Initializes the pattern matcher within an existing VIATRA Query engine.
300 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
301 *
302 * @param engine the existing VIATRA Query engine in which this matcher will be created.
303 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
304 *
305 */
306 private Matcher() {
307 super(querySpecification());
308 }
309
310 /**
311 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
312 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
313 * @return matches represented as a Match object.
314 *
315 */
316 public Collection<Inv20.Match> getAllMatches(final Legal_Union_Record pLur) {
317 return rawStreamAllMatches(new Object[]{pLur}).collect(Collectors.toSet());
318 }
319
320 /**
321 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
322 * </p>
323 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
324 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
325 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
326 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
327 * @return a stream of matches represented as a Match object.
328 *
329 */
330 public Stream<Inv20.Match> streamAllMatches(final Legal_Union_Record pLur) {
331 return rawStreamAllMatches(new Object[]{pLur});
332 }
333
334 /**
335 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
336 * Neither determinism nor randomness of selection is guaranteed.
337 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
338 * @return a match represented as a Match object, or null if no match is found.
339 *
340 */
341 public Optional<Inv20.Match> getOneArbitraryMatch(final Legal_Union_Record pLur) {
342 return rawGetOneArbitraryMatch(new Object[]{pLur});
343 }
344
345 /**
346 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
347 * under any possible substitution of the unspecified parameters (if any).
348 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
349 * @return true if the input is a valid (partial) match of the pattern.
350 *
351 */
352 public boolean hasMatch(final Legal_Union_Record pLur) {
353 return rawHasMatch(new Object[]{pLur});
354 }
355
356 /**
357 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
358 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
359 * @return the number of pattern matches found.
360 *
361 */
362 public int countMatches(final Legal_Union_Record pLur) {
363 return rawCountMatches(new Object[]{pLur});
364 }
365
366 /**
367 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
368 * Neither determinism nor randomness of selection is guaranteed.
369 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
370 * @param processor the action that will process the selected match.
371 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
372 *
373 */
374 public boolean forOneArbitraryMatch(final Legal_Union_Record pLur, final Consumer<? super Inv20.Match> processor) {
375 return rawForOneArbitraryMatch(new Object[]{pLur}, processor);
376 }
377
378 /**
379 * Returns a new (partial) match.
380 * This can be used e.g. to call the matcher with a partial match.
381 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
382 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
383 * @return the (partial) match object.
384 *
385 */
386 public Inv20.Match newMatch(final Legal_Union_Record pLur) {
387 return Inv20.Match.newMatch(pLur);
388 }
389
390 /**
391 * Retrieve the set of values that occur in matches for lur.
392 * @return the Set of all values or empty set if there are no matches
393 *
394 */
395 protected Stream<Legal_Union_Record> rawStreamAllValuesOflur(final Object[] parameters) {
396 return rawStreamAllValues(POSITION_LUR, parameters).map(Legal_Union_Record.class::cast);
397 }
398
399 /**
400 * Retrieve the set of values that occur in matches for lur.
401 * @return the Set of all values or empty set if there are no matches
402 *
403 */
404 public Set<Legal_Union_Record> getAllValuesOflur() {
405 return rawStreamAllValuesOflur(emptyArray()).collect(Collectors.toSet());
406 }
407
408 /**
409 * Retrieve the set of values that occur in matches for lur.
410 * @return the Set of all values or empty set if there are no matches
411 *
412 */
413 public Stream<Legal_Union_Record> streamAllValuesOflur() {
414 return rawStreamAllValuesOflur(emptyArray());
415 }
416
417 @Override
418 protected Inv20.Match tupleToMatch(final Tuple t) {
419 try {
420 return Inv20.Match.newMatch((Legal_Union_Record) t.get(POSITION_LUR));
421 } catch(ClassCastException e) {
422 LOGGER.error("Element(s) in tuple not properly typed!",e);
423 return null;
424 }
425 }
426
427 @Override
428 protected Inv20.Match arrayToMatch(final Object[] match) {
429 try {
430 return Inv20.Match.newMatch((Legal_Union_Record) match[POSITION_LUR]);
431 } catch(ClassCastException e) {
432 LOGGER.error("Element(s) in array not properly typed!",e);
433 return null;
434 }
435 }
436
437 @Override
438 protected Inv20.Match arrayToMatchMutable(final Object[] match) {
439 try {
440 return Inv20.Match.newMutableMatch((Legal_Union_Record) match[POSITION_LUR]);
441 } catch(ClassCastException e) {
442 LOGGER.error("Element(s) in array not properly typed!",e);
443 return null;
444 }
445 }
446
447 /**
448 * @return the singleton instance of the query specification of this pattern
449 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
450 *
451 */
452 public static IQuerySpecification<Inv20.Matcher> querySpecification() {
453 return Inv20.instance();
454 }
455 }
456
457 private Inv20() {
458 super(GeneratedPQuery.INSTANCE);
459 }
460
461 /**
462 * @return the singleton instance of the query specification
463 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
464 *
465 */
466 public static Inv20 instance() {
467 try{
468 return LazyHolder.INSTANCE;
469 } catch (ExceptionInInitializerError err) {
470 throw processInitializerError(err);
471 }
472 }
473
474 @Override
475 protected Inv20.Matcher instantiate(final ViatraQueryEngine engine) {
476 return Inv20.Matcher.on(engine);
477 }
478
479 @Override
480 public Inv20.Matcher instantiate() {
481 return Inv20.Matcher.create();
482 }
483
484 @Override
485 public Inv20.Match newEmptyMatch() {
486 return Inv20.Match.newEmptyMatch();
487 }
488
489 @Override
490 public Inv20.Match newMatch(final Object... parameters) {
491 return Inv20.Match.newMatch((Taxation.Legal_Union_Record) parameters[0]);
492 }
493
494 /**
495 * Inner class allowing the singleton instance of {@link Inv20} to be created
496 * <b>not</b> at the class load time of the outer class,
497 * but rather at the first call to {@link Inv20#instance()}.
498 *
499 * <p> This workaround is required e.g. to support recursion.
500 *
501 */
502 private static class LazyHolder {
503 private static final Inv20 INSTANCE = new Inv20();
504
505 /**
506 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
507 * This initialization order is required to support indirect recursion.
508 *
509 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
510 *
511 */
512 private static final Object STATIC_INITIALIZER = ensureInitialized();
513
514 public static Object ensureInitialized() {
515 INSTANCE.ensureInitializedInternal();
516 return null;
517 }
518 }
519
520 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
521 private static final Inv20.GeneratedPQuery INSTANCE = new GeneratedPQuery();
522
523 private final PParameter parameter_lur = new PParameter("lur", "Taxation.Legal_Union_Record", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Legal_Union_Record")), PParameterDirection.INOUT);
524
525 private final List<PParameter> parameters = Arrays.asList(parameter_lur);
526
527 private GeneratedPQuery() {
528 super(PVisibility.PUBLIC);
529 }
530
531 @Override
532 public String getFullyQualifiedName() {
533 return "queries.inv20";
534 }
535
536 @Override
537 public List<String> getParameterNames() {
538 return Arrays.asList("lur");
539 }
540
541 @Override
542 public List<PParameter> getParameters() {
543 return parameters;
544 }
545
546 @Override
547 public Set<PBody> doGetContainedBodies() {
548 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
549 Set<PBody> bodies = new LinkedHashSet<>();
550 {
551 PBody body = new PBody(this);
552 PVariable var_lur = body.getOrCreateVariableByName("lur");
553 PVariable var_iA = body.getOrCreateVariableByName("iA");
554 PVariable var_iB = body.getOrCreateVariableByName("iB");
555 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
556 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
557 new ExportedParameter(body, var_lur, parameter_lur)
558 ));
559 // Legal_Union_Record.individual_A(lur, iA)
560 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
561 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
562 new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "individual_A")));
563 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
564 new Equality(body, var__virtual_0_, var_iA);
565 // Legal_Union_Record.individual_B(lur, iB)
566 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
567 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
568 new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "individual_B")));
569 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
570 new Equality(body, var__virtual_1_, var_iB);
571 // iA == iB
572 new Equality(body, var_iA, var_iB);
573 bodies.add(body);
574 }
575 {
576 PAnnotation annotation = new PAnnotation("Constraint");
577 annotation.addAttribute("message", "inv20");
578 annotation.addAttribute("severity", "error");
579 annotation.addAttribute("key", Arrays.asList(new Object[] {
580 new ParameterReference("lur")
581 }));
582 addAnnotation(annotation);
583 }
584 return bodies;
585 }
586 }
587}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv33.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv33.java
new file mode 100644
index 00000000..f90cca26
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv33.java
@@ -0,0 +1,665 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Physical_Person;
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 * //inv21-MultiplicityChecked
54 * //inv22-MultiplicityChecked
55 * //inv23-MultiplicityChecked
56 * //inv24-MultiplicityChecked
57 * //inv25-MultiplicityChecked
58 * //inv26-MultiplicityChanged
59 * //inv27-dupOfInv24
60 * //inv28-dubOfInv23
61 * //inv29-MultiplicityChanged
62 * //inv30-AttributeRemoved
63 * //inv31-AttributeRemoved
64 * //inv32-AttributeRemoved
65 *
66 * //inv33-attribute-handled by multiplicity
67 * {@literal @}Constraint(message = "inv33", severity = "error", key = {p})
68 * pattern inv33(p : Physical_Person) {
69 * Physical_Person.birth_year(p, by);
70 * check(2018-by {@literal <} 0);
71 * } or {
72 * Physical_Person.birth_year(p, by);
73 * check(2018-by {@literal >} 100);
74 * }
75 * </pre></code>
76 *
77 * @see Matcher
78 * @see Match
79 *
80 */
81@SuppressWarnings("all")
82public final class Inv33 extends BaseGeneratedEMFQuerySpecification<Inv33.Matcher> {
83 /**
84 * Pattern-specific match representation of the queries.inv33 pattern,
85 * to be used in conjunction with {@link Matcher}.
86 *
87 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
88 * Each instance is a (possibly partial) substitution of pattern parameters,
89 * usable to represent a match of the pattern in the result of a query,
90 * or to specify the bound (fixed) input parameters when issuing a query.
91 *
92 * @see Matcher
93 *
94 */
95 public static abstract class Match extends BasePatternMatch {
96 private Physical_Person fP;
97
98 private static List<String> parameterNames = makeImmutableList("p");
99
100 private Match(final Physical_Person pP) {
101 this.fP = pP;
102 }
103
104 @Override
105 public Object get(final String parameterName) {
106 switch(parameterName) {
107 case "p": return this.fP;
108 default: return null;
109 }
110 }
111
112 @Override
113 public Object get(final int index) {
114 switch(index) {
115 case 0: return this.fP;
116 default: return null;
117 }
118 }
119
120 public Physical_Person getP() {
121 return this.fP;
122 }
123
124 @Override
125 public boolean set(final String parameterName, final Object newValue) {
126 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
127 if ("p".equals(parameterName) ) {
128 this.fP = (Physical_Person) newValue;
129 return true;
130 }
131 return false;
132 }
133
134 public void setP(final Physical_Person pP) {
135 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
136 this.fP = pP;
137 }
138
139 @Override
140 public String patternName() {
141 return "queries.inv33";
142 }
143
144 @Override
145 public List<String> parameterNames() {
146 return Inv33.Match.parameterNames;
147 }
148
149 @Override
150 public Object[] toArray() {
151 return new Object[]{fP};
152 }
153
154 @Override
155 public Inv33.Match toImmutable() {
156 return isMutable() ? newMatch(fP) : this;
157 }
158
159 @Override
160 public String prettyPrint() {
161 StringBuilder result = new StringBuilder();
162 result.append("\"p\"=" + prettyPrintValue(fP));
163 return result.toString();
164 }
165
166 @Override
167 public int hashCode() {
168 return Objects.hash(fP);
169 }
170
171 @Override
172 public boolean equals(final Object obj) {
173 if (this == obj)
174 return true;
175 if (obj == null) {
176 return false;
177 }
178 if ((obj instanceof Inv33.Match)) {
179 Inv33.Match other = (Inv33.Match) obj;
180 return Objects.equals(fP, other.fP);
181 } else {
182 // this should be infrequent
183 if (!(obj instanceof IPatternMatch)) {
184 return false;
185 }
186 IPatternMatch otherSig = (IPatternMatch) obj;
187 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
188 }
189 }
190
191 @Override
192 public Inv33 specification() {
193 return Inv33.instance();
194 }
195
196 /**
197 * Returns an empty, mutable match.
198 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
199 *
200 * @return the empty match.
201 *
202 */
203 public static Inv33.Match newEmptyMatch() {
204 return new Mutable(null);
205 }
206
207 /**
208 * Returns a mutable (partial) match.
209 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
210 *
211 * @param pP the fixed value of pattern parameter p, or null if not bound.
212 * @return the new, mutable (partial) match object.
213 *
214 */
215 public static Inv33.Match newMutableMatch(final Physical_Person pP) {
216 return new Mutable(pP);
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 pP the fixed value of pattern parameter p, or null if not bound.
224 * @return the (partial) match object.
225 *
226 */
227 public static Inv33.Match newMatch(final Physical_Person pP) {
228 return new Immutable(pP);
229 }
230
231 private static final class Mutable extends Inv33.Match {
232 Mutable(final Physical_Person pP) {
233 super(pP);
234 }
235
236 @Override
237 public boolean isMutable() {
238 return true;
239 }
240 }
241
242 private static final class Immutable extends Inv33.Match {
243 Immutable(final Physical_Person pP) {
244 super(pP);
245 }
246
247 @Override
248 public boolean isMutable() {
249 return false;
250 }
251 }
252 }
253
254 /**
255 * Generated pattern matcher API of the queries.inv33 pattern,
256 * providing pattern-specific query methods.
257 *
258 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
259 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
260 *
261 * <p>Matches of the pattern will be represented as {@link Match}.
262 *
263 * <p>Original source:
264 * <code><pre>
265 * //inv21-MultiplicityChecked
266 * //inv22-MultiplicityChecked
267 * //inv23-MultiplicityChecked
268 * //inv24-MultiplicityChecked
269 * //inv25-MultiplicityChecked
270 * //inv26-MultiplicityChanged
271 * //inv27-dupOfInv24
272 * //inv28-dubOfInv23
273 * //inv29-MultiplicityChanged
274 * //inv30-AttributeRemoved
275 * //inv31-AttributeRemoved
276 * //inv32-AttributeRemoved
277 *
278 * //inv33-attribute-handled by multiplicity
279 * {@literal @}Constraint(message = "inv33", severity = "error", key = {p})
280 * pattern inv33(p : Physical_Person) {
281 * Physical_Person.birth_year(p, by);
282 * check(2018-by {@literal <} 0);
283 * } or {
284 * Physical_Person.birth_year(p, by);
285 * check(2018-by {@literal >} 100);
286 * }
287 * </pre></code>
288 *
289 * @see Match
290 * @see Inv33
291 *
292 */
293 public static class Matcher extends BaseMatcher<Inv33.Match> {
294 /**
295 * Initializes the pattern matcher within an existing VIATRA Query engine.
296 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
297 *
298 * @param engine the existing VIATRA Query engine in which this matcher will be created.
299 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
300 *
301 */
302 public static Inv33.Matcher on(final ViatraQueryEngine engine) {
303 // check if matcher already exists
304 Matcher matcher = engine.getExistingMatcher(querySpecification());
305 if (matcher == null) {
306 matcher = (Matcher)engine.getMatcher(querySpecification());
307 }
308 return matcher;
309 }
310
311 /**
312 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
313 * @return an initialized matcher
314 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
315 *
316 */
317 public static Inv33.Matcher create() {
318 return new Matcher();
319 }
320
321 private static final int POSITION_P = 0;
322
323 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv33.Matcher.class);
324
325 /**
326 * Initializes the pattern matcher within an existing VIATRA Query engine.
327 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
328 *
329 * @param engine the existing VIATRA Query engine in which this matcher will be created.
330 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
331 *
332 */
333 private Matcher() {
334 super(querySpecification());
335 }
336
337 /**
338 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
339 * @param pP the fixed value of pattern parameter p, or null if not bound.
340 * @return matches represented as a Match object.
341 *
342 */
343 public Collection<Inv33.Match> getAllMatches(final Physical_Person pP) {
344 return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet());
345 }
346
347 /**
348 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
349 * </p>
350 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
351 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
352 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
353 * @param pP the fixed value of pattern parameter p, or null if not bound.
354 * @return a stream of matches represented as a Match object.
355 *
356 */
357 public Stream<Inv33.Match> streamAllMatches(final Physical_Person pP) {
358 return rawStreamAllMatches(new Object[]{pP});
359 }
360
361 /**
362 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
363 * Neither determinism nor randomness of selection is guaranteed.
364 * @param pP the fixed value of pattern parameter p, or null if not bound.
365 * @return a match represented as a Match object, or null if no match is found.
366 *
367 */
368 public Optional<Inv33.Match> getOneArbitraryMatch(final Physical_Person pP) {
369 return rawGetOneArbitraryMatch(new Object[]{pP});
370 }
371
372 /**
373 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
374 * under any possible substitution of the unspecified parameters (if any).
375 * @param pP the fixed value of pattern parameter p, or null if not bound.
376 * @return true if the input is a valid (partial) match of the pattern.
377 *
378 */
379 public boolean hasMatch(final Physical_Person pP) {
380 return rawHasMatch(new Object[]{pP});
381 }
382
383 /**
384 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
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 Physical_Person pP) {
390 return rawCountMatches(new Object[]{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 pP the fixed value of pattern parameter p, or null if not bound.
397 * @param processor the action that will process the selected match.
398 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
399 *
400 */
401 public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer<? super Inv33.Match> processor) {
402 return rawForOneArbitraryMatch(new Object[]{pP}, processor);
403 }
404
405 /**
406 * Returns a new (partial) match.
407 * This can be used e.g. to call the matcher with a partial match.
408 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
409 * @param pP the fixed value of pattern parameter p, or null if not bound.
410 * @return the (partial) match object.
411 *
412 */
413 public Inv33.Match newMatch(final Physical_Person pP) {
414 return Inv33.Match.newMatch(pP);
415 }
416
417 /**
418 * Retrieve the set of values that occur in matches for p.
419 * @return the Set of all values or empty set if there are no matches
420 *
421 */
422 protected Stream<Physical_Person> rawStreamAllValuesOfp(final Object[] parameters) {
423 return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast);
424 }
425
426 /**
427 * Retrieve the set of values that occur in matches for p.
428 * @return the Set of all values or empty set if there are no matches
429 *
430 */
431 public Set<Physical_Person> getAllValuesOfp() {
432 return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet());
433 }
434
435 /**
436 * Retrieve the set of values that occur in matches for p.
437 * @return the Set of all values or empty set if there are no matches
438 *
439 */
440 public Stream<Physical_Person> streamAllValuesOfp() {
441 return rawStreamAllValuesOfp(emptyArray());
442 }
443
444 @Override
445 protected Inv33.Match tupleToMatch(final Tuple t) {
446 try {
447 return Inv33.Match.newMatch((Physical_Person) t.get(POSITION_P));
448 } catch(ClassCastException e) {
449 LOGGER.error("Element(s) in tuple not properly typed!",e);
450 return null;
451 }
452 }
453
454 @Override
455 protected Inv33.Match arrayToMatch(final Object[] match) {
456 try {
457 return Inv33.Match.newMatch((Physical_Person) match[POSITION_P]);
458 } catch(ClassCastException e) {
459 LOGGER.error("Element(s) in array not properly typed!",e);
460 return null;
461 }
462 }
463
464 @Override
465 protected Inv33.Match arrayToMatchMutable(final Object[] match) {
466 try {
467 return Inv33.Match.newMutableMatch((Physical_Person) match[POSITION_P]);
468 } catch(ClassCastException e) {
469 LOGGER.error("Element(s) in array not properly typed!",e);
470 return null;
471 }
472 }
473
474 /**
475 * @return the singleton instance of the query specification of this pattern
476 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
477 *
478 */
479 public static IQuerySpecification<Inv33.Matcher> querySpecification() {
480 return Inv33.instance();
481 }
482 }
483
484 private Inv33() {
485 super(GeneratedPQuery.INSTANCE);
486 }
487
488 /**
489 * @return the singleton instance of the query specification
490 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
491 *
492 */
493 public static Inv33 instance() {
494 try{
495 return LazyHolder.INSTANCE;
496 } catch (ExceptionInInitializerError err) {
497 throw processInitializerError(err);
498 }
499 }
500
501 @Override
502 protected Inv33.Matcher instantiate(final ViatraQueryEngine engine) {
503 return Inv33.Matcher.on(engine);
504 }
505
506 @Override
507 public Inv33.Matcher instantiate() {
508 return Inv33.Matcher.create();
509 }
510
511 @Override
512 public Inv33.Match newEmptyMatch() {
513 return Inv33.Match.newEmptyMatch();
514 }
515
516 @Override
517 public Inv33.Match newMatch(final Object... parameters) {
518 return Inv33.Match.newMatch((Taxation.Physical_Person) parameters[0]);
519 }
520
521 /**
522 * Inner class allowing the singleton instance of {@link Inv33} to be created
523 * <b>not</b> at the class load time of the outer class,
524 * but rather at the first call to {@link Inv33#instance()}.
525 *
526 * <p> This workaround is required e.g. to support recursion.
527 *
528 */
529 private static class LazyHolder {
530 private static final Inv33 INSTANCE = new Inv33();
531
532 /**
533 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
534 * This initialization order is required to support indirect recursion.
535 *
536 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
537 *
538 */
539 private static final Object STATIC_INITIALIZER = ensureInitialized();
540
541 public static Object ensureInitialized() {
542 INSTANCE.ensureInitializedInternal();
543 return null;
544 }
545 }
546
547 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
548 private static final Inv33.GeneratedPQuery INSTANCE = new GeneratedPQuery();
549
550 private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT);
551
552 private final List<PParameter> parameters = Arrays.asList(parameter_p);
553
554 private GeneratedPQuery() {
555 super(PVisibility.PUBLIC);
556 }
557
558 @Override
559 public String getFullyQualifiedName() {
560 return "queries.inv33";
561 }
562
563 @Override
564 public List<String> getParameterNames() {
565 return Arrays.asList("p");
566 }
567
568 @Override
569 public List<PParameter> getParameters() {
570 return parameters;
571 }
572
573 @Override
574 public Set<PBody> doGetContainedBodies() {
575 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
576 Set<PBody> bodies = new LinkedHashSet<>();
577 {
578 PBody body = new PBody(this);
579 PVariable var_p = body.getOrCreateVariableByName("p");
580 PVariable var_by = body.getOrCreateVariableByName("by");
581 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
582 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
583 new ExportedParameter(body, var_p, parameter_p)
584 ));
585 // Physical_Person.birth_year(p, by)
586 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
587 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
588 new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year")));
589 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
590 new Equality(body, var__virtual_0_, var_by);
591 // check(2018-by < 0)
592 new ExpressionEvaluation(body, new IExpressionEvaluator() {
593
594 @Override
595 public String getShortDescription() {
596 return "Expression evaluation from pattern inv33";
597 }
598
599 @Override
600 public Iterable<String> getInputParameterNames() {
601 return Arrays.asList("by");}
602
603 @Override
604 public Object evaluateExpression(IValueProvider provider) throws Exception {
605 Integer by = (Integer) provider.getValue("by");
606 return evaluateExpression_1_1(by);
607 }
608 }, null);
609 bodies.add(body);
610 }
611 {
612 PBody body = new PBody(this);
613 PVariable var_p = body.getOrCreateVariableByName("p");
614 PVariable var_by = body.getOrCreateVariableByName("by");
615 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
616 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
617 new ExportedParameter(body, var_p, parameter_p)
618 ));
619 // Physical_Person.birth_year(p, by)
620 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
621 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
622 new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year")));
623 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
624 new Equality(body, var__virtual_0_, var_by);
625 // check(2018-by > 100)
626 new ExpressionEvaluation(body, new IExpressionEvaluator() {
627
628 @Override
629 public String getShortDescription() {
630 return "Expression evaluation from pattern inv33";
631 }
632
633 @Override
634 public Iterable<String> getInputParameterNames() {
635 return Arrays.asList("by");}
636
637 @Override
638 public Object evaluateExpression(IValueProvider provider) throws Exception {
639 Integer by = (Integer) provider.getValue("by");
640 return evaluateExpression_2_1(by);
641 }
642 }, null);
643 bodies.add(body);
644 }
645 {
646 PAnnotation annotation = new PAnnotation("Constraint");
647 annotation.addAttribute("message", "inv33");
648 annotation.addAttribute("severity", "error");
649 annotation.addAttribute("key", Arrays.asList(new Object[] {
650 new ParameterReference("p")
651 }));
652 addAnnotation(annotation);
653 }
654 return bodies;
655 }
656 }
657
658 private static boolean evaluateExpression_1_1(final Integer by) {
659 return ((2018 - (by).intValue()) < 0);
660 }
661
662 private static boolean evaluateExpression_2_1(final Integer by) {
663 return ((2018 - (by).intValue()) > 100);
664 }
665}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv34.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv34.java
new file mode 100644
index 00000000..89a24686
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv34.java
@@ -0,0 +1,639 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Physical_Person;
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 * //inv34-attribute-handled by multiplicity
54 * {@literal @}Constraint(message = "inv34", severity = "error", key = {p})
55 * pattern inv34(p : Physical_Person) {
56 * Physical_Person.birth_month(p, birthMonth);
57 * check(birthMonth {@literal <} 1);
58 * } or {
59 * Physical_Person.birth_month(p, birthMonth);
60 * check(birthMonth {@literal >} 12);
61 * }
62 * </pre></code>
63 *
64 * @see Matcher
65 * @see Match
66 *
67 */
68@SuppressWarnings("all")
69public final class Inv34 extends BaseGeneratedEMFQuerySpecification<Inv34.Matcher> {
70 /**
71 * Pattern-specific match representation of the queries.inv34 pattern,
72 * to be used in conjunction with {@link Matcher}.
73 *
74 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
75 * Each instance is a (possibly partial) substitution of pattern parameters,
76 * usable to represent a match of the pattern in the result of a query,
77 * or to specify the bound (fixed) input parameters when issuing a query.
78 *
79 * @see Matcher
80 *
81 */
82 public static abstract class Match extends BasePatternMatch {
83 private Physical_Person fP;
84
85 private static List<String> parameterNames = makeImmutableList("p");
86
87 private Match(final Physical_Person pP) {
88 this.fP = pP;
89 }
90
91 @Override
92 public Object get(final String parameterName) {
93 switch(parameterName) {
94 case "p": return this.fP;
95 default: return null;
96 }
97 }
98
99 @Override
100 public Object get(final int index) {
101 switch(index) {
102 case 0: return this.fP;
103 default: return null;
104 }
105 }
106
107 public Physical_Person getP() {
108 return this.fP;
109 }
110
111 @Override
112 public boolean set(final String parameterName, final Object newValue) {
113 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
114 if ("p".equals(parameterName) ) {
115 this.fP = (Physical_Person) newValue;
116 return true;
117 }
118 return false;
119 }
120
121 public void setP(final Physical_Person pP) {
122 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
123 this.fP = pP;
124 }
125
126 @Override
127 public String patternName() {
128 return "queries.inv34";
129 }
130
131 @Override
132 public List<String> parameterNames() {
133 return Inv34.Match.parameterNames;
134 }
135
136 @Override
137 public Object[] toArray() {
138 return new Object[]{fP};
139 }
140
141 @Override
142 public Inv34.Match toImmutable() {
143 return isMutable() ? newMatch(fP) : this;
144 }
145
146 @Override
147 public String prettyPrint() {
148 StringBuilder result = new StringBuilder();
149 result.append("\"p\"=" + prettyPrintValue(fP));
150 return result.toString();
151 }
152
153 @Override
154 public int hashCode() {
155 return Objects.hash(fP);
156 }
157
158 @Override
159 public boolean equals(final Object obj) {
160 if (this == obj)
161 return true;
162 if (obj == null) {
163 return false;
164 }
165 if ((obj instanceof Inv34.Match)) {
166 Inv34.Match other = (Inv34.Match) obj;
167 return Objects.equals(fP, other.fP);
168 } else {
169 // this should be infrequent
170 if (!(obj instanceof IPatternMatch)) {
171 return false;
172 }
173 IPatternMatch otherSig = (IPatternMatch) obj;
174 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
175 }
176 }
177
178 @Override
179 public Inv34 specification() {
180 return Inv34.instance();
181 }
182
183 /**
184 * Returns an empty, mutable match.
185 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
186 *
187 * @return the empty match.
188 *
189 */
190 public static Inv34.Match newEmptyMatch() {
191 return new Mutable(null);
192 }
193
194 /**
195 * Returns a mutable (partial) match.
196 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
197 *
198 * @param pP the fixed value of pattern parameter p, or null if not bound.
199 * @return the new, mutable (partial) match object.
200 *
201 */
202 public static Inv34.Match newMutableMatch(final Physical_Person pP) {
203 return new Mutable(pP);
204 }
205
206 /**
207 * Returns a new (partial) match.
208 * This can be used e.g. to call the matcher with a partial match.
209 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
210 * @param pP the fixed value of pattern parameter p, or null if not bound.
211 * @return the (partial) match object.
212 *
213 */
214 public static Inv34.Match newMatch(final Physical_Person pP) {
215 return new Immutable(pP);
216 }
217
218 private static final class Mutable extends Inv34.Match {
219 Mutable(final Physical_Person pP) {
220 super(pP);
221 }
222
223 @Override
224 public boolean isMutable() {
225 return true;
226 }
227 }
228
229 private static final class Immutable extends Inv34.Match {
230 Immutable(final Physical_Person pP) {
231 super(pP);
232 }
233
234 @Override
235 public boolean isMutable() {
236 return false;
237 }
238 }
239 }
240
241 /**
242 * Generated pattern matcher API of the queries.inv34 pattern,
243 * providing pattern-specific query methods.
244 *
245 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
246 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
247 *
248 * <p>Matches of the pattern will be represented as {@link Match}.
249 *
250 * <p>Original source:
251 * <code><pre>
252 * //inv34-attribute-handled by multiplicity
253 * {@literal @}Constraint(message = "inv34", severity = "error", key = {p})
254 * pattern inv34(p : Physical_Person) {
255 * Physical_Person.birth_month(p, birthMonth);
256 * check(birthMonth {@literal <} 1);
257 * } or {
258 * Physical_Person.birth_month(p, birthMonth);
259 * check(birthMonth {@literal >} 12);
260 * }
261 * </pre></code>
262 *
263 * @see Match
264 * @see Inv34
265 *
266 */
267 public static class Matcher extends BaseMatcher<Inv34.Match> {
268 /**
269 * Initializes the pattern matcher within an existing VIATRA Query engine.
270 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
271 *
272 * @param engine the existing VIATRA Query engine in which this matcher will be created.
273 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
274 *
275 */
276 public static Inv34.Matcher on(final ViatraQueryEngine engine) {
277 // check if matcher already exists
278 Matcher matcher = engine.getExistingMatcher(querySpecification());
279 if (matcher == null) {
280 matcher = (Matcher)engine.getMatcher(querySpecification());
281 }
282 return matcher;
283 }
284
285 /**
286 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
287 * @return an initialized matcher
288 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
289 *
290 */
291 public static Inv34.Matcher create() {
292 return new Matcher();
293 }
294
295 private static final int POSITION_P = 0;
296
297 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv34.Matcher.class);
298
299 /**
300 * Initializes the pattern matcher within an existing VIATRA Query engine.
301 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
302 *
303 * @param engine the existing VIATRA Query engine in which this matcher will be created.
304 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
305 *
306 */
307 private Matcher() {
308 super(querySpecification());
309 }
310
311 /**
312 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
313 * @param pP the fixed value of pattern parameter p, or null if not bound.
314 * @return matches represented as a Match object.
315 *
316 */
317 public Collection<Inv34.Match> getAllMatches(final Physical_Person pP) {
318 return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet());
319 }
320
321 /**
322 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
323 * </p>
324 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
325 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
326 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
327 * @param pP the fixed value of pattern parameter p, or null if not bound.
328 * @return a stream of matches represented as a Match object.
329 *
330 */
331 public Stream<Inv34.Match> streamAllMatches(final Physical_Person pP) {
332 return rawStreamAllMatches(new Object[]{pP});
333 }
334
335 /**
336 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
337 * Neither determinism nor randomness of selection is guaranteed.
338 * @param pP the fixed value of pattern parameter p, or null if not bound.
339 * @return a match represented as a Match object, or null if no match is found.
340 *
341 */
342 public Optional<Inv34.Match> getOneArbitraryMatch(final Physical_Person pP) {
343 return rawGetOneArbitraryMatch(new Object[]{pP});
344 }
345
346 /**
347 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
348 * under any possible substitution of the unspecified parameters (if any).
349 * @param pP the fixed value of pattern parameter p, or null if not bound.
350 * @return true if the input is a valid (partial) match of the pattern.
351 *
352 */
353 public boolean hasMatch(final Physical_Person pP) {
354 return rawHasMatch(new Object[]{pP});
355 }
356
357 /**
358 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
359 * @param pP the fixed value of pattern parameter p, or null if not bound.
360 * @return the number of pattern matches found.
361 *
362 */
363 public int countMatches(final Physical_Person pP) {
364 return rawCountMatches(new Object[]{pP});
365 }
366
367 /**
368 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
369 * Neither determinism nor randomness of selection is guaranteed.
370 * @param pP the fixed value of pattern parameter p, or null if not bound.
371 * @param processor the action that will process the selected match.
372 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
373 *
374 */
375 public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer<? super Inv34.Match> processor) {
376 return rawForOneArbitraryMatch(new Object[]{pP}, processor);
377 }
378
379 /**
380 * Returns a new (partial) match.
381 * This can be used e.g. to call the matcher with a partial match.
382 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
383 * @param pP the fixed value of pattern parameter p, or null if not bound.
384 * @return the (partial) match object.
385 *
386 */
387 public Inv34.Match newMatch(final Physical_Person pP) {
388 return Inv34.Match.newMatch(pP);
389 }
390
391 /**
392 * Retrieve the set of values that occur in matches for p.
393 * @return the Set of all values or empty set if there are no matches
394 *
395 */
396 protected Stream<Physical_Person> rawStreamAllValuesOfp(final Object[] parameters) {
397 return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast);
398 }
399
400 /**
401 * Retrieve the set of values that occur in matches for p.
402 * @return the Set of all values or empty set if there are no matches
403 *
404 */
405 public Set<Physical_Person> getAllValuesOfp() {
406 return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet());
407 }
408
409 /**
410 * Retrieve the set of values that occur in matches for p.
411 * @return the Set of all values or empty set if there are no matches
412 *
413 */
414 public Stream<Physical_Person> streamAllValuesOfp() {
415 return rawStreamAllValuesOfp(emptyArray());
416 }
417
418 @Override
419 protected Inv34.Match tupleToMatch(final Tuple t) {
420 try {
421 return Inv34.Match.newMatch((Physical_Person) t.get(POSITION_P));
422 } catch(ClassCastException e) {
423 LOGGER.error("Element(s) in tuple not properly typed!",e);
424 return null;
425 }
426 }
427
428 @Override
429 protected Inv34.Match arrayToMatch(final Object[] match) {
430 try {
431 return Inv34.Match.newMatch((Physical_Person) match[POSITION_P]);
432 } catch(ClassCastException e) {
433 LOGGER.error("Element(s) in array not properly typed!",e);
434 return null;
435 }
436 }
437
438 @Override
439 protected Inv34.Match arrayToMatchMutable(final Object[] match) {
440 try {
441 return Inv34.Match.newMutableMatch((Physical_Person) match[POSITION_P]);
442 } catch(ClassCastException e) {
443 LOGGER.error("Element(s) in array not properly typed!",e);
444 return null;
445 }
446 }
447
448 /**
449 * @return the singleton instance of the query specification of this pattern
450 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
451 *
452 */
453 public static IQuerySpecification<Inv34.Matcher> querySpecification() {
454 return Inv34.instance();
455 }
456 }
457
458 private Inv34() {
459 super(GeneratedPQuery.INSTANCE);
460 }
461
462 /**
463 * @return the singleton instance of the query specification
464 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
465 *
466 */
467 public static Inv34 instance() {
468 try{
469 return LazyHolder.INSTANCE;
470 } catch (ExceptionInInitializerError err) {
471 throw processInitializerError(err);
472 }
473 }
474
475 @Override
476 protected Inv34.Matcher instantiate(final ViatraQueryEngine engine) {
477 return Inv34.Matcher.on(engine);
478 }
479
480 @Override
481 public Inv34.Matcher instantiate() {
482 return Inv34.Matcher.create();
483 }
484
485 @Override
486 public Inv34.Match newEmptyMatch() {
487 return Inv34.Match.newEmptyMatch();
488 }
489
490 @Override
491 public Inv34.Match newMatch(final Object... parameters) {
492 return Inv34.Match.newMatch((Taxation.Physical_Person) parameters[0]);
493 }
494
495 /**
496 * Inner class allowing the singleton instance of {@link Inv34} to be created
497 * <b>not</b> at the class load time of the outer class,
498 * but rather at the first call to {@link Inv34#instance()}.
499 *
500 * <p> This workaround is required e.g. to support recursion.
501 *
502 */
503 private static class LazyHolder {
504 private static final Inv34 INSTANCE = new Inv34();
505
506 /**
507 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
508 * This initialization order is required to support indirect recursion.
509 *
510 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
511 *
512 */
513 private static final Object STATIC_INITIALIZER = ensureInitialized();
514
515 public static Object ensureInitialized() {
516 INSTANCE.ensureInitializedInternal();
517 return null;
518 }
519 }
520
521 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
522 private static final Inv34.GeneratedPQuery INSTANCE = new GeneratedPQuery();
523
524 private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT);
525
526 private final List<PParameter> parameters = Arrays.asList(parameter_p);
527
528 private GeneratedPQuery() {
529 super(PVisibility.PUBLIC);
530 }
531
532 @Override
533 public String getFullyQualifiedName() {
534 return "queries.inv34";
535 }
536
537 @Override
538 public List<String> getParameterNames() {
539 return Arrays.asList("p");
540 }
541
542 @Override
543 public List<PParameter> getParameters() {
544 return parameters;
545 }
546
547 @Override
548 public Set<PBody> doGetContainedBodies() {
549 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
550 Set<PBody> bodies = new LinkedHashSet<>();
551 {
552 PBody body = new PBody(this);
553 PVariable var_p = body.getOrCreateVariableByName("p");
554 PVariable var_birthMonth = body.getOrCreateVariableByName("birthMonth");
555 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
556 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
557 new ExportedParameter(body, var_p, parameter_p)
558 ));
559 // Physical_Person.birth_month(p, birthMonth)
560 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
561 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
562 new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_month")));
563 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
564 new Equality(body, var__virtual_0_, var_birthMonth);
565 // check(birthMonth < 1)
566 new ExpressionEvaluation(body, new IExpressionEvaluator() {
567
568 @Override
569 public String getShortDescription() {
570 return "Expression evaluation from pattern inv34";
571 }
572
573 @Override
574 public Iterable<String> getInputParameterNames() {
575 return Arrays.asList("birthMonth");}
576
577 @Override
578 public Object evaluateExpression(IValueProvider provider) throws Exception {
579 Integer birthMonth = (Integer) provider.getValue("birthMonth");
580 return evaluateExpression_1_1(birthMonth);
581 }
582 }, null);
583 bodies.add(body);
584 }
585 {
586 PBody body = new PBody(this);
587 PVariable var_p = body.getOrCreateVariableByName("p");
588 PVariable var_birthMonth = body.getOrCreateVariableByName("birthMonth");
589 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
590 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
591 new ExportedParameter(body, var_p, parameter_p)
592 ));
593 // Physical_Person.birth_month(p, birthMonth)
594 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
595 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
596 new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_month")));
597 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
598 new Equality(body, var__virtual_0_, var_birthMonth);
599 // check(birthMonth > 12)
600 new ExpressionEvaluation(body, new IExpressionEvaluator() {
601
602 @Override
603 public String getShortDescription() {
604 return "Expression evaluation from pattern inv34";
605 }
606
607 @Override
608 public Iterable<String> getInputParameterNames() {
609 return Arrays.asList("birthMonth");}
610
611 @Override
612 public Object evaluateExpression(IValueProvider provider) throws Exception {
613 Integer birthMonth = (Integer) provider.getValue("birthMonth");
614 return evaluateExpression_2_1(birthMonth);
615 }
616 }, null);
617 bodies.add(body);
618 }
619 {
620 PAnnotation annotation = new PAnnotation("Constraint");
621 annotation.addAttribute("message", "inv34");
622 annotation.addAttribute("severity", "error");
623 annotation.addAttribute("key", Arrays.asList(new Object[] {
624 new ParameterReference("p")
625 }));
626 addAnnotation(annotation);
627 }
628 return bodies;
629 }
630 }
631
632 private static boolean evaluateExpression_1_1(final Integer birthMonth) {
633 return ((birthMonth).intValue() < 1);
634 }
635
636 private static boolean evaluateExpression_2_1(final Integer birthMonth) {
637 return ((birthMonth).intValue() > 12);
638 }
639}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv35.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv35.java
new file mode 100644
index 00000000..b5da21b4
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv35.java
@@ -0,0 +1,639 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Physical_Person;
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 * //inv35-attribute-handled by multiplicity
54 * {@literal @}Constraint(message = "inv35", severity = "error", key = {p})
55 * pattern inv35(p : Physical_Person) {
56 * Physical_Person.birth_day(p, birthDay);
57 * check(birthDay {@literal <} 1);
58 * } or {
59 * Physical_Person.birth_day(p, birthDay);
60 * check(birthDay {@literal >} 28);
61 * }
62 * </pre></code>
63 *
64 * @see Matcher
65 * @see Match
66 *
67 */
68@SuppressWarnings("all")
69public final class Inv35 extends BaseGeneratedEMFQuerySpecification<Inv35.Matcher> {
70 /**
71 * Pattern-specific match representation of the queries.inv35 pattern,
72 * to be used in conjunction with {@link Matcher}.
73 *
74 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
75 * Each instance is a (possibly partial) substitution of pattern parameters,
76 * usable to represent a match of the pattern in the result of a query,
77 * or to specify the bound (fixed) input parameters when issuing a query.
78 *
79 * @see Matcher
80 *
81 */
82 public static abstract class Match extends BasePatternMatch {
83 private Physical_Person fP;
84
85 private static List<String> parameterNames = makeImmutableList("p");
86
87 private Match(final Physical_Person pP) {
88 this.fP = pP;
89 }
90
91 @Override
92 public Object get(final String parameterName) {
93 switch(parameterName) {
94 case "p": return this.fP;
95 default: return null;
96 }
97 }
98
99 @Override
100 public Object get(final int index) {
101 switch(index) {
102 case 0: return this.fP;
103 default: return null;
104 }
105 }
106
107 public Physical_Person getP() {
108 return this.fP;
109 }
110
111 @Override
112 public boolean set(final String parameterName, final Object newValue) {
113 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
114 if ("p".equals(parameterName) ) {
115 this.fP = (Physical_Person) newValue;
116 return true;
117 }
118 return false;
119 }
120
121 public void setP(final Physical_Person pP) {
122 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
123 this.fP = pP;
124 }
125
126 @Override
127 public String patternName() {
128 return "queries.inv35";
129 }
130
131 @Override
132 public List<String> parameterNames() {
133 return Inv35.Match.parameterNames;
134 }
135
136 @Override
137 public Object[] toArray() {
138 return new Object[]{fP};
139 }
140
141 @Override
142 public Inv35.Match toImmutable() {
143 return isMutable() ? newMatch(fP) : this;
144 }
145
146 @Override
147 public String prettyPrint() {
148 StringBuilder result = new StringBuilder();
149 result.append("\"p\"=" + prettyPrintValue(fP));
150 return result.toString();
151 }
152
153 @Override
154 public int hashCode() {
155 return Objects.hash(fP);
156 }
157
158 @Override
159 public boolean equals(final Object obj) {
160 if (this == obj)
161 return true;
162 if (obj == null) {
163 return false;
164 }
165 if ((obj instanceof Inv35.Match)) {
166 Inv35.Match other = (Inv35.Match) obj;
167 return Objects.equals(fP, other.fP);
168 } else {
169 // this should be infrequent
170 if (!(obj instanceof IPatternMatch)) {
171 return false;
172 }
173 IPatternMatch otherSig = (IPatternMatch) obj;
174 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
175 }
176 }
177
178 @Override
179 public Inv35 specification() {
180 return Inv35.instance();
181 }
182
183 /**
184 * Returns an empty, mutable match.
185 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
186 *
187 * @return the empty match.
188 *
189 */
190 public static Inv35.Match newEmptyMatch() {
191 return new Mutable(null);
192 }
193
194 /**
195 * Returns a mutable (partial) match.
196 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
197 *
198 * @param pP the fixed value of pattern parameter p, or null if not bound.
199 * @return the new, mutable (partial) match object.
200 *
201 */
202 public static Inv35.Match newMutableMatch(final Physical_Person pP) {
203 return new Mutable(pP);
204 }
205
206 /**
207 * Returns a new (partial) match.
208 * This can be used e.g. to call the matcher with a partial match.
209 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
210 * @param pP the fixed value of pattern parameter p, or null if not bound.
211 * @return the (partial) match object.
212 *
213 */
214 public static Inv35.Match newMatch(final Physical_Person pP) {
215 return new Immutable(pP);
216 }
217
218 private static final class Mutable extends Inv35.Match {
219 Mutable(final Physical_Person pP) {
220 super(pP);
221 }
222
223 @Override
224 public boolean isMutable() {
225 return true;
226 }
227 }
228
229 private static final class Immutable extends Inv35.Match {
230 Immutable(final Physical_Person pP) {
231 super(pP);
232 }
233
234 @Override
235 public boolean isMutable() {
236 return false;
237 }
238 }
239 }
240
241 /**
242 * Generated pattern matcher API of the queries.inv35 pattern,
243 * providing pattern-specific query methods.
244 *
245 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
246 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
247 *
248 * <p>Matches of the pattern will be represented as {@link Match}.
249 *
250 * <p>Original source:
251 * <code><pre>
252 * //inv35-attribute-handled by multiplicity
253 * {@literal @}Constraint(message = "inv35", severity = "error", key = {p})
254 * pattern inv35(p : Physical_Person) {
255 * Physical_Person.birth_day(p, birthDay);
256 * check(birthDay {@literal <} 1);
257 * } or {
258 * Physical_Person.birth_day(p, birthDay);
259 * check(birthDay {@literal >} 28);
260 * }
261 * </pre></code>
262 *
263 * @see Match
264 * @see Inv35
265 *
266 */
267 public static class Matcher extends BaseMatcher<Inv35.Match> {
268 /**
269 * Initializes the pattern matcher within an existing VIATRA Query engine.
270 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
271 *
272 * @param engine the existing VIATRA Query engine in which this matcher will be created.
273 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
274 *
275 */
276 public static Inv35.Matcher on(final ViatraQueryEngine engine) {
277 // check if matcher already exists
278 Matcher matcher = engine.getExistingMatcher(querySpecification());
279 if (matcher == null) {
280 matcher = (Matcher)engine.getMatcher(querySpecification());
281 }
282 return matcher;
283 }
284
285 /**
286 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
287 * @return an initialized matcher
288 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
289 *
290 */
291 public static Inv35.Matcher create() {
292 return new Matcher();
293 }
294
295 private static final int POSITION_P = 0;
296
297 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv35.Matcher.class);
298
299 /**
300 * Initializes the pattern matcher within an existing VIATRA Query engine.
301 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
302 *
303 * @param engine the existing VIATRA Query engine in which this matcher will be created.
304 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
305 *
306 */
307 private Matcher() {
308 super(querySpecification());
309 }
310
311 /**
312 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
313 * @param pP the fixed value of pattern parameter p, or null if not bound.
314 * @return matches represented as a Match object.
315 *
316 */
317 public Collection<Inv35.Match> getAllMatches(final Physical_Person pP) {
318 return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet());
319 }
320
321 /**
322 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
323 * </p>
324 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
325 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
326 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
327 * @param pP the fixed value of pattern parameter p, or null if not bound.
328 * @return a stream of matches represented as a Match object.
329 *
330 */
331 public Stream<Inv35.Match> streamAllMatches(final Physical_Person pP) {
332 return rawStreamAllMatches(new Object[]{pP});
333 }
334
335 /**
336 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
337 * Neither determinism nor randomness of selection is guaranteed.
338 * @param pP the fixed value of pattern parameter p, or null if not bound.
339 * @return a match represented as a Match object, or null if no match is found.
340 *
341 */
342 public Optional<Inv35.Match> getOneArbitraryMatch(final Physical_Person pP) {
343 return rawGetOneArbitraryMatch(new Object[]{pP});
344 }
345
346 /**
347 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
348 * under any possible substitution of the unspecified parameters (if any).
349 * @param pP the fixed value of pattern parameter p, or null if not bound.
350 * @return true if the input is a valid (partial) match of the pattern.
351 *
352 */
353 public boolean hasMatch(final Physical_Person pP) {
354 return rawHasMatch(new Object[]{pP});
355 }
356
357 /**
358 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
359 * @param pP the fixed value of pattern parameter p, or null if not bound.
360 * @return the number of pattern matches found.
361 *
362 */
363 public int countMatches(final Physical_Person pP) {
364 return rawCountMatches(new Object[]{pP});
365 }
366
367 /**
368 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
369 * Neither determinism nor randomness of selection is guaranteed.
370 * @param pP the fixed value of pattern parameter p, or null if not bound.
371 * @param processor the action that will process the selected match.
372 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
373 *
374 */
375 public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer<? super Inv35.Match> processor) {
376 return rawForOneArbitraryMatch(new Object[]{pP}, processor);
377 }
378
379 /**
380 * Returns a new (partial) match.
381 * This can be used e.g. to call the matcher with a partial match.
382 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
383 * @param pP the fixed value of pattern parameter p, or null if not bound.
384 * @return the (partial) match object.
385 *
386 */
387 public Inv35.Match newMatch(final Physical_Person pP) {
388 return Inv35.Match.newMatch(pP);
389 }
390
391 /**
392 * Retrieve the set of values that occur in matches for p.
393 * @return the Set of all values or empty set if there are no matches
394 *
395 */
396 protected Stream<Physical_Person> rawStreamAllValuesOfp(final Object[] parameters) {
397 return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast);
398 }
399
400 /**
401 * Retrieve the set of values that occur in matches for p.
402 * @return the Set of all values or empty set if there are no matches
403 *
404 */
405 public Set<Physical_Person> getAllValuesOfp() {
406 return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet());
407 }
408
409 /**
410 * Retrieve the set of values that occur in matches for p.
411 * @return the Set of all values or empty set if there are no matches
412 *
413 */
414 public Stream<Physical_Person> streamAllValuesOfp() {
415 return rawStreamAllValuesOfp(emptyArray());
416 }
417
418 @Override
419 protected Inv35.Match tupleToMatch(final Tuple t) {
420 try {
421 return Inv35.Match.newMatch((Physical_Person) t.get(POSITION_P));
422 } catch(ClassCastException e) {
423 LOGGER.error("Element(s) in tuple not properly typed!",e);
424 return null;
425 }
426 }
427
428 @Override
429 protected Inv35.Match arrayToMatch(final Object[] match) {
430 try {
431 return Inv35.Match.newMatch((Physical_Person) match[POSITION_P]);
432 } catch(ClassCastException e) {
433 LOGGER.error("Element(s) in array not properly typed!",e);
434 return null;
435 }
436 }
437
438 @Override
439 protected Inv35.Match arrayToMatchMutable(final Object[] match) {
440 try {
441 return Inv35.Match.newMutableMatch((Physical_Person) match[POSITION_P]);
442 } catch(ClassCastException e) {
443 LOGGER.error("Element(s) in array not properly typed!",e);
444 return null;
445 }
446 }
447
448 /**
449 * @return the singleton instance of the query specification of this pattern
450 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
451 *
452 */
453 public static IQuerySpecification<Inv35.Matcher> querySpecification() {
454 return Inv35.instance();
455 }
456 }
457
458 private Inv35() {
459 super(GeneratedPQuery.INSTANCE);
460 }
461
462 /**
463 * @return the singleton instance of the query specification
464 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
465 *
466 */
467 public static Inv35 instance() {
468 try{
469 return LazyHolder.INSTANCE;
470 } catch (ExceptionInInitializerError err) {
471 throw processInitializerError(err);
472 }
473 }
474
475 @Override
476 protected Inv35.Matcher instantiate(final ViatraQueryEngine engine) {
477 return Inv35.Matcher.on(engine);
478 }
479
480 @Override
481 public Inv35.Matcher instantiate() {
482 return Inv35.Matcher.create();
483 }
484
485 @Override
486 public Inv35.Match newEmptyMatch() {
487 return Inv35.Match.newEmptyMatch();
488 }
489
490 @Override
491 public Inv35.Match newMatch(final Object... parameters) {
492 return Inv35.Match.newMatch((Taxation.Physical_Person) parameters[0]);
493 }
494
495 /**
496 * Inner class allowing the singleton instance of {@link Inv35} to be created
497 * <b>not</b> at the class load time of the outer class,
498 * but rather at the first call to {@link Inv35#instance()}.
499 *
500 * <p> This workaround is required e.g. to support recursion.
501 *
502 */
503 private static class LazyHolder {
504 private static final Inv35 INSTANCE = new Inv35();
505
506 /**
507 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
508 * This initialization order is required to support indirect recursion.
509 *
510 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
511 *
512 */
513 private static final Object STATIC_INITIALIZER = ensureInitialized();
514
515 public static Object ensureInitialized() {
516 INSTANCE.ensureInitializedInternal();
517 return null;
518 }
519 }
520
521 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
522 private static final Inv35.GeneratedPQuery INSTANCE = new GeneratedPQuery();
523
524 private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT);
525
526 private final List<PParameter> parameters = Arrays.asList(parameter_p);
527
528 private GeneratedPQuery() {
529 super(PVisibility.PUBLIC);
530 }
531
532 @Override
533 public String getFullyQualifiedName() {
534 return "queries.inv35";
535 }
536
537 @Override
538 public List<String> getParameterNames() {
539 return Arrays.asList("p");
540 }
541
542 @Override
543 public List<PParameter> getParameters() {
544 return parameters;
545 }
546
547 @Override
548 public Set<PBody> doGetContainedBodies() {
549 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
550 Set<PBody> bodies = new LinkedHashSet<>();
551 {
552 PBody body = new PBody(this);
553 PVariable var_p = body.getOrCreateVariableByName("p");
554 PVariable var_birthDay = body.getOrCreateVariableByName("birthDay");
555 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
556 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
557 new ExportedParameter(body, var_p, parameter_p)
558 ));
559 // Physical_Person.birth_day(p, birthDay)
560 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
561 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
562 new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_day")));
563 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
564 new Equality(body, var__virtual_0_, var_birthDay);
565 // check(birthDay < 1)
566 new ExpressionEvaluation(body, new IExpressionEvaluator() {
567
568 @Override
569 public String getShortDescription() {
570 return "Expression evaluation from pattern inv35";
571 }
572
573 @Override
574 public Iterable<String> getInputParameterNames() {
575 return Arrays.asList("birthDay");}
576
577 @Override
578 public Object evaluateExpression(IValueProvider provider) throws Exception {
579 Integer birthDay = (Integer) provider.getValue("birthDay");
580 return evaluateExpression_1_1(birthDay);
581 }
582 }, null);
583 bodies.add(body);
584 }
585 {
586 PBody body = new PBody(this);
587 PVariable var_p = body.getOrCreateVariableByName("p");
588 PVariable var_birthDay = body.getOrCreateVariableByName("birthDay");
589 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
590 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
591 new ExportedParameter(body, var_p, parameter_p)
592 ));
593 // Physical_Person.birth_day(p, birthDay)
594 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
595 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
596 new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_day")));
597 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
598 new Equality(body, var__virtual_0_, var_birthDay);
599 // check(birthDay > 28)
600 new ExpressionEvaluation(body, new IExpressionEvaluator() {
601
602 @Override
603 public String getShortDescription() {
604 return "Expression evaluation from pattern inv35";
605 }
606
607 @Override
608 public Iterable<String> getInputParameterNames() {
609 return Arrays.asList("birthDay");}
610
611 @Override
612 public Object evaluateExpression(IValueProvider provider) throws Exception {
613 Integer birthDay = (Integer) provider.getValue("birthDay");
614 return evaluateExpression_2_1(birthDay);
615 }
616 }, null);
617 bodies.add(body);
618 }
619 {
620 PAnnotation annotation = new PAnnotation("Constraint");
621 annotation.addAttribute("message", "inv35");
622 annotation.addAttribute("severity", "error");
623 annotation.addAttribute("key", Arrays.asList(new Object[] {
624 new ParameterReference("p")
625 }));
626 addAnnotation(annotation);
627 }
628 return bodies;
629 }
630 }
631
632 private static boolean evaluateExpression_1_1(final Integer birthDay) {
633 return ((birthDay).intValue() < 1);
634 }
635
636 private static boolean evaluateExpression_2_1(final Integer birthDay) {
637 return ((birthDay).intValue() > 28);
638 }
639}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv47.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv47.java
new file mode 100644
index 00000000..d86f31c9
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv47.java
@@ -0,0 +1,636 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Legal_Union_Record;
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.basicdeferred.NegativePatternCall;
41import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
42import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
43import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
44import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
45import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
46import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
47import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
48import queries.X_inv47;
49
50/**
51 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
52 *
53 * <p>Original source:
54 * <code><pre>
55 * //inv36-AttributeRemoved
56 * //inv37-AttributeRemoved
57 * //inv38-AttributeRemoved
58 * //inv39-AttributeRemoved
59 * //inv40-AttributeRemoved
60 * //inv41-AttributeRemoved
61 * //inv42-AttributeRemoved
62 * //inv43-AttributeRemoved
63 * //inv44-AttributeRemoved
64 * //inv45-AttributeRemoved
65 * //inv46-AttributeRemoved
66 *
67 * //inv47-attributes-handled by multiplicity
68 * {@literal @}Constraint(message = "inv47", severity = "error", key = {lur})
69 * pattern inv47(lur : Legal_Union_Record) {
70 * Legal_Union_Record.end_year(lur, endY);
71 * Legal_Union_Record.start_year(lur, startY);
72 * neg find x_inv47(lur);
73 * check(startY {@literal >}= endY);
74 * }
75 * </pre></code>
76 *
77 * @see Matcher
78 * @see Match
79 *
80 */
81@SuppressWarnings("all")
82public final class Inv47 extends BaseGeneratedEMFQuerySpecification<Inv47.Matcher> {
83 /**
84 * Pattern-specific match representation of the queries.inv47 pattern,
85 * to be used in conjunction with {@link Matcher}.
86 *
87 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
88 * Each instance is a (possibly partial) substitution of pattern parameters,
89 * usable to represent a match of the pattern in the result of a query,
90 * or to specify the bound (fixed) input parameters when issuing a query.
91 *
92 * @see Matcher
93 *
94 */
95 public static abstract class Match extends BasePatternMatch {
96 private Legal_Union_Record fLur;
97
98 private static List<String> parameterNames = makeImmutableList("lur");
99
100 private Match(final Legal_Union_Record pLur) {
101 this.fLur = pLur;
102 }
103
104 @Override
105 public Object get(final String parameterName) {
106 switch(parameterName) {
107 case "lur": return this.fLur;
108 default: return null;
109 }
110 }
111
112 @Override
113 public Object get(final int index) {
114 switch(index) {
115 case 0: return this.fLur;
116 default: return null;
117 }
118 }
119
120 public Legal_Union_Record getLur() {
121 return this.fLur;
122 }
123
124 @Override
125 public boolean set(final String parameterName, final Object newValue) {
126 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
127 if ("lur".equals(parameterName) ) {
128 this.fLur = (Legal_Union_Record) newValue;
129 return true;
130 }
131 return false;
132 }
133
134 public void setLur(final Legal_Union_Record pLur) {
135 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
136 this.fLur = pLur;
137 }
138
139 @Override
140 public String patternName() {
141 return "queries.inv47";
142 }
143
144 @Override
145 public List<String> parameterNames() {
146 return Inv47.Match.parameterNames;
147 }
148
149 @Override
150 public Object[] toArray() {
151 return new Object[]{fLur};
152 }
153
154 @Override
155 public Inv47.Match toImmutable() {
156 return isMutable() ? newMatch(fLur) : this;
157 }
158
159 @Override
160 public String prettyPrint() {
161 StringBuilder result = new StringBuilder();
162 result.append("\"lur\"=" + prettyPrintValue(fLur));
163 return result.toString();
164 }
165
166 @Override
167 public int hashCode() {
168 return Objects.hash(fLur);
169 }
170
171 @Override
172 public boolean equals(final Object obj) {
173 if (this == obj)
174 return true;
175 if (obj == null) {
176 return false;
177 }
178 if ((obj instanceof Inv47.Match)) {
179 Inv47.Match other = (Inv47.Match) obj;
180 return Objects.equals(fLur, other.fLur);
181 } else {
182 // this should be infrequent
183 if (!(obj instanceof IPatternMatch)) {
184 return false;
185 }
186 IPatternMatch otherSig = (IPatternMatch) obj;
187 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
188 }
189 }
190
191 @Override
192 public Inv47 specification() {
193 return Inv47.instance();
194 }
195
196 /**
197 * Returns an empty, mutable match.
198 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
199 *
200 * @return the empty match.
201 *
202 */
203 public static Inv47.Match newEmptyMatch() {
204 return new Mutable(null);
205 }
206
207 /**
208 * Returns a mutable (partial) match.
209 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
210 *
211 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
212 * @return the new, mutable (partial) match object.
213 *
214 */
215 public static Inv47.Match newMutableMatch(final Legal_Union_Record pLur) {
216 return new Mutable(pLur);
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 pLur the fixed value of pattern parameter lur, or null if not bound.
224 * @return the (partial) match object.
225 *
226 */
227 public static Inv47.Match newMatch(final Legal_Union_Record pLur) {
228 return new Immutable(pLur);
229 }
230
231 private static final class Mutable extends Inv47.Match {
232 Mutable(final Legal_Union_Record pLur) {
233 super(pLur);
234 }
235
236 @Override
237 public boolean isMutable() {
238 return true;
239 }
240 }
241
242 private static final class Immutable extends Inv47.Match {
243 Immutable(final Legal_Union_Record pLur) {
244 super(pLur);
245 }
246
247 @Override
248 public boolean isMutable() {
249 return false;
250 }
251 }
252 }
253
254 /**
255 * Generated pattern matcher API of the queries.inv47 pattern,
256 * providing pattern-specific query methods.
257 *
258 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
259 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
260 *
261 * <p>Matches of the pattern will be represented as {@link Match}.
262 *
263 * <p>Original source:
264 * <code><pre>
265 * //inv36-AttributeRemoved
266 * //inv37-AttributeRemoved
267 * //inv38-AttributeRemoved
268 * //inv39-AttributeRemoved
269 * //inv40-AttributeRemoved
270 * //inv41-AttributeRemoved
271 * //inv42-AttributeRemoved
272 * //inv43-AttributeRemoved
273 * //inv44-AttributeRemoved
274 * //inv45-AttributeRemoved
275 * //inv46-AttributeRemoved
276 *
277 * //inv47-attributes-handled by multiplicity
278 * {@literal @}Constraint(message = "inv47", severity = "error", key = {lur})
279 * pattern inv47(lur : Legal_Union_Record) {
280 * Legal_Union_Record.end_year(lur, endY);
281 * Legal_Union_Record.start_year(lur, startY);
282 * neg find x_inv47(lur);
283 * check(startY {@literal >}= endY);
284 * }
285 * </pre></code>
286 *
287 * @see Match
288 * @see Inv47
289 *
290 */
291 public static class Matcher extends BaseMatcher<Inv47.Match> {
292 /**
293 * Initializes the pattern matcher within an existing VIATRA Query engine.
294 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
295 *
296 * @param engine the existing VIATRA Query engine in which this matcher will be created.
297 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
298 *
299 */
300 public static Inv47.Matcher on(final ViatraQueryEngine engine) {
301 // check if matcher already exists
302 Matcher matcher = engine.getExistingMatcher(querySpecification());
303 if (matcher == null) {
304 matcher = (Matcher)engine.getMatcher(querySpecification());
305 }
306 return matcher;
307 }
308
309 /**
310 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
311 * @return an initialized matcher
312 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
313 *
314 */
315 public static Inv47.Matcher create() {
316 return new Matcher();
317 }
318
319 private static final int POSITION_LUR = 0;
320
321 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv47.Matcher.class);
322
323 /**
324 * Initializes the pattern matcher within an existing VIATRA Query engine.
325 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
326 *
327 * @param engine the existing VIATRA Query engine in which this matcher will be created.
328 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
329 *
330 */
331 private Matcher() {
332 super(querySpecification());
333 }
334
335 /**
336 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
337 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
338 * @return matches represented as a Match object.
339 *
340 */
341 public Collection<Inv47.Match> getAllMatches(final Legal_Union_Record pLur) {
342 return rawStreamAllMatches(new Object[]{pLur}).collect(Collectors.toSet());
343 }
344
345 /**
346 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
347 * </p>
348 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
349 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
350 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
351 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
352 * @return a stream of matches represented as a Match object.
353 *
354 */
355 public Stream<Inv47.Match> streamAllMatches(final Legal_Union_Record pLur) {
356 return rawStreamAllMatches(new Object[]{pLur});
357 }
358
359 /**
360 * Returns 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 pLur the fixed value of pattern parameter lur, 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<Inv47.Match> getOneArbitraryMatch(final Legal_Union_Record pLur) {
367 return rawGetOneArbitraryMatch(new Object[]{pLur});
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 pLur the fixed value of pattern parameter lur, or null if not bound.
374 * @return true if the input is a valid (partial) match of the pattern.
375 *
376 */
377 public boolean hasMatch(final Legal_Union_Record pLur) {
378 return rawHasMatch(new Object[]{pLur});
379 }
380
381 /**
382 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
383 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
384 * @return the number of pattern matches found.
385 *
386 */
387 public int countMatches(final Legal_Union_Record pLur) {
388 return rawCountMatches(new Object[]{pLur});
389 }
390
391 /**
392 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
393 * Neither determinism nor randomness of selection is guaranteed.
394 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
395 * @param processor the action that will process the selected match.
396 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
397 *
398 */
399 public boolean forOneArbitraryMatch(final Legal_Union_Record pLur, final Consumer<? super Inv47.Match> processor) {
400 return rawForOneArbitraryMatch(new Object[]{pLur}, processor);
401 }
402
403 /**
404 * Returns a new (partial) match.
405 * This can be used e.g. to call the matcher with a partial match.
406 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
407 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
408 * @return the (partial) match object.
409 *
410 */
411 public Inv47.Match newMatch(final Legal_Union_Record pLur) {
412 return Inv47.Match.newMatch(pLur);
413 }
414
415 /**
416 * Retrieve the set of values that occur in matches for lur.
417 * @return the Set of all values or empty set if there are no matches
418 *
419 */
420 protected Stream<Legal_Union_Record> rawStreamAllValuesOflur(final Object[] parameters) {
421 return rawStreamAllValues(POSITION_LUR, parameters).map(Legal_Union_Record.class::cast);
422 }
423
424 /**
425 * Retrieve the set of values that occur in matches for lur.
426 * @return the Set of all values or empty set if there are no matches
427 *
428 */
429 public Set<Legal_Union_Record> getAllValuesOflur() {
430 return rawStreamAllValuesOflur(emptyArray()).collect(Collectors.toSet());
431 }
432
433 /**
434 * Retrieve the set of values that occur in matches for lur.
435 * @return the Set of all values or empty set if there are no matches
436 *
437 */
438 public Stream<Legal_Union_Record> streamAllValuesOflur() {
439 return rawStreamAllValuesOflur(emptyArray());
440 }
441
442 @Override
443 protected Inv47.Match tupleToMatch(final Tuple t) {
444 try {
445 return Inv47.Match.newMatch((Legal_Union_Record) t.get(POSITION_LUR));
446 } catch(ClassCastException e) {
447 LOGGER.error("Element(s) in tuple not properly typed!",e);
448 return null;
449 }
450 }
451
452 @Override
453 protected Inv47.Match arrayToMatch(final Object[] match) {
454 try {
455 return Inv47.Match.newMatch((Legal_Union_Record) match[POSITION_LUR]);
456 } catch(ClassCastException e) {
457 LOGGER.error("Element(s) in array not properly typed!",e);
458 return null;
459 }
460 }
461
462 @Override
463 protected Inv47.Match arrayToMatchMutable(final Object[] match) {
464 try {
465 return Inv47.Match.newMutableMatch((Legal_Union_Record) match[POSITION_LUR]);
466 } catch(ClassCastException e) {
467 LOGGER.error("Element(s) in array not properly typed!",e);
468 return null;
469 }
470 }
471
472 /**
473 * @return the singleton instance of the query specification of this pattern
474 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
475 *
476 */
477 public static IQuerySpecification<Inv47.Matcher> querySpecification() {
478 return Inv47.instance();
479 }
480 }
481
482 private Inv47() {
483 super(GeneratedPQuery.INSTANCE);
484 }
485
486 /**
487 * @return the singleton instance of the query specification
488 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
489 *
490 */
491 public static Inv47 instance() {
492 try{
493 return LazyHolder.INSTANCE;
494 } catch (ExceptionInInitializerError err) {
495 throw processInitializerError(err);
496 }
497 }
498
499 @Override
500 protected Inv47.Matcher instantiate(final ViatraQueryEngine engine) {
501 return Inv47.Matcher.on(engine);
502 }
503
504 @Override
505 public Inv47.Matcher instantiate() {
506 return Inv47.Matcher.create();
507 }
508
509 @Override
510 public Inv47.Match newEmptyMatch() {
511 return Inv47.Match.newEmptyMatch();
512 }
513
514 @Override
515 public Inv47.Match newMatch(final Object... parameters) {
516 return Inv47.Match.newMatch((Taxation.Legal_Union_Record) parameters[0]);
517 }
518
519 /**
520 * Inner class allowing the singleton instance of {@link Inv47} to be created
521 * <b>not</b> at the class load time of the outer class,
522 * but rather at the first call to {@link Inv47#instance()}.
523 *
524 * <p> This workaround is required e.g. to support recursion.
525 *
526 */
527 private static class LazyHolder {
528 private static final Inv47 INSTANCE = new Inv47();
529
530 /**
531 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
532 * This initialization order is required to support indirect recursion.
533 *
534 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
535 *
536 */
537 private static final Object STATIC_INITIALIZER = ensureInitialized();
538
539 public static Object ensureInitialized() {
540 INSTANCE.ensureInitializedInternal();
541 return null;
542 }
543 }
544
545 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
546 private static final Inv47.GeneratedPQuery INSTANCE = new GeneratedPQuery();
547
548 private final PParameter parameter_lur = new PParameter("lur", "Taxation.Legal_Union_Record", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Legal_Union_Record")), PParameterDirection.INOUT);
549
550 private final List<PParameter> parameters = Arrays.asList(parameter_lur);
551
552 private GeneratedPQuery() {
553 super(PVisibility.PUBLIC);
554 }
555
556 @Override
557 public String getFullyQualifiedName() {
558 return "queries.inv47";
559 }
560
561 @Override
562 public List<String> getParameterNames() {
563 return Arrays.asList("lur");
564 }
565
566 @Override
567 public List<PParameter> getParameters() {
568 return parameters;
569 }
570
571 @Override
572 public Set<PBody> doGetContainedBodies() {
573 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
574 Set<PBody> bodies = new LinkedHashSet<>();
575 {
576 PBody body = new PBody(this);
577 PVariable var_lur = body.getOrCreateVariableByName("lur");
578 PVariable var_endY = body.getOrCreateVariableByName("endY");
579 PVariable var_startY = body.getOrCreateVariableByName("startY");
580 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
581 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
582 new ExportedParameter(body, var_lur, parameter_lur)
583 ));
584 // Legal_Union_Record.end_year(lur, endY)
585 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
586 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
587 new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "end_year")));
588 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
589 new Equality(body, var__virtual_0_, var_endY);
590 // Legal_Union_Record.start_year(lur, startY)
591 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
592 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
593 new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "start_year")));
594 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
595 new Equality(body, var__virtual_1_, var_startY);
596 // neg find x_inv47(lur)
597 new NegativePatternCall(body, Tuples.flatTupleOf(var_lur), X_inv47.instance().getInternalQueryRepresentation());
598 // check(startY >= endY)
599 new ExpressionEvaluation(body, new IExpressionEvaluator() {
600
601 @Override
602 public String getShortDescription() {
603 return "Expression evaluation from pattern inv47";
604 }
605
606 @Override
607 public Iterable<String> getInputParameterNames() {
608 return Arrays.asList("endY", "startY");}
609
610 @Override
611 public Object evaluateExpression(IValueProvider provider) throws Exception {
612 Integer endY = (Integer) provider.getValue("endY");
613 Integer startY = (Integer) provider.getValue("startY");
614 return evaluateExpression_1_1(endY, startY);
615 }
616 }, null);
617 bodies.add(body);
618 }
619 {
620 PAnnotation annotation = new PAnnotation("Constraint");
621 annotation.addAttribute("message", "inv47");
622 annotation.addAttribute("severity", "error");
623 annotation.addAttribute("key", Arrays.asList(new Object[] {
624 new ParameterReference("lur")
625 }));
626 addAnnotation(annotation);
627 }
628 return bodies;
629 }
630 }
631
632 private static boolean evaluateExpression_1_1(final Integer endY, final Integer startY) {
633 boolean _greaterEqualsThan = (startY.compareTo(endY) >= 0);
634 return _greaterEqualsThan;
635 }
636}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv48.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv48.java
new file mode 100644
index 00000000..66c66988
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv48.java
@@ -0,0 +1,566 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Physical_Person;
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.NegativePatternCall;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
39import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
40import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
41import queries.X_inv48_Dis;
42import queries.X_inv48_notDis;
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 * //inv48-attributes-handled by multiplicity
50 * {@literal @}Constraint(message = "inv48", severity = "error", key = {p})
51 * pattern inv48(p : Physical_Person) {
52 * neg find x_inv48_notDis(p);
53 * neg find x_inv48_Dis(p);
54 * }
55 * </pre></code>
56 *
57 * @see Matcher
58 * @see Match
59 *
60 */
61@SuppressWarnings("all")
62public final class Inv48 extends BaseGeneratedEMFQuerySpecification<Inv48.Matcher> {
63 /**
64 * Pattern-specific match representation of the queries.inv48 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 Physical_Person fP;
77
78 private static List<String> parameterNames = makeImmutableList("p");
79
80 private Match(final Physical_Person pP) {
81 this.fP = pP;
82 }
83
84 @Override
85 public Object get(final String parameterName) {
86 switch(parameterName) {
87 case "p": return this.fP;
88 default: return null;
89 }
90 }
91
92 @Override
93 public Object get(final int index) {
94 switch(index) {
95 case 0: return this.fP;
96 default: return null;
97 }
98 }
99
100 public Physical_Person getP() {
101 return this.fP;
102 }
103
104 @Override
105 public boolean set(final String parameterName, final Object newValue) {
106 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
107 if ("p".equals(parameterName) ) {
108 this.fP = (Physical_Person) newValue;
109 return true;
110 }
111 return false;
112 }
113
114 public void setP(final Physical_Person pP) {
115 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
116 this.fP = pP;
117 }
118
119 @Override
120 public String patternName() {
121 return "queries.inv48";
122 }
123
124 @Override
125 public List<String> parameterNames() {
126 return Inv48.Match.parameterNames;
127 }
128
129 @Override
130 public Object[] toArray() {
131 return new Object[]{fP};
132 }
133
134 @Override
135 public Inv48.Match toImmutable() {
136 return isMutable() ? newMatch(fP) : this;
137 }
138
139 @Override
140 public String prettyPrint() {
141 StringBuilder result = new StringBuilder();
142 result.append("\"p\"=" + prettyPrintValue(fP));
143 return result.toString();
144 }
145
146 @Override
147 public int hashCode() {
148 return Objects.hash(fP);
149 }
150
151 @Override
152 public boolean equals(final Object obj) {
153 if (this == obj)
154 return true;
155 if (obj == null) {
156 return false;
157 }
158 if ((obj instanceof Inv48.Match)) {
159 Inv48.Match other = (Inv48.Match) obj;
160 return Objects.equals(fP, other.fP);
161 } else {
162 // this should be infrequent
163 if (!(obj instanceof IPatternMatch)) {
164 return false;
165 }
166 IPatternMatch otherSig = (IPatternMatch) obj;
167 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
168 }
169 }
170
171 @Override
172 public Inv48 specification() {
173 return Inv48.instance();
174 }
175
176 /**
177 * Returns an empty, mutable match.
178 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
179 *
180 * @return the empty match.
181 *
182 */
183 public static Inv48.Match newEmptyMatch() {
184 return new Mutable(null);
185 }
186
187 /**
188 * Returns a mutable (partial) match.
189 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
190 *
191 * @param pP the fixed value of pattern parameter p, or null if not bound.
192 * @return the new, mutable (partial) match object.
193 *
194 */
195 public static Inv48.Match newMutableMatch(final Physical_Person pP) {
196 return new Mutable(pP);
197 }
198
199 /**
200 * Returns a new (partial) match.
201 * This can be used e.g. to call the matcher with a partial match.
202 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
203 * @param pP the fixed value of pattern parameter p, or null if not bound.
204 * @return the (partial) match object.
205 *
206 */
207 public static Inv48.Match newMatch(final Physical_Person pP) {
208 return new Immutable(pP);
209 }
210
211 private static final class Mutable extends Inv48.Match {
212 Mutable(final Physical_Person pP) {
213 super(pP);
214 }
215
216 @Override
217 public boolean isMutable() {
218 return true;
219 }
220 }
221
222 private static final class Immutable extends Inv48.Match {
223 Immutable(final Physical_Person pP) {
224 super(pP);
225 }
226
227 @Override
228 public boolean isMutable() {
229 return false;
230 }
231 }
232 }
233
234 /**
235 * Generated pattern matcher API of the queries.inv48 pattern,
236 * providing pattern-specific query methods.
237 *
238 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
239 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
240 *
241 * <p>Matches of the pattern will be represented as {@link Match}.
242 *
243 * <p>Original source:
244 * <code><pre>
245 * //inv48-attributes-handled by multiplicity
246 * {@literal @}Constraint(message = "inv48", severity = "error", key = {p})
247 * pattern inv48(p : Physical_Person) {
248 * neg find x_inv48_notDis(p);
249 * neg find x_inv48_Dis(p);
250 * }
251 * </pre></code>
252 *
253 * @see Match
254 * @see Inv48
255 *
256 */
257 public static class Matcher extends BaseMatcher<Inv48.Match> {
258 /**
259 * Initializes the pattern matcher within an existing VIATRA Query engine.
260 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
261 *
262 * @param engine the existing VIATRA Query engine in which this matcher will be created.
263 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
264 *
265 */
266 public static Inv48.Matcher on(final ViatraQueryEngine engine) {
267 // check if matcher already exists
268 Matcher matcher = engine.getExistingMatcher(querySpecification());
269 if (matcher == null) {
270 matcher = (Matcher)engine.getMatcher(querySpecification());
271 }
272 return matcher;
273 }
274
275 /**
276 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
277 * @return an initialized matcher
278 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
279 *
280 */
281 public static Inv48.Matcher create() {
282 return new Matcher();
283 }
284
285 private static final int POSITION_P = 0;
286
287 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv48.Matcher.class);
288
289 /**
290 * Initializes the pattern matcher within an existing VIATRA Query engine.
291 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
292 *
293 * @param engine the existing VIATRA Query engine in which this matcher will be created.
294 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
295 *
296 */
297 private Matcher() {
298 super(querySpecification());
299 }
300
301 /**
302 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
303 * @param pP the fixed value of pattern parameter p, or null if not bound.
304 * @return matches represented as a Match object.
305 *
306 */
307 public Collection<Inv48.Match> getAllMatches(final Physical_Person pP) {
308 return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet());
309 }
310
311 /**
312 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
313 * </p>
314 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
315 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
316 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
317 * @param pP the fixed value of pattern parameter p, or null if not bound.
318 * @return a stream of matches represented as a Match object.
319 *
320 */
321 public Stream<Inv48.Match> streamAllMatches(final Physical_Person pP) {
322 return rawStreamAllMatches(new Object[]{pP});
323 }
324
325 /**
326 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
327 * Neither determinism nor randomness of selection is guaranteed.
328 * @param pP the fixed value of pattern parameter p, or null if not bound.
329 * @return a match represented as a Match object, or null if no match is found.
330 *
331 */
332 public Optional<Inv48.Match> getOneArbitraryMatch(final Physical_Person pP) {
333 return rawGetOneArbitraryMatch(new Object[]{pP});
334 }
335
336 /**
337 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
338 * under any possible substitution of the unspecified parameters (if any).
339 * @param pP the fixed value of pattern parameter p, or null if not bound.
340 * @return true if the input is a valid (partial) match of the pattern.
341 *
342 */
343 public boolean hasMatch(final Physical_Person pP) {
344 return rawHasMatch(new Object[]{pP});
345 }
346
347 /**
348 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
349 * @param pP the fixed value of pattern parameter p, or null if not bound.
350 * @return the number of pattern matches found.
351 *
352 */
353 public int countMatches(final Physical_Person pP) {
354 return rawCountMatches(new Object[]{pP});
355 }
356
357 /**
358 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
359 * Neither determinism nor randomness of selection is guaranteed.
360 * @param pP the fixed value of pattern parameter p, or null if not bound.
361 * @param processor the action that will process the selected match.
362 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
363 *
364 */
365 public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer<? super Inv48.Match> processor) {
366 return rawForOneArbitraryMatch(new Object[]{pP}, processor);
367 }
368
369 /**
370 * Returns a new (partial) match.
371 * This can be used e.g. to call the matcher with a partial match.
372 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
373 * @param pP the fixed value of pattern parameter p, or null if not bound.
374 * @return the (partial) match object.
375 *
376 */
377 public Inv48.Match newMatch(final Physical_Person pP) {
378 return Inv48.Match.newMatch(pP);
379 }
380
381 /**
382 * Retrieve the set of values that occur in matches for p.
383 * @return the Set of all values or empty set if there are no matches
384 *
385 */
386 protected Stream<Physical_Person> rawStreamAllValuesOfp(final Object[] parameters) {
387 return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast);
388 }
389
390 /**
391 * Retrieve the set of values that occur in matches for p.
392 * @return the Set of all values or empty set if there are no matches
393 *
394 */
395 public Set<Physical_Person> getAllValuesOfp() {
396 return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet());
397 }
398
399 /**
400 * Retrieve the set of values that occur in matches for p.
401 * @return the Set of all values or empty set if there are no matches
402 *
403 */
404 public Stream<Physical_Person> streamAllValuesOfp() {
405 return rawStreamAllValuesOfp(emptyArray());
406 }
407
408 @Override
409 protected Inv48.Match tupleToMatch(final Tuple t) {
410 try {
411 return Inv48.Match.newMatch((Physical_Person) t.get(POSITION_P));
412 } catch(ClassCastException e) {
413 LOGGER.error("Element(s) in tuple not properly typed!",e);
414 return null;
415 }
416 }
417
418 @Override
419 protected Inv48.Match arrayToMatch(final Object[] match) {
420 try {
421 return Inv48.Match.newMatch((Physical_Person) match[POSITION_P]);
422 } catch(ClassCastException e) {
423 LOGGER.error("Element(s) in array not properly typed!",e);
424 return null;
425 }
426 }
427
428 @Override
429 protected Inv48.Match arrayToMatchMutable(final Object[] match) {
430 try {
431 return Inv48.Match.newMutableMatch((Physical_Person) match[POSITION_P]);
432 } catch(ClassCastException e) {
433 LOGGER.error("Element(s) in array not properly typed!",e);
434 return null;
435 }
436 }
437
438 /**
439 * @return the singleton instance of the query specification of this pattern
440 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
441 *
442 */
443 public static IQuerySpecification<Inv48.Matcher> querySpecification() {
444 return Inv48.instance();
445 }
446 }
447
448 private Inv48() {
449 super(GeneratedPQuery.INSTANCE);
450 }
451
452 /**
453 * @return the singleton instance of the query specification
454 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
455 *
456 */
457 public static Inv48 instance() {
458 try{
459 return LazyHolder.INSTANCE;
460 } catch (ExceptionInInitializerError err) {
461 throw processInitializerError(err);
462 }
463 }
464
465 @Override
466 protected Inv48.Matcher instantiate(final ViatraQueryEngine engine) {
467 return Inv48.Matcher.on(engine);
468 }
469
470 @Override
471 public Inv48.Matcher instantiate() {
472 return Inv48.Matcher.create();
473 }
474
475 @Override
476 public Inv48.Match newEmptyMatch() {
477 return Inv48.Match.newEmptyMatch();
478 }
479
480 @Override
481 public Inv48.Match newMatch(final Object... parameters) {
482 return Inv48.Match.newMatch((Taxation.Physical_Person) parameters[0]);
483 }
484
485 /**
486 * Inner class allowing the singleton instance of {@link Inv48} to be created
487 * <b>not</b> at the class load time of the outer class,
488 * but rather at the first call to {@link Inv48#instance()}.
489 *
490 * <p> This workaround is required e.g. to support recursion.
491 *
492 */
493 private static class LazyHolder {
494 private static final Inv48 INSTANCE = new Inv48();
495
496 /**
497 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
498 * This initialization order is required to support indirect recursion.
499 *
500 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
501 *
502 */
503 private static final Object STATIC_INITIALIZER = ensureInitialized();
504
505 public static Object ensureInitialized() {
506 INSTANCE.ensureInitializedInternal();
507 return null;
508 }
509 }
510
511 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
512 private static final Inv48.GeneratedPQuery INSTANCE = new GeneratedPQuery();
513
514 private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT);
515
516 private final List<PParameter> parameters = Arrays.asList(parameter_p);
517
518 private GeneratedPQuery() {
519 super(PVisibility.PUBLIC);
520 }
521
522 @Override
523 public String getFullyQualifiedName() {
524 return "queries.inv48";
525 }
526
527 @Override
528 public List<String> getParameterNames() {
529 return Arrays.asList("p");
530 }
531
532 @Override
533 public List<PParameter> getParameters() {
534 return parameters;
535 }
536
537 @Override
538 public Set<PBody> doGetContainedBodies() {
539 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
540 Set<PBody> bodies = new LinkedHashSet<>();
541 {
542 PBody body = new PBody(this);
543 PVariable var_p = body.getOrCreateVariableByName("p");
544 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
545 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
546 new ExportedParameter(body, var_p, parameter_p)
547 ));
548 // neg find x_inv48_notDis(p)
549 new NegativePatternCall(body, Tuples.flatTupleOf(var_p), X_inv48_notDis.instance().getInternalQueryRepresentation());
550 // neg find x_inv48_Dis(p)
551 new NegativePatternCall(body, Tuples.flatTupleOf(var_p), X_inv48_Dis.instance().getInternalQueryRepresentation());
552 bodies.add(body);
553 }
554 {
555 PAnnotation annotation = new PAnnotation("Constraint");
556 annotation.addAttribute("message", "inv48");
557 annotation.addAttribute("severity", "error");
558 annotation.addAttribute("key", Arrays.asList(new Object[] {
559 new ParameterReference("p")
560 }));
561 addAnnotation(annotation);
562 }
563 return bodies;
564 }
565 }
566}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv49.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv49.java
new file mode 100644
index 00000000..3f8b975e
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv49.java
@@ -0,0 +1,561 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Legal_Union_Record;
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.NegativePatternCall;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
39import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
40import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
41import queries.X_inv49_1;
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 * //inv49-OclKindOf-handled by multiplicity
49 * {@literal @}Constraint(message = "inv49", severity = "error", key = {lur})
50 * pattern inv49(lur : Legal_Union_Record) {
51 * neg find x_inv49_1(lur);
52 * }
53 * </pre></code>
54 *
55 * @see Matcher
56 * @see Match
57 *
58 */
59@SuppressWarnings("all")
60public final class Inv49 extends BaseGeneratedEMFQuerySpecification<Inv49.Matcher> {
61 /**
62 * Pattern-specific match representation of the queries.inv49 pattern,
63 * to be used in conjunction with {@link Matcher}.
64 *
65 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
66 * Each instance is a (possibly partial) substitution of pattern parameters,
67 * usable to represent a match of the pattern in the result of a query,
68 * or to specify the bound (fixed) input parameters when issuing a query.
69 *
70 * @see Matcher
71 *
72 */
73 public static abstract class Match extends BasePatternMatch {
74 private Legal_Union_Record fLur;
75
76 private static List<String> parameterNames = makeImmutableList("lur");
77
78 private Match(final Legal_Union_Record pLur) {
79 this.fLur = pLur;
80 }
81
82 @Override
83 public Object get(final String parameterName) {
84 switch(parameterName) {
85 case "lur": return this.fLur;
86 default: return null;
87 }
88 }
89
90 @Override
91 public Object get(final int index) {
92 switch(index) {
93 case 0: return this.fLur;
94 default: return null;
95 }
96 }
97
98 public Legal_Union_Record getLur() {
99 return this.fLur;
100 }
101
102 @Override
103 public boolean set(final String parameterName, final Object newValue) {
104 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
105 if ("lur".equals(parameterName) ) {
106 this.fLur = (Legal_Union_Record) newValue;
107 return true;
108 }
109 return false;
110 }
111
112 public void setLur(final Legal_Union_Record pLur) {
113 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
114 this.fLur = pLur;
115 }
116
117 @Override
118 public String patternName() {
119 return "queries.inv49";
120 }
121
122 @Override
123 public List<String> parameterNames() {
124 return Inv49.Match.parameterNames;
125 }
126
127 @Override
128 public Object[] toArray() {
129 return new Object[]{fLur};
130 }
131
132 @Override
133 public Inv49.Match toImmutable() {
134 return isMutable() ? newMatch(fLur) : this;
135 }
136
137 @Override
138 public String prettyPrint() {
139 StringBuilder result = new StringBuilder();
140 result.append("\"lur\"=" + prettyPrintValue(fLur));
141 return result.toString();
142 }
143
144 @Override
145 public int hashCode() {
146 return Objects.hash(fLur);
147 }
148
149 @Override
150 public boolean equals(final Object obj) {
151 if (this == obj)
152 return true;
153 if (obj == null) {
154 return false;
155 }
156 if ((obj instanceof Inv49.Match)) {
157 Inv49.Match other = (Inv49.Match) obj;
158 return Objects.equals(fLur, other.fLur);
159 } else {
160 // this should be infrequent
161 if (!(obj instanceof IPatternMatch)) {
162 return false;
163 }
164 IPatternMatch otherSig = (IPatternMatch) obj;
165 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
166 }
167 }
168
169 @Override
170 public Inv49 specification() {
171 return Inv49.instance();
172 }
173
174 /**
175 * Returns an empty, mutable match.
176 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
177 *
178 * @return the empty match.
179 *
180 */
181 public static Inv49.Match newEmptyMatch() {
182 return new Mutable(null);
183 }
184
185 /**
186 * Returns a mutable (partial) match.
187 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
188 *
189 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
190 * @return the new, mutable (partial) match object.
191 *
192 */
193 public static Inv49.Match newMutableMatch(final Legal_Union_Record pLur) {
194 return new Mutable(pLur);
195 }
196
197 /**
198 * Returns a new (partial) match.
199 * This can be used e.g. to call the matcher with a partial match.
200 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
201 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
202 * @return the (partial) match object.
203 *
204 */
205 public static Inv49.Match newMatch(final Legal_Union_Record pLur) {
206 return new Immutable(pLur);
207 }
208
209 private static final class Mutable extends Inv49.Match {
210 Mutable(final Legal_Union_Record pLur) {
211 super(pLur);
212 }
213
214 @Override
215 public boolean isMutable() {
216 return true;
217 }
218 }
219
220 private static final class Immutable extends Inv49.Match {
221 Immutable(final Legal_Union_Record pLur) {
222 super(pLur);
223 }
224
225 @Override
226 public boolean isMutable() {
227 return false;
228 }
229 }
230 }
231
232 /**
233 * Generated pattern matcher API of the queries.inv49 pattern,
234 * providing pattern-specific query methods.
235 *
236 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
237 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
238 *
239 * <p>Matches of the pattern will be represented as {@link Match}.
240 *
241 * <p>Original source:
242 * <code><pre>
243 * //inv49-OclKindOf-handled by multiplicity
244 * {@literal @}Constraint(message = "inv49", severity = "error", key = {lur})
245 * pattern inv49(lur : Legal_Union_Record) {
246 * neg find x_inv49_1(lur);
247 * }
248 * </pre></code>
249 *
250 * @see Match
251 * @see Inv49
252 *
253 */
254 public static class Matcher extends BaseMatcher<Inv49.Match> {
255 /**
256 * Initializes the pattern matcher within an existing VIATRA Query engine.
257 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
258 *
259 * @param engine the existing VIATRA Query engine in which this matcher will be created.
260 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
261 *
262 */
263 public static Inv49.Matcher on(final ViatraQueryEngine engine) {
264 // check if matcher already exists
265 Matcher matcher = engine.getExistingMatcher(querySpecification());
266 if (matcher == null) {
267 matcher = (Matcher)engine.getMatcher(querySpecification());
268 }
269 return matcher;
270 }
271
272 /**
273 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
274 * @return an initialized matcher
275 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
276 *
277 */
278 public static Inv49.Matcher create() {
279 return new Matcher();
280 }
281
282 private static final int POSITION_LUR = 0;
283
284 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv49.Matcher.class);
285
286 /**
287 * Initializes the pattern matcher within an existing VIATRA Query engine.
288 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
289 *
290 * @param engine the existing VIATRA Query engine in which this matcher will be created.
291 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
292 *
293 */
294 private Matcher() {
295 super(querySpecification());
296 }
297
298 /**
299 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
300 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
301 * @return matches represented as a Match object.
302 *
303 */
304 public Collection<Inv49.Match> getAllMatches(final Legal_Union_Record pLur) {
305 return rawStreamAllMatches(new Object[]{pLur}).collect(Collectors.toSet());
306 }
307
308 /**
309 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
310 * </p>
311 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
312 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
313 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
314 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
315 * @return a stream of matches represented as a Match object.
316 *
317 */
318 public Stream<Inv49.Match> streamAllMatches(final Legal_Union_Record pLur) {
319 return rawStreamAllMatches(new Object[]{pLur});
320 }
321
322 /**
323 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
324 * Neither determinism nor randomness of selection is guaranteed.
325 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
326 * @return a match represented as a Match object, or null if no match is found.
327 *
328 */
329 public Optional<Inv49.Match> getOneArbitraryMatch(final Legal_Union_Record pLur) {
330 return rawGetOneArbitraryMatch(new Object[]{pLur});
331 }
332
333 /**
334 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
335 * under any possible substitution of the unspecified parameters (if any).
336 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
337 * @return true if the input is a valid (partial) match of the pattern.
338 *
339 */
340 public boolean hasMatch(final Legal_Union_Record pLur) {
341 return rawHasMatch(new Object[]{pLur});
342 }
343
344 /**
345 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
346 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
347 * @return the number of pattern matches found.
348 *
349 */
350 public int countMatches(final Legal_Union_Record pLur) {
351 return rawCountMatches(new Object[]{pLur});
352 }
353
354 /**
355 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
356 * Neither determinism nor randomness of selection is guaranteed.
357 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
358 * @param processor the action that will process the selected match.
359 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
360 *
361 */
362 public boolean forOneArbitraryMatch(final Legal_Union_Record pLur, final Consumer<? super Inv49.Match> processor) {
363 return rawForOneArbitraryMatch(new Object[]{pLur}, processor);
364 }
365
366 /**
367 * Returns a new (partial) match.
368 * This can be used e.g. to call the matcher with a partial match.
369 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
370 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
371 * @return the (partial) match object.
372 *
373 */
374 public Inv49.Match newMatch(final Legal_Union_Record pLur) {
375 return Inv49.Match.newMatch(pLur);
376 }
377
378 /**
379 * Retrieve the set of values that occur in matches for lur.
380 * @return the Set of all values or empty set if there are no matches
381 *
382 */
383 protected Stream<Legal_Union_Record> rawStreamAllValuesOflur(final Object[] parameters) {
384 return rawStreamAllValues(POSITION_LUR, parameters).map(Legal_Union_Record.class::cast);
385 }
386
387 /**
388 * Retrieve the set of values that occur in matches for lur.
389 * @return the Set of all values or empty set if there are no matches
390 *
391 */
392 public Set<Legal_Union_Record> getAllValuesOflur() {
393 return rawStreamAllValuesOflur(emptyArray()).collect(Collectors.toSet());
394 }
395
396 /**
397 * Retrieve the set of values that occur in matches for lur.
398 * @return the Set of all values or empty set if there are no matches
399 *
400 */
401 public Stream<Legal_Union_Record> streamAllValuesOflur() {
402 return rawStreamAllValuesOflur(emptyArray());
403 }
404
405 @Override
406 protected Inv49.Match tupleToMatch(final Tuple t) {
407 try {
408 return Inv49.Match.newMatch((Legal_Union_Record) t.get(POSITION_LUR));
409 } catch(ClassCastException e) {
410 LOGGER.error("Element(s) in tuple not properly typed!",e);
411 return null;
412 }
413 }
414
415 @Override
416 protected Inv49.Match arrayToMatch(final Object[] match) {
417 try {
418 return Inv49.Match.newMatch((Legal_Union_Record) match[POSITION_LUR]);
419 } catch(ClassCastException e) {
420 LOGGER.error("Element(s) in array not properly typed!",e);
421 return null;
422 }
423 }
424
425 @Override
426 protected Inv49.Match arrayToMatchMutable(final Object[] match) {
427 try {
428 return Inv49.Match.newMutableMatch((Legal_Union_Record) match[POSITION_LUR]);
429 } catch(ClassCastException e) {
430 LOGGER.error("Element(s) in array not properly typed!",e);
431 return null;
432 }
433 }
434
435 /**
436 * @return the singleton instance of the query specification of this pattern
437 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
438 *
439 */
440 public static IQuerySpecification<Inv49.Matcher> querySpecification() {
441 return Inv49.instance();
442 }
443 }
444
445 private Inv49() {
446 super(GeneratedPQuery.INSTANCE);
447 }
448
449 /**
450 * @return the singleton instance of the query specification
451 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
452 *
453 */
454 public static Inv49 instance() {
455 try{
456 return LazyHolder.INSTANCE;
457 } catch (ExceptionInInitializerError err) {
458 throw processInitializerError(err);
459 }
460 }
461
462 @Override
463 protected Inv49.Matcher instantiate(final ViatraQueryEngine engine) {
464 return Inv49.Matcher.on(engine);
465 }
466
467 @Override
468 public Inv49.Matcher instantiate() {
469 return Inv49.Matcher.create();
470 }
471
472 @Override
473 public Inv49.Match newEmptyMatch() {
474 return Inv49.Match.newEmptyMatch();
475 }
476
477 @Override
478 public Inv49.Match newMatch(final Object... parameters) {
479 return Inv49.Match.newMatch((Taxation.Legal_Union_Record) parameters[0]);
480 }
481
482 /**
483 * Inner class allowing the singleton instance of {@link Inv49} to be created
484 * <b>not</b> at the class load time of the outer class,
485 * but rather at the first call to {@link Inv49#instance()}.
486 *
487 * <p> This workaround is required e.g. to support recursion.
488 *
489 */
490 private static class LazyHolder {
491 private static final Inv49 INSTANCE = new Inv49();
492
493 /**
494 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
495 * This initialization order is required to support indirect recursion.
496 *
497 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
498 *
499 */
500 private static final Object STATIC_INITIALIZER = ensureInitialized();
501
502 public static Object ensureInitialized() {
503 INSTANCE.ensureInitializedInternal();
504 return null;
505 }
506 }
507
508 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
509 private static final Inv49.GeneratedPQuery INSTANCE = new GeneratedPQuery();
510
511 private final PParameter parameter_lur = new PParameter("lur", "Taxation.Legal_Union_Record", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Legal_Union_Record")), PParameterDirection.INOUT);
512
513 private final List<PParameter> parameters = Arrays.asList(parameter_lur);
514
515 private GeneratedPQuery() {
516 super(PVisibility.PUBLIC);
517 }
518
519 @Override
520 public String getFullyQualifiedName() {
521 return "queries.inv49";
522 }
523
524 @Override
525 public List<String> getParameterNames() {
526 return Arrays.asList("lur");
527 }
528
529 @Override
530 public List<PParameter> getParameters() {
531 return parameters;
532 }
533
534 @Override
535 public Set<PBody> doGetContainedBodies() {
536 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
537 Set<PBody> bodies = new LinkedHashSet<>();
538 {
539 PBody body = new PBody(this);
540 PVariable var_lur = body.getOrCreateVariableByName("lur");
541 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
542 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
543 new ExportedParameter(body, var_lur, parameter_lur)
544 ));
545 // neg find x_inv49_1(lur)
546 new NegativePatternCall(body, Tuples.flatTupleOf(var_lur), X_inv49_1.instance().getInternalQueryRepresentation());
547 bodies.add(body);
548 }
549 {
550 PAnnotation annotation = new PAnnotation("Constraint");
551 annotation.addAttribute("message", "inv49");
552 annotation.addAttribute("severity", "error");
553 annotation.addAttribute("key", Arrays.asList(new Object[] {
554 new ParameterReference("lur")
555 }));
556 addAnnotation(annotation);
557 }
558 return bodies;
559 }
560 }
561}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_eligAll.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_eligAll.java
new file mode 100644
index 00000000..89ae2bcc
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_eligAll.java
@@ -0,0 +1,606 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Dependent;
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.basicdeferred.Equality;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue;
39import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
42import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
43import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
44import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
45import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
46
47/**
48 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
49 *
50 * <p>Original source:
51 * <code><pre>
52 * pattern x_inv03_eligAll(dep : Dependent) {
53 * Dependent.birth_year(dep, by);
54 * check(2018-by {@literal <}= 21);
55 * } or {
56 * Dependent.continued_studies(dep, true);
57 * }
58 * </pre></code>
59 *
60 * @see Matcher
61 * @see Match
62 *
63 */
64@SuppressWarnings("all")
65public final class X_inv03_eligAll extends BaseGeneratedEMFQuerySpecification<X_inv03_eligAll.Matcher> {
66 /**
67 * Pattern-specific match representation of the queries.x_inv03_eligAll 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 Dependent fDep;
80
81 private static List<String> parameterNames = makeImmutableList("dep");
82
83 private Match(final Dependent pDep) {
84 this.fDep = pDep;
85 }
86
87 @Override
88 public Object get(final String parameterName) {
89 switch(parameterName) {
90 case "dep": return this.fDep;
91 default: return null;
92 }
93 }
94
95 @Override
96 public Object get(final int index) {
97 switch(index) {
98 case 0: return this.fDep;
99 default: return null;
100 }
101 }
102
103 public Dependent getDep() {
104 return this.fDep;
105 }
106
107 @Override
108 public boolean set(final String parameterName, final Object newValue) {
109 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
110 if ("dep".equals(parameterName) ) {
111 this.fDep = (Dependent) newValue;
112 return true;
113 }
114 return false;
115 }
116
117 public void setDep(final Dependent pDep) {
118 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
119 this.fDep = pDep;
120 }
121
122 @Override
123 public String patternName() {
124 return "queries.x_inv03_eligAll";
125 }
126
127 @Override
128 public List<String> parameterNames() {
129 return X_inv03_eligAll.Match.parameterNames;
130 }
131
132 @Override
133 public Object[] toArray() {
134 return new Object[]{fDep};
135 }
136
137 @Override
138 public X_inv03_eligAll.Match toImmutable() {
139 return isMutable() ? newMatch(fDep) : this;
140 }
141
142 @Override
143 public String prettyPrint() {
144 StringBuilder result = new StringBuilder();
145 result.append("\"dep\"=" + prettyPrintValue(fDep));
146 return result.toString();
147 }
148
149 @Override
150 public int hashCode() {
151 return Objects.hash(fDep);
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 X_inv03_eligAll.Match)) {
162 X_inv03_eligAll.Match other = (X_inv03_eligAll.Match) obj;
163 return Objects.equals(fDep, other.fDep);
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 X_inv03_eligAll specification() {
176 return X_inv03_eligAll.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 X_inv03_eligAll.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 pDep the fixed value of pattern parameter dep, or null if not bound.
195 * @return the new, mutable (partial) match object.
196 *
197 */
198 public static X_inv03_eligAll.Match newMutableMatch(final Dependent pDep) {
199 return new Mutable(pDep);
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 pDep the fixed value of pattern parameter dep, or null if not bound.
207 * @return the (partial) match object.
208 *
209 */
210 public static X_inv03_eligAll.Match newMatch(final Dependent pDep) {
211 return new Immutable(pDep);
212 }
213
214 private static final class Mutable extends X_inv03_eligAll.Match {
215 Mutable(final Dependent pDep) {
216 super(pDep);
217 }
218
219 @Override
220 public boolean isMutable() {
221 return true;
222 }
223 }
224
225 private static final class Immutable extends X_inv03_eligAll.Match {
226 Immutable(final Dependent pDep) {
227 super(pDep);
228 }
229
230 @Override
231 public boolean isMutable() {
232 return false;
233 }
234 }
235 }
236
237 /**
238 * Generated pattern matcher API of the queries.x_inv03_eligAll 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 * pattern x_inv03_eligAll(dep : Dependent) {
249 * Dependent.birth_year(dep, by);
250 * check(2018-by {@literal <}= 21);
251 * } or {
252 * Dependent.continued_studies(dep, true);
253 * }
254 * </pre></code>
255 *
256 * @see Match
257 * @see X_inv03_eligAll
258 *
259 */
260 public static class Matcher extends BaseMatcher<X_inv03_eligAll.Match> {
261 /**
262 * Initializes the pattern matcher within an existing VIATRA Query engine.
263 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
264 *
265 * @param engine the existing VIATRA Query engine in which this matcher will be created.
266 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
267 *
268 */
269 public static X_inv03_eligAll.Matcher on(final ViatraQueryEngine engine) {
270 // check if matcher already exists
271 Matcher matcher = engine.getExistingMatcher(querySpecification());
272 if (matcher == null) {
273 matcher = (Matcher)engine.getMatcher(querySpecification());
274 }
275 return matcher;
276 }
277
278 /**
279 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
280 * @return an initialized matcher
281 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
282 *
283 */
284 public static X_inv03_eligAll.Matcher create() {
285 return new Matcher();
286 }
287
288 private static final int POSITION_DEP = 0;
289
290 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv03_eligAll.Matcher.class);
291
292 /**
293 * Initializes the pattern matcher within an existing VIATRA Query engine.
294 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
295 *
296 * @param engine the existing VIATRA Query engine in which this matcher will be created.
297 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
298 *
299 */
300 private Matcher() {
301 super(querySpecification());
302 }
303
304 /**
305 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
306 * @param pDep the fixed value of pattern parameter dep, or null if not bound.
307 * @return matches represented as a Match object.
308 *
309 */
310 public Collection<X_inv03_eligAll.Match> getAllMatches(final Dependent pDep) {
311 return rawStreamAllMatches(new Object[]{pDep}).collect(Collectors.toSet());
312 }
313
314 /**
315 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
316 * </p>
317 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
318 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
319 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
320 * @param pDep the fixed value of pattern parameter dep, or null if not bound.
321 * @return a stream of matches represented as a Match object.
322 *
323 */
324 public Stream<X_inv03_eligAll.Match> streamAllMatches(final Dependent pDep) {
325 return rawStreamAllMatches(new Object[]{pDep});
326 }
327
328 /**
329 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
330 * Neither determinism nor randomness of selection is guaranteed.
331 * @param pDep the fixed value of pattern parameter dep, or null if not bound.
332 * @return a match represented as a Match object, or null if no match is found.
333 *
334 */
335 public Optional<X_inv03_eligAll.Match> getOneArbitraryMatch(final Dependent pDep) {
336 return rawGetOneArbitraryMatch(new Object[]{pDep});
337 }
338
339 /**
340 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
341 * under any possible substitution of the unspecified parameters (if any).
342 * @param pDep the fixed value of pattern parameter dep, or null if not bound.
343 * @return true if the input is a valid (partial) match of the pattern.
344 *
345 */
346 public boolean hasMatch(final Dependent pDep) {
347 return rawHasMatch(new Object[]{pDep});
348 }
349
350 /**
351 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
352 * @param pDep the fixed value of pattern parameter dep, or null if not bound.
353 * @return the number of pattern matches found.
354 *
355 */
356 public int countMatches(final Dependent pDep) {
357 return rawCountMatches(new Object[]{pDep});
358 }
359
360 /**
361 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
362 * Neither determinism nor randomness of selection is guaranteed.
363 * @param pDep the fixed value of pattern parameter dep, or null if not bound.
364 * @param processor the action that will process the selected match.
365 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
366 *
367 */
368 public boolean forOneArbitraryMatch(final Dependent pDep, final Consumer<? super X_inv03_eligAll.Match> processor) {
369 return rawForOneArbitraryMatch(new Object[]{pDep}, processor);
370 }
371
372 /**
373 * Returns a new (partial) match.
374 * This can be used e.g. to call the matcher with a partial match.
375 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
376 * @param pDep the fixed value of pattern parameter dep, or null if not bound.
377 * @return the (partial) match object.
378 *
379 */
380 public X_inv03_eligAll.Match newMatch(final Dependent pDep) {
381 return X_inv03_eligAll.Match.newMatch(pDep);
382 }
383
384 /**
385 * Retrieve the set of values that occur in matches for dep.
386 * @return the Set of all values or empty set if there are no matches
387 *
388 */
389 protected Stream<Dependent> rawStreamAllValuesOfdep(final Object[] parameters) {
390 return rawStreamAllValues(POSITION_DEP, parameters).map(Dependent.class::cast);
391 }
392
393 /**
394 * Retrieve the set of values that occur in matches for dep.
395 * @return the Set of all values or empty set if there are no matches
396 *
397 */
398 public Set<Dependent> getAllValuesOfdep() {
399 return rawStreamAllValuesOfdep(emptyArray()).collect(Collectors.toSet());
400 }
401
402 /**
403 * Retrieve the set of values that occur in matches for dep.
404 * @return the Set of all values or empty set if there are no matches
405 *
406 */
407 public Stream<Dependent> streamAllValuesOfdep() {
408 return rawStreamAllValuesOfdep(emptyArray());
409 }
410
411 @Override
412 protected X_inv03_eligAll.Match tupleToMatch(final Tuple t) {
413 try {
414 return X_inv03_eligAll.Match.newMatch((Dependent) t.get(POSITION_DEP));
415 } catch(ClassCastException e) {
416 LOGGER.error("Element(s) in tuple not properly typed!",e);
417 return null;
418 }
419 }
420
421 @Override
422 protected X_inv03_eligAll.Match arrayToMatch(final Object[] match) {
423 try {
424 return X_inv03_eligAll.Match.newMatch((Dependent) match[POSITION_DEP]);
425 } catch(ClassCastException e) {
426 LOGGER.error("Element(s) in array not properly typed!",e);
427 return null;
428 }
429 }
430
431 @Override
432 protected X_inv03_eligAll.Match arrayToMatchMutable(final Object[] match) {
433 try {
434 return X_inv03_eligAll.Match.newMutableMatch((Dependent) match[POSITION_DEP]);
435 } catch(ClassCastException e) {
436 LOGGER.error("Element(s) in array not properly typed!",e);
437 return null;
438 }
439 }
440
441 /**
442 * @return the singleton instance of the query specification of this pattern
443 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
444 *
445 */
446 public static IQuerySpecification<X_inv03_eligAll.Matcher> querySpecification() {
447 return X_inv03_eligAll.instance();
448 }
449 }
450
451 private X_inv03_eligAll() {
452 super(GeneratedPQuery.INSTANCE);
453 }
454
455 /**
456 * @return the singleton instance of the query specification
457 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
458 *
459 */
460 public static X_inv03_eligAll instance() {
461 try{
462 return LazyHolder.INSTANCE;
463 } catch (ExceptionInInitializerError err) {
464 throw processInitializerError(err);
465 }
466 }
467
468 @Override
469 protected X_inv03_eligAll.Matcher instantiate(final ViatraQueryEngine engine) {
470 return X_inv03_eligAll.Matcher.on(engine);
471 }
472
473 @Override
474 public X_inv03_eligAll.Matcher instantiate() {
475 return X_inv03_eligAll.Matcher.create();
476 }
477
478 @Override
479 public X_inv03_eligAll.Match newEmptyMatch() {
480 return X_inv03_eligAll.Match.newEmptyMatch();
481 }
482
483 @Override
484 public X_inv03_eligAll.Match newMatch(final Object... parameters) {
485 return X_inv03_eligAll.Match.newMatch((Taxation.Dependent) parameters[0]);
486 }
487
488 /**
489 * Inner class allowing the singleton instance of {@link X_inv03_eligAll} to be created
490 * <b>not</b> at the class load time of the outer class,
491 * but rather at the first call to {@link X_inv03_eligAll#instance()}.
492 *
493 * <p> This workaround is required e.g. to support recursion.
494 *
495 */
496 private static class LazyHolder {
497 private static final X_inv03_eligAll INSTANCE = new X_inv03_eligAll();
498
499 /**
500 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
501 * This initialization order is required to support indirect recursion.
502 *
503 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
504 *
505 */
506 private static final Object STATIC_INITIALIZER = ensureInitialized();
507
508 public static Object ensureInitialized() {
509 INSTANCE.ensureInitializedInternal();
510 return null;
511 }
512 }
513
514 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
515 private static final X_inv03_eligAll.GeneratedPQuery INSTANCE = new GeneratedPQuery();
516
517 private final PParameter parameter_dep = new PParameter("dep", "Taxation.Dependent", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Dependent")), PParameterDirection.INOUT);
518
519 private final List<PParameter> parameters = Arrays.asList(parameter_dep);
520
521 private GeneratedPQuery() {
522 super(PVisibility.PUBLIC);
523 }
524
525 @Override
526 public String getFullyQualifiedName() {
527 return "queries.x_inv03_eligAll";
528 }
529
530 @Override
531 public List<String> getParameterNames() {
532 return Arrays.asList("dep");
533 }
534
535 @Override
536 public List<PParameter> getParameters() {
537 return parameters;
538 }
539
540 @Override
541 public Set<PBody> doGetContainedBodies() {
542 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
543 Set<PBody> bodies = new LinkedHashSet<>();
544 {
545 PBody body = new PBody(this);
546 PVariable var_dep = body.getOrCreateVariableByName("dep");
547 PVariable var_by = body.getOrCreateVariableByName("by");
548 new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
549 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
550 new ExportedParameter(body, var_dep, parameter_dep)
551 ));
552 // Dependent.birth_year(dep, by)
553 new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
554 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
555 new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year")));
556 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
557 new Equality(body, var__virtual_0_, var_by);
558 // check(2018-by <= 21)
559 new ExpressionEvaluation(body, new IExpressionEvaluator() {
560
561 @Override
562 public String getShortDescription() {
563 return "Expression evaluation from pattern x_inv03_eligAll";
564 }
565
566 @Override
567 public Iterable<String> getInputParameterNames() {
568 return Arrays.asList("by");}
569
570 @Override
571 public Object evaluateExpression(IValueProvider provider) throws Exception {
572 Integer by = (Integer) provider.getValue("by");
573 return evaluateExpression_1_1(by);
574 }
575 }, null);
576 bodies.add(body);
577 }
578 {
579 PBody body = new PBody(this);
580 PVariable var_dep = body.getOrCreateVariableByName("dep");
581 new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
582 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
583 new ExportedParameter(body, var_dep, parameter_dep)
584 ));
585 // Dependent.continued_studies(dep, true)
586 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
587 new ConstantValue(body, var__virtual_0_, true);
588 new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
589 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
590 new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Dependent", "continued_studies")));
591 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EBoolean")));
592 new Equality(body, var__virtual_1_, var__virtual_0_);
593 bodies.add(body);
594 }
595 return bodies;
596 }
597 }
598
599 private static boolean evaluateExpression_1_1(final Integer by) {
600 return ((2018 - (by).intValue()) <= 21);
601 }
602
603 private static boolean evaluateExpression_2_1() {
604 return true;
605 }
606}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_hasAll.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_hasAll.java
new file mode 100644
index 00000000..66e47407
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_hasAll.java
@@ -0,0 +1,551 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Dependent;
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 x_inv03_hasAll(dep : Dependent) {
47 * Dependent.allowances(dep, _);
48 * }
49 * </pre></code>
50 *
51 * @see Matcher
52 * @see Match
53 *
54 */
55@SuppressWarnings("all")
56public final class X_inv03_hasAll extends BaseGeneratedEMFQuerySpecification<X_inv03_hasAll.Matcher> {
57 /**
58 * Pattern-specific match representation of the queries.x_inv03_hasAll 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 Dependent fDep;
71
72 private static List<String> parameterNames = makeImmutableList("dep");
73
74 private Match(final Dependent pDep) {
75 this.fDep = pDep;
76 }
77
78 @Override
79 public Object get(final String parameterName) {
80 switch(parameterName) {
81 case "dep": return this.fDep;
82 default: return null;
83 }
84 }
85
86 @Override
87 public Object get(final int index) {
88 switch(index) {
89 case 0: return this.fDep;
90 default: return null;
91 }
92 }
93
94 public Dependent getDep() {
95 return this.fDep;
96 }
97
98 @Override
99 public boolean set(final String parameterName, final Object newValue) {
100 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
101 if ("dep".equals(parameterName) ) {
102 this.fDep = (Dependent) newValue;
103 return true;
104 }
105 return false;
106 }
107
108 public void setDep(final Dependent pDep) {
109 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
110 this.fDep = pDep;
111 }
112
113 @Override
114 public String patternName() {
115 return "queries.x_inv03_hasAll";
116 }
117
118 @Override
119 public List<String> parameterNames() {
120 return X_inv03_hasAll.Match.parameterNames;
121 }
122
123 @Override
124 public Object[] toArray() {
125 return new Object[]{fDep};
126 }
127
128 @Override
129 public X_inv03_hasAll.Match toImmutable() {
130 return isMutable() ? newMatch(fDep) : this;
131 }
132
133 @Override
134 public String prettyPrint() {
135 StringBuilder result = new StringBuilder();
136 result.append("\"dep\"=" + prettyPrintValue(fDep));
137 return result.toString();
138 }
139
140 @Override
141 public int hashCode() {
142 return Objects.hash(fDep);
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 X_inv03_hasAll.Match)) {
153 X_inv03_hasAll.Match other = (X_inv03_hasAll.Match) obj;
154 return Objects.equals(fDep, other.fDep);
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 X_inv03_hasAll specification() {
167 return X_inv03_hasAll.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 X_inv03_hasAll.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 pDep the fixed value of pattern parameter dep, or null if not bound.
186 * @return the new, mutable (partial) match object.
187 *
188 */
189 public static X_inv03_hasAll.Match newMutableMatch(final Dependent pDep) {
190 return new Mutable(pDep);
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 pDep the fixed value of pattern parameter dep, or null if not bound.
198 * @return the (partial) match object.
199 *
200 */
201 public static X_inv03_hasAll.Match newMatch(final Dependent pDep) {
202 return new Immutable(pDep);
203 }
204
205 private static final class Mutable extends X_inv03_hasAll.Match {
206 Mutable(final Dependent pDep) {
207 super(pDep);
208 }
209
210 @Override
211 public boolean isMutable() {
212 return true;
213 }
214 }
215
216 private static final class Immutable extends X_inv03_hasAll.Match {
217 Immutable(final Dependent pDep) {
218 super(pDep);
219 }
220
221 @Override
222 public boolean isMutable() {
223 return false;
224 }
225 }
226 }
227
228 /**
229 * Generated pattern matcher API of the queries.x_inv03_hasAll 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 x_inv03_hasAll(dep : Dependent) {
240 * Dependent.allowances(dep, _);
241 * }
242 * </pre></code>
243 *
244 * @see Match
245 * @see X_inv03_hasAll
246 *
247 */
248 public static class Matcher extends BaseMatcher<X_inv03_hasAll.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 X_inv03_hasAll.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 X_inv03_hasAll.Matcher create() {
273 return new Matcher();
274 }
275
276 private static final int POSITION_DEP = 0;
277
278 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv03_hasAll.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 pDep the fixed value of pattern parameter dep, or null if not bound.
295 * @return matches represented as a Match object.
296 *
297 */
298 public Collection<X_inv03_hasAll.Match> getAllMatches(final Dependent pDep) {
299 return rawStreamAllMatches(new Object[]{pDep}).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 pDep the fixed value of pattern parameter dep, or null if not bound.
309 * @return a stream of matches represented as a Match object.
310 *
311 */
312 public Stream<X_inv03_hasAll.Match> streamAllMatches(final Dependent pDep) {
313 return rawStreamAllMatches(new Object[]{pDep});
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 pDep the fixed value of pattern parameter dep, 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<X_inv03_hasAll.Match> getOneArbitraryMatch(final Dependent pDep) {
324 return rawGetOneArbitraryMatch(new Object[]{pDep});
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 pDep the fixed value of pattern parameter dep, 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 Dependent pDep) {
335 return rawHasMatch(new Object[]{pDep});
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 pDep the fixed value of pattern parameter dep, or null if not bound.
341 * @return the number of pattern matches found.
342 *
343 */
344 public int countMatches(final Dependent pDep) {
345 return rawCountMatches(new Object[]{pDep});
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 pDep the fixed value of pattern parameter dep, 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 Dependent pDep, final Consumer<? super X_inv03_hasAll.Match> processor) {
357 return rawForOneArbitraryMatch(new Object[]{pDep}, 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 pDep the fixed value of pattern parameter dep, or null if not bound.
365 * @return the (partial) match object.
366 *
367 */
368 public X_inv03_hasAll.Match newMatch(final Dependent pDep) {
369 return X_inv03_hasAll.Match.newMatch(pDep);
370 }
371
372 /**
373 * Retrieve the set of values that occur in matches for dep.
374 * @return the Set of all values or empty set if there are no matches
375 *
376 */
377 protected Stream<Dependent> rawStreamAllValuesOfdep(final Object[] parameters) {
378 return rawStreamAllValues(POSITION_DEP, parameters).map(Dependent.class::cast);
379 }
380
381 /**
382 * Retrieve the set of values that occur in matches for dep.
383 * @return the Set of all values or empty set if there are no matches
384 *
385 */
386 public Set<Dependent> getAllValuesOfdep() {
387 return rawStreamAllValuesOfdep(emptyArray()).collect(Collectors.toSet());
388 }
389
390 /**
391 * Retrieve the set of values that occur in matches for dep.
392 * @return the Set of all values or empty set if there are no matches
393 *
394 */
395 public Stream<Dependent> streamAllValuesOfdep() {
396 return rawStreamAllValuesOfdep(emptyArray());
397 }
398
399 @Override
400 protected X_inv03_hasAll.Match tupleToMatch(final Tuple t) {
401 try {
402 return X_inv03_hasAll.Match.newMatch((Dependent) t.get(POSITION_DEP));
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 X_inv03_hasAll.Match arrayToMatch(final Object[] match) {
411 try {
412 return X_inv03_hasAll.Match.newMatch((Dependent) match[POSITION_DEP]);
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 X_inv03_hasAll.Match arrayToMatchMutable(final Object[] match) {
421 try {
422 return X_inv03_hasAll.Match.newMutableMatch((Dependent) match[POSITION_DEP]);
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<X_inv03_hasAll.Matcher> querySpecification() {
435 return X_inv03_hasAll.instance();
436 }
437 }
438
439 private X_inv03_hasAll() {
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 X_inv03_hasAll instance() {
449 try{
450 return LazyHolder.INSTANCE;
451 } catch (ExceptionInInitializerError err) {
452 throw processInitializerError(err);
453 }
454 }
455
456 @Override
457 protected X_inv03_hasAll.Matcher instantiate(final ViatraQueryEngine engine) {
458 return X_inv03_hasAll.Matcher.on(engine);
459 }
460
461 @Override
462 public X_inv03_hasAll.Matcher instantiate() {
463 return X_inv03_hasAll.Matcher.create();
464 }
465
466 @Override
467 public X_inv03_hasAll.Match newEmptyMatch() {
468 return X_inv03_hasAll.Match.newEmptyMatch();
469 }
470
471 @Override
472 public X_inv03_hasAll.Match newMatch(final Object... parameters) {
473 return X_inv03_hasAll.Match.newMatch((Taxation.Dependent) parameters[0]);
474 }
475
476 /**
477 * Inner class allowing the singleton instance of {@link X_inv03_hasAll} 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 X_inv03_hasAll#instance()}.
480 *
481 * <p> This workaround is required e.g. to support recursion.
482 *
483 */
484 private static class LazyHolder {
485 private static final X_inv03_hasAll INSTANCE = new X_inv03_hasAll();
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 X_inv03_hasAll.GeneratedPQuery INSTANCE = new GeneratedPQuery();
504
505 private final PParameter parameter_dep = new PParameter("dep", "Taxation.Dependent", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Dependent")), PParameterDirection.INOUT);
506
507 private final List<PParameter> parameters = Arrays.asList(parameter_dep);
508
509 private GeneratedPQuery() {
510 super(PVisibility.PUBLIC);
511 }
512
513 @Override
514 public String getFullyQualifiedName() {
515 return "queries.x_inv03_hasAll";
516 }
517
518 @Override
519 public List<String> getParameterNames() {
520 return Arrays.asList("dep");
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_dep = body.getOrCreateVariableByName("dep");
535 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
536 new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
537 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
538 new ExportedParameter(body, var_dep, parameter_dep)
539 ));
540 // Dependent.allowances(dep, _)
541 new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
542 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
543 new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Dependent", "allowances")));
544 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance")));
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.queries/src-gen/queries/X_inv05_inRange.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv05_inRange.java
new file mode 100644
index 00000000..4c2a7299
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv05_inRange.java
@@ -0,0 +1,628 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Income;
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.basicdeferred.Equality;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
42import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
43import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
44import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
45
46/**
47 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
48 *
49 * <p>Original source:
50 * <code><pre>
51 * pattern x_inv05_inRange(inc : Income) {
52 * Income.details.worked_days(inc, wd);
53 * check(wd {@literal <} 1);
54 * } or {
55 * Income.details.worked_days(inc, wd);
56 * check(wd {@literal >} 25);
57 * }
58 * </pre></code>
59 *
60 * @see Matcher
61 * @see Match
62 *
63 */
64@SuppressWarnings("all")
65public final class X_inv05_inRange extends BaseGeneratedEMFQuerySpecification<X_inv05_inRange.Matcher> {
66 /**
67 * Pattern-specific match representation of the queries.x_inv05_inRange 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 Income fInc;
80
81 private static List<String> parameterNames = makeImmutableList("inc");
82
83 private Match(final Income pInc) {
84 this.fInc = pInc;
85 }
86
87 @Override
88 public Object get(final String parameterName) {
89 switch(parameterName) {
90 case "inc": return this.fInc;
91 default: return null;
92 }
93 }
94
95 @Override
96 public Object get(final int index) {
97 switch(index) {
98 case 0: return this.fInc;
99 default: return null;
100 }
101 }
102
103 public Income getInc() {
104 return this.fInc;
105 }
106
107 @Override
108 public boolean set(final String parameterName, final Object newValue) {
109 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
110 if ("inc".equals(parameterName) ) {
111 this.fInc = (Income) newValue;
112 return true;
113 }
114 return false;
115 }
116
117 public void setInc(final Income pInc) {
118 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
119 this.fInc = pInc;
120 }
121
122 @Override
123 public String patternName() {
124 return "queries.x_inv05_inRange";
125 }
126
127 @Override
128 public List<String> parameterNames() {
129 return X_inv05_inRange.Match.parameterNames;
130 }
131
132 @Override
133 public Object[] toArray() {
134 return new Object[]{fInc};
135 }
136
137 @Override
138 public X_inv05_inRange.Match toImmutable() {
139 return isMutable() ? newMatch(fInc) : this;
140 }
141
142 @Override
143 public String prettyPrint() {
144 StringBuilder result = new StringBuilder();
145 result.append("\"inc\"=" + prettyPrintValue(fInc));
146 return result.toString();
147 }
148
149 @Override
150 public int hashCode() {
151 return Objects.hash(fInc);
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 X_inv05_inRange.Match)) {
162 X_inv05_inRange.Match other = (X_inv05_inRange.Match) obj;
163 return Objects.equals(fInc, other.fInc);
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 X_inv05_inRange specification() {
176 return X_inv05_inRange.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 X_inv05_inRange.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 pInc the fixed value of pattern parameter inc, or null if not bound.
195 * @return the new, mutable (partial) match object.
196 *
197 */
198 public static X_inv05_inRange.Match newMutableMatch(final Income pInc) {
199 return new Mutable(pInc);
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 pInc the fixed value of pattern parameter inc, or null if not bound.
207 * @return the (partial) match object.
208 *
209 */
210 public static X_inv05_inRange.Match newMatch(final Income pInc) {
211 return new Immutable(pInc);
212 }
213
214 private static final class Mutable extends X_inv05_inRange.Match {
215 Mutable(final Income pInc) {
216 super(pInc);
217 }
218
219 @Override
220 public boolean isMutable() {
221 return true;
222 }
223 }
224
225 private static final class Immutable extends X_inv05_inRange.Match {
226 Immutable(final Income pInc) {
227 super(pInc);
228 }
229
230 @Override
231 public boolean isMutable() {
232 return false;
233 }
234 }
235 }
236
237 /**
238 * Generated pattern matcher API of the queries.x_inv05_inRange 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 * pattern x_inv05_inRange(inc : Income) {
249 * Income.details.worked_days(inc, wd);
250 * check(wd {@literal <} 1);
251 * } or {
252 * Income.details.worked_days(inc, wd);
253 * check(wd {@literal >} 25);
254 * }
255 * </pre></code>
256 *
257 * @see Match
258 * @see X_inv05_inRange
259 *
260 */
261 public static class Matcher extends BaseMatcher<X_inv05_inRange.Match> {
262 /**
263 * Initializes the pattern matcher within an existing VIATRA Query engine.
264 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
265 *
266 * @param engine the existing VIATRA Query engine in which this matcher will be created.
267 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
268 *
269 */
270 public static X_inv05_inRange.Matcher on(final ViatraQueryEngine engine) {
271 // check if matcher already exists
272 Matcher matcher = engine.getExistingMatcher(querySpecification());
273 if (matcher == null) {
274 matcher = (Matcher)engine.getMatcher(querySpecification());
275 }
276 return matcher;
277 }
278
279 /**
280 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
281 * @return an initialized matcher
282 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
283 *
284 */
285 public static X_inv05_inRange.Matcher create() {
286 return new Matcher();
287 }
288
289 private static final int POSITION_INC = 0;
290
291 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv05_inRange.Matcher.class);
292
293 /**
294 * Initializes the pattern matcher within an existing VIATRA Query engine.
295 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
296 *
297 * @param engine the existing VIATRA Query engine in which this matcher will be created.
298 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
299 *
300 */
301 private Matcher() {
302 super(querySpecification());
303 }
304
305 /**
306 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
307 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
308 * @return matches represented as a Match object.
309 *
310 */
311 public Collection<X_inv05_inRange.Match> getAllMatches(final Income pInc) {
312 return rawStreamAllMatches(new Object[]{pInc}).collect(Collectors.toSet());
313 }
314
315 /**
316 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
317 * </p>
318 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
319 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
320 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
321 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
322 * @return a stream of matches represented as a Match object.
323 *
324 */
325 public Stream<X_inv05_inRange.Match> streamAllMatches(final Income pInc) {
326 return rawStreamAllMatches(new Object[]{pInc});
327 }
328
329 /**
330 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
331 * Neither determinism nor randomness of selection is guaranteed.
332 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
333 * @return a match represented as a Match object, or null if no match is found.
334 *
335 */
336 public Optional<X_inv05_inRange.Match> getOneArbitraryMatch(final Income pInc) {
337 return rawGetOneArbitraryMatch(new Object[]{pInc});
338 }
339
340 /**
341 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
342 * under any possible substitution of the unspecified parameters (if any).
343 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
344 * @return true if the input is a valid (partial) match of the pattern.
345 *
346 */
347 public boolean hasMatch();
348
349 /**
350 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
351 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
352 * @return the number of pattern matches found.
353 *
354 */
355 public int countMatches(final Income pInc) {
356 return rawCountMatches(new Object[]{pInc});
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 pInc the fixed value of pattern parameter inc, 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 Income pInc, final Consumer<? super X_inv05_inRange.Match> processor) {
368 return rawForOneArbitraryMatch(new Object[]{pInc}, 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 pInc the fixed value of pattern parameter inc, or null if not bound.
376 * @return the (partial) match object.
377 *
378 */
379 public X_inv05_inRange.Match newMatch(final Income pInc) {
380 return X_inv05_inRange.Match.newMatch(pInc);
381 }
382
383 /**
384 * Retrieve the set of values that occur in matches for inc.
385 * @return the Set of all values or empty set if there are no matches
386 *
387 */
388 protected Stream<Income> rawStreamAllValuesOfinc(final Object[] parameters) {
389 return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast);
390 }
391
392 /**
393 * Retrieve the set of values that occur in matches for inc.
394 * @return the Set of all values or empty set if there are no matches
395 *
396 */
397 public Set<Income> getAllValuesOfinc() {
398 return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet());
399 }
400
401 /**
402 * Retrieve the set of values that occur in matches for inc.
403 * @return the Set of all values or empty set if there are no matches
404 *
405 */
406 public Stream<Income> streamAllValuesOfinc() {
407 return rawStreamAllValuesOfinc(emptyArray());
408 }
409
410 @Override
411 protected X_inv05_inRange.Match tupleToMatch(final Tuple t) {
412 try {
413 return X_inv05_inRange.Match.newMatch((Income) t.get(POSITION_INC));
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 X_inv05_inRange.Match arrayToMatch(final Object[] match) {
422 try {
423 return X_inv05_inRange.Match.newMatch((Income) match[POSITION_INC]);
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 X_inv05_inRange.Match arrayToMatchMutable(final Object[] match) {
432 try {
433 return X_inv05_inRange.Match.newMutableMatch((Income) match[POSITION_INC]);
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<X_inv05_inRange.Matcher> querySpecification() {
446 return X_inv05_inRange.instance();
447 }
448 }
449
450 private X_inv05_inRange() {
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 X_inv05_inRange instance() {
460 try{
461 return LazyHolder.INSTANCE;
462 } catch (ExceptionInInitializerError err) {
463 throw processInitializerError(err);
464 }
465 }
466
467 @Override
468 protected X_inv05_inRange.Matcher instantiate(final ViatraQueryEngine engine) {
469 return X_inv05_inRange.Matcher.on(engine);
470 }
471
472 @Override
473 public X_inv05_inRange.Matcher instantiate() {
474 return X_inv05_inRange.Matcher.create();
475 }
476
477 @Override
478 public X_inv05_inRange.Match newEmptyMatch() {
479 return X_inv05_inRange.Match.newEmptyMatch();
480 }
481
482 @Override
483 public X_inv05_inRange.Match newMatch(final Object... parameters) {
484 return X_inv05_inRange.Match.newMatch((Taxation.Income) parameters[0]);
485 }
486
487 /**
488 * Inner class allowing the singleton instance of {@link X_inv05_inRange} 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 X_inv05_inRange#instance()}.
491 *
492 * <p> This workaround is required e.g. to support recursion.
493 *
494 */
495 private static class LazyHolder {
496 private static final X_inv05_inRange INSTANCE = new X_inv05_inRange();
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 X_inv05_inRange.GeneratedPQuery INSTANCE = new GeneratedPQuery();
515
516 private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT);
517
518 private final List<PParameter> parameters = Arrays.asList(parameter_inc);
519
520 private GeneratedPQuery() {
521 super(PVisibility.PUBLIC);
522 }
523
524 @Override
525 public String getFullyQualifiedName() {
526 return "queries.x_inv05_inRange";
527 }
528
529 @Override
530 public List<String> getParameterNames() {
531 return Arrays.asList("inc");
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_inc = body.getOrCreateVariableByName("inc");
546 PVariable var_wd = body.getOrCreateVariableByName("wd");
547 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
548 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
549 new ExportedParameter(body, var_inc, parameter_inc)
550 ));
551 // Income.details.worked_days(inc, wd)
552 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
553 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
554 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details")));
555 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail")));
556 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
557 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "worked_days")));
558 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
559 new Equality(body, var__virtual_1_, var_wd);
560 // check(wd < 1)
561 new ExpressionEvaluation(body, new IExpressionEvaluator() {
562
563 @Override
564 public String getShortDescription() {
565 return "Expression evaluation from pattern x_inv05_inRange";
566 }
567
568 @Override
569 public Iterable<String> getInputParameterNames() {
570 return Arrays.asList("wd");}
571
572 @Override
573 public Object evaluateExpression(IValueProvider provider) throws Exception {
574 Integer wd = (Integer) provider.getValue("wd");
575 return evaluateExpression_1_1(wd);
576 }
577 }, null);
578 bodies.add(body);
579 }
580 {
581 PBody body = new PBody(this);
582 PVariable var_inc = body.getOrCreateVariableByName("inc");
583 PVariable var_wd = body.getOrCreateVariableByName("wd");
584 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
585 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
586 new ExportedParameter(body, var_inc, parameter_inc)
587 ));
588 // Income.details.worked_days(inc, wd)
589 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
590 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
591 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details")));
592 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail")));
593 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
594 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "worked_days")));
595 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
596 new Equality(body, var__virtual_1_, var_wd);
597 // check(wd > 25)
598 new ExpressionEvaluation(body, new IExpressionEvaluator() {
599
600 @Override
601 public String getShortDescription() {
602 return "Expression evaluation from pattern x_inv05_inRange";
603 }
604
605 @Override
606 public Iterable<String> getInputParameterNames() {
607 return Arrays.asList("wd");}
608
609 @Override
610 public Object evaluateExpression(IValueProvider provider) throws Exception {
611 Integer wd = (Integer) provider.getValue("wd");
612 return evaluateExpression_2_1(wd);
613 }
614 }, null);
615 bodies.add(body);
616 }
617 return bodies;
618 }
619 }
620
621 private static boolean evaluateExpression_1_1(final Integer wd) {
622 return ((wd).intValue() < 1);
623 }
624
625 private static boolean evaluateExpression_2_1(final Integer wd) {
626 return ((wd).intValue() > 25);
627 }
628}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_inRange.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_inRange.java
new file mode 100644
index 00000000..7974c256
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_inRange.java
@@ -0,0 +1,630 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Income;
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.basicdeferred.Equality;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
42import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
43import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
44import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
45
46/**
47 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
48 *
49 * <p>Original source:
50 * <code><pre>
51 * pattern x_inv08_inRange(inc : Income) {
52 * Income.details.distance(inc, dist);
53 * check(dist {@literal <} 0);
54 * } or {
55 * Income.details.distance(inc, dist);
56 * check(dist {@literal >} 100);
57 * }
58 * </pre></code>
59 *
60 * @see Matcher
61 * @see Match
62 *
63 */
64@SuppressWarnings("all")
65public final class X_inv08_inRange extends BaseGeneratedEMFQuerySpecification<X_inv08_inRange.Matcher> {
66 /**
67 * Pattern-specific match representation of the queries.x_inv08_inRange 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 Income fInc;
80
81 private static List<String> parameterNames = makeImmutableList("inc");
82
83 private Match(final Income pInc) {
84 this.fInc = pInc;
85 }
86
87 @Override
88 public Object get(final String parameterName) {
89 switch(parameterName) {
90 case "inc": return this.fInc;
91 default: return null;
92 }
93 }
94
95 @Override
96 public Object get(final int index) {
97 switch(index) {
98 case 0: return this.fInc;
99 default: return null;
100 }
101 }
102
103 public Income getInc() {
104 return this.fInc;
105 }
106
107 @Override
108 public boolean set(final String parameterName, final Object newValue) {
109 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
110 if ("inc".equals(parameterName) ) {
111 this.fInc = (Income) newValue;
112 return true;
113 }
114 return false;
115 }
116
117 public void setInc(final Income pInc) {
118 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
119 this.fInc = pInc;
120 }
121
122 @Override
123 public String patternName() {
124 return "queries.x_inv08_inRange";
125 }
126
127 @Override
128 public List<String> parameterNames() {
129 return X_inv08_inRange.Match.parameterNames;
130 }
131
132 @Override
133 public Object[] toArray() {
134 return new Object[]{fInc};
135 }
136
137 @Override
138 public X_inv08_inRange.Match toImmutable() {
139 return isMutable() ? newMatch(fInc) : this;
140 }
141
142 @Override
143 public String prettyPrint() {
144 StringBuilder result = new StringBuilder();
145 result.append("\"inc\"=" + prettyPrintValue(fInc));
146 return result.toString();
147 }
148
149 @Override
150 public int hashCode() {
151 return Objects.hash(fInc);
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 X_inv08_inRange.Match)) {
162 X_inv08_inRange.Match other = (X_inv08_inRange.Match) obj;
163 return Objects.equals(fInc, other.fInc);
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 X_inv08_inRange specification() {
176 return X_inv08_inRange.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 X_inv08_inRange.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 pInc the fixed value of pattern parameter inc, or null if not bound.
195 * @return the new, mutable (partial) match object.
196 *
197 */
198 public static X_inv08_inRange.Match newMutableMatch(final Income pInc) {
199 return new Mutable(pInc);
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 pInc the fixed value of pattern parameter inc, or null if not bound.
207 * @return the (partial) match object.
208 *
209 */
210 public static X_inv08_inRange.Match newMatch(final Income pInc) {
211 return new Immutable(pInc);
212 }
213
214 private static final class Mutable extends X_inv08_inRange.Match {
215 Mutable(final Income pInc) {
216 super(pInc);
217 }
218
219 @Override
220 public boolean isMutable() {
221 return true;
222 }
223 }
224
225 private static final class Immutable extends X_inv08_inRange.Match {
226 Immutable(final Income pInc) {
227 super(pInc);
228 }
229
230 @Override
231 public boolean isMutable() {
232 return false;
233 }
234 }
235 }
236
237 /**
238 * Generated pattern matcher API of the queries.x_inv08_inRange 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 * pattern x_inv08_inRange(inc : Income) {
249 * Income.details.distance(inc, dist);
250 * check(dist {@literal <} 0);
251 * } or {
252 * Income.details.distance(inc, dist);
253 * check(dist {@literal >} 100);
254 * }
255 * </pre></code>
256 *
257 * @see Match
258 * @see X_inv08_inRange
259 *
260 */
261 public static class Matcher extends BaseMatcher<X_inv08_inRange.Match> {
262 /**
263 * Initializes the pattern matcher within an existing VIATRA Query engine.
264 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
265 *
266 * @param engine the existing VIATRA Query engine in which this matcher will be created.
267 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
268 *
269 */
270 public static X_inv08_inRange.Matcher on(final ViatraQueryEngine engine) {
271 // check if matcher already exists
272 Matcher matcher = engine.getExistingMatcher(querySpecification());
273 if (matcher == null) {
274 matcher = (Matcher)engine.getMatcher(querySpecification());
275 }
276 return matcher;
277 }
278
279 /**
280 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
281 * @return an initialized matcher
282 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
283 *
284 */
285 public static X_inv08_inRange.Matcher create() {
286 return new Matcher();
287 }
288
289 private static final int POSITION_INC = 0;
290
291 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv08_inRange.Matcher.class);
292
293 /**
294 * Initializes the pattern matcher within an existing VIATRA Query engine.
295 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
296 *
297 * @param engine the existing VIATRA Query engine in which this matcher will be created.
298 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
299 *
300 */
301 private Matcher() {
302 super(querySpecification());
303 }
304
305 /**
306 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
307 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
308 * @return matches represented as a Match object.
309 *
310 */
311 public Collection<X_inv08_inRange.Match> getAllMatches(final Income pInc) {
312 return rawStreamAllMatches(new Object[]{pInc}).collect(Collectors.toSet());
313 }
314
315 /**
316 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
317 * </p>
318 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
319 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
320 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
321 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
322 * @return a stream of matches represented as a Match object.
323 *
324 */
325 public Stream<X_inv08_inRange.Match> streamAllMatches(final Income pInc) {
326 return rawStreamAllMatches(new Object[]{pInc});
327 }
328
329 /**
330 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
331 * Neither determinism nor randomness of selection is guaranteed.
332 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
333 * @return a match represented as a Match object, or null if no match is found.
334 *
335 */
336 public Optional<X_inv08_inRange.Match> getOneArbitraryMatch(final Income pInc) {
337 return rawGetOneArbitraryMatch(new Object[]{pInc});
338 }
339
340 /**
341 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
342 * under any possible substitution of the unspecified parameters (if any).
343 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
344 * @return true if the input is a valid (partial) match of the pattern.
345 *
346 */
347 public boolean hasMatch(final Income pInc) {
348 return rawHasMatch(new Object[]{pInc});
349 }
350
351 /**
352 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
353 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
354 * @return the number of pattern matches found.
355 *
356 */
357 public int countMatches(final Income pInc) {
358 return rawCountMatches(new Object[]{pInc});
359 }
360
361 /**
362 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
363 * Neither determinism nor randomness of selection is guaranteed.
364 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
365 * @param processor the action that will process the selected match.
366 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
367 *
368 */
369 public boolean forOneArbitraryMatch(final Income pInc, final Consumer<? super X_inv08_inRange.Match> processor) {
370 return rawForOneArbitraryMatch(new Object[]{pInc}, processor);
371 }
372
373 /**
374 * Returns a new (partial) match.
375 * This can be used e.g. to call the matcher with a partial match.
376 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
377 * @param pInc the fixed value of pattern parameter inc, or null if not bound.
378 * @return the (partial) match object.
379 *
380 */
381 public X_inv08_inRange.Match newMatch(final Income pInc) {
382 return X_inv08_inRange.Match.newMatch(pInc);
383 }
384
385 /**
386 * Retrieve the set of values that occur in matches for inc.
387 * @return the Set of all values or empty set if there are no matches
388 *
389 */
390 protected Stream<Income> rawStreamAllValuesOfinc(final Object[] parameters) {
391 return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast);
392 }
393
394 /**
395 * Retrieve the set of values that occur in matches for inc.
396 * @return the Set of all values or empty set if there are no matches
397 *
398 */
399 public Set<Income> getAllValuesOfinc() {
400 return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet());
401 }
402
403 /**
404 * Retrieve the set of values that occur in matches for inc.
405 * @return the Set of all values or empty set if there are no matches
406 *
407 */
408 public Stream<Income> streamAllValuesOfinc() {
409 return rawStreamAllValuesOfinc(emptyArray());
410 }
411
412 @Override
413 protected X_inv08_inRange.Match tupleToMatch(final Tuple t) {
414 try {
415 return X_inv08_inRange.Match.newMatch((Income) t.get(POSITION_INC));
416 } catch(ClassCastException e) {
417 LOGGER.error("Element(s) in tuple not properly typed!",e);
418 return null;
419 }
420 }
421
422 @Override
423 protected X_inv08_inRange.Match arrayToMatch(final Object[] match) {
424 try {
425 return X_inv08_inRange.Match.newMatch((Income) match[POSITION_INC]);
426 } catch(ClassCastException e) {
427 LOGGER.error("Element(s) in array not properly typed!",e);
428 return null;
429 }
430 }
431
432 @Override
433 protected X_inv08_inRange.Match arrayToMatchMutable(final Object[] match) {
434 try {
435 return X_inv08_inRange.Match.newMutableMatch((Income) match[POSITION_INC]);
436 } catch(ClassCastException e) {
437 LOGGER.error("Element(s) in array not properly typed!",e);
438 return null;
439 }
440 }
441
442 /**
443 * @return the singleton instance of the query specification of this pattern
444 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
445 *
446 */
447 public static IQuerySpecification<X_inv08_inRange.Matcher> querySpecification() {
448 return X_inv08_inRange.instance();
449 }
450 }
451
452 private X_inv08_inRange() {
453 super(GeneratedPQuery.INSTANCE);
454 }
455
456 /**
457 * @return the singleton instance of the query specification
458 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
459 *
460 */
461 public static X_inv08_inRange instance() {
462 try{
463 return LazyHolder.INSTANCE;
464 } catch (ExceptionInInitializerError err) {
465 throw processInitializerError(err);
466 }
467 }
468
469 @Override
470 protected X_inv08_inRange.Matcher instantiate(final ViatraQueryEngine engine) {
471 return X_inv08_inRange.Matcher.on(engine);
472 }
473
474 @Override
475 public X_inv08_inRange.Matcher instantiate() {
476 return X_inv08_inRange.Matcher.create();
477 }
478
479 @Override
480 public X_inv08_inRange.Match newEmptyMatch() {
481 return X_inv08_inRange.Match.newEmptyMatch();
482 }
483
484 @Override
485 public X_inv08_inRange.Match newMatch(final Object... parameters) {
486 return X_inv08_inRange.Match.newMatch((Taxation.Income) parameters[0]);
487 }
488
489 /**
490 * Inner class allowing the singleton instance of {@link X_inv08_inRange} to be created
491 * <b>not</b> at the class load time of the outer class,
492 * but rather at the first call to {@link X_inv08_inRange#instance()}.
493 *
494 * <p> This workaround is required e.g. to support recursion.
495 *
496 */
497 private static class LazyHolder {
498 private static final X_inv08_inRange INSTANCE = new X_inv08_inRange();
499
500 /**
501 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
502 * This initialization order is required to support indirect recursion.
503 *
504 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
505 *
506 */
507 private static final Object STATIC_INITIALIZER = ensureInitialized();
508
509 public static Object ensureInitialized() {
510 INSTANCE.ensureInitializedInternal();
511 return null;
512 }
513 }
514
515 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
516 private static final X_inv08_inRange.GeneratedPQuery INSTANCE = new GeneratedPQuery();
517
518 private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT);
519
520 private final List<PParameter> parameters = Arrays.asList(parameter_inc);
521
522 private GeneratedPQuery() {
523 super(PVisibility.PUBLIC);
524 }
525
526 @Override
527 public String getFullyQualifiedName() {
528 return "queries.x_inv08_inRange";
529 }
530
531 @Override
532 public List<String> getParameterNames() {
533 return Arrays.asList("inc");
534 }
535
536 @Override
537 public List<PParameter> getParameters() {
538 return parameters;
539 }
540
541 @Override
542 public Set<PBody> doGetContainedBodies() {
543 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
544 Set<PBody> bodies = new LinkedHashSet<>();
545 {
546 PBody body = new PBody(this);
547 PVariable var_inc = body.getOrCreateVariableByName("inc");
548 PVariable var_dist = body.getOrCreateVariableByName("dist");
549 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
550 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
551 new ExportedParameter(body, var_inc, parameter_inc)
552 ));
553 // Income.details.distance(inc, dist)
554 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
555 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
556 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details")));
557 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail")));
558 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
559 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "distance")));
560 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
561 new Equality(body, var__virtual_1_, var_dist);
562 // check(dist < 0)
563 new ExpressionEvaluation(body, new IExpressionEvaluator() {
564
565 @Override
566 public String getShortDescription() {
567 return "Expression evaluation from pattern x_inv08_inRange";
568 }
569
570 @Override
571 public Iterable<String> getInputParameterNames() {
572 return Arrays.asList("dist");}
573
574 @Override
575 public Object evaluateExpression(IValueProvider provider) throws Exception {
576 Double dist = (Double) provider.getValue("dist");
577 return evaluateExpression_1_1(dist);
578 }
579 }, null);
580 bodies.add(body);
581 }
582 {
583 PBody body = new PBody(this);
584 PVariable var_inc = body.getOrCreateVariableByName("inc");
585 PVariable var_dist = body.getOrCreateVariableByName("dist");
586 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
587 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
588 new ExportedParameter(body, var_inc, parameter_inc)
589 ));
590 // Income.details.distance(inc, dist)
591 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
592 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
593 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details")));
594 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail")));
595 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
596 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "distance")));
597 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
598 new Equality(body, var__virtual_1_, var_dist);
599 // check(dist > 100)
600 new ExpressionEvaluation(body, new IExpressionEvaluator() {
601
602 @Override
603 public String getShortDescription() {
604 return "Expression evaluation from pattern x_inv08_inRange";
605 }
606
607 @Override
608 public Iterable<String> getInputParameterNames() {
609 return Arrays.asList("dist");}
610
611 @Override
612 public Object evaluateExpression(IValueProvider provider) throws Exception {
613 Double dist = (Double) provider.getValue("dist");
614 return evaluateExpression_2_1(dist);
615 }
616 }, null);
617 bodies.add(body);
618 }
619 return bodies;
620 }
621 }
622
623 private static boolean evaluateExpression_1_1(final Double dist) {
624 return ((dist).doubleValue() < 0);
625 }
626
627 private static boolean evaluateExpression_2_1(final Double dist) {
628 return ((dist).doubleValue() > 100);
629 }
630}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_noType.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_noType.java
new file mode 100644
index 00000000..2bffe499
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_noType.java
@@ -0,0 +1,551 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Income;
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 x_inv08_noType(inc : Income) {
47 * Income.income_type(inc, _);
48 * }
49 * </pre></code>
50 *
51 * @see Matcher
52 * @see Match
53 *
54 */
55@SuppressWarnings("all")
56public final class X_inv08_noType extends BaseGeneratedEMFQuerySpecification<X_inv08_noType.Matcher> {
57 /**
58 * Pattern-specific match representation of the queries.x_inv08_noType 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 Income fInc;
71
72 private static List<String> parameterNames = makeImmutableList("inc");
73
74 private Match(final Income pInc) {
75 this.fInc = pInc;
76 }
77
78 @Override
79 public Object get(final String parameterName) {
80 switch(parameterName) {
81 case "inc": return this.fInc;
82 default: return null;
83 }
84 }
85
86 @Override
87 public Object get(final int index) {
88 switch(index) {
89 case 0: return this.fInc;
90 default: return null;
91 }
92 }
93
94 public Income getInc() {
95 return this.fInc;
96 }
97
98 @Override
99 public boolean set(final String parameterName, final Object newValue) {
100 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
101 if ("inc".equals(parameterName) ) {
102 this.fInc = (Income) newValue;
103 return true;
104 }
105 return false;
106 }
107
108 public void setInc(final Income pInc) {
109 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
110 this.fInc = pInc;
111 }
112
113 @Override
114 public String patternName() {
115 return "queries.x_inv08_noType";
116 }
117
118 @Override
119 public List<String> parameterNames() {
120 return X_inv08_noType.Match.parameterNames;
121 }
122
123 @Override
124 public Object[] toArray() {
125 return new Object[]{fInc};
126 }
127
128 @Override
129 public X_inv08_noType.Match toImmutable() {
130 return isMutable() ? newMatch(fInc) : this;
131 }
132
133 @Override
134 public String prettyPrint() {
135 StringBuilder result = new StringBuilder();
136 result.append("\"inc\"=" + prettyPrintValue(fInc));
137 return result.toString();
138 }
139
140 @Override
141 public int hashCode() {
142 return Objects.hash(fInc);
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 X_inv08_noType.Match)) {
153 X_inv08_noType.Match other = (X_inv08_noType.Match) obj;
154 return Objects.equals(fInc, other.fInc);
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 X_inv08_noType specification() {
167 return X_inv08_noType.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 X_inv08_noType.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 pInc the fixed value of pattern parameter inc, or null if not bound.
186 * @return the new, mutable (partial) match object.
187 *
188 */
189 public static X_inv08_noType.Match newMutableMatch(final Income pInc) {
190 return new Mutable(pInc);
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 pInc the fixed value of pattern parameter inc, or null if not bound.
198 * @return the (partial) match object.
199 *
200 */
201 public static X_inv08_noType.Match newMatch(final Income pInc) {
202 return new Immutable(pInc);
203 }
204
205 private static final class Mutable extends X_inv08_noType.Match {
206 Mutable(final Income pInc) {
207 super(pInc);
208 }
209
210 @Override
211 public boolean isMutable() {
212 return true;
213 }
214 }
215
216 private static final class Immutable extends X_inv08_noType.Match {
217 Immutable(final Income pInc) {
218 super(pInc);
219 }
220
221 @Override
222 public boolean isMutable() {
223 return false;
224 }
225 }
226 }
227
228 /**
229 * Generated pattern matcher API of the queries.x_inv08_noType 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 x_inv08_noType(inc : Income) {
240 * Income.income_type(inc, _);
241 * }
242 * </pre></code>
243 *
244 * @see Match
245 * @see X_inv08_noType
246 *
247 */
248 public static class Matcher extends BaseMatcher<X_inv08_noType.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 X_inv08_noType.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 X_inv08_noType.Matcher create() {
273 return new Matcher();
274 }
275
276 private static final int POSITION_INC = 0;
277
278 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv08_noType.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 pInc the fixed value of pattern parameter inc, or null if not bound.
295 * @return matches represented as a Match object.
296 *
297 */
298 public Collection<X_inv08_noType.Match> getAllMatches(final Income pInc) {
299 return rawStreamAllMatches(new Object[]{pInc}).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 pInc the fixed value of pattern parameter inc, or null if not bound.
309 * @return a stream of matches represented as a Match object.
310 *
311 */
312 public Stream<X_inv08_noType.Match> streamAllMatches(final Income pInc) {
313 return rawStreamAllMatches(new Object[]{pInc});
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 pInc the fixed value of pattern parameter inc, 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<X_inv08_noType.Match> getOneArbitraryMatch(final Income pInc) {
324 return rawGetOneArbitraryMatch(new Object[]{pInc});
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 pInc the fixed value of pattern parameter inc, 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 Income pInc) {
335 return rawHasMatch(new Object[]{pInc});
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 pInc the fixed value of pattern parameter inc, or null if not bound.
341 * @return the number of pattern matches found.
342 *
343 */
344 public int countMatches(final Income pInc) {
345 return rawCountMatches(new Object[]{pInc});
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 pInc the fixed value of pattern parameter inc, 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 Income pInc, final Consumer<? super X_inv08_noType.Match> processor) {
357 return rawForOneArbitraryMatch(new Object[]{pInc}, 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 pInc the fixed value of pattern parameter inc, or null if not bound.
365 * @return the (partial) match object.
366 *
367 */
368 public X_inv08_noType.Match newMatch(final Income pInc) {
369 return X_inv08_noType.Match.newMatch(pInc);
370 }
371
372 /**
373 * Retrieve the set of values that occur in matches for inc.
374 * @return the Set of all values or empty set if there are no matches
375 *
376 */
377 protected Stream<Income> rawStreamAllValuesOfinc(final Object[] parameters) {
378 return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast);
379 }
380
381 /**
382 * Retrieve the set of values that occur in matches for inc.
383 * @return the Set of all values or empty set if there are no matches
384 *
385 */
386 public Set<Income> getAllValuesOfinc() {
387 return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet());
388 }
389
390 /**
391 * Retrieve the set of values that occur in matches for inc.
392 * @return the Set of all values or empty set if there are no matches
393 *
394 */
395 public Stream<Income> streamAllValuesOfinc() {
396 return rawStreamAllValuesOfinc(emptyArray());
397 }
398
399 @Override
400 protected X_inv08_noType.Match tupleToMatch(final Tuple t) {
401 try {
402 return X_inv08_noType.Match.newMatch((Income) t.get(POSITION_INC));
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 X_inv08_noType.Match arrayToMatch(final Object[] match) {
411 try {
412 return X_inv08_noType.Match.newMatch((Income) match[POSITION_INC]);
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 X_inv08_noType.Match arrayToMatchMutable(final Object[] match) {
421 try {
422 return X_inv08_noType.Match.newMutableMatch((Income) match[POSITION_INC]);
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<X_inv08_noType.Matcher> querySpecification() {
435 return X_inv08_noType.instance();
436 }
437 }
438
439 private X_inv08_noType() {
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 X_inv08_noType instance() {
449 try{
450 return LazyHolder.INSTANCE;
451 } catch (ExceptionInInitializerError err) {
452 throw processInitializerError(err);
453 }
454 }
455
456 @Override
457 protected X_inv08_noType.Matcher instantiate(final ViatraQueryEngine engine) {
458 return X_inv08_noType.Matcher.on(engine);
459 }
460
461 @Override
462 public X_inv08_noType.Matcher instantiate() {
463 return X_inv08_noType.Matcher.create();
464 }
465
466 @Override
467 public X_inv08_noType.Match newEmptyMatch() {
468 return X_inv08_noType.Match.newEmptyMatch();
469 }
470
471 @Override
472 public X_inv08_noType.Match newMatch(final Object... parameters) {
473 return X_inv08_noType.Match.newMatch((Taxation.Income) parameters[0]);
474 }
475
476 /**
477 * Inner class allowing the singleton instance of {@link X_inv08_noType} 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 X_inv08_noType#instance()}.
480 *
481 * <p> This workaround is required e.g. to support recursion.
482 *
483 */
484 private static class LazyHolder {
485 private static final X_inv08_noType INSTANCE = new X_inv08_noType();
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 X_inv08_noType.GeneratedPQuery INSTANCE = new GeneratedPQuery();
504
505 private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT);
506
507 private final List<PParameter> parameters = Arrays.asList(parameter_inc);
508
509 private GeneratedPQuery() {
510 super(PVisibility.PUBLIC);
511 }
512
513 @Override
514 public String getFullyQualifiedName() {
515 return "queries.x_inv08_noType";
516 }
517
518 @Override
519 public List<String> getParameterNames() {
520 return Arrays.asList("inc");
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_inc = body.getOrCreateVariableByName("inc");
535 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
536 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
537 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
538 new ExportedParameter(body, var_inc, parameter_inc)
539 ));
540 // Income.income_type(inc, _)
541 new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
542 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
543 new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_type")));
544 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Type")));
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.queries/src-gen/queries/X_inv08_notEI.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_notEI.java
new file mode 100644
index 00000000..4b4029a8
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_notEI.java
@@ -0,0 +1,544 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Employment_Income;
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.basicdeferred.ExportedParameter;
31import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
32import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
33import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
34import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
35import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
36import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
37import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
38
39/**
40 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
41 *
42 * <p>Original source:
43 * <code><pre>
44 * pattern x_inv08_notEI(type : Employment_Income) {
45 * Employment_Income(type);
46 * }
47 * </pre></code>
48 *
49 * @see Matcher
50 * @see Match
51 *
52 */
53@SuppressWarnings("all")
54public final class X_inv08_notEI extends BaseGeneratedEMFQuerySpecification<X_inv08_notEI.Matcher> {
55 /**
56 * Pattern-specific match representation of the queries.x_inv08_notEI pattern,
57 * to be used in conjunction with {@link Matcher}.
58 *
59 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
60 * Each instance is a (possibly partial) substitution of pattern parameters,
61 * usable to represent a match of the pattern in the result of a query,
62 * or to specify the bound (fixed) input parameters when issuing a query.
63 *
64 * @see Matcher
65 *
66 */
67 public static abstract class Match extends BasePatternMatch {
68 private Employment_Income fType;
69
70 private static List<String> parameterNames = makeImmutableList("type");
71
72 private Match(final Employment_Income pType) {
73 this.fType = pType;
74 }
75
76 @Override
77 public Object get(final String parameterName) {
78 switch(parameterName) {
79 case "type": return this.fType;
80 default: return null;
81 }
82 }
83
84 @Override
85 public Object get(final int index) {
86 switch(index) {
87 case 0: return this.fType;
88 default: return null;
89 }
90 }
91
92 public Employment_Income getType() {
93 return this.fType;
94 }
95
96 @Override
97 public boolean set(final String parameterName, final Object newValue) {
98 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
99 if ("type".equals(parameterName) ) {
100 this.fType = (Employment_Income) newValue;
101 return true;
102 }
103 return false;
104 }
105
106 public void setType(final Employment_Income pType) {
107 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
108 this.fType = pType;
109 }
110
111 @Override
112 public String patternName() {
113 return "queries.x_inv08_notEI";
114 }
115
116 @Override
117 public List<String> parameterNames() {
118 return X_inv08_notEI.Match.parameterNames;
119 }
120
121 @Override
122 public Object[] toArray() {
123 return new Object[]{fType};
124 }
125
126 @Override
127 public X_inv08_notEI.Match toImmutable() {
128 return isMutable() ? newMatch(fType) : this;
129 }
130
131 @Override
132 public String prettyPrint() {
133 StringBuilder result = new StringBuilder();
134 result.append("\"type\"=" + prettyPrintValue(fType));
135 return result.toString();
136 }
137
138 @Override
139 public int hashCode() {
140 return Objects.hash(fType);
141 }
142
143 @Override
144 public boolean equals(final Object obj) {
145 if (this == obj)
146 return true;
147 if (obj == null) {
148 return false;
149 }
150 if ((obj instanceof X_inv08_notEI.Match)) {
151 X_inv08_notEI.Match other = (X_inv08_notEI.Match) obj;
152 return Objects.equals(fType, other.fType);
153 } else {
154 // this should be infrequent
155 if (!(obj instanceof IPatternMatch)) {
156 return false;
157 }
158 IPatternMatch otherSig = (IPatternMatch) obj;
159 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
160 }
161 }
162
163 @Override
164 public X_inv08_notEI specification() {
165 return X_inv08_notEI.instance();
166 }
167
168 /**
169 * Returns an empty, mutable match.
170 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
171 *
172 * @return the empty match.
173 *
174 */
175 public static X_inv08_notEI.Match newEmptyMatch() {
176 return new Mutable(null);
177 }
178
179 /**
180 * Returns a mutable (partial) match.
181 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
182 *
183 * @param pType the fixed value of pattern parameter type, or null if not bound.
184 * @return the new, mutable (partial) match object.
185 *
186 */
187 public static X_inv08_notEI.Match newMutableMatch(final Employment_Income pType) {
188 return new Mutable(pType);
189 }
190
191 /**
192 * Returns a new (partial) match.
193 * This can be used e.g. to call the matcher with a partial match.
194 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
195 * @param pType the fixed value of pattern parameter type, or null if not bound.
196 * @return the (partial) match object.
197 *
198 */
199 public static X_inv08_notEI.Match newMatch(final Employment_Income pType) {
200 return new Immutable(pType);
201 }
202
203 private static final class Mutable extends X_inv08_notEI.Match {
204 Mutable(final Employment_Income pType) {
205 super(pType);
206 }
207
208 @Override
209 public boolean isMutable() {
210 return true;
211 }
212 }
213
214 private static final class Immutable extends X_inv08_notEI.Match {
215 Immutable(final Employment_Income pType) {
216 super(pType);
217 }
218
219 @Override
220 public boolean isMutable() {
221 return false;
222 }
223 }
224 }
225
226 /**
227 * Generated pattern matcher API of the queries.x_inv08_notEI pattern,
228 * providing pattern-specific query methods.
229 *
230 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
231 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
232 *
233 * <p>Matches of the pattern will be represented as {@link Match}.
234 *
235 * <p>Original source:
236 * <code><pre>
237 * pattern x_inv08_notEI(type : Employment_Income) {
238 * Employment_Income(type);
239 * }
240 * </pre></code>
241 *
242 * @see Match
243 * @see X_inv08_notEI
244 *
245 */
246 public static class Matcher extends BaseMatcher<X_inv08_notEI.Match> {
247 /**
248 * Initializes the pattern matcher within an existing VIATRA Query engine.
249 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
250 *
251 * @param engine the existing VIATRA Query engine in which this matcher will be created.
252 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
253 *
254 */
255 public static X_inv08_notEI.Matcher on(final ViatraQueryEngine engine) {
256 // check if matcher already exists
257 Matcher matcher = engine.getExistingMatcher(querySpecification());
258 if (matcher == null) {
259 matcher = (Matcher)engine.getMatcher(querySpecification());
260 }
261 return matcher;
262 }
263
264 /**
265 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
266 * @return an initialized matcher
267 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
268 *
269 */
270 public static X_inv08_notEI.Matcher create() {
271 return new Matcher();
272 }
273
274 private static final int POSITION_TYPE = 0;
275
276 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv08_notEI.Matcher.class);
277
278 /**
279 * Initializes the pattern matcher within an existing VIATRA Query engine.
280 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
281 *
282 * @param engine the existing VIATRA Query engine in which this matcher will be created.
283 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
284 *
285 */
286 private Matcher() {
287 super(querySpecification());
288 }
289
290 /**
291 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
292 * @param pType the fixed value of pattern parameter type, or null if not bound.
293 * @return matches represented as a Match object.
294 *
295 */
296 public Collection<X_inv08_notEI.Match> getAllMatches(final Employment_Income pType) {
297 return rawStreamAllMatches(new Object[]{pType}).collect(Collectors.toSet());
298 }
299
300 /**
301 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
302 * </p>
303 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
304 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
305 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
306 * @param pType the fixed value of pattern parameter type, or null if not bound.
307 * @return a stream of matches represented as a Match object.
308 *
309 */
310 public Stream<X_inv08_notEI.Match> streamAllMatches(final Employment_Income pType) {
311 return rawStreamAllMatches(new Object[]{pType});
312 }
313
314 /**
315 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
316 * Neither determinism nor randomness of selection is guaranteed.
317 * @param pType the fixed value of pattern parameter type, or null if not bound.
318 * @return a match represented as a Match object, or null if no match is found.
319 *
320 */
321 public Optional<X_inv08_notEI.Match> getOneArbitraryMatch(final Employment_Income pType) {
322 return rawGetOneArbitraryMatch(new Object[]{pType});
323 }
324
325 /**
326 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
327 * under any possible substitution of the unspecified parameters (if any).
328 * @param pType the fixed value of pattern parameter type, or null if not bound.
329 * @return true if the input is a valid (partial) match of the pattern.
330 *
331 */
332 public boolean hasMatch(final Employment_Income pType) {
333 return rawHasMatch(new Object[]{pType});
334 }
335
336 /**
337 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
338 * @param pType the fixed value of pattern parameter type, or null if not bound.
339 * @return the number of pattern matches found.
340 *
341 */
342 public int countMatches(final Employment_Income pType) {
343 return rawCountMatches(new Object[]{pType});
344 }
345
346 /**
347 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
348 * Neither determinism nor randomness of selection is guaranteed.
349 * @param pType the fixed value of pattern parameter type, or null if not bound.
350 * @param processor the action that will process the selected match.
351 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
352 *
353 */
354 public boolean forOneArbitraryMatch(final Employment_Income pType, final Consumer<? super X_inv08_notEI.Match> processor) {
355 return rawForOneArbitraryMatch(new Object[]{pType}, processor);
356 }
357
358 /**
359 * Returns a new (partial) match.
360 * This can be used e.g. to call the matcher with a partial match.
361 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
362 * @param pType the fixed value of pattern parameter type, or null if not bound.
363 * @return the (partial) match object.
364 *
365 */
366 public X_inv08_notEI.Match newMatch(final Employment_Income pType) {
367 return X_inv08_notEI.Match.newMatch(pType);
368 }
369
370 /**
371 * Retrieve the set of values that occur in matches for type.
372 * @return the Set of all values or empty set if there are no matches
373 *
374 */
375 protected Stream<Employment_Income> rawStreamAllValuesOftype(final Object[] parameters) {
376 return rawStreamAllValues(POSITION_TYPE, parameters).map(Employment_Income.class::cast);
377 }
378
379 /**
380 * Retrieve the set of values that occur in matches for type.
381 * @return the Set of all values or empty set if there are no matches
382 *
383 */
384 public Set<Employment_Income> getAllValuesOftype() {
385 return rawStreamAllValuesOftype(emptyArray()).collect(Collectors.toSet());
386 }
387
388 /**
389 * Retrieve the set of values that occur in matches for type.
390 * @return the Set of all values or empty set if there are no matches
391 *
392 */
393 public Stream<Employment_Income> streamAllValuesOftype() {
394 return rawStreamAllValuesOftype(emptyArray());
395 }
396
397 @Override
398 protected X_inv08_notEI.Match tupleToMatch(final Tuple t) {
399 try {
400 return X_inv08_notEI.Match.newMatch((Employment_Income) t.get(POSITION_TYPE));
401 } catch(ClassCastException e) {
402 LOGGER.error("Element(s) in tuple not properly typed!",e);
403 return null;
404 }
405 }
406
407 @Override
408 protected X_inv08_notEI.Match arrayToMatch(final Object[] match) {
409 try {
410 return X_inv08_notEI.Match.newMatch((Employment_Income) match[POSITION_TYPE]);
411 } catch(ClassCastException e) {
412 LOGGER.error("Element(s) in array not properly typed!",e);
413 return null;
414 }
415 }
416
417 @Override
418 protected X_inv08_notEI.Match arrayToMatchMutable(final Object[] match) {
419 try {
420 return X_inv08_notEI.Match.newMutableMatch((Employment_Income) match[POSITION_TYPE]);
421 } catch(ClassCastException e) {
422 LOGGER.error("Element(s) in array not properly typed!",e);
423 return null;
424 }
425 }
426
427 /**
428 * @return the singleton instance of the query specification of this pattern
429 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
430 *
431 */
432 public static IQuerySpecification<X_inv08_notEI.Matcher> querySpecification() {
433 return X_inv08_notEI.instance();
434 }
435 }
436
437 private X_inv08_notEI() {
438 super(GeneratedPQuery.INSTANCE);
439 }
440
441 /**
442 * @return the singleton instance of the query specification
443 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
444 *
445 */
446 public static X_inv08_notEI instance() {
447 try{
448 return LazyHolder.INSTANCE;
449 } catch (ExceptionInInitializerError err) {
450 throw processInitializerError(err);
451 }
452 }
453
454 @Override
455 protected X_inv08_notEI.Matcher instantiate(final ViatraQueryEngine engine) {
456 return X_inv08_notEI.Matcher.on(engine);
457 }
458
459 @Override
460 public X_inv08_notEI.Matcher instantiate() {
461 return X_inv08_notEI.Matcher.create();
462 }
463
464 @Override
465 public X_inv08_notEI.Match newEmptyMatch() {
466 return X_inv08_notEI.Match.newEmptyMatch();
467 }
468
469 @Override
470 public X_inv08_notEI.Match newMatch(final Object... parameters) {
471 return X_inv08_notEI.Match.newMatch((Taxation.Employment_Income) parameters[0]);
472 }
473
474 /**
475 * Inner class allowing the singleton instance of {@link X_inv08_notEI} to be created
476 * <b>not</b> at the class load time of the outer class,
477 * but rather at the first call to {@link X_inv08_notEI#instance()}.
478 *
479 * <p> This workaround is required e.g. to support recursion.
480 *
481 */
482 private static class LazyHolder {
483 private static final X_inv08_notEI INSTANCE = new X_inv08_notEI();
484
485 /**
486 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
487 * This initialization order is required to support indirect recursion.
488 *
489 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
490 *
491 */
492 private static final Object STATIC_INITIALIZER = ensureInitialized();
493
494 public static Object ensureInitialized() {
495 INSTANCE.ensureInitializedInternal();
496 return null;
497 }
498 }
499
500 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
501 private static final X_inv08_notEI.GeneratedPQuery INSTANCE = new GeneratedPQuery();
502
503 private final PParameter parameter_type = new PParameter("type", "Taxation.Employment_Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Employment_Income")), PParameterDirection.INOUT);
504
505 private final List<PParameter> parameters = Arrays.asList(parameter_type);
506
507 private GeneratedPQuery() {
508 super(PVisibility.PUBLIC);
509 }
510
511 @Override
512 public String getFullyQualifiedName() {
513 return "queries.x_inv08_notEI";
514 }
515
516 @Override
517 public List<String> getParameterNames() {
518 return Arrays.asList("type");
519 }
520
521 @Override
522 public List<PParameter> getParameters() {
523 return parameters;
524 }
525
526 @Override
527 public Set<PBody> doGetContainedBodies() {
528 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
529 Set<PBody> bodies = new LinkedHashSet<>();
530 {
531 PBody body = new PBody(this);
532 PVariable var_type = body.getOrCreateVariableByName("type");
533 new TypeConstraint(body, Tuples.flatTupleOf(var_type), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Employment_Income")));
534 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
535 new ExportedParameter(body, var_type, parameter_type)
536 ));
537 // Employment_Income(type)
538 new TypeConstraint(body, Tuples.flatTupleOf(var_type), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Employment_Income")));
539 bodies.add(body);
540 }
541 return bodies;
542 }
543 }
544}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incNotOver100.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incNotOver100.java
new file mode 100644
index 00000000..35b30b0f
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incNotOver100.java
@@ -0,0 +1,610 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Expense;
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.stream.Stream;
15import org.apache.log4j.Logger;
16import org.eclipse.emf.ecore.EClass;
17import org.eclipse.emf.ecore.EDataType;
18import org.eclipse.viatra.query.runtime.api.IPatternMatch;
19import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
20import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
21import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
22import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
23import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
24import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
25import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey;
26import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
27import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
28import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
29import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
30import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
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.Tuples;
40import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
41
42/**
43 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
44 *
45 * <p>Original source:
46 * <code><pre>
47 * pattern x_inv11_incNotOver100(exp : Expense) {
48 * Expense.income.income_amount(exp, incVal);
49 * check(incVal / 2 {@literal <}= 50);
50 * } or {
51 * Expense.declared_amount(exp, decl);
52 * check(decl {@literal <} 50);
53 * } or {
54 * Expense.income.income_amount(exp, incVal);
55 * Expense.declared_amount(exp, decl);
56 * check(decl {@literal >} incVal/2);
57 * }
58 * </pre></code>
59 *
60 * @see Matcher
61 * @see Match
62 *
63 */
64@SuppressWarnings("all")
65public final class X_inv11_incNotOver100 extends BaseGeneratedEMFQuerySpecification<X_inv11_incNotOver100.Matcher> {
66 /**
67 * Pattern-specific match representation of the queries.x_inv11_incNotOver100 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 Expense fExp;
80
81 private static List<String> parameterNames = makeImmutableList("exp");
82
83 private Match(final Expense pExp) {
84 this.fExp = pExp;
85 }
86
87 @Override
88 public Object get(final String parameterName) {
89 switch(parameterName) {
90 case "exp": return this.fExp;
91 default: return null;
92 }
93 }
94
95 @Override
96 public Object get(final int index) {
97 switch(index) {
98 case 0: return this.fExp;
99 default: return null;
100 }
101 }
102
103 public Expense getExp() {
104 return this.fExp;
105 }
106
107 @Override
108 public boolean set(final String parameterName, final Object newValue) {
109 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
110 if ("exp".equals(parameterName) ) {
111 this.fExp = (Expense) newValue;
112 return true;
113 }
114 return false;
115 }
116
117 public void setExp(final Expense pExp) {
118 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
119 this.fExp = pExp;
120 }
121
122 @Override
123 public String patternName() {
124 return "queries.x_inv11_incNotOver100";
125 }
126
127 @Override
128 public List<String> parameterNames() {
129 return X_inv11_incNotOver100.Match.parameterNames;
130 }
131
132 @Override
133 public Object[] toArray() {
134 return new Object[]{fExp};
135 }
136
137 @Override
138 public X_inv11_incNotOver100.Match toImmutable() {
139 return isMutable() ? newMatch(fExp) : this;
140 }
141
142 @Override
143 public String prettyPrint() {
144 StringBuilder result = new StringBuilder();
145 result.append("\"exp\"=" + prettyPrintValue(fExp));
146 return result.toString();
147 }
148
149 @Override
150 public int hashCode() {
151 return Objects.hash(fExp);
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 X_inv11_incNotOver100.Match)) {
162 X_inv11_incNotOver100.Match other = (X_inv11_incNotOver100.Match) obj;
163 return Objects.equals(fExp, other.fExp);
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 X_inv11_incNotOver100 specification() {
176 return X_inv11_incNotOver100.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 X_inv11_incNotOver100.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 pExp the fixed value of pattern parameter exp, or null if not bound.
195 * @return the new, mutable (partial) match object.
196 *
197 */
198 public static X_inv11_incNotOver100.Match newMutableMatch(final Expense pExp) {
199 return new Mutable(pExp);
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 pExp the fixed value of pattern parameter exp, or null if not bound.
207 * @return the (partial) match object.
208 *
209 */
210 public static X_inv11_incNotOver100.Match newMatch(final Expense pExp) {
211 return new Immutable(pExp);
212 }
213
214 private static final class Mutable extends X_inv11_incNotOver100.Match {
215 Mutable(final Expense pExp) {
216 super(pExp);
217 }
218
219 @Override
220 public boolean isMutable() {
221 return true;
222 }
223 }
224
225 private static final class Immutable extends X_inv11_incNotOver100.Match {
226 Immutable(final Expense pExp) {
227 super(pExp);
228 }
229
230 @Override
231 public boolean isMutable() {
232 return false;
233 }
234 }
235 }
236
237 /**
238 * Generated pattern matcher API of the queries.x_inv11_incNotOver100 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 * pattern x_inv11_incNotOver100(exp : Expense) {
249 * Expense.income.income_amount(exp, incVal);
250 * check(incVal / 2 {@literal <}= 50);
251 * } or {
252 * Expense.declared_amount(exp, decl);
253 * check(decl {@literal <} 50);
254 * } or {
255 * Expense.income.income_amount(exp, incVal);
256 * Expense.declared_amount(exp, decl);
257 * check(decl {@literal >} incVal/2);
258 * }
259 * </pre></code>
260 *
261 * @see Match
262 * @see X_inv11_incNotOver100
263 *
264 */
265 public static class Matcher extends BaseMatcher<X_inv11_incNotOver100.Match> {
266 /**
267 * Initializes the pattern matcher within an existing VIATRA Query engine.
268 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
269 *
270 * @param engine the existing VIATRA Query engine in which this matcher will be created.
271 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
272 *
273 */
274 public static X_inv11_incNotOver100.Matcher on(final ViatraQueryEngine engine) {
275 // check if matcher already exists
276 Matcher matcher = engine.getExistingMatcher(querySpecification());
277 if (matcher == null) {
278 matcher = (Matcher)engine.getMatcher(querySpecification());
279 }
280 return matcher;
281 }
282
283 /**
284 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
285 * @return an initialized matcher
286 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
287 *
288 */
289 public static X_inv11_incNotOver100.Matcher create() {
290 return new Matcher();
291 }
292
293 private static final int POSITION_EXP = 0;
294
295 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv11_incNotOver100.Matcher.class);
296
297 /**
298 * Initializes the pattern matcher within an existing VIATRA Query engine.
299 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
300 *
301 * @param engine the existing VIATRA Query engine in which this matcher will be created.
302 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
303 *
304 */
305 private Matcher() {
306 super(querySpecification());
307 }
308
309 /**
310 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
311 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
312 * @return matches represented as a Match object.
313 *
314 */
315 public Collection<X_inv11_incNotOver100.Match> getAllMatches();
316
317 /**
318 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
319 * </p>
320 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
321 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
322 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
323 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
324 * @return a stream of matches represented as a Match object.
325 *
326 */
327 public Stream<X_inv11_incNotOver100.Match> streamAllMatches(final Expense pExp) {
328 return rawStreamAllMatches(new Object[]{pExp});
329 }
330
331 /**
332 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
333 * Neither determinism nor randomness of selection is guaranteed.
334 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
335 * @return a match represented as a Match object, or null if no match is found.
336 *
337 */
338 public Optional<X_inv11_incNotOver100.Match> getOneArbitraryMatch(final Expense pExp) {
339 return rawGetOneArbitraryMatch(new Object[]{pExp});
340 }
341
342 /**
343 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
344 * under any possible substitution of the unspecified parameters (if any).
345 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
346 * @return true if the input is a valid (partial) match of the pattern.
347 *
348 */
349 public boolean hasMatch(final Expense pExp) {
350 return rawHasMatch(new Object[]{pExp});
351 }
352
353 /**
354 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
355 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
356 * @return the number of pattern matches found.
357 *
358 */
359 public int countMatches(final Expense pExp) {
360 return rawCountMatches(new Object[]{pExp});
361 }
362
363 /**
364 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
365 * Neither determinism nor randomness of selection is guaranteed.
366 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
367 * @param processor the action that will process the selected match.
368 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
369 *
370 */
371 public boolean forOneArbitraryMatch();
372
373 /**
374 * Returns a new (partial) match.
375 * This can be used e.g. to call the matcher with a partial match.
376 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
377 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
378 * @return the (partial) match object.
379 *
380 */
381 public X_inv11_incNotOver100.Match newMatch(final Expense pExp) {
382 return X_inv11_incNotOver100.Match.newMatch(pExp);
383 }
384 }
385
386 private X_inv11_incNotOver100() {
387 super(GeneratedPQuery.INSTANCE);
388 }
389
390 /**
391 * @return the singleton instance of the query specification
392 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
393 *
394 */
395 public static X_inv11_incNotOver100 instance() {
396 try{
397 return LazyHolder.INSTANCE;
398 } catch (ExceptionInInitializerError err) {
399 throw processInitializerError(err);
400 }
401 }
402
403 @Override
404 protected X_inv11_incNotOver100.Matcher instantiate(final ViatraQueryEngine engine) {
405 return X_inv11_incNotOver100.Matcher.on(engine);
406 }
407
408 @Override
409 public X_inv11_incNotOver100.Matcher instantiate() {
410 return X_inv11_incNotOver100.Matcher.create();
411 }
412
413 @Override
414 public X_inv11_incNotOver100.Match newEmptyMatch() {
415 return X_inv11_incNotOver100.Match.newEmptyMatch();
416 }
417
418 @Override
419 public X_inv11_incNotOver100.Match newMatch(final Object... parameters) {
420 return X_inv11_incNotOver100.Match.newMatch((Taxation.Expense) parameters[0]);
421 }
422
423 /**
424 * Inner class allowing the singleton instance of {@link X_inv11_incNotOver100} to be created
425 * <b>not</b> at the class load time of the outer class,
426 * but rather at the first call to {@link X_inv11_incNotOver100#instance()}.
427 *
428 * <p> This workaround is required e.g. to support recursion.
429 *
430 */
431 private static class LazyHolder {
432 private static final X_inv11_incNotOver100 INSTANCE = new X_inv11_incNotOver100();
433
434 /**
435 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
436 * This initialization order is required to support indirect recursion.
437 *
438 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
439 *
440 */
441 private static final Object STATIC_INITIALIZER = ensureInitialized();
442
443 public static Object ensureInitialized() {
444 INSTANCE.ensureInitializedInternal();
445 return null;
446 }
447 }
448
449 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
450 private static final X_inv11_incNotOver100.GeneratedPQuery INSTANCE = new GeneratedPQuery();
451
452 private final PParameter parameter_exp = new PParameter("exp", "Taxation.Expense", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Expense")), PParameterDirection.INOUT);
453
454 private final List<PParameter> parameters = Arrays.asList(parameter_exp);
455
456 private GeneratedPQuery() {
457 super(PVisibility.PUBLIC);
458 }
459
460 @Override
461 public String getFullyQualifiedName() {
462 return "queries.x_inv11_incNotOver100";
463 }
464
465 @Override
466 public List<String> getParameterNames() {
467 return Arrays.asList("exp");
468 }
469
470 @Override
471 public List<PParameter> getParameters() {
472 return parameters;
473 }
474
475 @Override
476 public Set<PBody> doGetContainedBodies() {
477 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
478 Set<PBody> bodies = new LinkedHashSet<>();
479 {
480 PBody body = new PBody(this);
481 PVariable var_exp = body.getOrCreateVariableByName("exp");
482 PVariable var_incVal = body.getOrCreateVariableByName("incVal");
483 new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense")));
484 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
485 new ExportedParameter(body, var_exp, parameter_exp)
486 ));
487 // Expense.income.income_amount(exp, incVal)
488 new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense")));
489 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
490 new TypeConstraint(body, Tuples.flatTupleOf(var_exp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Expense", "income")));
491 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
492 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
493 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_amount")));
494 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
495 new Equality(body, var__virtual_1_, var_incVal);
496 // check(incVal / 2 <= 50)
497 new ExpressionEvaluation(body, new IExpressionEvaluator() {
498
499 @Override
500 public String getShortDescription() {
501 return "Expression evaluation from pattern x_inv11_incNotOver100";
502 }
503
504 @Override
505 public Iterable<String> getInputParameterNames() {
506 return Arrays.asList("incVal");}
507
508 @Override
509 public Object evaluateExpression(IValueProvider provider) throws Exception {
510 Double incVal = (Double) provider.getValue("incVal");
511 return evaluateExpression_1_1(incVal);
512 }
513 }, null);
514 bodies.add(body);
515 }
516 {
517 PBody body = new PBody(this);
518 PVariable var_exp = body.getOrCreateVariableByName("exp");
519 PVariable var_decl = body.getOrCreateVariableByName("decl");
520 new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense")));
521 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
522 new ExportedParameter(body, var_exp, parameter_exp)
523 ));
524 // Expense.declared_amount(exp, decl)
525 new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense")));
526 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
527 new TypeConstraint(body, Tuples.flatTupleOf(var_exp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Expense", "declared_amount")));
528 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
529 new Equality(body, var__virtual_0_, var_decl);
530 // check(decl < 50)
531 new ExpressionEvaluation(body, new IExpressionEvaluator() {
532
533 @Override
534 public String getShortDescription() {
535 return "Expression evaluation from pattern x_inv11_incNotOver100";
536 }
537
538 @Override
539 public Iterable<String> getInputParameterNames() {
540 return Arrays.asList("decl");}
541
542 @Override
543 public Object evaluateExpression(IValueProvider provider) throws Exception {
544 Double decl = (Double) provider.getValue("decl");
545 return evaluateExpression_2_1(decl);
546 }
547 }, null);
548 bodies.add(body);
549 }
550 {
551 PBody body = new PBody(this);
552 PVariable var_exp = body.getOrCreateVariableByName("exp");
553 PVariable var_incVal = body.getOrCreateVariableByName("incVal");
554 PVariable var_decl = body.getOrCreateVariableByName("decl");
555 new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense")));
556 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
557 new ExportedParameter(body, var_exp, parameter_exp)
558 ));
559 // Expense.income.income_amount(exp, incVal)
560 new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense")));
561 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
562 new TypeConstraint(body, Tuples.flatTupleOf(var_exp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Expense", "income")));
563 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
564 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
565 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_amount")));
566 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
567 new Equality(body, var__virtual_1_, var_incVal);
568 // Expense.declared_amount(exp, decl)
569 new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense")));
570 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
571 new TypeConstraint(body, Tuples.flatTupleOf(var_exp, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Expense", "declared_amount")));
572 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
573 new Equality(body, var__virtual_2_, var_decl);
574 // check(decl > incVal/2)
575 new ExpressionEvaluation(body, new IExpressionEvaluator() {
576
577 @Override
578 public String getShortDescription() {
579 return "Expression evaluation from pattern x_inv11_incNotOver100";
580 }
581
582 @Override
583 public Iterable<String> getInputParameterNames() {
584 return Arrays.asList("decl", "incVal");}
585
586 @Override
587 public Object evaluateExpression(IValueProvider provider) throws Exception {
588 Double decl = (Double) provider.getValue("decl");
589 Double incVal = (Double) provider.getValue("incVal");
590 return evaluateExpression_3_1(decl, incVal);
591 }
592 }, null);
593 bodies.add(body);
594 }
595 return bodies;
596 }
597 }
598
599 private static boolean evaluateExpression_1_1(final Double incVal) {
600 return (((incVal).doubleValue() / 2) <= 50);
601 }
602
603 private static boolean evaluateExpression_2_1(final Double decl) {
604 return ((decl).doubleValue() < 50);
605 }
606
607 private static boolean evaluateExpression_3_1(final Double decl, final Double incVal) {
608 return ((decl).doubleValue() > ((incVal).doubleValue() / 2));
609 }
610}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incOver100.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incOver100.java
new file mode 100644
index 00000000..27f7a2dc
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incOver100.java
@@ -0,0 +1,629 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Expense;
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.basicdeferred.Equality;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
42import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
43import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
44import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
45
46/**
47 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
48 *
49 * <p>Original source:
50 * <code><pre>
51 * pattern x_inv11_incOver100(exp : Expense) {
52 * Expense.income.income_amount(exp, incVal);
53 * check(incVal / 2 {@literal >} 50);
54 *
55 * } or {
56 * Expense.declared_amount(exp, decl);
57 * check(decl != 50);
58 * }
59 * </pre></code>
60 *
61 * @see Matcher
62 * @see Match
63 *
64 */
65@SuppressWarnings("all")
66public final class X_inv11_incOver100 extends BaseGeneratedEMFQuerySpecification<X_inv11_incOver100.Matcher> {
67 /**
68 * Pattern-specific match representation of the queries.x_inv11_incOver100 pattern,
69 * to be used in conjunction with {@link Matcher}.
70 *
71 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
72 * Each instance is a (possibly partial) substitution of pattern parameters,
73 * usable to represent a match of the pattern in the result of a query,
74 * or to specify the bound (fixed) input parameters when issuing a query.
75 *
76 * @see Matcher
77 *
78 */
79 public static abstract class Match extends BasePatternMatch {
80 private Expense fExp;
81
82 private static List<String> parameterNames = makeImmutableList("exp");
83
84 private Match(final Expense pExp) {
85 this.fExp = pExp;
86 }
87
88 @Override
89 public Object get(final String parameterName) {
90 switch(parameterName) {
91 case "exp": return this.fExp;
92 default: return null;
93 }
94 }
95
96 @Override
97 public Object get(final int index) {
98 switch(index) {
99 case 0: return this.fExp;
100 default: return null;
101 }
102 }
103
104 public Expense getExp() {
105 return this.fExp;
106 }
107
108 @Override
109 public boolean set(final String parameterName, final Object newValue) {
110 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
111 if ("exp".equals(parameterName) ) {
112 this.fExp = (Expense) newValue;
113 return true;
114 }
115 return false;
116 }
117
118 public void setExp(final Expense pExp) {
119 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
120 this.fExp = pExp;
121 }
122
123 @Override
124 public String patternName() {
125 return "queries.x_inv11_incOver100";
126 }
127
128 @Override
129 public List<String> parameterNames() {
130 return X_inv11_incOver100.Match.parameterNames;
131 }
132
133 @Override
134 public Object[] toArray() {
135 return new Object[]{fExp};
136 }
137
138 @Override
139 public X_inv11_incOver100.Match toImmutable() {
140 return isMutable() ? newMatch(fExp) : this;
141 }
142
143 @Override
144 public String prettyPrint() {
145 StringBuilder result = new StringBuilder();
146 result.append("\"exp\"=" + prettyPrintValue(fExp));
147 return result.toString();
148 }
149
150 @Override
151 public int hashCode() {
152 return Objects.hash(fExp);
153 }
154
155 @Override
156 public boolean equals(final Object obj) {
157 if (this == obj)
158 return true;
159 if (obj == null) {
160 return false;
161 }
162 if ((obj instanceof X_inv11_incOver100.Match)) {
163 X_inv11_incOver100.Match other = (X_inv11_incOver100.Match) obj;
164 return Objects.equals(fExp, other.fExp);
165 } else {
166 // this should be infrequent
167 if (!(obj instanceof IPatternMatch)) {
168 return false;
169 }
170 IPatternMatch otherSig = (IPatternMatch) obj;
171 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
172 }
173 }
174
175 @Override
176 public X_inv11_incOver100 specification() {
177 return X_inv11_incOver100.instance();
178 }
179
180 /**
181 * Returns an empty, mutable match.
182 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
183 *
184 * @return the empty match.
185 *
186 */
187 public static X_inv11_incOver100.Match newEmptyMatch() {
188 return new Mutable(null);
189 }
190
191 /**
192 * Returns a mutable (partial) match.
193 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
194 *
195 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
196 * @return the new, mutable (partial) match object.
197 *
198 */
199 public static X_inv11_incOver100.Match newMutableMatch(final Expense pExp) {
200 return new Mutable(pExp);
201 }
202
203 /**
204 * Returns a new (partial) match.
205 * This can be used e.g. to call the matcher with a partial match.
206 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
207 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
208 * @return the (partial) match object.
209 *
210 */
211 public static X_inv11_incOver100.Match newMatch(final Expense pExp) {
212 return new Immutable(pExp);
213 }
214
215 private static final class Mutable extends X_inv11_incOver100.Match {
216 Mutable(final Expense pExp) {
217 super(pExp);
218 }
219
220 @Override
221 public boolean isMutable() {
222 return true;
223 }
224 }
225
226 private static final class Immutable extends X_inv11_incOver100.Match {
227 Immutable(final Expense pExp) {
228 super(pExp);
229 }
230
231 @Override
232 public boolean isMutable() {
233 return false;
234 }
235 }
236 }
237
238 /**
239 * Generated pattern matcher API of the queries.x_inv11_incOver100 pattern,
240 * providing pattern-specific query methods.
241 *
242 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
243 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
244 *
245 * <p>Matches of the pattern will be represented as {@link Match}.
246 *
247 * <p>Original source:
248 * <code><pre>
249 * pattern x_inv11_incOver100(exp : Expense) {
250 * Expense.income.income_amount(exp, incVal);
251 * check(incVal / 2 {@literal >} 50);
252 *
253 * } or {
254 * Expense.declared_amount(exp, decl);
255 * check(decl != 50);
256 * }
257 * </pre></code>
258 *
259 * @see Match
260 * @see X_inv11_incOver100
261 *
262 */
263 public static class Matcher extends BaseMatcher<X_inv11_incOver100.Match> {
264 /**
265 * Initializes the pattern matcher within an existing VIATRA Query engine.
266 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
267 *
268 * @param engine the existing VIATRA Query engine in which this matcher will be created.
269 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
270 *
271 */
272 public static X_inv11_incOver100.Matcher on(final ViatraQueryEngine engine) {
273 // check if matcher already exists
274 Matcher matcher = engine.getExistingMatcher(querySpecification());
275 if (matcher == null) {
276 matcher = (Matcher)engine.getMatcher(querySpecification());
277 }
278 return matcher;
279 }
280
281 /**
282 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
283 * @return an initialized matcher
284 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
285 *
286 */
287 public static X_inv11_incOver100.Matcher create() {
288 return new Matcher();
289 }
290
291 private static final int POSITION_EXP = 0;
292
293 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv11_incOver100.Matcher.class);
294
295 /**
296 * Initializes the pattern matcher within an existing VIATRA Query engine.
297 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
298 *
299 * @param engine the existing VIATRA Query engine in which this matcher will be created.
300 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
301 *
302 */
303 private Matcher() {
304 super(querySpecification());
305 }
306
307 /**
308 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
309 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
310 * @return matches represented as a Match object.
311 *
312 */
313 public Collection<X_inv11_incOver100.Match> getAllMatches(final Expense pExp) {
314 return rawStreamAllMatches(new Object[]{pExp}).collect(Collectors.toSet());
315 }
316
317 /**
318 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
319 * </p>
320 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
321 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
322 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
323 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
324 * @return a stream of matches represented as a Match object.
325 *
326 */
327 public Stream<X_inv11_incOver100.Match> streamAllMatches(final Expense pExp) {
328 return rawStreamAllMatches(new Object[]{pExp});
329 }
330
331 /**
332 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
333 * Neither determinism nor randomness of selection is guaranteed.
334 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
335 * @return a match represented as a Match object, or null if no match is found.
336 *
337 */
338 public Optional<X_inv11_incOver100.Match> getOneArbitraryMatch(final Expense pExp) {
339 return rawGetOneArbitraryMatch(new Object[]{pExp});
340 }
341
342 /**
343 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
344 * under any possible substitution of the unspecified parameters (if any).
345 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
346 * @return true if the input is a valid (partial) match of the pattern.
347 *
348 */
349 public boolean hasMatch(final Expense pExp) {
350 return rawHasMatch(new Object[]{pExp});
351 }
352
353 /**
354 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
355 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
356 * @return the number of pattern matches found.
357 *
358 */
359 public int countMatches(final Expense pExp) {
360 return rawCountMatches(new Object[]{pExp});
361 }
362
363 /**
364 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
365 * Neither determinism nor randomness of selection is guaranteed.
366 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
367 * @param processor the action that will process the selected match.
368 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
369 *
370 */
371 public boolean forOneArbitraryMatch(final Expense pExp, final Consumer<? super X_inv11_incOver100.Match> processor) {
372 return rawForOneArbitraryMatch(new Object[]{pExp}, processor);
373 }
374
375 /**
376 * Returns a new (partial) match.
377 * This can be used e.g. to call the matcher with a partial match.
378 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
379 * @param pExp the fixed value of pattern parameter exp, or null if not bound.
380 * @return the (partial) match object.
381 *
382 */
383 public X_inv11_incOver100.Match newMatch(final Expense pExp) {
384 return X_inv11_incOver100.Match.newMatch(pExp);
385 }
386
387 /**
388 * Retrieve the set of values that occur in matches for exp.
389 * @return the Set of all values or empty set if there are no matches
390 *
391 */
392 protected Stream<Expense> rawStreamAllValuesOfexp(final Object[] parameters) {
393 return rawStreamAllValues(POSITION_EXP, parameters).map(Expense.class::cast);
394 }
395
396 /**
397 * Retrieve the set of values that occur in matches for exp.
398 * @return the Set of all values or empty set if there are no matches
399 *
400 */
401 public Set<Expense> getAllValuesOfexp() {
402 return rawStreamAllValuesOfexp(emptyArray()).collect(Collectors.toSet());
403 }
404
405 /**
406 * Retrieve the set of values that occur in matches for exp.
407 * @return the Set of all values or empty set if there are no matches
408 *
409 */
410 public Stream<Expense> streamAllValuesOfexp() {
411 return rawStreamAllValuesOfexp(emptyArray());
412 }
413
414 @Override
415 protected X_inv11_incOver100.Match tupleToMatch(final Tuple t) {
416 try {
417 return X_inv11_incOver100.Match.newMatch((Expense) t.get(POSITION_EXP));
418 } catch(ClassCastException e) {
419 LOGGER.error("Element(s) in tuple not properly typed!",e);
420 return null;
421 }
422 }
423
424 @Override
425 protected X_inv11_incOver100.Match arrayToMatch(final Object[] match) {
426 try {
427 return X_inv11_incOver100.Match.newMatch((Expense) match[POSITION_EXP]);
428 } catch(ClassCastException e) {
429 LOGGER.error("Element(s) in array not properly typed!",e);
430 return null;
431 }
432 }
433
434 @Override
435 protected X_inv11_incOver100.Match arrayToMatchMutable(final Object[] match) {
436 try {
437 return X_inv11_incOver100.Match.newMutableMatch((Expense) match[POSITION_EXP]);
438 } catch(ClassCastException e) {
439 LOGGER.error("Element(s) in array not properly typed!",e);
440 return null;
441 }
442 }
443
444 /**
445 * @return the singleton instance of the query specification of this pattern
446 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
447 *
448 */
449 public static IQuerySpecification<X_inv11_incOver100.Matcher> querySpecification() {
450 return X_inv11_incOver100.instance();
451 }
452 }
453
454 private X_inv11_incOver100() {
455 super(GeneratedPQuery.INSTANCE);
456 }
457
458 /**
459 * @return the singleton instance of the query specification
460 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
461 *
462 */
463 public static X_inv11_incOver100 instance() {
464 try{
465 return LazyHolder.INSTANCE;
466 } catch (ExceptionInInitializerError err) {
467 throw processInitializerError(err);
468 }
469 }
470
471 @Override
472 protected X_inv11_incOver100.Matcher instantiate(final ViatraQueryEngine engine) {
473 return X_inv11_incOver100.Matcher.on(engine);
474 }
475
476 @Override
477 public X_inv11_incOver100.Matcher instantiate() {
478 return X_inv11_incOver100.Matcher.create();
479 }
480
481 @Override
482 public X_inv11_incOver100.Match newEmptyMatch() {
483 return X_inv11_incOver100.Match.newEmptyMatch();
484 }
485
486 @Override
487 public X_inv11_incOver100.Match newMatch(final Object... parameters) {
488 return X_inv11_incOver100.Match.newMatch((Taxation.Expense) parameters[0]);
489 }
490
491 /**
492 * Inner class allowing the singleton instance of {@link X_inv11_incOver100} to be created
493 * <b>not</b> at the class load time of the outer class,
494 * but rather at the first call to {@link X_inv11_incOver100#instance()}.
495 *
496 * <p> This workaround is required e.g. to support recursion.
497 *
498 */
499 private static class LazyHolder {
500 private static final X_inv11_incOver100 INSTANCE = new X_inv11_incOver100();
501
502 /**
503 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
504 * This initialization order is required to support indirect recursion.
505 *
506 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
507 *
508 */
509 private static final Object STATIC_INITIALIZER = ensureInitialized();
510
511 public static Object ensureInitialized() {
512 INSTANCE.ensureInitializedInternal();
513 return null;
514 }
515 }
516
517 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
518 private static final X_inv11_incOver100.GeneratedPQuery INSTANCE = new GeneratedPQuery();
519
520 private final PParameter parameter_exp = new PParameter("exp", "Taxation.Expense", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Expense")), PParameterDirection.INOUT);
521
522 private final List<PParameter> parameters = Arrays.asList(parameter_exp);
523
524 private GeneratedPQuery() {
525 super(PVisibility.PUBLIC);
526 }
527
528 @Override
529 public String getFullyQualifiedName() {
530 return "queries.x_inv11_incOver100";
531 }
532
533 @Override
534 public List<String> getParameterNames() {
535 return Arrays.asList("exp");
536 }
537
538 @Override
539 public List<PParameter> getParameters() {
540 return parameters;
541 }
542
543 @Override
544 public Set<PBody> doGetContainedBodies() {
545 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
546 Set<PBody> bodies = new LinkedHashSet<>();
547 {
548 PBody body = new PBody(this);
549 PVariable var_exp = body.getOrCreateVariableByName("exp");
550 PVariable var_incVal = body.getOrCreateVariableByName("incVal");
551 new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense")));
552 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
553 new ExportedParameter(body, var_exp, parameter_exp)
554 ));
555 // Expense.income.income_amount(exp, incVal)
556 new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense")));
557 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
558 new TypeConstraint(body, Tuples.flatTupleOf(var_exp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Expense", "income")));
559 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income")));
560 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
561 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_amount")));
562 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
563 new Equality(body, var__virtual_1_, var_incVal);
564 // check(incVal / 2 > 50)
565 new ExpressionEvaluation(body, new IExpressionEvaluator() {
566
567 @Override
568 public String getShortDescription() {
569 return "Expression evaluation from pattern x_inv11_incOver100";
570 }
571
572 @Override
573 public Iterable<String> getInputParameterNames() {
574 return Arrays.asList("incVal");}
575
576 @Override
577 public Object evaluateExpression(IValueProvider provider) throws Exception {
578 Double incVal = (Double) provider.getValue("incVal");
579 return evaluateExpression_1_1(incVal);
580 }
581 }, null);
582 bodies.add(body);
583 }
584 {
585 PBody body = new PBody(this);
586 PVariable var_exp = body.getOrCreateVariableByName("exp");
587 PVariable var_decl = body.getOrCreateVariableByName("decl");
588 new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense")));
589 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
590 new ExportedParameter(body, var_exp, parameter_exp)
591 ));
592 // Expense.declared_amount(exp, decl)
593 new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense")));
594 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
595 new TypeConstraint(body, Tuples.flatTupleOf(var_exp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Expense", "declared_amount")));
596 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
597 new Equality(body, var__virtual_0_, var_decl);
598 // check(decl != 50)
599 new ExpressionEvaluation(body, new IExpressionEvaluator() {
600
601 @Override
602 public String getShortDescription() {
603 return "Expression evaluation from pattern x_inv11_incOver100";
604 }
605
606 @Override
607 public Iterable<String> getInputParameterNames() {
608 return Arrays.asList("decl");}
609
610 @Override
611 public Object evaluateExpression(IValueProvider provider) throws Exception {
612 Double decl = (Double) provider.getValue("decl");
613 return evaluateExpression_2_1(decl);
614 }
615 }, null);
616 bodies.add(body);
617 }
618 return bodies;
619 }
620 }
621
622 private static boolean evaluateExpression_1_1(final Double incVal) {
623 return (((incVal).doubleValue() / 2) > 50);
624 }
625
626 private static boolean evaluateExpression_2_1(final Double decl) {
627 return ((decl).doubleValue() != 50);
628 }
629}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notNonRes.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notNonRes.java
new file mode 100644
index 00000000..1c0e5109
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notNonRes.java
@@ -0,0 +1,543 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Non_Resident_Tax_Payer;
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.basicdeferred.ExportedParameter;
31import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
32import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
33import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
34import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
35import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
36import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
37
38/**
39 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
40 *
41 * <p>Original source:
42 * <code><pre>
43 * pattern x_inv12_notNonRes(tp : Non_Resident_Tax_Payer) {
44 * Non_Resident_Tax_Payer(tp);
45 * }
46 * </pre></code>
47 *
48 * @see Matcher
49 * @see Match
50 *
51 */
52@SuppressWarnings("all")
53public final class X_inv12_notNonRes extends BaseGeneratedEMFQuerySpecification<X_inv12_notNonRes.Matcher> {
54 /**
55 * Pattern-specific match representation of the queries.x_inv12_notNonRes pattern,
56 * to be used in conjunction with {@link Matcher}.
57 *
58 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
59 * Each instance is a (possibly partial) substitution of pattern parameters,
60 * usable to represent a match of the pattern in the result of a query,
61 * or to specify the bound (fixed) input parameters when issuing a query.
62 *
63 * @see Matcher
64 *
65 */
66 public static abstract class Match extends BasePatternMatch {
67 private Non_Resident_Tax_Payer fTp;
68
69 private static List<String> parameterNames = makeImmutableList("tp");
70
71 private Match(final Non_Resident_Tax_Payer pTp) {
72 this.fTp = pTp;
73 }
74
75 @Override
76 public Object get(final String parameterName) {
77 switch(parameterName) {
78 case "tp": return this.fTp;
79 default: return null;
80 }
81 }
82
83 @Override
84 public Object get(final int index) {
85 switch(index) {
86 case 0: return this.fTp;
87 default: return null;
88 }
89 }
90
91 public Non_Resident_Tax_Payer getTp() {
92 return this.fTp;
93 }
94
95 @Override
96 public boolean set(final String parameterName, final Object newValue) {
97 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
98 if ("tp".equals(parameterName) ) {
99 this.fTp = (Non_Resident_Tax_Payer) newValue;
100 return true;
101 }
102 return false;
103 }
104
105 public void setTp(final Non_Resident_Tax_Payer pTp) {
106 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
107 this.fTp = pTp;
108 }
109
110 @Override
111 public String patternName() {
112 return "queries.x_inv12_notNonRes";
113 }
114
115 @Override
116 public List<String> parameterNames() {
117 return X_inv12_notNonRes.Match.parameterNames;
118 }
119
120 @Override
121 public Object[] toArray() {
122 return new Object[]{fTp};
123 }
124
125 @Override
126 public X_inv12_notNonRes.Match toImmutable() {
127 return isMutable() ? newMatch(fTp) : this;
128 }
129
130 @Override
131 public String prettyPrint() {
132 StringBuilder result = new StringBuilder();
133 result.append("\"tp\"=" + prettyPrintValue(fTp));
134 return result.toString();
135 }
136
137 @Override
138 public int hashCode() {
139 return Objects.hash(fTp);
140 }
141
142 @Override
143 public boolean equals(final Object obj) {
144 if (this == obj)
145 return true;
146 if (obj == null) {
147 return false;
148 }
149 if ((obj instanceof X_inv12_notNonRes.Match)) {
150 X_inv12_notNonRes.Match other = (X_inv12_notNonRes.Match) obj;
151 return Objects.equals(fTp, other.fTp);
152 } else {
153 // this should be infrequent
154 if (!(obj instanceof IPatternMatch)) {
155 return false;
156 }
157 IPatternMatch otherSig = (IPatternMatch) obj;
158 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
159 }
160 }
161
162 @Override
163 public X_inv12_notNonRes specification() {
164 return X_inv12_notNonRes.instance();
165 }
166
167 /**
168 * Returns an empty, mutable match.
169 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
170 *
171 * @return the empty match.
172 *
173 */
174 public static X_inv12_notNonRes.Match newEmptyMatch() {
175 return new Mutable(null);
176 }
177
178 /**
179 * Returns a mutable (partial) match.
180 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
181 *
182 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
183 * @return the new, mutable (partial) match object.
184 *
185 */
186 public static X_inv12_notNonRes.Match newMutableMatch(final Non_Resident_Tax_Payer pTp) {
187 return new Mutable(pTp);
188 }
189
190 /**
191 * Returns a new (partial) match.
192 * This can be used e.g. to call the matcher with a partial match.
193 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
194 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
195 * @return the (partial) match object.
196 *
197 */
198 public static X_inv12_notNonRes.Match newMatch(final Non_Resident_Tax_Payer pTp) {
199 return new Immutable(pTp);
200 }
201
202 private static final class Mutable extends X_inv12_notNonRes.Match {
203 Mutable(final Non_Resident_Tax_Payer pTp) {
204 super(pTp);
205 }
206
207 @Override
208 public boolean isMutable() {
209 return true;
210 }
211 }
212
213 private static final class Immutable extends X_inv12_notNonRes.Match {
214 Immutable(final Non_Resident_Tax_Payer pTp) {
215 super(pTp);
216 }
217
218 @Override
219 public boolean isMutable() {
220 return false;
221 }
222 }
223 }
224
225 /**
226 * Generated pattern matcher API of the queries.x_inv12_notNonRes pattern,
227 * providing pattern-specific query methods.
228 *
229 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
230 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
231 *
232 * <p>Matches of the pattern will be represented as {@link Match}.
233 *
234 * <p>Original source:
235 * <code><pre>
236 * pattern x_inv12_notNonRes(tp : Non_Resident_Tax_Payer) {
237 * Non_Resident_Tax_Payer(tp);
238 * }
239 * </pre></code>
240 *
241 * @see Match
242 * @see X_inv12_notNonRes
243 *
244 */
245 public static class Matcher extends BaseMatcher<X_inv12_notNonRes.Match> {
246 /**
247 * Initializes the pattern matcher within an existing VIATRA Query engine.
248 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
249 *
250 * @param engine the existing VIATRA Query engine in which this matcher will be created.
251 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
252 *
253 */
254 public static X_inv12_notNonRes.Matcher on(final ViatraQueryEngine engine) {
255 // check if matcher already exists
256 Matcher matcher = engine.getExistingMatcher(querySpecification());
257 if (matcher == null) {
258 matcher = (Matcher)engine.getMatcher(querySpecification());
259 }
260 return matcher;
261 }
262
263 /**
264 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
265 * @return an initialized matcher
266 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
267 *
268 */
269 public static X_inv12_notNonRes.Matcher create() {
270 return new Matcher();
271 }
272
273 private static final int POSITION_TP = 0;
274
275 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv12_notNonRes.Matcher.class);
276
277 /**
278 * Initializes the pattern matcher within an existing VIATRA Query engine.
279 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
280 *
281 * @param engine the existing VIATRA Query engine in which this matcher will be created.
282 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
283 *
284 */
285 private Matcher() {
286 super(querySpecification());
287 }
288
289 /**
290 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
291 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
292 * @return matches represented as a Match object.
293 *
294 */
295 public Collection<X_inv12_notNonRes.Match> getAllMatches(final Non_Resident_Tax_Payer pTp) {
296 return rawStreamAllMatches(new Object[]{pTp}).collect(Collectors.toSet());
297 }
298
299 /**
300 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
301 * </p>
302 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
303 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
304 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
305 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
306 * @return a stream of matches represented as a Match object.
307 *
308 */
309 public Stream<X_inv12_notNonRes.Match> streamAllMatches(final Non_Resident_Tax_Payer pTp) {
310 return rawStreamAllMatches(new Object[]{pTp});
311 }
312
313 /**
314 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
315 * Neither determinism nor randomness of selection is guaranteed.
316 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
317 * @return a match represented as a Match object, or null if no match is found.
318 *
319 */
320 public Optional<X_inv12_notNonRes.Match> getOneArbitraryMatch(final Non_Resident_Tax_Payer pTp) {
321 return rawGetOneArbitraryMatch(new Object[]{pTp});
322 }
323
324 /**
325 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
326 * under any possible substitution of the unspecified parameters (if any).
327 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
328 * @return true if the input is a valid (partial) match of the pattern.
329 *
330 */
331 public boolean hasMatch(final Non_Resident_Tax_Payer pTp) {
332 return rawHasMatch(new Object[]{pTp});
333 }
334
335 /**
336 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
337 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
338 * @return the number of pattern matches found.
339 *
340 */
341 public int countMatches(final Non_Resident_Tax_Payer pTp) {
342 return rawCountMatches(new Object[]{pTp});
343 }
344
345 /**
346 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
347 * Neither determinism nor randomness of selection is guaranteed.
348 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
349 * @param processor the action that will process the selected match.
350 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
351 *
352 */
353 public boolean forOneArbitraryMatch(final Non_Resident_Tax_Payer pTp, final Consumer<? super X_inv12_notNonRes.Match> processor) {
354 return rawForOneArbitraryMatch(new Object[]{pTp}, processor);
355 }
356
357 /**
358 * Returns a new (partial) match.
359 * This can be used e.g. to call the matcher with a partial match.
360 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
361 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
362 * @return the (partial) match object.
363 *
364 */
365 public X_inv12_notNonRes.Match newMatch(final Non_Resident_Tax_Payer pTp) {
366 return X_inv12_notNonRes.Match.newMatch(pTp);
367 }
368
369 /**
370 * Retrieve the set of values that occur in matches for tp.
371 * @return the Set of all values or empty set if there are no matches
372 *
373 */
374 protected Stream<Non_Resident_Tax_Payer> rawStreamAllValuesOftp(final Object[] parameters) {
375 return rawStreamAllValues(POSITION_TP, parameters).map(Non_Resident_Tax_Payer.class::cast);
376 }
377
378 /**
379 * Retrieve the set of values that occur in matches for tp.
380 * @return the Set of all values or empty set if there are no matches
381 *
382 */
383 public Set<Non_Resident_Tax_Payer> getAllValuesOftp() {
384 return rawStreamAllValuesOftp(emptyArray()).collect(Collectors.toSet());
385 }
386
387 /**
388 * Retrieve the set of values that occur in matches for tp.
389 * @return the Set of all values or empty set if there are no matches
390 *
391 */
392 public Stream<Non_Resident_Tax_Payer> streamAllValuesOftp() {
393 return rawStreamAllValuesOftp(emptyArray());
394 }
395
396 @Override
397 protected X_inv12_notNonRes.Match tupleToMatch(final Tuple t) {
398 try {
399 return X_inv12_notNonRes.Match.newMatch((Non_Resident_Tax_Payer) t.get(POSITION_TP));
400 } catch(ClassCastException e) {
401 LOGGER.error("Element(s) in tuple not properly typed!",e);
402 return null;
403 }
404 }
405
406 @Override
407 protected X_inv12_notNonRes.Match arrayToMatch(final Object[] match) {
408 try {
409 return X_inv12_notNonRes.Match.newMatch((Non_Resident_Tax_Payer) match[POSITION_TP]);
410 } catch(ClassCastException e) {
411 LOGGER.error("Element(s) in array not properly typed!",e);
412 return null;
413 }
414 }
415
416 @Override
417 protected X_inv12_notNonRes.Match arrayToMatchMutable(final Object[] match) {
418 try {
419 return X_inv12_notNonRes.Match.newMutableMatch((Non_Resident_Tax_Payer) match[POSITION_TP]);
420 } catch(ClassCastException e) {
421 LOGGER.error("Element(s) in array not properly typed!",e);
422 return null;
423 }
424 }
425
426 /**
427 * @return the singleton instance of the query specification of this pattern
428 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
429 *
430 */
431 public static IQuerySpecification<X_inv12_notNonRes.Matcher> querySpecification() {
432 return X_inv12_notNonRes.instance();
433 }
434 }
435
436 private X_inv12_notNonRes() {
437 super(GeneratedPQuery.INSTANCE);
438 }
439
440 /**
441 * @return the singleton instance of the query specification
442 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
443 *
444 */
445 public static X_inv12_notNonRes instance() {
446 try{
447 return LazyHolder.INSTANCE;
448 } catch (ExceptionInInitializerError err) {
449 throw processInitializerError(err);
450 }
451 }
452
453 @Override
454 protected X_inv12_notNonRes.Matcher instantiate(final ViatraQueryEngine engine) {
455 return X_inv12_notNonRes.Matcher.on(engine);
456 }
457
458 @Override
459 public X_inv12_notNonRes.Matcher instantiate() {
460 return X_inv12_notNonRes.Matcher.create();
461 }
462
463 @Override
464 public X_inv12_notNonRes.Match newEmptyMatch() {
465 return X_inv12_notNonRes.Match.newEmptyMatch();
466 }
467
468 @Override
469 public X_inv12_notNonRes.Match newMatch(final Object... parameters) {
470 return X_inv12_notNonRes.Match.newMatch((Taxation.Non_Resident_Tax_Payer) parameters[0]);
471 }
472
473 /**
474 * Inner class allowing the singleton instance of {@link X_inv12_notNonRes} to be created
475 * <b>not</b> at the class load time of the outer class,
476 * but rather at the first call to {@link X_inv12_notNonRes#instance()}.
477 *
478 * <p> This workaround is required e.g. to support recursion.
479 *
480 */
481 private static class LazyHolder {
482 private static final X_inv12_notNonRes INSTANCE = new X_inv12_notNonRes();
483
484 /**
485 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
486 * This initialization order is required to support indirect recursion.
487 *
488 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
489 *
490 */
491 private static final Object STATIC_INITIALIZER = ensureInitialized();
492
493 public static Object ensureInitialized() {
494 INSTANCE.ensureInitializedInternal();
495 return null;
496 }
497 }
498
499 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
500 private static final X_inv12_notNonRes.GeneratedPQuery INSTANCE = new GeneratedPQuery();
501
502 private final PParameter parameter_tp;
503
504 private final List<PParameter> parameters = Arrays.asList(parameter_tp);
505
506 private GeneratedPQuery() {
507 super(PVisibility.PUBLIC);
508 }
509
510 @Override
511 public String getFullyQualifiedName() {
512 return "queries.x_inv12_notNonRes";
513 }
514
515 @Override
516 public List<String> getParameterNames() {
517 return Arrays.asList("tp");
518 }
519
520 @Override
521 public List<PParameter> getParameters() {
522 return parameters;
523 }
524
525 @Override
526 public Set<PBody> doGetContainedBodies() {
527 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
528 Set<PBody> bodies = new LinkedHashSet<>();
529 {
530 PBody body = new PBody(this);
531 PVariable var_tp = body.getOrCreateVariableByName("tp");
532 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Non_Resident_Tax_Payer")));
533 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
534 new ExportedParameter(body, var_tp, parameter_tp)
535 ));
536 // Non_Resident_Tax_Payer(tp)
537 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Non_Resident_Tax_Payer")));
538 bodies.add(body);
539 }
540 return bodies;
541 }
542 }
543}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notZZ.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notZZ.java
new file mode 100644
index 00000000..68a4098f
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notZZ.java
@@ -0,0 +1,555 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Habitual_Address;
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.PBody;
32import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
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.ConstantValue;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
38import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
40import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
41import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
42import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
43
44/**
45 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
46 *
47 * <p>Original source:
48 * <code><pre>
49 * pattern x_inv12_notZZ(hab_add : Habitual_Address) {
50 * Address.country(hab_add, ::ZZ);
51 * }
52 * </pre></code>
53 *
54 * @see Matcher
55 * @see Match
56 *
57 */
58@SuppressWarnings("all")
59public final class X_inv12_notZZ extends BaseGeneratedEMFQuerySpecification<X_inv12_notZZ.Matcher> {
60 /**
61 * Pattern-specific match representation of the queries.x_inv12_notZZ pattern,
62 * to be used in conjunction with {@link Matcher}.
63 *
64 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
65 * Each instance is a (possibly partial) substitution of pattern parameters,
66 * usable to represent a match of the pattern in the result of a query,
67 * or to specify the bound (fixed) input parameters when issuing a query.
68 *
69 * @see Matcher
70 *
71 */
72 public static abstract class Match extends BasePatternMatch {
73 private Habitual_Address fHab_add;
74
75 private static List<String> parameterNames = makeImmutableList("hab_add");
76
77 private Match(final Habitual_Address pHab_add) {
78 this.fHab_add = pHab_add;
79 }
80
81 @Override
82 public Object get(final String parameterName) {
83 switch(parameterName) {
84 case "hab_add": return this.fHab_add;
85 default: return null;
86 }
87 }
88
89 @Override
90 public Object get(final int index) {
91 switch(index) {
92 case 0: return this.fHab_add;
93 default: return null;
94 }
95 }
96
97 public Habitual_Address getHab_add() {
98 return this.fHab_add;
99 }
100
101 @Override
102 public boolean set(final String parameterName, final Object newValue) {
103 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
104 if ("hab_add".equals(parameterName) ) {
105 this.fHab_add = (Habitual_Address) newValue;
106 return true;
107 }
108 return false;
109 }
110
111 public void setHab_add(final Habitual_Address pHab_add) {
112 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
113 this.fHab_add = pHab_add;
114 }
115
116 @Override
117 public String patternName() {
118 return "queries.x_inv12_notZZ";
119 }
120
121 @Override
122 public List<String> parameterNames() {
123 return X_inv12_notZZ.Match.parameterNames;
124 }
125
126 @Override
127 public Object[] toArray() {
128 return new Object[]{fHab_add};
129 }
130
131 @Override
132 public X_inv12_notZZ.Match toImmutable() {
133 return isMutable() ? newMatch(fHab_add) : this;
134 }
135
136 @Override
137 public String prettyPrint() {
138 StringBuilder result = new StringBuilder();
139 result.append("\"hab_add\"=" + prettyPrintValue(fHab_add));
140 return result.toString();
141 }
142
143 @Override
144 public int hashCode() {
145 return Objects.hash(fHab_add);
146 }
147
148 @Override
149 public boolean equals(final Object obj) {
150 if (this == obj)
151 return true;
152 if (obj == null) {
153 return false;
154 }
155 if ((obj instanceof X_inv12_notZZ.Match)) {
156 X_inv12_notZZ.Match other = (X_inv12_notZZ.Match) obj;
157 return Objects.equals(fHab_add, other.fHab_add);
158 } else {
159 // this should be infrequent
160 if (!(obj instanceof IPatternMatch)) {
161 return false;
162 }
163 IPatternMatch otherSig = (IPatternMatch) obj;
164 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
165 }
166 }
167
168 @Override
169 public X_inv12_notZZ specification() {
170 return X_inv12_notZZ.instance();
171 }
172
173 /**
174 * Returns an empty, mutable match.
175 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
176 *
177 * @return the empty match.
178 *
179 */
180 public static X_inv12_notZZ.Match newEmptyMatch() {
181 return new Mutable(null);
182 }
183
184 /**
185 * Returns a mutable (partial) match.
186 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
187 *
188 * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound.
189 * @return the new, mutable (partial) match object.
190 *
191 */
192 public static X_inv12_notZZ.Match newMutableMatch(final Habitual_Address pHab_add) {
193 return new Mutable(pHab_add);
194 }
195
196 /**
197 * Returns a new (partial) match.
198 * This can be used e.g. to call the matcher with a partial match.
199 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
200 * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound.
201 * @return the (partial) match object.
202 *
203 */
204 public static X_inv12_notZZ.Match newMatch(final Habitual_Address pHab_add) {
205 return new Immutable(pHab_add);
206 }
207
208 private static final class Mutable extends X_inv12_notZZ.Match {
209 Mutable(final Habitual_Address pHab_add) {
210 super(pHab_add);
211 }
212
213 @Override
214 public boolean isMutable() {
215 return true;
216 }
217 }
218
219 private static final class Immutable extends X_inv12_notZZ.Match {
220 Immutable(final Habitual_Address pHab_add) {
221 super(pHab_add);
222 }
223
224 @Override
225 public boolean isMutable() {
226 return false;
227 }
228 }
229 }
230
231 /**
232 * Generated pattern matcher API of the queries.x_inv12_notZZ pattern,
233 * providing pattern-specific query methods.
234 *
235 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
236 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
237 *
238 * <p>Matches of the pattern will be represented as {@link Match}.
239 *
240 * <p>Original source:
241 * <code><pre>
242 * pattern x_inv12_notZZ(hab_add : Habitual_Address) {
243 * Address.country(hab_add, ::ZZ);
244 * }
245 * </pre></code>
246 *
247 * @see Match
248 * @see X_inv12_notZZ
249 *
250 */
251 public static class Matcher extends BaseMatcher<X_inv12_notZZ.Match> {
252 /**
253 * Initializes the pattern matcher within an existing VIATRA Query engine.
254 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
255 *
256 * @param engine the existing VIATRA Query engine in which this matcher will be created.
257 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
258 *
259 */
260 public static X_inv12_notZZ.Matcher on(final ViatraQueryEngine engine) {
261 // check if matcher already exists
262 Matcher matcher = engine.getExistingMatcher(querySpecification());
263 if (matcher == null) {
264 matcher = (Matcher)engine.getMatcher(querySpecification());
265 }
266 return matcher;
267 }
268
269 /**
270 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
271 * @return an initialized matcher
272 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
273 *
274 */
275 public static X_inv12_notZZ.Matcher create() {
276 return new Matcher();
277 }
278
279 private static final int POSITION_HAB_ADD = 0;
280
281 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv12_notZZ.Matcher.class);
282
283 /**
284 * Initializes the pattern matcher within an existing VIATRA Query engine.
285 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
286 *
287 * @param engine the existing VIATRA Query engine in which this matcher will be created.
288 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
289 *
290 */
291 private Matcher() {
292 super(querySpecification());
293 }
294
295 /**
296 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
297 * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound.
298 * @return matches represented as a Match object.
299 *
300 */
301 public Collection<X_inv12_notZZ.Match> getAllMatches(final Habitual_Address pHab_add) {
302 return rawStreamAllMatches(new Object[]{pHab_add}).collect(Collectors.toSet());
303 }
304
305 /**
306 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
307 * </p>
308 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
309 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
310 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
311 * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound.
312 * @return a stream of matches represented as a Match object.
313 *
314 */
315 public Stream<X_inv12_notZZ.Match> streamAllMatches(final Habitual_Address pHab_add) {
316 return rawStreamAllMatches(new Object[]{pHab_add});
317 }
318
319 /**
320 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
321 * Neither determinism nor randomness of selection is guaranteed.
322 * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound.
323 * @return a match represented as a Match object, or null if no match is found.
324 *
325 */
326 public Optional<X_inv12_notZZ.Match> getOneArbitraryMatch(final Habitual_Address pHab_add) {
327 return rawGetOneArbitraryMatch(new Object[]{pHab_add});
328 }
329
330 /**
331 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
332 * under any possible substitution of the unspecified parameters (if any).
333 * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound.
334 * @return true if the input is a valid (partial) match of the pattern.
335 *
336 */
337 public boolean hasMatch(final Habitual_Address pHab_add) {
338 return rawHasMatch(new Object[]{pHab_add});
339 }
340
341 /**
342 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
343 * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound.
344 * @return the number of pattern matches found.
345 *
346 */
347 public int countMatches(final Habitual_Address pHab_add) {
348 return rawCountMatches(new Object[]{pHab_add});
349 }
350
351 /**
352 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
353 * Neither determinism nor randomness of selection is guaranteed.
354 * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound.
355 * @param processor the action that will process the selected match.
356 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
357 *
358 */
359 public boolean forOneArbitraryMatch(final Habitual_Address pHab_add, final Consumer<? super X_inv12_notZZ.Match> processor) {
360 return rawForOneArbitraryMatch(new Object[]{pHab_add}, processor);
361 }
362
363 /**
364 * Returns a new (partial) match.
365 * This can be used e.g. to call the matcher with a partial match.
366 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
367 * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound.
368 * @return the (partial) match object.
369 *
370 */
371 public X_inv12_notZZ.Match newMatch(final Habitual_Address pHab_add) {
372 return X_inv12_notZZ.Match.newMatch(pHab_add);
373 }
374
375 /**
376 * Retrieve the set of values that occur in matches for hab_add.
377 * @return the Set of all values or empty set if there are no matches
378 *
379 */
380 protected Stream<Habitual_Address> rawStreamAllValuesOfhab_add(final Object[] parameters) {
381 return rawStreamAllValues(POSITION_HAB_ADD, parameters).map(Habitual_Address.class::cast);
382 }
383
384 /**
385 * Retrieve the set of values that occur in matches for hab_add.
386 * @return the Set of all values or empty set if there are no matches
387 *
388 */
389 public Set<Habitual_Address> getAllValuesOfhab_add() {
390 return rawStreamAllValuesOfhab_add(emptyArray()).collect(Collectors.toSet());
391 }
392
393 /**
394 * Retrieve the set of values that occur in matches for hab_add.
395 * @return the Set of all values or empty set if there are no matches
396 *
397 */
398 public Stream<Habitual_Address> streamAllValuesOfhab_add() {
399 return rawStreamAllValuesOfhab_add(emptyArray());
400 }
401
402 @Override
403 protected X_inv12_notZZ.Match tupleToMatch(final Tuple t) {
404 try {
405 return X_inv12_notZZ.Match.newMatch((Habitual_Address) t.get(POSITION_HAB_ADD));
406 } catch(ClassCastException e) {
407 LOGGER.error("Element(s) in tuple not properly typed!",e);
408 return null;
409 }
410 }
411
412 @Override
413 protected X_inv12_notZZ.Match arrayToMatch(final Object[] match) {
414 try {
415 return X_inv12_notZZ.Match.newMatch((Habitual_Address) match[POSITION_HAB_ADD]);
416 } catch(ClassCastException e) {
417 LOGGER.error("Element(s) in array not properly typed!",e);
418 return null;
419 }
420 }
421
422 @Override
423 protected X_inv12_notZZ.Match arrayToMatchMutable(final Object[] match) {
424 try {
425 return X_inv12_notZZ.Match.newMutableMatch((Habitual_Address) match[POSITION_HAB_ADD]);
426 } catch(ClassCastException e) {
427 LOGGER.error("Element(s) in array not properly typed!",e);
428 return null;
429 }
430 }
431
432 /**
433 * @return the singleton instance of the query specification of this pattern
434 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
435 *
436 */
437 public static IQuerySpecification<X_inv12_notZZ.Matcher> querySpecification() {
438 return X_inv12_notZZ.instance();
439 }
440 }
441
442 private X_inv12_notZZ() {
443 super(GeneratedPQuery.INSTANCE);
444 }
445
446 /**
447 * @return the singleton instance of the query specification
448 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
449 *
450 */
451 public static X_inv12_notZZ instance() {
452 try{
453 return LazyHolder.INSTANCE;
454 } catch (ExceptionInInitializerError err) {
455 throw processInitializerError(err);
456 }
457 }
458
459 @Override
460 protected X_inv12_notZZ.Matcher instantiate(final ViatraQueryEngine engine) {
461 return X_inv12_notZZ.Matcher.on(engine);
462 }
463
464 @Override
465 public X_inv12_notZZ.Matcher instantiate() {
466 return X_inv12_notZZ.Matcher.create();
467 }
468
469 @Override
470 public X_inv12_notZZ.Match newEmptyMatch() {
471 return X_inv12_notZZ.Match.newEmptyMatch();
472 }
473
474 @Override
475 public X_inv12_notZZ.Match newMatch(final Object... parameters) {
476 return X_inv12_notZZ.Match.newMatch((Taxation.Habitual_Address) parameters[0]);
477 }
478
479 /**
480 * Inner class allowing the singleton instance of {@link X_inv12_notZZ} to be created
481 * <b>not</b> at the class load time of the outer class,
482 * but rather at the first call to {@link X_inv12_notZZ#instance()}.
483 *
484 * <p> This workaround is required e.g. to support recursion.
485 *
486 */
487 private static class LazyHolder {
488 private static final X_inv12_notZZ INSTANCE = new X_inv12_notZZ();
489
490 /**
491 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
492 * This initialization order is required to support indirect recursion.
493 *
494 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
495 *
496 */
497 private static final Object STATIC_INITIALIZER = ensureInitialized();
498
499 public static Object ensureInitialized() {
500 INSTANCE.ensureInitializedInternal();
501 return null;
502 }
503 }
504
505 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
506 private static final X_inv12_notZZ.GeneratedPQuery INSTANCE = new GeneratedPQuery();
507
508 private final PParameter parameter_hab_add = new PParameter("hab_add", "Taxation.Habitual_Address", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Habitual_Address")), PParameterDirection.INOUT);
509
510 private final List<PParameter> parameters = Arrays.asList(parameter_hab_add);
511
512 private GeneratedPQuery() {
513 super(PVisibility.PUBLIC);
514 }
515
516 @Override
517 public String getFullyQualifiedName() {
518 return "queries.x_inv12_notZZ";
519 }
520
521 @Override
522 public List<String> getParameterNames() {
523 return Arrays.asList("hab_add");
524 }
525
526 @Override
527 public List<PParameter> getParameters() {
528 return parameters;
529 }
530
531 @Override
532 public Set<PBody> doGetContainedBodies() {
533 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
534 Set<PBody> bodies = new LinkedHashSet<>();
535 {
536 PBody body = new PBody(this);
537 PVariable var_hab_add = body.getOrCreateVariableByName("hab_add");
538 new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Habitual_Address")));
539 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
540 new ExportedParameter(body, var_hab_add, parameter_hab_add)
541 ));
542 // Address.country(hab_add, ::ZZ)
543 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
544 new ConstantValue(body, var__virtual_0_, getEnumLiteral("http:///TaxCard.ecore", "Country", "ZZ").getInstance());
545 new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Address")));
546 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
547 new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Address", "country")));
548 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http:///TaxCard.ecore", "Country")));
549 new Equality(body, var__virtual_1_, var__virtual_0_);
550 bodies.add(body);
551 }
552 return bodies;
553 }
554 }
555}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv13.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv13.java
new file mode 100644
index 00000000..ac0dd914
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv13.java
@@ -0,0 +1,544 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Resident_Tax_Payer;
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.basicdeferred.ExportedParameter;
31import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
32import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
33import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
34import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
35import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
36import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
37import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
38
39/**
40 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
41 *
42 * <p>Original source:
43 * <code><pre>
44 * pattern x_inv13(tp : Resident_Tax_Payer) {
45 * Resident_Tax_Payer(tp);
46 * }
47 * </pre></code>
48 *
49 * @see Matcher
50 * @see Match
51 *
52 */
53@SuppressWarnings("all")
54public final class X_inv13 extends BaseGeneratedEMFQuerySpecification<X_inv13.Matcher> {
55 /**
56 * Pattern-specific match representation of the queries.x_inv13 pattern,
57 * to be used in conjunction with {@link Matcher}.
58 *
59 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
60 * Each instance is a (possibly partial) substitution of pattern parameters,
61 * usable to represent a match of the pattern in the result of a query,
62 * or to specify the bound (fixed) input parameters when issuing a query.
63 *
64 * @see Matcher
65 *
66 */
67 public static abstract class Match extends BasePatternMatch {
68 private Resident_Tax_Payer fTp;
69
70 private static List<String> parameterNames = makeImmutableList("tp");
71
72 private Match(final Resident_Tax_Payer pTp) {
73 this.fTp = pTp;
74 }
75
76 @Override
77 public Object get(final String parameterName) {
78 switch(parameterName) {
79 case "tp": return this.fTp;
80 default: return null;
81 }
82 }
83
84 @Override
85 public Object get(final int index) {
86 switch(index) {
87 case 0: return this.fTp;
88 default: return null;
89 }
90 }
91
92 public Resident_Tax_Payer getTp() {
93 return this.fTp;
94 }
95
96 @Override
97 public boolean set(final String parameterName, final Object newValue) {
98 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
99 if ("tp".equals(parameterName) ) {
100 this.fTp = (Resident_Tax_Payer) newValue;
101 return true;
102 }
103 return false;
104 }
105
106 public void setTp(final Resident_Tax_Payer pTp) {
107 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
108 this.fTp = pTp;
109 }
110
111 @Override
112 public String patternName() {
113 return "queries.x_inv13";
114 }
115
116 @Override
117 public List<String> parameterNames() {
118 return X_inv13.Match.parameterNames;
119 }
120
121 @Override
122 public Object[] toArray() {
123 return new Object[]{fTp};
124 }
125
126 @Override
127 public X_inv13.Match toImmutable() {
128 return isMutable() ? newMatch(fTp) : this;
129 }
130
131 @Override
132 public String prettyPrint() {
133 StringBuilder result = new StringBuilder();
134 result.append("\"tp\"=" + prettyPrintValue(fTp));
135 return result.toString();
136 }
137
138 @Override
139 public int hashCode() {
140 return Objects.hash(fTp);
141 }
142
143 @Override
144 public boolean equals(final Object obj) {
145 if (this == obj)
146 return true;
147 if (obj == null) {
148 return false;
149 }
150 if ((obj instanceof X_inv13.Match)) {
151 X_inv13.Match other = (X_inv13.Match) obj;
152 return Objects.equals(fTp, other.fTp);
153 } else {
154 // this should be infrequent
155 if (!(obj instanceof IPatternMatch)) {
156 return false;
157 }
158 IPatternMatch otherSig = (IPatternMatch) obj;
159 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
160 }
161 }
162
163 @Override
164 public X_inv13 specification() {
165 return X_inv13.instance();
166 }
167
168 /**
169 * Returns an empty, mutable match.
170 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
171 *
172 * @return the empty match.
173 *
174 */
175 public static X_inv13.Match newEmptyMatch() {
176 return new Mutable(null);
177 }
178
179 /**
180 * Returns a mutable (partial) match.
181 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
182 *
183 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
184 * @return the new, mutable (partial) match object.
185 *
186 */
187 public static X_inv13.Match newMutableMatch(final Resident_Tax_Payer pTp) {
188 return new Mutable(pTp);
189 }
190
191 /**
192 * Returns a new (partial) match.
193 * This can be used e.g. to call the matcher with a partial match.
194 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
195 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
196 * @return the (partial) match object.
197 *
198 */
199 public static X_inv13.Match newMatch(final Resident_Tax_Payer pTp) {
200 return new Immutable(pTp);
201 }
202
203 private static final class Mutable extends X_inv13.Match {
204 Mutable(final Resident_Tax_Payer pTp) {
205 super(pTp);
206 }
207
208 @Override
209 public boolean isMutable() {
210 return true;
211 }
212 }
213
214 private static final class Immutable extends X_inv13.Match {
215 Immutable(final Resident_Tax_Payer pTp) {
216 super(pTp);
217 }
218
219 @Override
220 public boolean isMutable() {
221 return false;
222 }
223 }
224 }
225
226 /**
227 * Generated pattern matcher API of the queries.x_inv13 pattern,
228 * providing pattern-specific query methods.
229 *
230 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
231 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
232 *
233 * <p>Matches of the pattern will be represented as {@link Match}.
234 *
235 * <p>Original source:
236 * <code><pre>
237 * pattern x_inv13(tp : Resident_Tax_Payer) {
238 * Resident_Tax_Payer(tp);
239 * }
240 * </pre></code>
241 *
242 * @see Match
243 * @see X_inv13
244 *
245 */
246 public static class Matcher extends BaseMatcher<X_inv13.Match> {
247 /**
248 * Initializes the pattern matcher within an existing VIATRA Query engine.
249 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
250 *
251 * @param engine the existing VIATRA Query engine in which this matcher will be created.
252 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
253 *
254 */
255 public static X_inv13.Matcher on(final ViatraQueryEngine engine) {
256 // check if matcher already exists
257 Matcher matcher = engine.getExistingMatcher(querySpecification());
258 if (matcher == null) {
259 matcher = (Matcher)engine.getMatcher(querySpecification());
260 }
261 return matcher;
262 }
263
264 /**
265 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
266 * @return an initialized matcher
267 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
268 *
269 */
270 public static X_inv13.Matcher create() {
271 return new Matcher();
272 }
273
274 private static final int POSITION_TP = 0;
275
276 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv13.Matcher.class);
277
278 /**
279 * Initializes the pattern matcher within an existing VIATRA Query engine.
280 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
281 *
282 * @param engine the existing VIATRA Query engine in which this matcher will be created.
283 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
284 *
285 */
286 private Matcher() {
287 super(querySpecification());
288 }
289
290 /**
291 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
292 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
293 * @return matches represented as a Match object.
294 *
295 */
296 public Collection<X_inv13.Match> getAllMatches(final Resident_Tax_Payer pTp) {
297 return rawStreamAllMatches(new Object[]{pTp}).collect(Collectors.toSet());
298 }
299
300 /**
301 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
302 * </p>
303 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
304 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
305 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
306 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
307 * @return a stream of matches represented as a Match object.
308 *
309 */
310 public Stream<X_inv13.Match> streamAllMatches(final Resident_Tax_Payer pTp) {
311 return rawStreamAllMatches(new Object[]{pTp});
312 }
313
314 /**
315 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
316 * Neither determinism nor randomness of selection is guaranteed.
317 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
318 * @return a match represented as a Match object, or null if no match is found.
319 *
320 */
321 public Optional<X_inv13.Match> getOneArbitraryMatch(final Resident_Tax_Payer pTp) {
322 return rawGetOneArbitraryMatch(new Object[]{pTp});
323 }
324
325 /**
326 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
327 * under any possible substitution of the unspecified parameters (if any).
328 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
329 * @return true if the input is a valid (partial) match of the pattern.
330 *
331 */
332 public boolean hasMatch(final Resident_Tax_Payer pTp) {
333 return rawHasMatch(new Object[]{pTp});
334 }
335
336 /**
337 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
338 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
339 * @return the number of pattern matches found.
340 *
341 */
342 public int countMatches(final Resident_Tax_Payer pTp) {
343 return rawCountMatches(new Object[]{pTp});
344 }
345
346 /**
347 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
348 * Neither determinism nor randomness of selection is guaranteed.
349 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
350 * @param processor the action that will process the selected match.
351 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
352 *
353 */
354 public boolean forOneArbitraryMatch(final Resident_Tax_Payer pTp, final Consumer<? super X_inv13.Match> processor) {
355 return rawForOneArbitraryMatch(new Object[]{pTp}, processor);
356 }
357
358 /**
359 * Returns a new (partial) match.
360 * This can be used e.g. to call the matcher with a partial match.
361 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
362 * @param pTp the fixed value of pattern parameter tp, or null if not bound.
363 * @return the (partial) match object.
364 *
365 */
366 public X_inv13.Match newMatch(final Resident_Tax_Payer pTp) {
367 return X_inv13.Match.newMatch(pTp);
368 }
369
370 /**
371 * Retrieve the set of values that occur in matches for tp.
372 * @return the Set of all values or empty set if there are no matches
373 *
374 */
375 protected Stream<Resident_Tax_Payer> rawStreamAllValuesOftp(final Object[] parameters) {
376 return rawStreamAllValues(POSITION_TP, parameters).map(Resident_Tax_Payer.class::cast);
377 }
378
379 /**
380 * Retrieve the set of values that occur in matches for tp.
381 * @return the Set of all values or empty set if there are no matches
382 *
383 */
384 public Set<Resident_Tax_Payer> getAllValuesOftp() {
385 return rawStreamAllValuesOftp(emptyArray()).collect(Collectors.toSet());
386 }
387
388 /**
389 * Retrieve the set of values that occur in matches for tp.
390 * @return the Set of all values or empty set if there are no matches
391 *
392 */
393 public Stream<Resident_Tax_Payer> streamAllValuesOftp() {
394 return rawStreamAllValuesOftp(emptyArray());
395 }
396
397 @Override
398 protected X_inv13.Match tupleToMatch(final Tuple t) {
399 try {
400 return X_inv13.Match.newMatch((Resident_Tax_Payer) t.get(POSITION_TP));
401 } catch(ClassCastException e) {
402 LOGGER.error("Element(s) in tuple not properly typed!",e);
403 return null;
404 }
405 }
406
407 @Override
408 protected X_inv13.Match arrayToMatch(final Object[] match) {
409 try {
410 return X_inv13.Match.newMatch((Resident_Tax_Payer) match[POSITION_TP]);
411 } catch(ClassCastException e) {
412 LOGGER.error("Element(s) in array not properly typed!",e);
413 return null;
414 }
415 }
416
417 @Override
418 protected X_inv13.Match arrayToMatchMutable(final Object[] match) {
419 try {
420 return X_inv13.Match.newMutableMatch((Resident_Tax_Payer) match[POSITION_TP]);
421 } catch(ClassCastException e) {
422 LOGGER.error("Element(s) in array not properly typed!",e);
423 return null;
424 }
425 }
426
427 /**
428 * @return the singleton instance of the query specification of this pattern
429 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
430 *
431 */
432 public static IQuerySpecification<X_inv13.Matcher> querySpecification() {
433 return X_inv13.instance();
434 }
435 }
436
437 private X_inv13() {
438 super(GeneratedPQuery.INSTANCE);
439 }
440
441 /**
442 * @return the singleton instance of the query specification
443 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
444 *
445 */
446 public static X_inv13 instance() {
447 try{
448 return LazyHolder.INSTANCE;
449 } catch (ExceptionInInitializerError err) {
450 throw processInitializerError(err);
451 }
452 }
453
454 @Override
455 protected X_inv13.Matcher instantiate(final ViatraQueryEngine engine) {
456 return X_inv13.Matcher.on(engine);
457 }
458
459 @Override
460 public X_inv13.Matcher instantiate() {
461 return X_inv13.Matcher.create();
462 }
463
464 @Override
465 public X_inv13.Match newEmptyMatch() {
466 return X_inv13.Match.newEmptyMatch();
467 }
468
469 @Override
470 public X_inv13.Match newMatch(final Object... parameters) {
471 return X_inv13.Match.newMatch((Taxation.Resident_Tax_Payer) parameters[0]);
472 }
473
474 /**
475 * Inner class allowing the singleton instance of {@link X_inv13} to be created
476 * <b>not</b> at the class load time of the outer class,
477 * but rather at the first call to {@link X_inv13#instance()}.
478 *
479 * <p> This workaround is required e.g. to support recursion.
480 *
481 */
482 private static class LazyHolder {
483 private static final X_inv13 INSTANCE = new X_inv13();
484
485 /**
486 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
487 * This initialization order is required to support indirect recursion.
488 *
489 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
490 *
491 */
492 private static final Object STATIC_INITIALIZER = ensureInitialized();
493
494 public static Object ensureInitialized() {
495 INSTANCE.ensureInitializedInternal();
496 return null;
497 }
498 }
499
500 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
501 private static final X_inv13.GeneratedPQuery INSTANCE = new GeneratedPQuery();
502
503 private final PParameter parameter_tp = new PParameter("tp", "Taxation.Resident_Tax_Payer", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Resident_Tax_Payer")), PParameterDirection.INOUT);
504
505 private final List<PParameter> parameters = Arrays.asList(parameter_tp);
506
507 private GeneratedPQuery() {
508 super(PVisibility.PUBLIC);
509 }
510
511 @Override
512 public String getFullyQualifiedName() {
513 return "queries.x_inv13";
514 }
515
516 @Override
517 public List<String> getParameterNames() {
518 return Arrays.asList("tp");
519 }
520
521 @Override
522 public List<PParameter> getParameters() {
523 return parameters;
524 }
525
526 @Override
527 public Set<PBody> doGetContainedBodies() {
528 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
529 Set<PBody> bodies = new LinkedHashSet<>();
530 {
531 PBody body = new PBody(this);
532 PVariable var_tp = body.getOrCreateVariableByName("tp");
533 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Resident_Tax_Payer")));
534 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
535 new ExportedParameter(body, var_tp, parameter_tp)
536 ));
537 // Resident_Tax_Payer(tp)
538 new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Resident_Tax_Payer")));
539 bodies.add(body);
540 }
541 return bodies;
542 }
543 }
544}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv15.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv15.java
new file mode 100644
index 00000000..70d0a290
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv15.java
@@ -0,0 +1,637 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.External_Allowance;
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 x_inv15(ea : External_Allowance) {
47 * External_Allowance.person(ea, child);
48 * Household.children(h, child);//only one due to multiplicity
49 * Household.parents.individual_A(h, iA);
50 * Tax_Payer(iA);
51 * External_Allowance.reciver(ea, iA);
52 * } or {
53 * External_Allowance.person(ea, child);
54 * Household.children(h, child);//only one due to multiplicity
55 * Household.parents.individual_B(h, iB);
56 * Tax_Payer(iB);
57 * External_Allowance.reciver(ea, iB);
58 * }
59 * </pre></code>
60 *
61 * @see Matcher
62 * @see Match
63 *
64 */
65@SuppressWarnings("all")
66public final class X_inv15 extends BaseGeneratedEMFQuerySpecification<X_inv15.Matcher> {
67 /**
68 * Pattern-specific match representation of the queries.x_inv15 pattern,
69 * to be used in conjunction with {@link Matcher}.
70 *
71 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
72 * Each instance is a (possibly partial) substitution of pattern parameters,
73 * usable to represent a match of the pattern in the result of a query,
74 * or to specify the bound (fixed) input parameters when issuing a query.
75 *
76 * @see Matcher
77 *
78 */
79 public static abstract class Match extends BasePatternMatch {
80 private External_Allowance fEa;
81
82 private static List<String> parameterNames = makeImmutableList("ea");
83
84 private Match(final External_Allowance pEa) {
85 this.fEa = pEa;
86 }
87
88 @Override
89 public Object get(final String parameterName) {
90 switch(parameterName) {
91 case "ea": return this.fEa;
92 default: return null;
93 }
94 }
95
96 @Override
97 public Object get(final int index) {
98 switch(index) {
99 case 0: return this.fEa;
100 default: return null;
101 }
102 }
103
104 public External_Allowance getEa() {
105 return this.fEa;
106 }
107
108 @Override
109 public boolean set(final String parameterName, final Object newValue) {
110 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
111 if ("ea".equals(parameterName) ) {
112 this.fEa = (External_Allowance) newValue;
113 return true;
114 }
115 return false;
116 }
117
118 public void setEa(final External_Allowance pEa) {
119 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
120 this.fEa = pEa;
121 }
122
123 @Override
124 public String patternName() {
125 return "queries.x_inv15";
126 }
127
128 @Override
129 public List<String> parameterNames() {
130 return X_inv15.Match.parameterNames;
131 }
132
133 @Override
134 public Object[] toArray() {
135 return new Object[]{fEa};
136 }
137
138 @Override
139 public X_inv15.Match toImmutable() {
140 return isMutable() ? newMatch(fEa) : this;
141 }
142
143 @Override
144 public String prettyPrint() {
145 StringBuilder result = new StringBuilder();
146 result.append("\"ea\"=" + prettyPrintValue(fEa));
147 return result.toString();
148 }
149
150 @Override
151 public int hashCode() {
152 return Objects.hash(fEa);
153 }
154
155 @Override
156 public boolean equals(final Object obj) {
157 if (this == obj)
158 return true;
159 if (obj == null) {
160 return false;
161 }
162 if ((obj instanceof X_inv15.Match)) {
163 X_inv15.Match other = (X_inv15.Match) obj;
164 return Objects.equals(fEa, other.fEa);
165 } else {
166 // this should be infrequent
167 if (!(obj instanceof IPatternMatch)) {
168 return false;
169 }
170 IPatternMatch otherSig = (IPatternMatch) obj;
171 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
172 }
173 }
174
175 @Override
176 public X_inv15 specification() {
177 return X_inv15.instance();
178 }
179
180 /**
181 * Returns an empty, mutable match.
182 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
183 *
184 * @return the empty match.
185 *
186 */
187 public static X_inv15.Match newEmptyMatch() {
188 return new Mutable(null);
189 }
190
191 /**
192 * Returns a mutable (partial) match.
193 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
194 *
195 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
196 * @return the new, mutable (partial) match object.
197 *
198 */
199 public static X_inv15.Match newMutableMatch(final External_Allowance pEa) {
200 return new Mutable(pEa);
201 }
202
203 /**
204 * Returns a new (partial) match.
205 * This can be used e.g. to call the matcher with a partial match.
206 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
207 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
208 * @return the (partial) match object.
209 *
210 */
211 public static X_inv15.Match newMatch(final External_Allowance pEa) {
212 return new Immutable(pEa);
213 }
214
215 private static final class Mutable extends X_inv15.Match {
216 Mutable(final External_Allowance pEa) {
217 super(pEa);
218 }
219
220 @Override
221 public boolean isMutable() {
222 return true;
223 }
224 }
225
226 private static final class Immutable extends X_inv15.Match {
227 Immutable(final External_Allowance pEa) {
228 super(pEa);
229 }
230
231 @Override
232 public boolean isMutable() {
233 return false;
234 }
235 }
236 }
237
238 /**
239 * Generated pattern matcher API of the queries.x_inv15 pattern,
240 * providing pattern-specific query methods.
241 *
242 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
243 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
244 *
245 * <p>Matches of the pattern will be represented as {@link Match}.
246 *
247 * <p>Original source:
248 * <code><pre>
249 * pattern x_inv15(ea : External_Allowance) {
250 * External_Allowance.person(ea, child);
251 * Household.children(h, child);//only one due to multiplicity
252 * Household.parents.individual_A(h, iA);
253 * Tax_Payer(iA);
254 * External_Allowance.reciver(ea, iA);
255 * } or {
256 * External_Allowance.person(ea, child);
257 * Household.children(h, child);//only one due to multiplicity
258 * Household.parents.individual_B(h, iB);
259 * Tax_Payer(iB);
260 * External_Allowance.reciver(ea, iB);
261 * }
262 * </pre></code>
263 *
264 * @see Match
265 * @see X_inv15
266 *
267 */
268 public static class Matcher extends BaseMatcher<X_inv15.Match> {
269 /**
270 * Initializes the pattern matcher within an existing VIATRA Query engine.
271 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
272 *
273 * @param engine the existing VIATRA Query engine in which this matcher will be created.
274 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
275 *
276 */
277 public static X_inv15.Matcher on(final ViatraQueryEngine engine) {
278 // check if matcher already exists
279 Matcher matcher = engine.getExistingMatcher(querySpecification());
280 if (matcher == null) {
281 matcher = (Matcher)engine.getMatcher(querySpecification());
282 }
283 return matcher;
284 }
285
286 /**
287 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
288 * @return an initialized matcher
289 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
290 *
291 */
292 public static X_inv15.Matcher create() {
293 return new Matcher();
294 }
295
296 private static final int POSITION_EA = 0;
297
298 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv15.Matcher.class);
299
300 /**
301 * Initializes the pattern matcher within an existing VIATRA Query engine.
302 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
303 *
304 * @param engine the existing VIATRA Query engine in which this matcher will be created.
305 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
306 *
307 */
308 private Matcher() {
309 super(querySpecification());
310 }
311
312 /**
313 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
314 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
315 * @return matches represented as a Match object.
316 *
317 */
318 public Collection<X_inv15.Match> getAllMatches(final External_Allowance pEa) {
319 return rawStreamAllMatches(new Object[]{pEa}).collect(Collectors.toSet());
320 }
321
322 /**
323 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
324 * </p>
325 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
326 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
327 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
328 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
329 * @return a stream of matches represented as a Match object.
330 *
331 */
332 public Stream<X_inv15.Match> streamAllMatches(final External_Allowance pEa) {
333 return rawStreamAllMatches(new Object[]{pEa});
334 }
335
336 /**
337 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
338 * Neither determinism nor randomness of selection is guaranteed.
339 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
340 * @return a match represented as a Match object, or null if no match is found.
341 *
342 */
343 public Optional<X_inv15.Match> getOneArbitraryMatch(final External_Allowance pEa) {
344 return rawGetOneArbitraryMatch(new Object[]{pEa});
345 }
346
347 /**
348 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
349 * under any possible substitution of the unspecified parameters (if any).
350 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
351 * @return true if the input is a valid (partial) match of the pattern.
352 *
353 */
354 public boolean hasMatch(final External_Allowance pEa) {
355 return rawHasMatch(new Object[]{pEa});
356 }
357
358 /**
359 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
360 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
361 * @return the number of pattern matches found.
362 *
363 */
364 public int countMatches(final External_Allowance pEa) {
365 return rawCountMatches(new Object[]{pEa});
366 }
367
368 /**
369 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
370 * Neither determinism nor randomness of selection is guaranteed.
371 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
372 * @param processor the action that will process the selected match.
373 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
374 *
375 */
376 public boolean forOneArbitraryMatch(final External_Allowance pEa, final Consumer<? super X_inv15.Match> processor) {
377 return rawForOneArbitraryMatch(new Object[]{pEa}, processor);
378 }
379
380 /**
381 * Returns a new (partial) match.
382 * This can be used e.g. to call the matcher with a partial match.
383 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
384 * @param pEa the fixed value of pattern parameter ea, or null if not bound.
385 * @return the (partial) match object.
386 *
387 */
388 public X_inv15.Match newMatch(final External_Allowance pEa) {
389 return X_inv15.Match.newMatch(pEa);
390 }
391
392 /**
393 * Retrieve the set of values that occur in matches for ea.
394 * @return the Set of all values or empty set if there are no matches
395 *
396 */
397 protected Stream<External_Allowance> rawStreamAllValuesOfea(final Object[] parameters) {
398 return rawStreamAllValues(POSITION_EA, parameters).map(External_Allowance.class::cast);
399 }
400
401 /**
402 * Retrieve the set of values that occur in matches for ea.
403 * @return the Set of all values or empty set if there are no matches
404 *
405 */
406 public Set<External_Allowance> getAllValuesOfea() {
407 return rawStreamAllValuesOfea(emptyArray()).collect(Collectors.toSet());
408 }
409
410 /**
411 * Retrieve the set of values that occur in matches for ea.
412 * @return the Set of all values or empty set if there are no matches
413 *
414 */
415 public Stream<External_Allowance> streamAllValuesOfea() {
416 return rawStreamAllValuesOfea(emptyArray());
417 }
418
419 @Override
420 protected X_inv15.Match tupleToMatch(final Tuple t) {
421 try {
422 return X_inv15.Match.newMatch((External_Allowance) t.get(POSITION_EA));
423 } catch(ClassCastException e) {
424 LOGGER.error("Element(s) in tuple not properly typed!",e);
425 return null;
426 }
427 }
428
429 @Override
430 protected X_inv15.Match arrayToMatch(final Object[] match) {
431 try {
432 return X_inv15.Match.newMatch((External_Allowance) match[POSITION_EA]);
433 } catch(ClassCastException e) {
434 LOGGER.error("Element(s) in array not properly typed!",e);
435 return null;
436 }
437 }
438
439 @Override
440 protected X_inv15.Match arrayToMatchMutable(final Object[] match) {
441 try {
442 return X_inv15.Match.newMutableMatch((External_Allowance) match[POSITION_EA]);
443 } catch(ClassCastException e) {
444 LOGGER.error("Element(s) in array not properly typed!",e);
445 return null;
446 }
447 }
448
449 /**
450 * @return the singleton instance of the query specification of this pattern
451 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
452 *
453 */
454 public static IQuerySpecification<X_inv15.Matcher> querySpecification() {
455 return X_inv15.instance();
456 }
457 }
458
459 private X_inv15() {
460 super(GeneratedPQuery.INSTANCE);
461 }
462
463 /**
464 * @return the singleton instance of the query specification
465 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
466 *
467 */
468 public static X_inv15 instance() {
469 try{
470 return LazyHolder.INSTANCE;
471 } catch (ExceptionInInitializerError err) {
472 throw processInitializerError(err);
473 }
474 }
475
476 @Override
477 protected X_inv15.Matcher instantiate(final ViatraQueryEngine engine) {
478 return X_inv15.Matcher.on(engine);
479 }
480
481 @Override
482 public X_inv15.Matcher instantiate() {
483 return X_inv15.Matcher.create();
484 }
485
486 @Override
487 public X_inv15.Match newEmptyMatch() {
488 return X_inv15.Match.newEmptyMatch();
489 }
490
491 @Override
492 public X_inv15.Match newMatch(final Object... parameters) {
493 return X_inv15.Match.newMatch((Taxation.External_Allowance) parameters[0]);
494 }
495
496 /**
497 * Inner class allowing the singleton instance of {@link X_inv15} to be created
498 * <b>not</b> at the class load time of the outer class,
499 * but rather at the first call to {@link X_inv15#instance()}.
500 *
501 * <p> This workaround is required e.g. to support recursion.
502 *
503 */
504 private static class LazyHolder {
505 private static final X_inv15 INSTANCE = new X_inv15();
506
507 /**
508 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
509 * This initialization order is required to support indirect recursion.
510 *
511 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
512 *
513 */
514 private static final Object STATIC_INITIALIZER = ensureInitialized();
515
516 public static Object ensureInitialized() {
517 INSTANCE.ensureInitializedInternal();
518 return null;
519 }
520 }
521
522 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
523 private static final X_inv15.GeneratedPQuery INSTANCE = new GeneratedPQuery();
524
525 private final PParameter parameter_ea = new PParameter("ea", "Taxation.External_Allowance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "External_Allowance")), PParameterDirection.INOUT);
526
527 private final List<PParameter> parameters = Arrays.asList(parameter_ea);
528
529 private GeneratedPQuery() {
530 super(PVisibility.PUBLIC);
531 }
532
533 @Override
534 public String getFullyQualifiedName() {
535 return "queries.x_inv15";
536 }
537
538 @Override
539 public List<String> getParameterNames() {
540 return Arrays.asList("ea");
541 }
542
543 @Override
544 public List<PParameter> getParameters() {
545 return parameters;
546 }
547
548 @Override
549 public Set<PBody> doGetContainedBodies() {
550 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
551 Set<PBody> bodies = new LinkedHashSet<>();
552 {
553 PBody body = new PBody(this);
554 PVariable var_ea = body.getOrCreateVariableByName("ea");
555 PVariable var_child = body.getOrCreateVariableByName("child");
556 PVariable var_h = body.getOrCreateVariableByName("h");
557 PVariable var_iA = body.getOrCreateVariableByName("iA");
558 new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance")));
559 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
560 new ExportedParameter(body, var_ea, parameter_ea)
561 ));
562 // External_Allowance.person(ea, child)
563 new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance")));
564 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
565 new TypeConstraint(body, Tuples.flatTupleOf(var_ea, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "External_Allowance", "person")));
566 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
567 new Equality(body, var__virtual_0_, var_child);
568 // Household.children(h, child)
569 new TypeConstraint(body, Tuples.flatTupleOf(var_h), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Household")));
570 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
571 new TypeConstraint(body, Tuples.flatTupleOf(var_h, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Household", "children")));
572 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
573 new Equality(body, var__virtual_1_, var_child);
574 // //only one due to multiplicity Household.parents.individual_A(h, iA)
575 new TypeConstraint(body, Tuples.flatTupleOf(var_h), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Household")));
576 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
577 new TypeConstraint(body, Tuples.flatTupleOf(var_h, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Household", "parents")));
578 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
579 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
580 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "individual_A")));
581 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
582 new Equality(body, var__virtual_3_, var_iA);
583 // Tax_Payer(iA)
584 new TypeConstraint(body, Tuples.flatTupleOf(var_iA), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
585 // External_Allowance.reciver(ea, iA)
586 new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance")));
587 PVariable var__virtual_4_ = body.getOrCreateVariableByName(".virtual{4}");
588 new TypeConstraint(body, Tuples.flatTupleOf(var_ea, var__virtual_4_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "External_Allowance", "reciver")));
589 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
590 new Equality(body, var__virtual_4_, var_iA);
591 bodies.add(body);
592 }
593 {
594 PBody body = new PBody(this);
595 PVariable var_ea = body.getOrCreateVariableByName("ea");
596 PVariable var_child = body.getOrCreateVariableByName("child");
597 PVariable var_h = body.getOrCreateVariableByName("h");
598 PVariable var_iB = body.getOrCreateVariableByName("iB");
599 new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance")));
600 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
601 new ExportedParameter(body, var_ea, parameter_ea)
602 ));
603 // External_Allowance.person(ea, child)
604 new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance")));
605 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
606 new TypeConstraint(body, Tuples.flatTupleOf(var_ea, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "External_Allowance", "person")));
607 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
608 new Equality(body, var__virtual_0_, var_child);
609 // Household.children(h, child)
610 new TypeConstraint(body, Tuples.flatTupleOf(var_h), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Household")));
611 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
612 new TypeConstraint(body, Tuples.flatTupleOf(var_h, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Household", "children")));
613 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
614 new Equality(body, var__virtual_1_, var_child);
615 // //only one due to multiplicity Household.parents.individual_B(h, iB)
616 new TypeConstraint(body, Tuples.flatTupleOf(var_h), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Household")));
617 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
618 new TypeConstraint(body, Tuples.flatTupleOf(var_h, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Household", "parents")));
619 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
620 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
621 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "individual_B")));
622 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
623 new Equality(body, var__virtual_3_, var_iB);
624 // Tax_Payer(iB)
625 new TypeConstraint(body, Tuples.flatTupleOf(var_iB), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
626 // External_Allowance.reciver(ea, iB)
627 new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance")));
628 PVariable var__virtual_4_ = body.getOrCreateVariableByName(".virtual{4}");
629 new TypeConstraint(body, Tuples.flatTupleOf(var_ea, var__virtual_4_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "External_Allowance", "reciver")));
630 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
631 new Equality(body, var__virtual_4_, var_iB);
632 bodies.add(body);
633 }
634 return bodies;
635 }
636 }
637}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv47.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv47.java
new file mode 100644
index 00000000..c1477d21
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv47.java
@@ -0,0 +1,569 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Legal_Union_Record;
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.PBody;
32import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
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.ConstantValue;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
38import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
40import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
41import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
42import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
43
44/**
45 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
46 *
47 * <p>Original source:
48 * <code><pre>
49 * pattern x_inv47(lur : Legal_Union_Record) {
50 * Legal_Union_Record.separation_cause(lur, ::NONE);
51 * Legal_Union_Record.end_year(lur, -1);
52 * }
53 * </pre></code>
54 *
55 * @see Matcher
56 * @see Match
57 *
58 */
59@SuppressWarnings("all")
60public final class X_inv47 extends BaseGeneratedEMFQuerySpecification<X_inv47.Matcher> {
61 /**
62 * Pattern-specific match representation of the queries.x_inv47 pattern,
63 * to be used in conjunction with {@link Matcher}.
64 *
65 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
66 * Each instance is a (possibly partial) substitution of pattern parameters,
67 * usable to represent a match of the pattern in the result of a query,
68 * or to specify the bound (fixed) input parameters when issuing a query.
69 *
70 * @see Matcher
71 *
72 */
73 public static abstract class Match extends BasePatternMatch {
74 private Legal_Union_Record fLur;
75
76 private static List<String> parameterNames = makeImmutableList("lur");
77
78 private Match(final Legal_Union_Record pLur) {
79 this.fLur = pLur;
80 }
81
82 @Override
83 public Object get(final String parameterName) {
84 switch(parameterName) {
85 case "lur": return this.fLur;
86 default: return null;
87 }
88 }
89
90 @Override
91 public Object get(final int index) {
92 switch(index) {
93 case 0: return this.fLur;
94 default: return null;
95 }
96 }
97
98 public Legal_Union_Record getLur() {
99 return this.fLur;
100 }
101
102 @Override
103 public boolean set(final String parameterName, final Object newValue) {
104 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
105 if ("lur".equals(parameterName) ) {
106 this.fLur = (Legal_Union_Record) newValue;
107 return true;
108 }
109 return false;
110 }
111
112 public void setLur(final Legal_Union_Record pLur) {
113 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
114 this.fLur = pLur;
115 }
116
117 @Override
118 public String patternName() {
119 return "queries.x_inv47";
120 }
121
122 @Override
123 public List<String> parameterNames() {
124 return X_inv47.Match.parameterNames;
125 }
126
127 @Override
128 public Object[] toArray() {
129 return new Object[]{fLur};
130 }
131
132 @Override
133 public X_inv47.Match toImmutable() {
134 return isMutable() ? newMatch(fLur) : this;
135 }
136
137 @Override
138 public String prettyPrint() {
139 StringBuilder result = new StringBuilder();
140 result.append("\"lur\"=" + prettyPrintValue(fLur));
141 return result.toString();
142 }
143
144 @Override
145 public int hashCode() {
146 return Objects.hash(fLur);
147 }
148
149 @Override
150 public boolean equals(final Object obj) {
151 if (this == obj)
152 return true;
153 if (obj == null) {
154 return false;
155 }
156 if ((obj instanceof X_inv47.Match)) {
157 X_inv47.Match other = (X_inv47.Match) obj;
158 return Objects.equals(fLur, other.fLur);
159 } else {
160 // this should be infrequent
161 if (!(obj instanceof IPatternMatch)) {
162 return false;
163 }
164 IPatternMatch otherSig = (IPatternMatch) obj;
165 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
166 }
167 }
168
169 @Override
170 public X_inv47 specification() {
171 return X_inv47.instance();
172 }
173
174 /**
175 * Returns an empty, mutable match.
176 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
177 *
178 * @return the empty match.
179 *
180 */
181 public static X_inv47.Match newEmptyMatch() {
182 return new Mutable(null);
183 }
184
185 /**
186 * Returns a mutable (partial) match.
187 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
188 *
189 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
190 * @return the new, mutable (partial) match object.
191 *
192 */
193 public static X_inv47.Match newMutableMatch(final Legal_Union_Record pLur) {
194 return new Mutable(pLur);
195 }
196
197 /**
198 * Returns a new (partial) match.
199 * This can be used e.g. to call the matcher with a partial match.
200 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
201 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
202 * @return the (partial) match object.
203 *
204 */
205 public static X_inv47.Match newMatch(final Legal_Union_Record pLur) {
206 return new Immutable(pLur);
207 }
208
209 private static final class Mutable extends X_inv47.Match {
210 Mutable(final Legal_Union_Record pLur) {
211 super(pLur);
212 }
213
214 @Override
215 public boolean isMutable() {
216 return true;
217 }
218 }
219
220 private static final class Immutable extends X_inv47.Match {
221 Immutable(final Legal_Union_Record pLur) {
222 super(pLur);
223 }
224
225 @Override
226 public boolean isMutable() {
227 return false;
228 }
229 }
230 }
231
232 /**
233 * Generated pattern matcher API of the queries.x_inv47 pattern,
234 * providing pattern-specific query methods.
235 *
236 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
237 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
238 *
239 * <p>Matches of the pattern will be represented as {@link Match}.
240 *
241 * <p>Original source:
242 * <code><pre>
243 * pattern x_inv47(lur : Legal_Union_Record) {
244 * Legal_Union_Record.separation_cause(lur, ::NONE);
245 * Legal_Union_Record.end_year(lur, -1);
246 * }
247 * </pre></code>
248 *
249 * @see Match
250 * @see X_inv47
251 *
252 */
253 public static class Matcher extends BaseMatcher<X_inv47.Match> {
254 /**
255 * Initializes the pattern matcher within an existing VIATRA Query engine.
256 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
257 *
258 * @param engine the existing VIATRA Query engine in which this matcher will be created.
259 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
260 *
261 */
262 public static X_inv47.Matcher on(final ViatraQueryEngine engine) {
263 // check if matcher already exists
264 Matcher matcher = engine.getExistingMatcher(querySpecification());
265 if (matcher == null) {
266 matcher = (Matcher)engine.getMatcher(querySpecification());
267 }
268 return matcher;
269 }
270
271 /**
272 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
273 * @return an initialized matcher
274 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
275 *
276 */
277 public static X_inv47.Matcher create() {
278 return new Matcher();
279 }
280
281 private static final int POSITION_LUR = 0;
282
283 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv47.Matcher.class);
284
285 /**
286 * Initializes the pattern matcher within an existing VIATRA Query engine.
287 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
288 *
289 * @param engine the existing VIATRA Query engine in which this matcher will be created.
290 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
291 *
292 */
293 private Matcher() {
294 super(querySpecification());
295 }
296
297 /**
298 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
299 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
300 * @return matches represented as a Match object.
301 *
302 */
303 public Collection<X_inv47.Match> getAllMatches(final Legal_Union_Record pLur) {
304 return rawStreamAllMatches(new Object[]{pLur}).collect(Collectors.toSet());
305 }
306
307 /**
308 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
309 * </p>
310 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
311 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
312 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
313 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
314 * @return a stream of matches represented as a Match object.
315 *
316 */
317 public Stream<X_inv47.Match> streamAllMatches(final Legal_Union_Record pLur) {
318 return rawStreamAllMatches(new Object[]{pLur});
319 }
320
321 /**
322 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
323 * Neither determinism nor randomness of selection is guaranteed.
324 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
325 * @return a match represented as a Match object, or null if no match is found.
326 *
327 */
328 public Optional<X_inv47.Match> getOneArbitraryMatch(final Legal_Union_Record pLur) {
329 return rawGetOneArbitraryMatch(new Object[]{pLur});
330 }
331
332 /**
333 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
334 * under any possible substitution of the unspecified parameters (if any).
335 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
336 * @return true if the input is a valid (partial) match of the pattern.
337 *
338 */
339 public boolean hasMatch(final Legal_Union_Record pLur) {
340 return rawHasMatch(new Object[]{pLur});
341 }
342
343 /**
344 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
345 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
346 * @return the number of pattern matches found.
347 *
348 */
349 public int countMatches(final Legal_Union_Record pLur) {
350 return rawCountMatches(new Object[]{pLur});
351 }
352
353 /**
354 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
355 * Neither determinism nor randomness of selection is guaranteed.
356 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
357 * @param processor the action that will process the selected match.
358 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
359 *
360 */
361 public boolean forOneArbitraryMatch(final Legal_Union_Record pLur, final Consumer<? super X_inv47.Match> processor) {
362 return rawForOneArbitraryMatch(new Object[]{pLur}, processor);
363 }
364
365 /**
366 * Returns a new (partial) match.
367 * This can be used e.g. to call the matcher with a partial match.
368 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
369 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
370 * @return the (partial) match object.
371 *
372 */
373 public X_inv47.Match newMatch(final Legal_Union_Record pLur) {
374 return X_inv47.Match.newMatch(pLur);
375 }
376
377 /**
378 * Retrieve the set of values that occur in matches for lur.
379 * @return the Set of all values or empty set if there are no matches
380 *
381 */
382 protected Stream<Legal_Union_Record> rawStreamAllValuesOflur(final Object[] parameters) {
383 return rawStreamAllValues(POSITION_LUR, parameters).map(Legal_Union_Record.class::cast);
384 }
385
386 /**
387 * Retrieve the set of values that occur in matches for lur.
388 * @return the Set of all values or empty set if there are no matches
389 *
390 */
391 public Set<Legal_Union_Record> getAllValuesOflur() {
392 return rawStreamAllValuesOflur(emptyArray()).collect(Collectors.toSet());
393 }
394
395 /**
396 * Retrieve the set of values that occur in matches for lur.
397 * @return the Set of all values or empty set if there are no matches
398 *
399 */
400 public Stream<Legal_Union_Record> streamAllValuesOflur() {
401 return rawStreamAllValuesOflur(emptyArray());
402 }
403
404 @Override
405 protected X_inv47.Match tupleToMatch(final Tuple t) {
406 try {
407 return X_inv47.Match.newMatch((Legal_Union_Record) t.get(POSITION_LUR));
408 } catch(ClassCastException e) {
409 LOGGER.error("Element(s) in tuple not properly typed!",e);
410 return null;
411 }
412 }
413
414 @Override
415 protected X_inv47.Match arrayToMatch(final Object[] match) {
416 try {
417 return X_inv47.Match.newMatch((Legal_Union_Record) match[POSITION_LUR]);
418 } catch(ClassCastException e) {
419 LOGGER.error("Element(s) in array not properly typed!",e);
420 return null;
421 }
422 }
423
424 @Override
425 protected X_inv47.Match arrayToMatchMutable(final Object[] match) {
426 try {
427 return X_inv47.Match.newMutableMatch((Legal_Union_Record) match[POSITION_LUR]);
428 } catch(ClassCastException e) {
429 LOGGER.error("Element(s) in array not properly typed!",e);
430 return null;
431 }
432 }
433
434 /**
435 * @return the singleton instance of the query specification of this pattern
436 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
437 *
438 */
439 public static IQuerySpecification<X_inv47.Matcher> querySpecification() {
440 return X_inv47.instance();
441 }
442 }
443
444 private X_inv47() {
445 super(GeneratedPQuery.INSTANCE);
446 }
447
448 /**
449 * @return the singleton instance of the query specification
450 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
451 *
452 */
453 public static X_inv47 instance() {
454 try{
455 return LazyHolder.INSTANCE;
456 } catch (ExceptionInInitializerError err) {
457 throw processInitializerError(err);
458 }
459 }
460
461 @Override
462 protected X_inv47.Matcher instantiate(final ViatraQueryEngine engine) {
463 return X_inv47.Matcher.on(engine);
464 }
465
466 @Override
467 public X_inv47.Matcher instantiate() {
468 return X_inv47.Matcher.create();
469 }
470
471 @Override
472 public X_inv47.Match newEmptyMatch() {
473 return X_inv47.Match.newEmptyMatch();
474 }
475
476 @Override
477 public X_inv47.Match newMatch(final Object... parameters) {
478 return X_inv47.Match.newMatch((Taxation.Legal_Union_Record) parameters[0]);
479 }
480
481 /**
482 * Inner class allowing the singleton instance of {@link X_inv47} to be created
483 * <b>not</b> at the class load time of the outer class,
484 * but rather at the first call to {@link X_inv47#instance()}.
485 *
486 * <p> This workaround is required e.g. to support recursion.
487 *
488 */
489 private static class LazyHolder {
490 private static final X_inv47 INSTANCE = new X_inv47();
491
492 /**
493 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
494 * This initialization order is required to support indirect recursion.
495 *
496 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
497 *
498 */
499 private static final Object STATIC_INITIALIZER = ensureInitialized();
500
501 public static Object ensureInitialized() {
502 INSTANCE.ensureInitializedInternal();
503 return null;
504 }
505 }
506
507 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
508 private static final X_inv47.GeneratedPQuery INSTANCE = new GeneratedPQuery();
509
510 private final PParameter parameter_lur = new PParameter("lur", "Taxation.Legal_Union_Record", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Legal_Union_Record")), PParameterDirection.INOUT);
511
512 private final List<PParameter> parameters = Arrays.asList(parameter_lur);
513
514 private GeneratedPQuery() {
515 super(PVisibility.PUBLIC);
516 }
517
518 @Override
519 public String getFullyQualifiedName() {
520 return "queries.x_inv47";
521 }
522
523 @Override
524 public List<String> getParameterNames() {
525 return Arrays.asList("lur");
526 }
527
528 @Override
529 public List<PParameter> getParameters() {
530 return parameters;
531 }
532
533 @Override
534 public Set<PBody> doGetContainedBodies() {
535 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
536 Set<PBody> bodies = new LinkedHashSet<>();
537 {
538 PBody body = new PBody(this);
539 PVariable var_lur = body.getOrCreateVariableByName("lur");
540 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
541 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
542 new ExportedParameter(body, var_lur, parameter_lur)
543 ));
544 // Legal_Union_Record.separation_cause(lur, ::NONE)
545 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
546 new ConstantValue(body, var__virtual_0_, getEnumLiteral("http:///TaxCard.ecore", "Separation_Causes", "NONE").getInstance());
547 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
548 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
549 new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "separation_cause")));
550 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http:///TaxCard.ecore", "Separation_Causes")));
551 new Equality(body, var__virtual_1_, var__virtual_0_);
552 // Legal_Union_Record.end_year(lur, -1)
553 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
554 new ConstantValue(body, var__virtual_2_, -1);
555 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
556 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
557 new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "end_year")));
558 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
559 new Equality(body, var__virtual_3_, var__virtual_2_);
560 bodies.add(body);
561 }
562 return bodies;
563 }
564 }
565
566 private static int evaluateExpression_1_1() {
567 return 1;
568 }
569}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_3.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_3.java
new file mode 100644
index 00000000..2a522290
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_3.java
@@ -0,0 +1,555 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Physical_Person;
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.PBody;
32import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
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.ConstantValue;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
38import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
40import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
41import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
42import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
43
44/**
45 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
46 *
47 * <p>Original source:
48 * <code><pre>
49 * pattern x_inv48_3(p : Physical_Person) {
50 * Physical_Person.disability_type(p, ::NONE);
51 * }
52 * </pre></code>
53 *
54 * @see Matcher
55 * @see Match
56 *
57 */
58@SuppressWarnings("all")
59public final class X_inv48_3 extends BaseGeneratedEMFQuerySpecification<X_inv48_3.Matcher> {
60 /**
61 * Pattern-specific match representation of the queries.x_inv48_3 pattern,
62 * to be used in conjunction with {@link Matcher}.
63 *
64 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
65 * Each instance is a (possibly partial) substitution of pattern parameters,
66 * usable to represent a match of the pattern in the result of a query,
67 * or to specify the bound (fixed) input parameters when issuing a query.
68 *
69 * @see Matcher
70 *
71 */
72 public static abstract class Match extends BasePatternMatch {
73 private Physical_Person fP;
74
75 private static List<String> parameterNames = makeImmutableList("p");
76
77 private Match(final Physical_Person pP) {
78 this.fP = pP;
79 }
80
81 @Override
82 public Object get(final String parameterName) {
83 switch(parameterName) {
84 case "p": return this.fP;
85 default: return null;
86 }
87 }
88
89 @Override
90 public Object get(final int index) {
91 switch(index) {
92 case 0: return this.fP;
93 default: return null;
94 }
95 }
96
97 public Physical_Person getP() {
98 return this.fP;
99 }
100
101 @Override
102 public boolean set(final String parameterName, final Object newValue) {
103 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
104 if ("p".equals(parameterName) ) {
105 this.fP = (Physical_Person) newValue;
106 return true;
107 }
108 return false;
109 }
110
111 public void setP(final Physical_Person pP) {
112 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
113 this.fP = pP;
114 }
115
116 @Override
117 public String patternName() {
118 return "queries.x_inv48_3";
119 }
120
121 @Override
122 public List<String> parameterNames() {
123 return X_inv48_3.Match.parameterNames;
124 }
125
126 @Override
127 public Object[] toArray() {
128 return new Object[]{fP};
129 }
130
131 @Override
132 public X_inv48_3.Match toImmutable() {
133 return isMutable() ? newMatch(fP) : this;
134 }
135
136 @Override
137 public String prettyPrint() {
138 StringBuilder result = new StringBuilder();
139 result.append("\"p\"=" + prettyPrintValue(fP));
140 return result.toString();
141 }
142
143 @Override
144 public int hashCode() {
145 return Objects.hash(fP);
146 }
147
148 @Override
149 public boolean equals(final Object obj) {
150 if (this == obj)
151 return true;
152 if (obj == null) {
153 return false;
154 }
155 if ((obj instanceof X_inv48_3.Match)) {
156 X_inv48_3.Match other = (X_inv48_3.Match) obj;
157 return Objects.equals(fP, other.fP);
158 } else {
159 // this should be infrequent
160 if (!(obj instanceof IPatternMatch)) {
161 return false;
162 }
163 IPatternMatch otherSig = (IPatternMatch) obj;
164 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
165 }
166 }
167
168 @Override
169 public X_inv48_3 specification() {
170 return X_inv48_3.instance();
171 }
172
173 /**
174 * Returns an empty, mutable match.
175 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
176 *
177 * @return the empty match.
178 *
179 */
180 public static X_inv48_3.Match newEmptyMatch() {
181 return new Mutable(null);
182 }
183
184 /**
185 * Returns a mutable (partial) match.
186 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
187 *
188 * @param pP the fixed value of pattern parameter p, or null if not bound.
189 * @return the new, mutable (partial) match object.
190 *
191 */
192 public static X_inv48_3.Match newMutableMatch(final Physical_Person pP) {
193 return new Mutable(pP);
194 }
195
196 /**
197 * Returns a new (partial) match.
198 * This can be used e.g. to call the matcher with a partial match.
199 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
200 * @param pP the fixed value of pattern parameter p, or null if not bound.
201 * @return the (partial) match object.
202 *
203 */
204 public static X_inv48_3.Match newMatch(final Physical_Person pP) {
205 return new Immutable(pP);
206 }
207
208 private static final class Mutable extends X_inv48_3.Match {
209 Mutable(final Physical_Person pP) {
210 super(pP);
211 }
212
213 @Override
214 public boolean isMutable() {
215 return true;
216 }
217 }
218
219 private static final class Immutable extends X_inv48_3.Match {
220 Immutable(final Physical_Person pP) {
221 super(pP);
222 }
223
224 @Override
225 public boolean isMutable() {
226 return false;
227 }
228 }
229 }
230
231 /**
232 * Generated pattern matcher API of the queries.x_inv48_3 pattern,
233 * providing pattern-specific query methods.
234 *
235 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
236 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
237 *
238 * <p>Matches of the pattern will be represented as {@link Match}.
239 *
240 * <p>Original source:
241 * <code><pre>
242 * pattern x_inv48_3(p : Physical_Person) {
243 * Physical_Person.disability_type(p, ::NONE);
244 * }
245 * </pre></code>
246 *
247 * @see Match
248 * @see X_inv48_3
249 *
250 */
251 public static class Matcher extends BaseMatcher<X_inv48_3.Match> {
252 /**
253 * Initializes the pattern matcher within an existing VIATRA Query engine.
254 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
255 *
256 * @param engine the existing VIATRA Query engine in which this matcher will be created.
257 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
258 *
259 */
260 public static X_inv48_3.Matcher on(final ViatraQueryEngine engine) {
261 // check if matcher already exists
262 Matcher matcher = engine.getExistingMatcher(querySpecification());
263 if (matcher == null) {
264 matcher = (Matcher)engine.getMatcher(querySpecification());
265 }
266 return matcher;
267 }
268
269 /**
270 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
271 * @return an initialized matcher
272 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
273 *
274 */
275 public static X_inv48_3.Matcher create() {
276 return new Matcher();
277 }
278
279 private static final int POSITION_P = 0;
280
281 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv48_3.Matcher.class);
282
283 /**
284 * Initializes the pattern matcher within an existing VIATRA Query engine.
285 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
286 *
287 * @param engine the existing VIATRA Query engine in which this matcher will be created.
288 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
289 *
290 */
291 private Matcher() {
292 super(querySpecification());
293 }
294
295 /**
296 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
297 * @param pP the fixed value of pattern parameter p, or null if not bound.
298 * @return matches represented as a Match object.
299 *
300 */
301 public Collection<X_inv48_3.Match> getAllMatches(final Physical_Person pP) {
302 return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet());
303 }
304
305 /**
306 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
307 * </p>
308 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
309 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
310 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
311 * @param pP the fixed value of pattern parameter p, or null if not bound.
312 * @return a stream of matches represented as a Match object.
313 *
314 */
315 public Stream<X_inv48_3.Match> streamAllMatches(final Physical_Person pP) {
316 return rawStreamAllMatches(new Object[]{pP});
317 }
318
319 /**
320 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
321 * Neither determinism nor randomness of selection is guaranteed.
322 * @param pP the fixed value of pattern parameter p, or null if not bound.
323 * @return a match represented as a Match object, or null if no match is found.
324 *
325 */
326 public Optional<X_inv48_3.Match> getOneArbitraryMatch(final Physical_Person pP) {
327 return rawGetOneArbitraryMatch(new Object[]{pP});
328 }
329
330 /**
331 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
332 * under any possible substitution of the unspecified parameters (if any).
333 * @param pP the fixed value of pattern parameter p, or null if not bound.
334 * @return true if the input is a valid (partial) match of the pattern.
335 *
336 */
337 public boolean hasMatch(final Physical_Person pP) {
338 return rawHasMatch(new Object[]{pP});
339 }
340
341 /**
342 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
343 * @param pP the fixed value of pattern parameter p, or null if not bound.
344 * @return the number of pattern matches found.
345 *
346 */
347 public int countMatches(final Physical_Person pP) {
348 return rawCountMatches(new Object[]{pP});
349 }
350
351 /**
352 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
353 * Neither determinism nor randomness of selection is guaranteed.
354 * @param pP the fixed value of pattern parameter p, or null if not bound.
355 * @param processor the action that will process the selected match.
356 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
357 *
358 */
359 public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer<? super X_inv48_3.Match> processor) {
360 return rawForOneArbitraryMatch(new Object[]{pP}, processor);
361 }
362
363 /**
364 * Returns a new (partial) match.
365 * This can be used e.g. to call the matcher with a partial match.
366 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
367 * @param pP the fixed value of pattern parameter p, or null if not bound.
368 * @return the (partial) match object.
369 *
370 */
371 public X_inv48_3.Match newMatch(final Physical_Person pP) {
372 return X_inv48_3.Match.newMatch(pP);
373 }
374
375 /**
376 * Retrieve the set of values that occur in matches for p.
377 * @return the Set of all values or empty set if there are no matches
378 *
379 */
380 protected Stream<Physical_Person> rawStreamAllValuesOfp(final Object[] parameters) {
381 return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast);
382 }
383
384 /**
385 * Retrieve the set of values that occur in matches for p.
386 * @return the Set of all values or empty set if there are no matches
387 *
388 */
389 public Set<Physical_Person> getAllValuesOfp() {
390 return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet());
391 }
392
393 /**
394 * Retrieve the set of values that occur in matches for p.
395 * @return the Set of all values or empty set if there are no matches
396 *
397 */
398 public Stream<Physical_Person> streamAllValuesOfp() {
399 return rawStreamAllValuesOfp(emptyArray());
400 }
401
402 @Override
403 protected X_inv48_3.Match tupleToMatch(final Tuple t) {
404 try {
405 return X_inv48_3.Match.newMatch((Physical_Person) t.get(POSITION_P));
406 } catch(ClassCastException e) {
407 LOGGER.error("Element(s) in tuple not properly typed!",e);
408 return null;
409 }
410 }
411
412 @Override
413 protected X_inv48_3.Match arrayToMatch(final Object[] match) {
414 try {
415 return X_inv48_3.Match.newMatch((Physical_Person) match[POSITION_P]);
416 } catch(ClassCastException e) {
417 LOGGER.error("Element(s) in array not properly typed!",e);
418 return null;
419 }
420 }
421
422 @Override
423 protected X_inv48_3.Match arrayToMatchMutable(final Object[] match) {
424 try {
425 return X_inv48_3.Match.newMutableMatch((Physical_Person) match[POSITION_P]);
426 } catch(ClassCastException e) {
427 LOGGER.error("Element(s) in array not properly typed!",e);
428 return null;
429 }
430 }
431
432 /**
433 * @return the singleton instance of the query specification of this pattern
434 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
435 *
436 */
437 public static IQuerySpecification<X_inv48_3.Matcher> querySpecification() {
438 return X_inv48_3.instance();
439 }
440 }
441
442 private X_inv48_3() {
443 super(GeneratedPQuery.INSTANCE);
444 }
445
446 /**
447 * @return the singleton instance of the query specification
448 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
449 *
450 */
451 public static X_inv48_3 instance() {
452 try{
453 return LazyHolder.INSTANCE;
454 } catch (ExceptionInInitializerError err) {
455 throw processInitializerError(err);
456 }
457 }
458
459 @Override
460 protected X_inv48_3.Matcher instantiate(final ViatraQueryEngine engine) {
461 return X_inv48_3.Matcher.on(engine);
462 }
463
464 @Override
465 public X_inv48_3.Matcher instantiate() {
466 return X_inv48_3.Matcher.create();
467 }
468
469 @Override
470 public X_inv48_3.Match newEmptyMatch() {
471 return X_inv48_3.Match.newEmptyMatch();
472 }
473
474 @Override
475 public X_inv48_3.Match newMatch(final Object... parameters) {
476 return X_inv48_3.Match.newMatch((Taxation.Physical_Person) parameters[0]);
477 }
478
479 /**
480 * Inner class allowing the singleton instance of {@link X_inv48_3} to be created
481 * <b>not</b> at the class load time of the outer class,
482 * but rather at the first call to {@link X_inv48_3#instance()}.
483 *
484 * <p> This workaround is required e.g. to support recursion.
485 *
486 */
487 private static class LazyHolder {
488 private static final X_inv48_3 INSTANCE = new X_inv48_3();
489
490 /**
491 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
492 * This initialization order is required to support indirect recursion.
493 *
494 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
495 *
496 */
497 private static final Object STATIC_INITIALIZER = ensureInitialized();
498
499 public static Object ensureInitialized() {
500 INSTANCE.ensureInitializedInternal();
501 return null;
502 }
503 }
504
505 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
506 private static final X_inv48_3.GeneratedPQuery INSTANCE = new GeneratedPQuery();
507
508 private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT);
509
510 private final List<PParameter> parameters = Arrays.asList(parameter_p);
511
512 private GeneratedPQuery() {
513 super(PVisibility.PUBLIC);
514 }
515
516 @Override
517 public String getFullyQualifiedName() {
518 return "queries.x_inv48_3";
519 }
520
521 @Override
522 public List<String> getParameterNames() {
523 return Arrays.asList("p");
524 }
525
526 @Override
527 public List<PParameter> getParameters() {
528 return parameters;
529 }
530
531 @Override
532 public Set<PBody> doGetContainedBodies() {
533 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
534 Set<PBody> bodies = new LinkedHashSet<>();
535 {
536 PBody body = new PBody(this);
537 PVariable var_p = body.getOrCreateVariableByName("p");
538 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
539 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
540 new ExportedParameter(body, var_p, parameter_p)
541 ));
542 // Physical_Person.disability_type(p, ::NONE)
543 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
544 new ConstantValue(body, var__virtual_0_, getEnumLiteral("http:///TaxCard.ecore", "Disability_Types", "NONE").getInstance());
545 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
546 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
547 new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "disability_type")));
548 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http:///TaxCard.ecore", "Disability_Types")));
549 new Equality(body, var__virtual_1_, var__virtual_0_);
550 bodies.add(body);
551 }
552 return bodies;
553 }
554 }
555}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_Dis.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_Dis.java
new file mode 100644
index 00000000..2013f033
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_Dis.java
@@ -0,0 +1,610 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Physical_Person;
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.basicdeferred.Equality;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
39import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
42import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
43import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
44import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
45import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
46import queries.X_inv48_3;
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 * pattern x_inv48_Dis(p : Physical_Person) {
54 * neg find x_inv48_3(p);
55 * Physical_Person.disability_percentage(p, disPer);
56 * check(disPer {@literal >} 0.0);
57 * check(disPer {@literal <}= 1.0);
58 * }
59 * </pre></code>
60 *
61 * @see Matcher
62 * @see Match
63 *
64 */
65@SuppressWarnings("all")
66public final class X_inv48_Dis extends BaseGeneratedEMFQuerySpecification<X_inv48_Dis.Matcher> {
67 /**
68 * Pattern-specific match representation of the queries.x_inv48_Dis pattern,
69 * to be used in conjunction with {@link Matcher}.
70 *
71 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
72 * Each instance is a (possibly partial) substitution of pattern parameters,
73 * usable to represent a match of the pattern in the result of a query,
74 * or to specify the bound (fixed) input parameters when issuing a query.
75 *
76 * @see Matcher
77 *
78 */
79 public static abstract class Match extends BasePatternMatch {
80 private Physical_Person fP;
81
82 private static List<String> parameterNames = makeImmutableList("p");
83
84 private Match(final Physical_Person pP) {
85 this.fP = pP;
86 }
87
88 @Override
89 public Object get(final String parameterName) {
90 switch(parameterName) {
91 case "p": return this.fP;
92 default: return null;
93 }
94 }
95
96 @Override
97 public Object get(final int index) {
98 switch(index) {
99 case 0: return this.fP;
100 default: return null;
101 }
102 }
103
104 public Physical_Person getP() {
105 return this.fP;
106 }
107
108 @Override
109 public boolean set(final String parameterName, final Object newValue) {
110 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
111 if ("p".equals(parameterName) ) {
112 this.fP = (Physical_Person) newValue;
113 return true;
114 }
115 return false;
116 }
117
118 public void setP(final Physical_Person pP) {
119 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
120 this.fP = pP;
121 }
122
123 @Override
124 public String patternName() {
125 return "queries.x_inv48_Dis";
126 }
127
128 @Override
129 public List<String> parameterNames() {
130 return X_inv48_Dis.Match.parameterNames;
131 }
132
133 @Override
134 public Object[] toArray() {
135 return new Object[]{fP};
136 }
137
138 @Override
139 public X_inv48_Dis.Match toImmutable() {
140 return isMutable() ? newMatch(fP) : this;
141 }
142
143 @Override
144 public String prettyPrint() {
145 StringBuilder result = new StringBuilder();
146 result.append("\"p\"=" + prettyPrintValue(fP));
147 return result.toString();
148 }
149
150 @Override
151 public int hashCode() {
152 return Objects.hash(fP);
153 }
154
155 @Override
156 public boolean equals(final Object obj) {
157 if (this == obj)
158 return true;
159 if (obj == null) {
160 return false;
161 }
162 if ((obj instanceof X_inv48_Dis.Match)) {
163 X_inv48_Dis.Match other = (X_inv48_Dis.Match) obj;
164 return Objects.equals(fP, other.fP);
165 } else {
166 // this should be infrequent
167 if (!(obj instanceof IPatternMatch)) {
168 return false;
169 }
170 IPatternMatch otherSig = (IPatternMatch) obj;
171 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
172 }
173 }
174
175 @Override
176 public X_inv48_Dis specification() {
177 return X_inv48_Dis.instance();
178 }
179
180 /**
181 * Returns an empty, mutable match.
182 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
183 *
184 * @return the empty match.
185 *
186 */
187 public static X_inv48_Dis.Match newEmptyMatch() {
188 return new Mutable(null);
189 }
190
191 /**
192 * Returns a mutable (partial) match.
193 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
194 *
195 * @param pP the fixed value of pattern parameter p, or null if not bound.
196 * @return the new, mutable (partial) match object.
197 *
198 */
199 public static X_inv48_Dis.Match newMutableMatch(final Physical_Person pP) {
200 return new Mutable(pP);
201 }
202
203 /**
204 * Returns a new (partial) match.
205 * This can be used e.g. to call the matcher with a partial match.
206 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
207 * @param pP the fixed value of pattern parameter p, or null if not bound.
208 * @return the (partial) match object.
209 *
210 */
211 public static X_inv48_Dis.Match newMatch(final Physical_Person pP) {
212 return new Immutable(pP);
213 }
214
215 private static final class Mutable extends X_inv48_Dis.Match {
216 Mutable(final Physical_Person pP) {
217 super(pP);
218 }
219
220 @Override
221 public boolean isMutable() {
222 return true;
223 }
224 }
225
226 private static final class Immutable extends X_inv48_Dis.Match {
227 Immutable(final Physical_Person pP) {
228 super(pP);
229 }
230
231 @Override
232 public boolean isMutable() {
233 return false;
234 }
235 }
236 }
237
238 /**
239 * Generated pattern matcher API of the queries.x_inv48_Dis pattern,
240 * providing pattern-specific query methods.
241 *
242 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
243 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
244 *
245 * <p>Matches of the pattern will be represented as {@link Match}.
246 *
247 * <p>Original source:
248 * <code><pre>
249 * pattern x_inv48_Dis(p : Physical_Person) {
250 * neg find x_inv48_3(p);
251 * Physical_Person.disability_percentage(p, disPer);
252 * check(disPer {@literal >} 0.0);
253 * check(disPer {@literal <}= 1.0);
254 * }
255 * </pre></code>
256 *
257 * @see Match
258 * @see X_inv48_Dis
259 *
260 */
261 public static class Matcher extends BaseMatcher<X_inv48_Dis.Match> {
262 /**
263 * Initializes the pattern matcher within an existing VIATRA Query engine.
264 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
265 *
266 * @param engine the existing VIATRA Query engine in which this matcher will be created.
267 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
268 *
269 */
270 public static X_inv48_Dis.Matcher on(final ViatraQueryEngine engine) {
271 // check if matcher already exists
272 Matcher matcher = engine.getExistingMatcher(querySpecification());
273 if (matcher == null) {
274 matcher = (Matcher)engine.getMatcher(querySpecification());
275 }
276 return matcher;
277 }
278
279 /**
280 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
281 * @return an initialized matcher
282 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
283 *
284 */
285 public static X_inv48_Dis.Matcher create() {
286 return new Matcher();
287 }
288
289 private static final int POSITION_P = 0;
290
291 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv48_Dis.Matcher.class);
292
293 /**
294 * Initializes the pattern matcher within an existing VIATRA Query engine.
295 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
296 *
297 * @param engine the existing VIATRA Query engine in which this matcher will be created.
298 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
299 *
300 */
301 private Matcher() {
302 super(querySpecification());
303 }
304
305 /**
306 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
307 * @param pP the fixed value of pattern parameter p, or null if not bound.
308 * @return matches represented as a Match object.
309 *
310 */
311 public Collection<X_inv48_Dis.Match> getAllMatches(final Physical_Person pP) {
312 return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet());
313 }
314
315 /**
316 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
317 * </p>
318 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
319 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
320 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
321 * @param pP the fixed value of pattern parameter p, or null if not bound.
322 * @return a stream of matches represented as a Match object.
323 *
324 */
325 public Stream<X_inv48_Dis.Match> streamAllMatches(final Physical_Person pP) {
326 return rawStreamAllMatches(new Object[]{pP});
327 }
328
329 /**
330 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
331 * Neither determinism nor randomness of selection is guaranteed.
332 * @param pP the fixed value of pattern parameter p, or null if not bound.
333 * @return a match represented as a Match object, or null if no match is found.
334 *
335 */
336 public Optional<X_inv48_Dis.Match> getOneArbitraryMatch(final Physical_Person pP) {
337 return rawGetOneArbitraryMatch(new Object[]{pP});
338 }
339
340 /**
341 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
342 * under any possible substitution of the unspecified parameters (if any).
343 * @param pP the fixed value of pattern parameter p, or null if not bound.
344 * @return true if the input is a valid (partial) match of the pattern.
345 *
346 */
347 public boolean hasMatch(final Physical_Person pP) {
348 return rawHasMatch(new Object[]{pP});
349 }
350
351 /**
352 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
353 * @param pP the fixed value of pattern parameter p, or null if not bound.
354 * @return the number of pattern matches found.
355 *
356 */
357 public int countMatches(final Physical_Person pP) {
358 return rawCountMatches(new Object[]{pP});
359 }
360
361 /**
362 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
363 * Neither determinism nor randomness of selection is guaranteed.
364 * @param pP the fixed value of pattern parameter p, or null if not bound.
365 * @param processor the action that will process the selected match.
366 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
367 *
368 */
369 public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer<? super X_inv48_Dis.Match> processor) {
370 return rawForOneArbitraryMatch(new Object[]{pP}, processor);
371 }
372
373 /**
374 * Returns a new (partial) match.
375 * This can be used e.g. to call the matcher with a partial match.
376 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
377 * @param pP the fixed value of pattern parameter p, or null if not bound.
378 * @return the (partial) match object.
379 *
380 */
381 public X_inv48_Dis.Match newMatch(final Physical_Person pP) {
382 return X_inv48_Dis.Match.newMatch(pP);
383 }
384
385 /**
386 * Retrieve the set of values that occur in matches for p.
387 * @return the Set of all values or empty set if there are no matches
388 *
389 */
390 protected Stream<Physical_Person> rawStreamAllValuesOfp(final Object[] parameters) {
391 return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast);
392 }
393
394 /**
395 * Retrieve the set of values that occur in matches for p.
396 * @return the Set of all values or empty set if there are no matches
397 *
398 */
399 public Set<Physical_Person> getAllValuesOfp() {
400 return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet());
401 }
402
403 /**
404 * Retrieve the set of values that occur in matches for p.
405 * @return the Set of all values or empty set if there are no matches
406 *
407 */
408 public Stream<Physical_Person> streamAllValuesOfp() {
409 return rawStreamAllValuesOfp(emptyArray());
410 }
411
412 @Override
413 protected X_inv48_Dis.Match tupleToMatch(final Tuple t) {
414 try {
415 return X_inv48_Dis.Match.newMatch((Physical_Person) t.get(POSITION_P));
416 } catch(ClassCastException e) {
417 LOGGER.error("Element(s) in tuple not properly typed!",e);
418 return null;
419 }
420 }
421
422 @Override
423 protected X_inv48_Dis.Match arrayToMatch(final Object[] match) {
424 try {
425 return X_inv48_Dis.Match.newMatch((Physical_Person) match[POSITION_P]);
426 } catch(ClassCastException e) {
427 LOGGER.error("Element(s) in array not properly typed!",e);
428 return null;
429 }
430 }
431
432 @Override
433 protected X_inv48_Dis.Match arrayToMatchMutable(final Object[] match) {
434 try {
435 return X_inv48_Dis.Match.newMutableMatch((Physical_Person) match[POSITION_P]);
436 } catch(ClassCastException e) {
437 LOGGER.error("Element(s) in array not properly typed!",e);
438 return null;
439 }
440 }
441
442 /**
443 * @return the singleton instance of the query specification of this pattern
444 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
445 *
446 */
447 public static IQuerySpecification<X_inv48_Dis.Matcher> querySpecification() {
448 return X_inv48_Dis.instance();
449 }
450 }
451
452 private X_inv48_Dis() {
453 super(GeneratedPQuery.INSTANCE);
454 }
455
456 /**
457 * @return the singleton instance of the query specification
458 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
459 *
460 */
461 public static X_inv48_Dis instance() {
462 try{
463 return LazyHolder.INSTANCE;
464 } catch (ExceptionInInitializerError err) {
465 throw processInitializerError(err);
466 }
467 }
468
469 @Override
470 protected X_inv48_Dis.Matcher instantiate(final ViatraQueryEngine engine) {
471 return X_inv48_Dis.Matcher.on(engine);
472 }
473
474 @Override
475 public X_inv48_Dis.Matcher instantiate() {
476 return X_inv48_Dis.Matcher.create();
477 }
478
479 @Override
480 public X_inv48_Dis.Match newEmptyMatch() {
481 return X_inv48_Dis.Match.newEmptyMatch();
482 }
483
484 @Override
485 public X_inv48_Dis.Match newMatch(final Object... parameters) {
486 return X_inv48_Dis.Match.newMatch((Taxation.Physical_Person) parameters[0]);
487 }
488
489 /**
490 * Inner class allowing the singleton instance of {@link X_inv48_Dis} to be created
491 * <b>not</b> at the class load time of the outer class,
492 * but rather at the first call to {@link X_inv48_Dis#instance()}.
493 *
494 * <p> This workaround is required e.g. to support recursion.
495 *
496 */
497 private static class LazyHolder {
498 private static final X_inv48_Dis INSTANCE = new X_inv48_Dis();
499
500 /**
501 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
502 * This initialization order is required to support indirect recursion.
503 *
504 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
505 *
506 */
507 private static final Object STATIC_INITIALIZER = ensureInitialized();
508
509 public static Object ensureInitialized() {
510 INSTANCE.ensureInitializedInternal();
511 return null;
512 }
513 }
514
515 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
516 private static final X_inv48_Dis.GeneratedPQuery INSTANCE = new GeneratedPQuery();
517
518 private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT);
519
520 private final List<PParameter> parameters = Arrays.asList(parameter_p);
521
522 private GeneratedPQuery() {
523 super(PVisibility.PUBLIC);
524 }
525
526 @Override
527 public String getFullyQualifiedName() {
528 return "queries.x_inv48_Dis";
529 }
530
531 @Override
532 public List<String> getParameterNames() {
533 return Arrays.asList("p");
534 }
535
536 @Override
537 public List<PParameter> getParameters() {
538 return parameters;
539 }
540
541 @Override
542 public Set<PBody> doGetContainedBodies() {
543 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
544 Set<PBody> bodies = new LinkedHashSet<>();
545 {
546 PBody body = new PBody(this);
547 PVariable var_p = body.getOrCreateVariableByName("p");
548 PVariable var_disPer = body.getOrCreateVariableByName("disPer");
549 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
550 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
551 new ExportedParameter(body, var_p, parameter_p)
552 ));
553 // neg find x_inv48_3(p)
554 new NegativePatternCall(body, Tuples.flatTupleOf(var_p), X_inv48_3.instance().getInternalQueryRepresentation());
555 // Physical_Person.disability_percentage(p, disPer)
556 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
557 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
558 new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "disability_percentage")));
559 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
560 new Equality(body, var__virtual_0_, var_disPer);
561 // check(disPer > 0.0)
562 new ExpressionEvaluation(body, new IExpressionEvaluator() {
563
564 @Override
565 public String getShortDescription() {
566 return "Expression evaluation from pattern x_inv48_Dis";
567 }
568
569 @Override
570 public Iterable<String> getInputParameterNames() {
571 return Arrays.asList("disPer");}
572
573 @Override
574 public Object evaluateExpression(IValueProvider provider) throws Exception {
575 Double disPer = (Double) provider.getValue("disPer");
576 return evaluateExpression_1_1(disPer);
577 }
578 }, null);
579 // check(disPer <= 1.0)
580 new ExpressionEvaluation(body, new IExpressionEvaluator() {
581
582 @Override
583 public String getShortDescription() {
584 return "Expression evaluation from pattern x_inv48_Dis";
585 }
586
587 @Override
588 public Iterable<String> getInputParameterNames() {
589 return Arrays.asList("disPer");}
590
591 @Override
592 public Object evaluateExpression(IValueProvider provider) throws Exception {
593 Double disPer = (Double) provider.getValue("disPer");
594 return evaluateExpression_1_2(disPer);
595 }
596 }, null);
597 bodies.add(body);
598 }
599 return bodies;
600 }
601 }
602
603 private static boolean evaluateExpression_1_1(final Double disPer) {
604 return ((disPer).doubleValue() > 0.0);
605 }
606
607 private static boolean evaluateExpression_1_2(final Double disPer) {
608 return ((disPer).doubleValue() <= 1.0);
609 }
610}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_notDis.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_notDis.java
new file mode 100644
index 00000000..678a96d3
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_notDis.java
@@ -0,0 +1,569 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Physical_Person;
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.PBody;
32import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
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.ConstantValue;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
38import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
40import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
41import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
42import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
43
44/**
45 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
46 *
47 * <p>Original source:
48 * <code><pre>
49 * pattern x_inv48_notDis(p : Physical_Person) {
50 * Physical_Person.disability_type(p, ::NONE);
51 * Physical_Person.disability_percentage(p, 0.0);
52 * }
53 * </pre></code>
54 *
55 * @see Matcher
56 * @see Match
57 *
58 */
59@SuppressWarnings("all")
60public final class X_inv48_notDis extends BaseGeneratedEMFQuerySpecification<X_inv48_notDis.Matcher> {
61 /**
62 * Pattern-specific match representation of the queries.x_inv48_notDis pattern,
63 * to be used in conjunction with {@link Matcher}.
64 *
65 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
66 * Each instance is a (possibly partial) substitution of pattern parameters,
67 * usable to represent a match of the pattern in the result of a query,
68 * or to specify the bound (fixed) input parameters when issuing a query.
69 *
70 * @see Matcher
71 *
72 */
73 public static abstract class Match extends BasePatternMatch {
74 private Physical_Person fP;
75
76 private static List<String> parameterNames = makeImmutableList("p");
77
78 private Match(final Physical_Person pP) {
79 this.fP = pP;
80 }
81
82 @Override
83 public Object get(final String parameterName) {
84 switch(parameterName) {
85 case "p": return this.fP;
86 default: return null;
87 }
88 }
89
90 @Override
91 public Object get(final int index) {
92 switch(index) {
93 case 0: return this.fP;
94 default: return null;
95 }
96 }
97
98 public Physical_Person getP() {
99 return this.fP;
100 }
101
102 @Override
103 public boolean set(final String parameterName, final Object newValue) {
104 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
105 if ("p".equals(parameterName) ) {
106 this.fP = (Physical_Person) newValue;
107 return true;
108 }
109 return false;
110 }
111
112 public void setP(final Physical_Person pP) {
113 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
114 this.fP = pP;
115 }
116
117 @Override
118 public String patternName() {
119 return "queries.x_inv48_notDis";
120 }
121
122 @Override
123 public List<String> parameterNames() {
124 return X_inv48_notDis.Match.parameterNames;
125 }
126
127 @Override
128 public Object[] toArray() {
129 return new Object[]{fP};
130 }
131
132 @Override
133 public X_inv48_notDis.Match toImmutable() {
134 return isMutable() ? newMatch(fP) : this;
135 }
136
137 @Override
138 public String prettyPrint() {
139 StringBuilder result = new StringBuilder();
140 result.append("\"p\"=" + prettyPrintValue(fP));
141 return result.toString();
142 }
143
144 @Override
145 public int hashCode() {
146 return Objects.hash(fP);
147 }
148
149 @Override
150 public boolean equals(final Object obj) {
151 if (this == obj)
152 return true;
153 if (obj == null) {
154 return false;
155 }
156 if ((obj instanceof X_inv48_notDis.Match)) {
157 X_inv48_notDis.Match other = (X_inv48_notDis.Match) obj;
158 return Objects.equals(fP, other.fP);
159 } else {
160 // this should be infrequent
161 if (!(obj instanceof IPatternMatch)) {
162 return false;
163 }
164 IPatternMatch otherSig = (IPatternMatch) obj;
165 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
166 }
167 }
168
169 @Override
170 public X_inv48_notDis specification() {
171 return X_inv48_notDis.instance();
172 }
173
174 /**
175 * Returns an empty, mutable match.
176 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
177 *
178 * @return the empty match.
179 *
180 */
181 public static X_inv48_notDis.Match newEmptyMatch() {
182 return new Mutable(null);
183 }
184
185 /**
186 * Returns a mutable (partial) match.
187 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
188 *
189 * @param pP the fixed value of pattern parameter p, or null if not bound.
190 * @return the new, mutable (partial) match object.
191 *
192 */
193 public static X_inv48_notDis.Match newMutableMatch(final Physical_Person pP) {
194 return new Mutable(pP);
195 }
196
197 /**
198 * Returns a new (partial) match.
199 * This can be used e.g. to call the matcher with a partial match.
200 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
201 * @param pP the fixed value of pattern parameter p, or null if not bound.
202 * @return the (partial) match object.
203 *
204 */
205 public static X_inv48_notDis.Match newMatch(final Physical_Person pP) {
206 return new Immutable(pP);
207 }
208
209 private static final class Mutable extends X_inv48_notDis.Match {
210 Mutable(final Physical_Person pP) {
211 super(pP);
212 }
213
214 @Override
215 public boolean isMutable() {
216 return true;
217 }
218 }
219
220 private static final class Immutable extends X_inv48_notDis.Match {
221 Immutable(final Physical_Person pP) {
222 super(pP);
223 }
224
225 @Override
226 public boolean isMutable() {
227 return false;
228 }
229 }
230 }
231
232 /**
233 * Generated pattern matcher API of the queries.x_inv48_notDis pattern,
234 * providing pattern-specific query methods.
235 *
236 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
237 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
238 *
239 * <p>Matches of the pattern will be represented as {@link Match}.
240 *
241 * <p>Original source:
242 * <code><pre>
243 * pattern x_inv48_notDis(p : Physical_Person) {
244 * Physical_Person.disability_type(p, ::NONE);
245 * Physical_Person.disability_percentage(p, 0.0);
246 * }
247 * </pre></code>
248 *
249 * @see Match
250 * @see X_inv48_notDis
251 *
252 */
253 public static class Matcher extends BaseMatcher<X_inv48_notDis.Match> {
254 /**
255 * Initializes the pattern matcher within an existing VIATRA Query engine.
256 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
257 *
258 * @param engine the existing VIATRA Query engine in which this matcher will be created.
259 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
260 *
261 */
262 public static X_inv48_notDis.Matcher on(final ViatraQueryEngine engine) {
263 // check if matcher already exists
264 Matcher matcher = engine.getExistingMatcher(querySpecification());
265 if (matcher == null) {
266 matcher = (Matcher)engine.getMatcher(querySpecification());
267 }
268 return matcher;
269 }
270
271 /**
272 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
273 * @return an initialized matcher
274 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
275 *
276 */
277 public static X_inv48_notDis.Matcher create() {
278 return new Matcher();
279 }
280
281 private static final int POSITION_P = 0;
282
283 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv48_notDis.Matcher.class);
284
285 /**
286 * Initializes the pattern matcher within an existing VIATRA Query engine.
287 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
288 *
289 * @param engine the existing VIATRA Query engine in which this matcher will be created.
290 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
291 *
292 */
293 private Matcher() {
294 super(querySpecification());
295 }
296
297 /**
298 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
299 * @param pP the fixed value of pattern parameter p, or null if not bound.
300 * @return matches represented as a Match object.
301 *
302 */
303 public Collection<X_inv48_notDis.Match> getAllMatches(final Physical_Person pP) {
304 return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet());
305 }
306
307 /**
308 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
309 * </p>
310 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
311 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
312 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
313 * @param pP the fixed value of pattern parameter p, or null if not bound.
314 * @return a stream of matches represented as a Match object.
315 *
316 */
317 public Stream<X_inv48_notDis.Match> streamAllMatches(final Physical_Person pP) {
318 return rawStreamAllMatches(new Object[]{pP});
319 }
320
321 /**
322 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
323 * Neither determinism nor randomness of selection is guaranteed.
324 * @param pP the fixed value of pattern parameter p, or null if not bound.
325 * @return a match represented as a Match object, or null if no match is found.
326 *
327 */
328 public Optional<X_inv48_notDis.Match> getOneArbitraryMatch(final Physical_Person pP) {
329 return rawGetOneArbitraryMatch(new Object[]{pP});
330 }
331
332 /**
333 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
334 * under any possible substitution of the unspecified parameters (if any).
335 * @param pP the fixed value of pattern parameter p, or null if not bound.
336 * @return true if the input is a valid (partial) match of the pattern.
337 *
338 */
339 public boolean hasMatch(final Physical_Person pP) {
340 return rawHasMatch(new Object[]{pP});
341 }
342
343 /**
344 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
345 * @param pP the fixed value of pattern parameter p, or null if not bound.
346 * @return the number of pattern matches found.
347 *
348 */
349 public int countMatches(final Physical_Person pP) {
350 return rawCountMatches(new Object[]{pP});
351 }
352
353 /**
354 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
355 * Neither determinism nor randomness of selection is guaranteed.
356 * @param pP the fixed value of pattern parameter p, or null if not bound.
357 * @param processor the action that will process the selected match.
358 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
359 *
360 */
361 public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer<? super X_inv48_notDis.Match> processor) {
362 return rawForOneArbitraryMatch(new Object[]{pP}, processor);
363 }
364
365 /**
366 * Returns a new (partial) match.
367 * This can be used e.g. to call the matcher with a partial match.
368 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
369 * @param pP the fixed value of pattern parameter p, or null if not bound.
370 * @return the (partial) match object.
371 *
372 */
373 public X_inv48_notDis.Match newMatch(final Physical_Person pP) {
374 return X_inv48_notDis.Match.newMatch(pP);
375 }
376
377 /**
378 * Retrieve the set of values that occur in matches for p.
379 * @return the Set of all values or empty set if there are no matches
380 *
381 */
382 protected Stream<Physical_Person> rawStreamAllValuesOfp(final Object[] parameters) {
383 return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast);
384 }
385
386 /**
387 * Retrieve the set of values that occur in matches for p.
388 * @return the Set of all values or empty set if there are no matches
389 *
390 */
391 public Set<Physical_Person> getAllValuesOfp() {
392 return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet());
393 }
394
395 /**
396 * Retrieve the set of values that occur in matches for p.
397 * @return the Set of all values or empty set if there are no matches
398 *
399 */
400 public Stream<Physical_Person> streamAllValuesOfp() {
401 return rawStreamAllValuesOfp(emptyArray());
402 }
403
404 @Override
405 protected X_inv48_notDis.Match tupleToMatch(final Tuple t) {
406 try {
407 return X_inv48_notDis.Match.newMatch((Physical_Person) t.get(POSITION_P));
408 } catch(ClassCastException e) {
409 LOGGER.error("Element(s) in tuple not properly typed!",e);
410 return null;
411 }
412 }
413
414 @Override
415 protected X_inv48_notDis.Match arrayToMatch(final Object[] match) {
416 try {
417 return X_inv48_notDis.Match.newMatch((Physical_Person) match[POSITION_P]);
418 } catch(ClassCastException e) {
419 LOGGER.error("Element(s) in array not properly typed!",e);
420 return null;
421 }
422 }
423
424 @Override
425 protected X_inv48_notDis.Match arrayToMatchMutable(final Object[] match) {
426 try {
427 return X_inv48_notDis.Match.newMutableMatch((Physical_Person) match[POSITION_P]);
428 } catch(ClassCastException e) {
429 LOGGER.error("Element(s) in array not properly typed!",e);
430 return null;
431 }
432 }
433
434 /**
435 * @return the singleton instance of the query specification of this pattern
436 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
437 *
438 */
439 public static IQuerySpecification<X_inv48_notDis.Matcher> querySpecification() {
440 return X_inv48_notDis.instance();
441 }
442 }
443
444 private X_inv48_notDis() {
445 super(GeneratedPQuery.INSTANCE);
446 }
447
448 /**
449 * @return the singleton instance of the query specification
450 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
451 *
452 */
453 public static X_inv48_notDis instance() {
454 try{
455 return LazyHolder.INSTANCE;
456 } catch (ExceptionInInitializerError err) {
457 throw processInitializerError(err);
458 }
459 }
460
461 @Override
462 protected X_inv48_notDis.Matcher instantiate(final ViatraQueryEngine engine) {
463 return X_inv48_notDis.Matcher.on(engine);
464 }
465
466 @Override
467 public X_inv48_notDis.Matcher instantiate() {
468 return X_inv48_notDis.Matcher.create();
469 }
470
471 @Override
472 public X_inv48_notDis.Match newEmptyMatch() {
473 return X_inv48_notDis.Match.newEmptyMatch();
474 }
475
476 @Override
477 public X_inv48_notDis.Match newMatch(final Object... parameters) {
478 return X_inv48_notDis.Match.newMatch((Taxation.Physical_Person) parameters[0]);
479 }
480
481 /**
482 * Inner class allowing the singleton instance of {@link X_inv48_notDis} to be created
483 * <b>not</b> at the class load time of the outer class,
484 * but rather at the first call to {@link X_inv48_notDis#instance()}.
485 *
486 * <p> This workaround is required e.g. to support recursion.
487 *
488 */
489 private static class LazyHolder {
490 private static final X_inv48_notDis INSTANCE = new X_inv48_notDis();
491
492 /**
493 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
494 * This initialization order is required to support indirect recursion.
495 *
496 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
497 *
498 */
499 private static final Object STATIC_INITIALIZER = ensureInitialized();
500
501 public static Object ensureInitialized() {
502 INSTANCE.ensureInitializedInternal();
503 return null;
504 }
505 }
506
507 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
508 private static final X_inv48_notDis.GeneratedPQuery INSTANCE = new GeneratedPQuery();
509
510 private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT);
511
512 private final List<PParameter> parameters = Arrays.asList(parameter_p);
513
514 private GeneratedPQuery() {
515 super(PVisibility.PUBLIC);
516 }
517
518 @Override
519 public String getFullyQualifiedName() {
520 return "queries.x_inv48_notDis";
521 }
522
523 @Override
524 public List<String> getParameterNames() {
525 return Arrays.asList("p");
526 }
527
528 @Override
529 public List<PParameter> getParameters() {
530 return parameters;
531 }
532
533 @Override
534 public Set<PBody> doGetContainedBodies() {
535 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
536 Set<PBody> bodies = new LinkedHashSet<>();
537 {
538 PBody body = new PBody(this);
539 PVariable var_p = body.getOrCreateVariableByName("p");
540 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
541 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
542 new ExportedParameter(body, var_p, parameter_p)
543 ));
544 // Physical_Person.disability_type(p, ::NONE)
545 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
546 new ConstantValue(body, var__virtual_0_, getEnumLiteral("http:///TaxCard.ecore", "Disability_Types", "NONE").getInstance());
547 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
548 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
549 new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "disability_type")));
550 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http:///TaxCard.ecore", "Disability_Types")));
551 new Equality(body, var__virtual_1_, var__virtual_0_);
552 // Physical_Person.disability_percentage(p, 0.0)
553 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
554 new ConstantValue(body, var__virtual_2_, 0.0);
555 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
556 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
557 new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "disability_percentage")));
558 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble")));
559 new Equality(body, var__virtual_3_, var__virtual_2_);
560 bodies.add(body);
561 }
562 return bodies;
563 }
564 }
565
566 private static double evaluateExpression_1_1() {
567 return 0.0;
568 }
569}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_1.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_1.java
new file mode 100644
index 00000000..e05ec5cd
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_1.java
@@ -0,0 +1,579 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Legal_Union_Record;
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.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.X_inv49_2;
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 * pattern x_inv49_1(lur : Legal_Union_Record) {
50 * Legal_Union_Record.individual_A(lur, iA);
51 * Legal_Union_Record.individual_B(lur, iB);
52 * Tax_Payer(iA);
53 * Physical_Person(iB);
54 * neg find x_inv49_2(iB);
55 * iA != iB;
56 * }
57 * </pre></code>
58 *
59 * @see Matcher
60 * @see Match
61 *
62 */
63@SuppressWarnings("all")
64public final class X_inv49_1 extends BaseGeneratedEMFQuerySpecification<X_inv49_1.Matcher> {
65 /**
66 * Pattern-specific match representation of the queries.x_inv49_1 pattern,
67 * to be used in conjunction with {@link Matcher}.
68 *
69 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
70 * Each instance is a (possibly partial) substitution of pattern parameters,
71 * usable to represent a match of the pattern in the result of a query,
72 * or to specify the bound (fixed) input parameters when issuing a query.
73 *
74 * @see Matcher
75 *
76 */
77 public static abstract class Match extends BasePatternMatch {
78 private Legal_Union_Record fLur;
79
80 private static List<String> parameterNames = makeImmutableList("lur");
81
82 private Match(final Legal_Union_Record pLur) {
83 this.fLur = pLur;
84 }
85
86 @Override
87 public Object get(final String parameterName) {
88 switch(parameterName) {
89 case "lur": return this.fLur;
90 default: return null;
91 }
92 }
93
94 @Override
95 public Object get(final int index) {
96 switch(index) {
97 case 0: return this.fLur;
98 default: return null;
99 }
100 }
101
102 public Legal_Union_Record getLur() {
103 return this.fLur;
104 }
105
106 @Override
107 public boolean set(final String parameterName, final Object newValue) {
108 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
109 if ("lur".equals(parameterName) ) {
110 this.fLur = (Legal_Union_Record) newValue;
111 return true;
112 }
113 return false;
114 }
115
116 public void setLur(final Legal_Union_Record pLur) {
117 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
118 this.fLur = pLur;
119 }
120
121 @Override
122 public String patternName() {
123 return "queries.x_inv49_1";
124 }
125
126 @Override
127 public List<String> parameterNames() {
128 return X_inv49_1.Match.parameterNames;
129 }
130
131 @Override
132 public Object[] toArray() {
133 return new Object[]{fLur};
134 }
135
136 @Override
137 public X_inv49_1.Match toImmutable() {
138 return isMutable() ? newMatch(fLur) : this;
139 }
140
141 @Override
142 public String prettyPrint() {
143 StringBuilder result = new StringBuilder();
144 result.append("\"lur\"=" + prettyPrintValue(fLur));
145 return result.toString();
146 }
147
148 @Override
149 public int hashCode() {
150 return Objects.hash(fLur);
151 }
152
153 @Override
154 public boolean equals(final Object obj) {
155 if (this == obj)
156 return true;
157 if (obj == null) {
158 return false;
159 }
160 if ((obj instanceof X_inv49_1.Match)) {
161 X_inv49_1.Match other = (X_inv49_1.Match) obj;
162 return Objects.equals(fLur, other.fLur);
163 } else {
164 // this should be infrequent
165 if (!(obj instanceof IPatternMatch)) {
166 return false;
167 }
168 IPatternMatch otherSig = (IPatternMatch) obj;
169 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
170 }
171 }
172
173 @Override
174 public X_inv49_1 specification() {
175 return X_inv49_1.instance();
176 }
177
178 /**
179 * Returns an empty, mutable match.
180 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
181 *
182 * @return the empty match.
183 *
184 */
185 public static X_inv49_1.Match newEmptyMatch() {
186 return new Mutable(null);
187 }
188
189 /**
190 * Returns a mutable (partial) match.
191 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
192 *
193 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
194 * @return the new, mutable (partial) match object.
195 *
196 */
197 public static X_inv49_1.Match newMutableMatch(final Legal_Union_Record pLur) {
198 return new Mutable(pLur);
199 }
200
201 /**
202 * Returns a new (partial) match.
203 * This can be used e.g. to call the matcher with a partial match.
204 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
205 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
206 * @return the (partial) match object.
207 *
208 */
209 public static X_inv49_1.Match newMatch(final Legal_Union_Record pLur) {
210 return new Immutable(pLur);
211 }
212
213 private static final class Mutable extends X_inv49_1.Match {
214 Mutable(final Legal_Union_Record pLur) {
215 super(pLur);
216 }
217
218 @Override
219 public boolean isMutable() {
220 return true;
221 }
222 }
223
224 private static final class Immutable extends X_inv49_1.Match {
225 Immutable(final Legal_Union_Record pLur) {
226 super(pLur);
227 }
228
229 @Override
230 public boolean isMutable() {
231 return false;
232 }
233 }
234 }
235
236 /**
237 * Generated pattern matcher API of the queries.x_inv49_1 pattern,
238 * providing pattern-specific query methods.
239 *
240 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
241 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
242 *
243 * <p>Matches of the pattern will be represented as {@link Match}.
244 *
245 * <p>Original source:
246 * <code><pre>
247 * pattern x_inv49_1(lur : Legal_Union_Record) {
248 * Legal_Union_Record.individual_A(lur, iA);
249 * Legal_Union_Record.individual_B(lur, iB);
250 * Tax_Payer(iA);
251 * Physical_Person(iB);
252 * neg find x_inv49_2(iB);
253 * iA != iB;
254 * }
255 * </pre></code>
256 *
257 * @see Match
258 * @see X_inv49_1
259 *
260 */
261 public static class Matcher extends BaseMatcher<X_inv49_1.Match> {
262 /**
263 * Initializes the pattern matcher within an existing VIATRA Query engine.
264 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
265 *
266 * @param engine the existing VIATRA Query engine in which this matcher will be created.
267 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
268 *
269 */
270 public static X_inv49_1.Matcher on(final ViatraQueryEngine engine) {
271 // check if matcher already exists
272 Matcher matcher = engine.getExistingMatcher(querySpecification());
273 if (matcher == null) {
274 matcher = (Matcher)engine.getMatcher(querySpecification());
275 }
276 return matcher;
277 }
278
279 /**
280 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
281 * @return an initialized matcher
282 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
283 *
284 */
285 public static X_inv49_1.Matcher create() {
286 return new Matcher();
287 }
288
289 private static final int POSITION_LUR = 0;
290
291 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv49_1.Matcher.class);
292
293 /**
294 * Initializes the pattern matcher within an existing VIATRA Query engine.
295 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
296 *
297 * @param engine the existing VIATRA Query engine in which this matcher will be created.
298 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
299 *
300 */
301 private Matcher() {
302 super(querySpecification());
303 }
304
305 /**
306 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
307 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
308 * @return matches represented as a Match object.
309 *
310 */
311 public Collection<X_inv49_1.Match> getAllMatches(final Legal_Union_Record pLur) {
312 return rawStreamAllMatches(new Object[]{pLur}).collect(Collectors.toSet());
313 }
314
315 /**
316 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
317 * </p>
318 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
319 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
320 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
321 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
322 * @return a stream of matches represented as a Match object.
323 *
324 */
325 public Stream<X_inv49_1.Match> streamAllMatches(final Legal_Union_Record pLur) {
326 return rawStreamAllMatches(new Object[]{pLur});
327 }
328
329 /**
330 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
331 * Neither determinism nor randomness of selection is guaranteed.
332 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
333 * @return a match represented as a Match object, or null if no match is found.
334 *
335 */
336 public Optional<X_inv49_1.Match> getOneArbitraryMatch(final Legal_Union_Record pLur) {
337 return rawGetOneArbitraryMatch(new Object[]{pLur});
338 }
339
340 /**
341 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
342 * under any possible substitution of the unspecified parameters (if any).
343 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
344 * @return true if the input is a valid (partial) match of the pattern.
345 *
346 */
347 public boolean hasMatch(final Legal_Union_Record pLur) {
348 return rawHasMatch(new Object[]{pLur});
349 }
350
351 /**
352 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
353 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
354 * @return the number of pattern matches found.
355 *
356 */
357 public int countMatches(final Legal_Union_Record pLur) {
358 return rawCountMatches(new Object[]{pLur});
359 }
360
361 /**
362 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
363 * Neither determinism nor randomness of selection is guaranteed.
364 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
365 * @param processor the action that will process the selected match.
366 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
367 *
368 */
369 public boolean forOneArbitraryMatch(final Legal_Union_Record pLur, final Consumer<? super X_inv49_1.Match> processor) {
370 return rawForOneArbitraryMatch(new Object[]{pLur}, processor);
371 }
372
373 /**
374 * Returns a new (partial) match.
375 * This can be used e.g. to call the matcher with a partial match.
376 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
377 * @param pLur the fixed value of pattern parameter lur, or null if not bound.
378 * @return the (partial) match object.
379 *
380 */
381 public X_inv49_1.Match newMatch(final Legal_Union_Record pLur) {
382 return X_inv49_1.Match.newMatch(pLur);
383 }
384
385 /**
386 * Retrieve the set of values that occur in matches for lur.
387 * @return the Set of all values or empty set if there are no matches
388 *
389 */
390 protected Stream<Legal_Union_Record> rawStreamAllValuesOflur(final Object[] parameters) {
391 return rawStreamAllValues(POSITION_LUR, parameters).map(Legal_Union_Record.class::cast);
392 }
393
394 /**
395 * Retrieve the set of values that occur in matches for lur.
396 * @return the Set of all values or empty set if there are no matches
397 *
398 */
399 public Set<Legal_Union_Record> getAllValuesOflur() {
400 return rawStreamAllValuesOflur(emptyArray()).collect(Collectors.toSet());
401 }
402
403 /**
404 * Retrieve the set of values that occur in matches for lur.
405 * @return the Set of all values or empty set if there are no matches
406 *
407 */
408 public Stream<Legal_Union_Record> streamAllValuesOflur() {
409 return rawStreamAllValuesOflur(emptyArray());
410 }
411
412 @Override
413 protected X_inv49_1.Match tupleToMatch(final Tuple t) {
414 try {
415 return X_inv49_1.Match.newMatch((Legal_Union_Record) t.get(POSITION_LUR));
416 } catch(ClassCastException e) {
417 LOGGER.error("Element(s) in tuple not properly typed!",e);
418 return null;
419 }
420 }
421
422 @Override
423 protected X_inv49_1.Match arrayToMatch(final Object[] match) {
424 try {
425 return X_inv49_1.Match.newMatch((Legal_Union_Record) match[POSITION_LUR]);
426 } catch(ClassCastException e) {
427 LOGGER.error("Element(s) in array not properly typed!",e);
428 return null;
429 }
430 }
431
432 @Override
433 protected X_inv49_1.Match arrayToMatchMutable(final Object[] match) {
434 try {
435 return X_inv49_1.Match.newMutableMatch((Legal_Union_Record) match[POSITION_LUR]);
436 } catch(ClassCastException e) {
437 LOGGER.error("Element(s) in array not properly typed!",e);
438 return null;
439 }
440 }
441
442 /**
443 * @return the singleton instance of the query specification of this pattern
444 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
445 *
446 */
447 public static IQuerySpecification<X_inv49_1.Matcher> querySpecification() {
448 return X_inv49_1.instance();
449 }
450 }
451
452 private X_inv49_1() {
453 super(GeneratedPQuery.INSTANCE);
454 }
455
456 /**
457 * @return the singleton instance of the query specification
458 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
459 *
460 */
461 public static X_inv49_1 instance() {
462 try{
463 return LazyHolder.INSTANCE;
464 } catch (ExceptionInInitializerError err) {
465 throw processInitializerError(err);
466 }
467 }
468
469 @Override
470 protected X_inv49_1.Matcher instantiate(final ViatraQueryEngine engine) {
471 return X_inv49_1.Matcher.on(engine);
472 }
473
474 @Override
475 public X_inv49_1.Matcher instantiate() {
476 return X_inv49_1.Matcher.create();
477 }
478
479 @Override
480 public X_inv49_1.Match newEmptyMatch() {
481 return X_inv49_1.Match.newEmptyMatch();
482 }
483
484 @Override
485 public X_inv49_1.Match newMatch(final Object... parameters) {
486 return X_inv49_1.Match.newMatch((Taxation.Legal_Union_Record) parameters[0]);
487 }
488
489 /**
490 * Inner class allowing the singleton instance of {@link X_inv49_1} to be created
491 * <b>not</b> at the class load time of the outer class,
492 * but rather at the first call to {@link X_inv49_1#instance()}.
493 *
494 * <p> This workaround is required e.g. to support recursion.
495 *
496 */
497 private static class LazyHolder {
498 private static final X_inv49_1 INSTANCE = new X_inv49_1();
499
500 /**
501 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
502 * This initialization order is required to support indirect recursion.
503 *
504 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
505 *
506 */
507 private static final Object STATIC_INITIALIZER = ensureInitialized();
508
509 public static Object ensureInitialized() {
510 INSTANCE.ensureInitializedInternal();
511 return null;
512 }
513 }
514
515 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
516 private static final X_inv49_1.GeneratedPQuery INSTANCE = new GeneratedPQuery();
517
518 private final PParameter parameter_lur = new PParameter("lur", "Taxation.Legal_Union_Record", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Legal_Union_Record")), PParameterDirection.INOUT);
519
520 private final List<PParameter> parameters = Arrays.asList(parameter_lur);
521
522 private GeneratedPQuery() {
523 super(PVisibility.PUBLIC);
524 }
525
526 @Override
527 public String getFullyQualifiedName() {
528 return "queries.x_inv49_1";
529 }
530
531 @Override
532 public List<String> getParameterNames() {
533 return Arrays.asList("lur");
534 }
535
536 @Override
537 public List<PParameter> getParameters() {
538 return parameters;
539 }
540
541 @Override
542 public Set<PBody> doGetContainedBodies() {
543 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
544 Set<PBody> bodies = new LinkedHashSet<>();
545 {
546 PBody body = new PBody(this);
547 PVariable var_lur = body.getOrCreateVariableByName("lur");
548 PVariable var_iA = body.getOrCreateVariableByName("iA");
549 PVariable var_iB = body.getOrCreateVariableByName("iB");
550 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
551 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
552 new ExportedParameter(body, var_lur, parameter_lur)
553 ));
554 // Legal_Union_Record.individual_A(lur, iA)
555 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
556 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
557 new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "individual_A")));
558 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
559 new Equality(body, var__virtual_0_, var_iA);
560 // Legal_Union_Record.individual_B(lur, iB)
561 new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record")));
562 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
563 new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "individual_B")));
564 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
565 new Equality(body, var__virtual_1_, var_iB);
566 // Tax_Payer(iA)
567 new TypeConstraint(body, Tuples.flatTupleOf(var_iA), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer")));
568 // Physical_Person(iB)
569 new TypeConstraint(body, Tuples.flatTupleOf(var_iB), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person")));
570 // neg find x_inv49_2(iB)
571 new NegativePatternCall(body, Tuples.flatTupleOf(var_iB), X_inv49_2.instance().getInternalQueryRepresentation());
572 // iA != iB
573 new Inequality(body, var_iA, var_iB);
574 bodies.add(body);
575 }
576 return bodies;
577 }
578 }
579}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_2.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_2.java
new file mode 100644
index 00000000..43ce44b4
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_2.java
@@ -0,0 +1,544 @@
1/**
2 * Generated from platform:/resource/case.study.a.queries/src/queries/case_study_A.vql
3 */
4package queries;
5
6import Taxation.Dependent;
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.basicdeferred.ExportedParameter;
31import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
32import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
33import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
34import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
35import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
36import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
37import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
38
39/**
40 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
41 *
42 * <p>Original source:
43 * <code><pre>
44 * pattern x_inv49_2(iB: Dependent) {
45 * Dependent(iB);
46 * }
47 * </pre></code>
48 *
49 * @see Matcher
50 * @see Match
51 *
52 */
53@SuppressWarnings("all")
54public final class X_inv49_2 extends BaseGeneratedEMFQuerySpecification<X_inv49_2.Matcher> {
55 /**
56 * Pattern-specific match representation of the queries.x_inv49_2 pattern,
57 * to be used in conjunction with {@link Matcher}.
58 *
59 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
60 * Each instance is a (possibly partial) substitution of pattern parameters,
61 * usable to represent a match of the pattern in the result of a query,
62 * or to specify the bound (fixed) input parameters when issuing a query.
63 *
64 * @see Matcher
65 *
66 */
67 public static abstract class Match extends BasePatternMatch {
68 private Dependent fIB;
69
70 private static List<String> parameterNames = makeImmutableList("iB");
71
72 private Match(final Dependent pIB) {
73 this.fIB = pIB;
74 }
75
76 @Override
77 public Object get(final String parameterName) {
78 switch(parameterName) {
79 case "iB": return this.fIB;
80 default: return null;
81 }
82 }
83
84 @Override
85 public Object get(final int index) {
86 switch(index) {
87 case 0: return this.fIB;
88 default: return null;
89 }
90 }
91
92 public Dependent getIB() {
93 return this.fIB;
94 }
95
96 @Override
97 public boolean set(final String parameterName, final Object newValue) {
98 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
99 if ("iB".equals(parameterName) ) {
100 this.fIB = (Dependent) newValue;
101 return true;
102 }
103 return false;
104 }
105
106 public void setIB(final Dependent pIB) {
107 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
108 this.fIB = pIB;
109 }
110
111 @Override
112 public String patternName() {
113 return "queries.x_inv49_2";
114 }
115
116 @Override
117 public List<String> parameterNames() {
118 return X_inv49_2.Match.parameterNames;
119 }
120
121 @Override
122 public Object[] toArray() {
123 return new Object[]{fIB};
124 }
125
126 @Override
127 public X_inv49_2.Match toImmutable() {
128 return isMutable() ? newMatch(fIB) : this;
129 }
130
131 @Override
132 public String prettyPrint() {
133 StringBuilder result = new StringBuilder();
134 result.append("\"iB\"=" + prettyPrintValue(fIB));
135 return result.toString();
136 }
137
138 @Override
139 public int hashCode() {
140 return Objects.hash(fIB);
141 }
142
143 @Override
144 public boolean equals(final Object obj) {
145 if (this == obj)
146 return true;
147 if (obj == null) {
148 return false;
149 }
150 if ((obj instanceof X_inv49_2.Match)) {
151 X_inv49_2.Match other = (X_inv49_2.Match) obj;
152 return Objects.equals(fIB, other.fIB);
153 } else {
154 // this should be infrequent
155 if (!(obj instanceof IPatternMatch)) {
156 return false;
157 }
158 IPatternMatch otherSig = (IPatternMatch) obj;
159 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
160 }
161 }
162
163 @Override
164 public X_inv49_2 specification() {
165 return X_inv49_2.instance();
166 }
167
168 /**
169 * Returns an empty, mutable match.
170 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
171 *
172 * @return the empty match.
173 *
174 */
175 public static X_inv49_2.Match newEmptyMatch() {
176 return new Mutable(null);
177 }
178
179 /**
180 * Returns a mutable (partial) match.
181 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
182 *
183 * @param pIB the fixed value of pattern parameter iB, or null if not bound.
184 * @return the new, mutable (partial) match object.
185 *
186 */
187 public static X_inv49_2.Match newMutableMatch(final Dependent pIB) {
188 return new Mutable(pIB);
189 }
190
191 /**
192 * Returns a new (partial) match.
193 * This can be used e.g. to call the matcher with a partial match.
194 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
195 * @param pIB the fixed value of pattern parameter iB, or null if not bound.
196 * @return the (partial) match object.
197 *
198 */
199 public static X_inv49_2.Match newMatch(final Dependent pIB) {
200 return new Immutable(pIB);
201 }
202
203 private static final class Mutable extends X_inv49_2.Match {
204 Mutable(final Dependent pIB) {
205 super(pIB);
206 }
207
208 @Override
209 public boolean isMutable() {
210 return true;
211 }
212 }
213
214 private static final class Immutable extends X_inv49_2.Match {
215 Immutable(final Dependent pIB) {
216 super(pIB);
217 }
218
219 @Override
220 public boolean isMutable() {
221 return false;
222 }
223 }
224 }
225
226 /**
227 * Generated pattern matcher API of the queries.x_inv49_2 pattern,
228 * providing pattern-specific query methods.
229 *
230 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
231 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
232 *
233 * <p>Matches of the pattern will be represented as {@link Match}.
234 *
235 * <p>Original source:
236 * <code><pre>
237 * pattern x_inv49_2(iB: Dependent) {
238 * Dependent(iB);
239 * }
240 * </pre></code>
241 *
242 * @see Match
243 * @see X_inv49_2
244 *
245 */
246 public static class Matcher extends BaseMatcher<X_inv49_2.Match> {
247 /**
248 * Initializes the pattern matcher within an existing VIATRA Query engine.
249 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
250 *
251 * @param engine the existing VIATRA Query engine in which this matcher will be created.
252 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
253 *
254 */
255 public static X_inv49_2.Matcher on(final ViatraQueryEngine engine) {
256 // check if matcher already exists
257 Matcher matcher = engine.getExistingMatcher(querySpecification());
258 if (matcher == null) {
259 matcher = (Matcher)engine.getMatcher(querySpecification());
260 }
261 return matcher;
262 }
263
264 /**
265 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
266 * @return an initialized matcher
267 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
268 *
269 */
270 public static X_inv49_2.Matcher create() {
271 return new Matcher();
272 }
273
274 private static final int POSITION_IB = 0;
275
276 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv49_2.Matcher.class);
277
278 /**
279 * Initializes the pattern matcher within an existing VIATRA Query engine.
280 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
281 *
282 * @param engine the existing VIATRA Query engine in which this matcher will be created.
283 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
284 *
285 */
286 private Matcher() {
287 super(querySpecification());
288 }
289
290 /**
291 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
292 * @param pIB the fixed value of pattern parameter iB, or null if not bound.
293 * @return matches represented as a Match object.
294 *
295 */
296 public Collection<X_inv49_2.Match> getAllMatches(final Dependent pIB) {
297 return rawStreamAllMatches(new Object[]{pIB}).collect(Collectors.toSet());
298 }
299
300 /**
301 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
302 * </p>
303 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
304 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
305 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
306 * @param pIB the fixed value of pattern parameter iB, or null if not bound.
307 * @return a stream of matches represented as a Match object.
308 *
309 */
310 public Stream<X_inv49_2.Match> streamAllMatches(final Dependent pIB) {
311 return rawStreamAllMatches(new Object[]{pIB});
312 }
313
314 /**
315 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
316 * Neither determinism nor randomness of selection is guaranteed.
317 * @param pIB the fixed value of pattern parameter iB, or null if not bound.
318 * @return a match represented as a Match object, or null if no match is found.
319 *
320 */
321 public Optional<X_inv49_2.Match> getOneArbitraryMatch(final Dependent pIB) {
322 return rawGetOneArbitraryMatch(new Object[]{pIB});
323 }
324
325 /**
326 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
327 * under any possible substitution of the unspecified parameters (if any).
328 * @param pIB the fixed value of pattern parameter iB, or null if not bound.
329 * @return true if the input is a valid (partial) match of the pattern.
330 *
331 */
332 public boolean hasMatch(final Dependent pIB) {
333 return rawHasMatch(new Object[]{pIB});
334 }
335
336 /**
337 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
338 * @param pIB the fixed value of pattern parameter iB, or null if not bound.
339 * @return the number of pattern matches found.
340 *
341 */
342 public int countMatches(final Dependent pIB) {
343 return rawCountMatches(new Object[]{pIB});
344 }
345
346 /**
347 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
348 * Neither determinism nor randomness of selection is guaranteed.
349 * @param pIB the fixed value of pattern parameter iB, or null if not bound.
350 * @param processor the action that will process the selected match.
351 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
352 *
353 */
354 public boolean forOneArbitraryMatch(final Dependent pIB, final Consumer<? super X_inv49_2.Match> processor) {
355 return rawForOneArbitraryMatch(new Object[]{pIB}, processor);
356 }
357
358 /**
359 * Returns a new (partial) match.
360 * This can be used e.g. to call the matcher with a partial match.
361 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
362 * @param pIB the fixed value of pattern parameter iB, or null if not bound.
363 * @return the (partial) match object.
364 *
365 */
366 public X_inv49_2.Match newMatch(final Dependent pIB) {
367 return X_inv49_2.Match.newMatch(pIB);
368 }
369
370 /**
371 * Retrieve the set of values that occur in matches for iB.
372 * @return the Set of all values or empty set if there are no matches
373 *
374 */
375 protected Stream<Dependent> rawStreamAllValuesOfiB(final Object[] parameters) {
376 return rawStreamAllValues(POSITION_IB, parameters).map(Dependent.class::cast);
377 }
378
379 /**
380 * Retrieve the set of values that occur in matches for iB.
381 * @return the Set of all values or empty set if there are no matches
382 *
383 */
384 public Set<Dependent> getAllValuesOfiB() {
385 return rawStreamAllValuesOfiB(emptyArray()).collect(Collectors.toSet());
386 }
387
388 /**
389 * Retrieve the set of values that occur in matches for iB.
390 * @return the Set of all values or empty set if there are no matches
391 *
392 */
393 public Stream<Dependent> streamAllValuesOfiB() {
394 return rawStreamAllValuesOfiB(emptyArray());
395 }
396
397 @Override
398 protected X_inv49_2.Match tupleToMatch(final Tuple t) {
399 try {
400 return X_inv49_2.Match.newMatch((Dependent) t.get(POSITION_IB));
401 } catch(ClassCastException e) {
402 LOGGER.error("Element(s) in tuple not properly typed!",e);
403 return null;
404 }
405 }
406
407 @Override
408 protected X_inv49_2.Match arrayToMatch(final Object[] match) {
409 try {
410 return X_inv49_2.Match.newMatch((Dependent) match[POSITION_IB]);
411 } catch(ClassCastException e) {
412 LOGGER.error("Element(s) in array not properly typed!",e);
413 return null;
414 }
415 }
416
417 @Override
418 protected X_inv49_2.Match arrayToMatchMutable(final Object[] match) {
419 try {
420 return X_inv49_2.Match.newMutableMatch((Dependent) match[POSITION_IB]);
421 } catch(ClassCastException e) {
422 LOGGER.error("Element(s) in array not properly typed!",e);
423 return null;
424 }
425 }
426
427 /**
428 * @return the singleton instance of the query specification of this pattern
429 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
430 *
431 */
432 public static IQuerySpecification<X_inv49_2.Matcher> querySpecification() {
433 return X_inv49_2.instance();
434 }
435 }
436
437 private X_inv49_2() {
438 super(GeneratedPQuery.INSTANCE);
439 }
440
441 /**
442 * @return the singleton instance of the query specification
443 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
444 *
445 */
446 public static X_inv49_2 instance() {
447 try{
448 return LazyHolder.INSTANCE;
449 } catch (ExceptionInInitializerError err) {
450 throw processInitializerError(err);
451 }
452 }
453
454 @Override
455 protected X_inv49_2.Matcher instantiate(final ViatraQueryEngine engine) {
456 return X_inv49_2.Matcher.on(engine);
457 }
458
459 @Override
460 public X_inv49_2.Matcher instantiate() {
461 return X_inv49_2.Matcher.create();
462 }
463
464 @Override
465 public X_inv49_2.Match newEmptyMatch() {
466 return X_inv49_2.Match.newEmptyMatch();
467 }
468
469 @Override
470 public X_inv49_2.Match newMatch(final Object... parameters) {
471 return X_inv49_2.Match.newMatch((Taxation.Dependent) parameters[0]);
472 }
473
474 /**
475 * Inner class allowing the singleton instance of {@link X_inv49_2} to be created
476 * <b>not</b> at the class load time of the outer class,
477 * but rather at the first call to {@link X_inv49_2#instance()}.
478 *
479 * <p> This workaround is required e.g. to support recursion.
480 *
481 */
482 private static class LazyHolder {
483 private static final X_inv49_2 INSTANCE = new X_inv49_2();
484
485 /**
486 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
487 * This initialization order is required to support indirect recursion.
488 *
489 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
490 *
491 */
492 private static final Object STATIC_INITIALIZER = ensureInitialized();
493
494 public static Object ensureInitialized() {
495 INSTANCE.ensureInitializedInternal();
496 return null;
497 }
498 }
499
500 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
501 private static final X_inv49_2.GeneratedPQuery INSTANCE = new GeneratedPQuery();
502
503 private final PParameter parameter_iB = new PParameter("iB", "Taxation.Dependent", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Dependent")), PParameterDirection.INOUT);
504
505 private final List<PParameter> parameters = Arrays.asList(parameter_iB);
506
507 private GeneratedPQuery() {
508 super(PVisibility.PUBLIC);
509 }
510
511 @Override
512 public String getFullyQualifiedName() {
513 return "queries.x_inv49_2";
514 }
515
516 @Override
517 public List<String> getParameterNames() {
518 return Arrays.asList("iB");
519 }
520
521 @Override
522 public List<PParameter> getParameters() {
523 return parameters;
524 }
525
526 @Override
527 public Set<PBody> doGetContainedBodies() {
528 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
529 Set<PBody> bodies = new LinkedHashSet<>();
530 {
531 PBody body = new PBody(this);
532 PVariable var_iB = body.getOrCreateVariableByName("iB");
533 new TypeConstraint(body, Tuples.flatTupleOf(var_iB), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
534 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
535 new ExportedParameter(body, var_iB, parameter_iB)
536 ));
537 // Dependent(iB)
538 new TypeConstraint(body, Tuples.flatTupleOf(var_iB), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent")));
539 bodies.add(body);
540 }
541 return bodies;
542 }
543 }
544}