aboutsummaryrefslogtreecommitdiffstats
path: root/Tests/MODELS2020-CaseStudies/case.study.familyTree.run
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/MODELS2020-CaseStudies/case.study.familyTree.run')
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/.FamilyTreeConstraints.java._tracebin333 -> 632 bytes
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/familyTreeConstraints.vql27
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/errors.txt16
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/generation.logicproblem154
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/log.txt2
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.gml76
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.pngbin93940 -> 97536 bytes
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.xmi8
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/plugin.xml3
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.FamilyTreeConstraints.java._tracebin333 -> 632 bytes
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.gitignore4
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/FamilyTreeConstraints.java33
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/MemberHasParent.java551
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/ParentTooYoung.java775
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/TwoMembersHaveNoParent.java723
-rw-r--r--Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src/queries/familyTreeConstraints.vql27
16 files changed, 2319 insertions, 80 deletions
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/.FamilyTreeConstraints.java._trace b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/.FamilyTreeConstraints.java._trace
index 80158bd8..12849bfe 100644
--- a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/.FamilyTreeConstraints.java._trace
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/.FamilyTreeConstraints.java._trace
Binary files differ
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/familyTreeConstraints.vql b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/familyTreeConstraints.vql
index 1b9b6659..a204443a 100644
--- a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/familyTreeConstraints.vql
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/bin/queries/familyTreeConstraints.vql
@@ -9,14 +9,25 @@ pattern memberIsItsOwnParent(m: Member) = {
9 m == p; 9 m == p;
10} 10}
11 11
12//@Constraint(message="parentTooYoung", severity="error", key={m, p}) 12@Constraint(message="twoMembersHaveNoParent", severity="error", key={m1, m2})
13//pattern parentTooYoung(m: Member, p: Member) = { 13pattern twoMembersHaveNoParent(m1:Member, m2:Member) = {
14// FamilyTree.members(_, m); 14 neg find memberHasParent(m1);
15// Member.parents(m, p); 15 neg find memberHasParent(m2);
16// Member.age(m, mAge); 16 m1 != m2;
17// Member.age(p, pAge); 17}
18// check (mAge <= (pAge + 12)); 18
19//} 19pattern memberHasParent(m: Member) = {
20 Member.parents(m, _);
21}
22
23@Constraint(message="parentTooYoung", severity="error", key={m, p})
24pattern parentTooYoung(m: Member, p: Member) = {
25 FamilyTree.members(_, m);
26 Member.parents(m, p);
27 Member.age(m, mAge);
28 Member.age(p, pAge);
29 check (mAge <= (pAge + 12));
30}
20 31
21 32
22 33
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/errors.txt b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/errors.txt
new file mode 100644
index 00000000..b7eed629
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/errors.txt
@@ -0,0 +1,16 @@
1Error occured (NullPointerException):
2 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.PConstraintTransformer.hasValueExpression(PConstraintTransformer.java:487)
3 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.PConstraintTransformer._transformConstraint(PConstraintTransformer.java:614)
4 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.PConstraintTransformer.transformConstraint(PConstraintTransformer.java:689)
5 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.RelationDefinitionIndexer.transformPattern(RelationDefinitionIndexer.java:169)
6 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.RelationDefinitionIndexer.generateRelationDefinitions(RelationDefinitionIndexer.java:51)
7 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.PatternGenerator.transformBaseProperties(PatternGenerator.java:747)
8 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.PatternProvider.generateQueries(PatternProvider.java:59)
9 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.ModelGenerationMethodProvider.createModelGenerationMethod(ModelGenerationMethodProvider.java:57)
10 hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner.solve(ViatraReasoner.java:96)
11 hu.bme.mit.inf.dslreasoner.application.execution.GenerationTaskExecutor.executeGenerationTask(GenerationTaskExecutor.java:316)
12 hu.bme.mit.inf.dslreasoner.application.execution.ScriptExecutor._execute(ScriptExecutor.java:129)
13 hu.bme.mit.inf.dslreasoner.application.execution.ScriptExecutor.execute(ScriptExecutor.java:338)
14 hu.bme.mit.inf.dslreasoner.application.execution.ScriptExecutor.executeScript(ScriptExecutor.java:110)
15 hu.bme.mit.inf.dslreasoner.application.execution.StandaloneScriptExecutor.executeScript(StandaloneScriptExecutor.java:149)
16 run.FamilyTreeGen.main(FamilyTreeGen.java:7)
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/generation.logicproblem b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/generation.logicproblem
index dd3b15b1..327ce8b0 100644
--- a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/generation.logicproblem
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/debug/generation.logicproblem
@@ -123,7 +123,7 @@
123 </expression> 123 </expression>
124 </value> 124 </value>
125 </assertions> 125 </assertions>
126 <assertions name="errorpattern queries memberIsItsOwnParent" annotations="//@annotations.5"> 126 <assertions name="errorpattern queries memberIsItsOwnParent" annotations="//@annotations.8">
127 <value xsi:type="language_1:Forall"> 127 <value xsi:type="language_1:Forall">
128 <quantifiedVariables name="p0"> 128 <quantifiedVariables name="p0">
129 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/> 129 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
@@ -135,6 +135,38 @@
135 </expression> 135 </expression>
136 </value> 136 </value>
137 </assertions> 137 </assertions>
138 <assertions name="errorpattern queries twoMembersHaveNoParent" annotations="//@annotations.9">
139 <value xsi:type="language_1:Forall">
140 <quantifiedVariables name="p0">
141 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
142 </quantifiedVariables>
143 <quantifiedVariables name="p1">
144 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
145 </quantifiedVariables>
146 <expression xsi:type="language_1:Not">
147 <operand xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.6">
148 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@assertions.5/@value/@quantifiedVariables.0"/>
149 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@assertions.5/@value/@quantifiedVariables.1"/>
150 </operand>
151 </expression>
152 </value>
153 </assertions>
154 <assertions name="errorpattern queries parentTooYoung" annotations="//@annotations.10">
155 <value xsi:type="language_1:Forall">
156 <quantifiedVariables name="p0">
157 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
158 </quantifiedVariables>
159 <quantifiedVariables name="p1">
160 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
161 </quantifiedVariables>
162 <expression xsi:type="language_1:Not">
163 <operand xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.8">
164 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@assertions.6/@value/@quantifiedVariables.0"/>
165 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@assertions.6/@value/@quantifiedVariables.1"/>
166 </operand>
167 </expression>
168 </value>
169 </assertions>
138 <relations xsi:type="language_1:RelationDeclaration" name="members reference FamilyTree"> 170 <relations xsi:type="language_1:RelationDeclaration" name="members reference FamilyTree">
139 <parameters xsi:type="language_1:ComplexTypeReference" referred="//@types.0"/> 171 <parameters xsi:type="language_1:ComplexTypeReference" referred="//@types.0"/>
140 <parameters xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/> 172 <parameters xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
@@ -178,7 +210,114 @@
178 </operands> 210 </operands>
179 </value> 211 </value>
180 </relations> 212 </relations>
181 <containmentHierarchies typesOrderedInHierarchy="//@types.0 //@types.1" containmentRelations="//@relations.0"/> 213 <relations xsi:type="language_1:RelationDefinition" name="pattern queries twoMembersHaveNoParent" annotations="//@annotations.5">
214 <parameters xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
215 <parameters xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
216 <variables name="parameter m1">
217 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
218 </variables>
219 <variables name="parameter m2">
220 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
221 </variables>
222 <value xsi:type="language_1:Or">
223 <operands xsi:type="language_1:And">
224 <operands xsi:type="language_1:InstanceOf">
225 <value xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.6/@variables.0"/>
226 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
227 </operands>
228 <operands xsi:type="language_1:InstanceOf">
229 <value xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.6/@variables.1"/>
230 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
231 </operands>
232 <operands xsi:type="language_1:Not">
233 <operand xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.7">
234 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.6/@variables.0"/>
235 </operand>
236 </operands>
237 <operands xsi:type="language_1:Not">
238 <operand xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.7">
239 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.6/@variables.1"/>
240 </operand>
241 </operands>
242 <operands xsi:type="language_1:Distinct">
243 <operands xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.6/@variables.0"/>
244 <operands xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.6/@variables.1"/>
245 </operands>
246 </operands>
247 </value>
248 </relations>
249 <relations xsi:type="language_1:RelationDefinition" name="pattern queries memberHasParent" annotations="//@annotations.6">
250 <parameters xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
251 <variables name="parameter m">
252 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
253 </variables>
254 <value xsi:type="language_1:Or">
255 <operands xsi:type="language_1:Exists">
256 <quantifiedVariables name="variable 0">
257 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
258 </quantifiedVariables>
259 <expression xsi:type="language_1:And">
260 <operands xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.2">
261 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.7/@variables.0"/>
262 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.7/@value/@operands.0/@quantifiedVariables.0"/>
263 </operands>
264 <operands xsi:type="language_1:InstanceOf">
265 <value xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.7/@value/@operands.0/@quantifiedVariables.0"/>
266 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
267 </operands>
268 </expression>
269 </operands>
270 </value>
271 </relations>
272 <relations xsi:type="language_1:RelationDefinition" name="pattern queries parentTooYoung" annotations="//@annotations.7">
273 <parameters xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
274 <parameters xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
275 <variables name="parameter m">
276 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
277 </variables>
278 <variables name="parameter p">
279 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.1"/>
280 </variables>
281 <value xsi:type="language_1:Or">
282 <operands xsi:type="language_1:Exists">
283 <quantifiedVariables name="variable 0">
284 <range xsi:type="language_1:ComplexTypeReference" referred="//@types.0"/>
285 </quantifiedVariables>
286 <quantifiedVariables name="variable mAge">
287 <range xsi:type="language_1:IntTypeReference"/>
288 </quantifiedVariables>
289 <quantifiedVariables name="variable pAge">
290 <range xsi:type="language_1:IntTypeReference"/>
291 </quantifiedVariables>
292 <expression xsi:type="language_1:And">
293 <operands xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.0">
294 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.8/@value/@operands.0/@quantifiedVariables.0"/>
295 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.8/@variables.0"/>
296 </operands>
297 <operands xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.2">
298 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.8/@variables.0"/>
299 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.8/@variables.1"/>
300 </operands>
301 <operands xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.4">
302 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.8/@variables.0"/>
303 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.8/@value/@operands.0/@quantifiedVariables.1"/>
304 </operands>
305 <operands xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.4">
306 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.8/@variables.1"/>
307 <parameterSubstitutions xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.8/@value/@operands.0/@quantifiedVariables.2"/>
308 </operands>
309 <operands xsi:type="language_1:LessOrEqualThan">
310 <leftOperand xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.8/@value/@operands.0/@quantifiedVariables.1"/>
311 <rightOperand xsi:type="language_1:Plus">
312 <leftOperand xsi:type="language_1:SymbolicValue" symbolicReference="//@relations.8/@value/@operands.0/@quantifiedVariables.2"/>
313 <rightOperand xsi:type="language_1:IntLiteral" value="12"/>
314 </rightOperand>
315 </operands>
316 </expression>
317 </operands>
318 </value>
319 </relations>
320 <containmentHierarchies typesOrderedInHierarchy="//@types.1 //@types.0" containmentRelations="//@relations.0"/>
182 <annotations xsi:type="ecore2logicannotations:UpperMultiplicityAssertion" target="//@assertions.0" relation="//@relations.2" upper="2"/> 321 <annotations xsi:type="ecore2logicannotations:UpperMultiplicityAssertion" target="//@assertions.0" relation="//@relations.2" upper="2"/>
183 <annotations xsi:type="ecore2logicannotations:InverseRelationAssertion" target="//@assertions.1" inverseA="//@relations.1" inverseB="//@relations.2"/> 322 <annotations xsi:type="ecore2logicannotations:InverseRelationAssertion" target="//@assertions.1" inverseA="//@relations.1" inverseB="//@relations.2"/>
184 <annotations xsi:type="ecore2logicannotations:UpperMultiplicityAssertion" target="//@assertions.2" relation="//@relations.3" upper="1"/> 323 <annotations xsi:type="ecore2logicannotations:UpperMultiplicityAssertion" target="//@assertions.2" relation="//@relations.3" upper="1"/>
@@ -186,5 +325,16 @@
186 <annotations xsi:type="viatra2logicannotations:TransfomedViatraQuery" target="//@relations.5" patternFullyQualifiedName="queries.memberIsItsOwnParent"> 325 <annotations xsi:type="viatra2logicannotations:TransfomedViatraQuery" target="//@relations.5" patternFullyQualifiedName="queries.memberIsItsOwnParent">
187 <variableTrace targetLogicVariable="//@relations.5/@value/@operands.0/@quantifiedVariables.0"/> 326 <variableTrace targetLogicVariable="//@relations.5/@value/@operands.0/@quantifiedVariables.0"/>
188 </annotations> 327 </annotations>
328 <annotations xsi:type="viatra2logicannotations:TransfomedViatraQuery" target="//@relations.6" patternFullyQualifiedName="queries.twoMembersHaveNoParent"/>
329 <annotations xsi:type="viatra2logicannotations:TransfomedViatraQuery" target="//@relations.7" patternFullyQualifiedName="queries.memberHasParent">
330 <variableTrace targetLogicVariable="//@relations.7/@value/@operands.0/@quantifiedVariables.0"/>
331 </annotations>
332 <annotations xsi:type="viatra2logicannotations:TransfomedViatraQuery" target="//@relations.8" patternFullyQualifiedName="queries.parentTooYoung">
333 <variableTrace targetLogicVariable="//@relations.8/@value/@operands.0/@quantifiedVariables.0"/>
334 <variableTrace targetLogicVariable="//@relations.8/@value/@operands.0/@quantifiedVariables.1"/>
335 <variableTrace targetLogicVariable="//@relations.8/@value/@operands.0/@quantifiedVariables.2"/>
336 </annotations>
189 <annotations xsi:type="viatra2logicannotations:TransformedViatraWellformednessConstraint" target="//@assertions.4" query="//@annotations.4"/> 337 <annotations xsi:type="viatra2logicannotations:TransformedViatraWellformednessConstraint" target="//@assertions.4" query="//@annotations.4"/>
338 <annotations xsi:type="viatra2logicannotations:TransformedViatraWellformednessConstraint" target="//@assertions.5" query="//@annotations.5"/>
339 <annotations xsi:type="viatra2logicannotations:TransformedViatraWellformednessConstraint" target="//@assertions.6" query="//@annotations.7"/>
190</language:LogicProblem> 340</language:LogicProblem>
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/log.txt b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/log.txt
index 6186ec60..43befb00 100644
--- a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/log.txt
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/log.txt
@@ -1 +1 @@
Model generation finished Model generation started
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.gml b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.gml
index 0182add9..88392428 100644
--- a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.gml
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.gml
@@ -667,8 +667,8 @@ graph
667 ] 667 ]
668 edge 668 edge
669 [ 669 [
670 source 9 670 source 8
671 target 8 671 target 9
672 graphics 672 graphics
673 [ 673 [
674 fill "#000000" 674 fill "#000000"
@@ -686,8 +686,8 @@ graph
686 ] 686 ]
687 edge 687 edge
688 [ 688 [
689 source 8 689 source 9
690 target 9 690 target 8
691 graphics 691 graphics
692 [ 692 [
693 fill "#000000" 693 fill "#000000"
@@ -706,7 +706,7 @@ graph
706 edge 706 edge
707 [ 707 [
708 source 10 708 source 10
709 target 11 709 target 9
710 graphics 710 graphics
711 [ 711 [
712 fill "#000000" 712 fill "#000000"
@@ -724,8 +724,8 @@ graph
724 ] 724 ]
725 edge 725 edge
726 [ 726 [
727 source 8 727 source 10
728 target 10 728 target 8
729 graphics 729 graphics
730 [ 730 [
731 fill "#000000" 731 fill "#000000"
@@ -743,8 +743,8 @@ graph
743 ] 743 ]
744 edge 744 edge
745 [ 745 [
746 source 11 746 source 9
747 target 9 747 target 10
748 graphics 748 graphics
749 [ 749 [
750 fill "#000000" 750 fill "#000000"
@@ -781,7 +781,7 @@ graph
781 ] 781 ]
782 edge 782 edge
783 [ 783 [
784 source 10 784 source 9
785 target 8 785 target 8
786 graphics 786 graphics
787 [ 787 [
@@ -790,7 +790,7 @@ graph
790 ] 790 ]
791 LabelGraphics 791 LabelGraphics
792 [ 792 [
793 text "children reference Member" 793 text "parents reference Member"
794 fontSize 14 794 fontSize 14
795 fontName "Consolas" 795 fontName "Consolas"
796 configuration "AutoFlippingLabel" 796 configuration "AutoFlippingLabel"
@@ -820,7 +820,7 @@ graph
820 edge 820 edge
821 [ 821 [
822 source 9 822 source 9
823 target 8 823 target 10
824 graphics 824 graphics
825 [ 825 [
826 fill "#000000" 826 fill "#000000"
@@ -838,7 +838,7 @@ graph
838 ] 838 ]
839 edge 839 edge
840 [ 840 [
841 source 11 841 source 8
842 target 10 842 target 10
843 graphics 843 graphics
844 [ 844 [
@@ -858,26 +858,7 @@ graph
858 edge 858 edge
859 [ 859 [
860 source 10 860 source 10
861 target 8 861 target 9
862 graphics
863 [
864 fill "#000000"
865 targetArrow "standard"
866 ]
867 LabelGraphics
868 [
869 text "parents reference Member"
870 fontSize 14
871 fontName "Consolas"
872 configuration "AutoFlippingLabel"
873 model "six_pos"
874 position "thead"
875 ]
876 ]
877 edge
878 [
879 source 9
880 target 11
881 graphics 862 graphics
882 [ 863 [
883 fill "#000000" 864 fill "#000000"
@@ -914,27 +895,8 @@ graph
914 ] 895 ]
915 edge 896 edge
916 [ 897 [
917 source 8 898 source 9
918 target 10 899 target 5
919 graphics
920 [
921 fill "#000000"
922 targetArrow "standard"
923 ]
924 LabelGraphics
925 [
926 text "parents reference Member"
927 fontSize 14
928 fontName "Consolas"
929 configuration "AutoFlippingLabel"
930 model "six_pos"
931 position "thead"
932 ]
933 ]
934 edge
935 [
936 source 8
937 target 6
938 graphics 900 graphics
939 [ 901 [
940 fill "#000000" 902 fill "#000000"
@@ -952,7 +914,7 @@ graph
952 ] 914 ]
953 edge 915 edge
954 [ 916 [
955 source 9 917 source 8
956 target 5 918 target 5
957 graphics 919 graphics
958 [ 920 [
@@ -972,7 +934,7 @@ graph
972 edge 934 edge
973 [ 935 [
974 source 10 936 source 10
975 target 2 937 target 5
976 graphics 938 graphics
977 [ 939 [
978 fill "#000000" 940 fill "#000000"
@@ -991,7 +953,7 @@ graph
991 edge 953 edge
992 [ 954 [
993 source 11 955 source 11
994 target 4 956 target 6
995 graphics 957 graphics
996 [ 958 [
997 fill "#000000" 959 fill "#000000"
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.png b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.png
index 391d902b..4c0da9fb 100644
--- a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.png
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.png
Binary files differ
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.xmi b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.xmi
index 11e0e7c3..25c5bfed 100644
--- a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.xmi
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/outputs/models/1.xmi
@@ -1,8 +1,8 @@
1<?xml version="1.0" encoding="ASCII"?> 1<?xml version="1.0" encoding="ASCII"?>
2<familytree:FamilyTree xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:familytree="http://www.example.org/familytree" xsi:schemaLocation="http://www.example.org/familytree inputs/familytree.ecore"> 2<familytree:FamilyTree xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:familytree="http://www.example.org/familytree" xsi:schemaLocation="http://www.example.org/familytree inputs/familytree.ecore">
3 <members age="4" children="//@members.4" parents="//@members.3 //@members.4"/> 3 <members age="4" children="//@members.2 //@members.4" parents="//@members.1 //@members.2"/>
4 <members age="5" children="//@members.0"/>
5 <members age="4" children="//@members.0 //@members.4" parents="//@members.0 //@members.4"/>
4 <members/> 6 <members/>
5 <members age="1" children="//@members.3 //@members.4" parents="//@members.3 //@members.4"/> 7 <members age="4" children="//@members.2" parents="//@members.0 //@members.2"/>
6 <members age="3" children="//@members.0 //@members.2" parents="//@members.2"/>
7 <members age="5" children="//@members.0 //@members.2" parents="//@members.0 //@members.2"/>
8</familytree:FamilyTree> 8</familytree:FamilyTree>
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/plugin.xml b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/plugin.xml
index b32b0215..9364ebb2 100644
--- a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/plugin.xml
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/plugin.xml
@@ -2,6 +2,9 @@
2 <extension id="queries.FamilyTreeConstraints" point="org.eclipse.viatra.query.runtime.queryspecification"> 2 <extension id="queries.FamilyTreeConstraints" point="org.eclipse.viatra.query.runtime.queryspecification">
3 <group group="org.eclipse.viatra.query.runtime.extensibility.SingletonExtensionFactory:queries.FamilyTreeConstraints" id="queries.FamilyTreeConstraints"> 3 <group group="org.eclipse.viatra.query.runtime.extensibility.SingletonExtensionFactory:queries.FamilyTreeConstraints" id="queries.FamilyTreeConstraints">
4 <query-specification fqn="queries.memberIsItsOwnParent"/> 4 <query-specification fqn="queries.memberIsItsOwnParent"/>
5 <query-specification fqn="queries.twoMembersHaveNoParent"/>
6 <query-specification fqn="queries.memberHasParent"/>
7 <query-specification fqn="queries.parentTooYoung"/>
5 </group> 8 </group>
6 </extension> 9 </extension>
7</plugin> 10</plugin>
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.FamilyTreeConstraints.java._trace b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.FamilyTreeConstraints.java._trace
index 80158bd8..12849bfe 100644
--- a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.FamilyTreeConstraints.java._trace
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.FamilyTreeConstraints.java._trace
Binary files differ
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.gitignore b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.gitignore
index 1641b3f8..3be531f5 100644
--- a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.gitignore
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/.gitignore
@@ -2,3 +2,7 @@
2/.MemberIsItsOwnParent.java._trace 2/.MemberIsItsOwnParent.java._trace
3/FamilyTreeConstraints.java 3/FamilyTreeConstraints.java
4/MemberIsItsOwnParent.java 4/MemberIsItsOwnParent.java
5/.ParentTooYoung.java._trace
6/.MemberHasNoParent.java._trace
7/.MemberHasParent.java._trace
8/.TwoMembersHaveNoParent.java._trace
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/FamilyTreeConstraints.java b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/FamilyTreeConstraints.java
index a5c375c6..738b41c0 100644
--- a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/FamilyTreeConstraints.java
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/FamilyTreeConstraints.java
@@ -5,7 +5,10 @@ package queries;
5 5
6import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; 6import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
7import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; 7import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup;
8import queries.MemberHasParent;
8import queries.MemberIsItsOwnParent; 9import queries.MemberIsItsOwnParent;
10import queries.ParentTooYoung;
11import queries.TwoMembersHaveNoParent;
9 12
10/** 13/**
11 * A pattern group formed of all public patterns defined in familyTreeConstraints.vql. 14 * A pattern group formed of all public patterns defined in familyTreeConstraints.vql.
@@ -16,6 +19,9 @@ import queries.MemberIsItsOwnParent;
16 * 19 *
17 * <p> From package queries, the group contains the definition of the following patterns: <ul> 20 * <p> From package queries, the group contains the definition of the following patterns: <ul>
18 * <li>memberIsItsOwnParent</li> 21 * <li>memberIsItsOwnParent</li>
22 * <li>twoMembersHaveNoParent</li>
23 * <li>memberHasParent</li>
24 * <li>parentTooYoung</li>
19 * </ul> 25 * </ul>
20 * 26 *
21 * @see IQueryGroup 27 * @see IQueryGroup
@@ -41,6 +47,9 @@ public final class FamilyTreeConstraints extends BaseGeneratedPatternGroup {
41 47
42 private FamilyTreeConstraints() { 48 private FamilyTreeConstraints() {
43 querySpecifications.add(MemberIsItsOwnParent.instance()); 49 querySpecifications.add(MemberIsItsOwnParent.instance());
50 querySpecifications.add(TwoMembersHaveNoParent.instance());
51 querySpecifications.add(MemberHasParent.instance());
52 querySpecifications.add(ParentTooYoung.instance());
44 } 53 }
45 54
46 public MemberIsItsOwnParent getMemberIsItsOwnParent() { 55 public MemberIsItsOwnParent getMemberIsItsOwnParent() {
@@ -50,4 +59,28 @@ public final class FamilyTreeConstraints extends BaseGeneratedPatternGroup {
50 public MemberIsItsOwnParent.Matcher getMemberIsItsOwnParent(final ViatraQueryEngine engine) { 59 public MemberIsItsOwnParent.Matcher getMemberIsItsOwnParent(final ViatraQueryEngine engine) {
51 return MemberIsItsOwnParent.Matcher.on(engine); 60 return MemberIsItsOwnParent.Matcher.on(engine);
52 } 61 }
62
63 public TwoMembersHaveNoParent getTwoMembersHaveNoParent() {
64 return TwoMembersHaveNoParent.instance();
65 }
66
67 public TwoMembersHaveNoParent.Matcher getTwoMembersHaveNoParent(final ViatraQueryEngine engine) {
68 return TwoMembersHaveNoParent.Matcher.on(engine);
69 }
70
71 public MemberHasParent getMemberHasParent() {
72 return MemberHasParent.instance();
73 }
74
75 public MemberHasParent.Matcher getMemberHasParent(final ViatraQueryEngine engine) {
76 return MemberHasParent.Matcher.on(engine);
77 }
78
79 public ParentTooYoung getParentTooYoung() {
80 return ParentTooYoung.instance();
81 }
82
83 public ParentTooYoung.Matcher getParentTooYoung(final ViatraQueryEngine engine) {
84 return ParentTooYoung.Matcher.on(engine);
85 }
53} 86}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/MemberHasParent.java b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/MemberHasParent.java
new file mode 100644
index 00000000..82b83d0c
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/MemberHasParent.java
@@ -0,0 +1,551 @@
1/**
2 * Generated from platform:/resource/case.study.familyTree.run/src/queries/familyTreeConstraints.vql
3 */
4package queries;
5
6import familytree.Member;
7import java.util.Arrays;
8import java.util.Collection;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Objects;
12import java.util.Optional;
13import java.util.Set;
14import java.util.function.Consumer;
15import java.util.stream.Collectors;
16import java.util.stream.Stream;
17import org.apache.log4j.Logger;
18import org.eclipse.emf.ecore.EClass;
19import org.eclipse.viatra.query.runtime.api.IPatternMatch;
20import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
21import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
22import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
24import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
25import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
26import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
27import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
28import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
29import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
30import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
31import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
34import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
37import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
39import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
40
41/**
42 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
43 *
44 * <p>Original source:
45 * <code><pre>
46 * pattern memberHasParent(m: Member) = {
47 * Member.parents(m, _);
48 * }
49 * </pre></code>
50 *
51 * @see Matcher
52 * @see Match
53 *
54 */
55@SuppressWarnings("all")
56public final class MemberHasParent extends BaseGeneratedEMFQuerySpecification<MemberHasParent.Matcher> {
57 /**
58 * Pattern-specific match representation of the queries.memberHasParent pattern,
59 * to be used in conjunction with {@link Matcher}.
60 *
61 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
62 * Each instance is a (possibly partial) substitution of pattern parameters,
63 * usable to represent a match of the pattern in the result of a query,
64 * or to specify the bound (fixed) input parameters when issuing a query.
65 *
66 * @see Matcher
67 *
68 */
69 public static abstract class Match extends BasePatternMatch {
70 private Member fM;
71
72 private static List<String> parameterNames = makeImmutableList("m");
73
74 private Match(final Member pM) {
75 this.fM = pM;
76 }
77
78 @Override
79 public Object get(final String parameterName) {
80 switch(parameterName) {
81 case "m": return this.fM;
82 default: return null;
83 }
84 }
85
86 @Override
87 public Object get(final int index) {
88 switch(index) {
89 case 0: return this.fM;
90 default: return null;
91 }
92 }
93
94 public Member getM() {
95 return this.fM;
96 }
97
98 @Override
99 public boolean set(final String parameterName, final Object newValue) {
100 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
101 if ("m".equals(parameterName) ) {
102 this.fM = (Member) newValue;
103 return true;
104 }
105 return false;
106 }
107
108 public void setM(final Member pM) {
109 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
110 this.fM = pM;
111 }
112
113 @Override
114 public String patternName() {
115 return "queries.memberHasParent";
116 }
117
118 @Override
119 public List<String> parameterNames() {
120 return MemberHasParent.Match.parameterNames;
121 }
122
123 @Override
124 public Object[] toArray() {
125 return new Object[]{fM};
126 }
127
128 @Override
129 public MemberHasParent.Match toImmutable() {
130 return isMutable() ? newMatch(fM) : this;
131 }
132
133 @Override
134 public String prettyPrint() {
135 StringBuilder result = new StringBuilder();
136 result.append("\"m\"=" + prettyPrintValue(fM));
137 return result.toString();
138 }
139
140 @Override
141 public int hashCode() {
142 return Objects.hash(fM);
143 }
144
145 @Override
146 public boolean equals(final Object obj) {
147 if (this == obj)
148 return true;
149 if (obj == null) {
150 return false;
151 }
152 if ((obj instanceof MemberHasParent.Match)) {
153 MemberHasParent.Match other = (MemberHasParent.Match) obj;
154 return Objects.equals(fM, other.fM);
155 } else {
156 // this should be infrequent
157 if (!(obj instanceof IPatternMatch)) {
158 return false;
159 }
160 IPatternMatch otherSig = (IPatternMatch) obj;
161 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
162 }
163 }
164
165 @Override
166 public MemberHasParent specification() {
167 return MemberHasParent.instance();
168 }
169
170 /**
171 * Returns an empty, mutable match.
172 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
173 *
174 * @return the empty match.
175 *
176 */
177 public static MemberHasParent.Match newEmptyMatch() {
178 return new Mutable(null);
179 }
180
181 /**
182 * Returns a mutable (partial) match.
183 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
184 *
185 * @param pM the fixed value of pattern parameter m, or null if not bound.
186 * @return the new, mutable (partial) match object.
187 *
188 */
189 public static MemberHasParent.Match newMutableMatch(final Member pM) {
190 return new Mutable(pM);
191 }
192
193 /**
194 * Returns a new (partial) match.
195 * This can be used e.g. to call the matcher with a partial match.
196 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
197 * @param pM the fixed value of pattern parameter m, or null if not bound.
198 * @return the (partial) match object.
199 *
200 */
201 public static MemberHasParent.Match newMatch(final Member pM) {
202 return new Immutable(pM);
203 }
204
205 private static final class Mutable extends MemberHasParent.Match {
206 Mutable(final Member pM) {
207 super(pM);
208 }
209
210 @Override
211 public boolean isMutable() {
212 return true;
213 }
214 }
215
216 private static final class Immutable extends MemberHasParent.Match {
217 Immutable(final Member pM) {
218 super(pM);
219 }
220
221 @Override
222 public boolean isMutable() {
223 return false;
224 }
225 }
226 }
227
228 /**
229 * Generated pattern matcher API of the queries.memberHasParent pattern,
230 * providing pattern-specific query methods.
231 *
232 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
233 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
234 *
235 * <p>Matches of the pattern will be represented as {@link Match}.
236 *
237 * <p>Original source:
238 * <code><pre>
239 * pattern memberHasParent(m: Member) = {
240 * Member.parents(m, _);
241 * }
242 * </pre></code>
243 *
244 * @see Match
245 * @see MemberHasParent
246 *
247 */
248 public static class Matcher extends BaseMatcher<MemberHasParent.Match> {
249 /**
250 * Initializes the pattern matcher within an existing VIATRA Query engine.
251 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
252 *
253 * @param engine the existing VIATRA Query engine in which this matcher will be created.
254 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
255 *
256 */
257 public static MemberHasParent.Matcher on(final ViatraQueryEngine engine) {
258 // check if matcher already exists
259 Matcher matcher = engine.getExistingMatcher(querySpecification());
260 if (matcher == null) {
261 matcher = (Matcher)engine.getMatcher(querySpecification());
262 }
263 return matcher;
264 }
265
266 /**
267 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
268 * @return an initialized matcher
269 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
270 *
271 */
272 public static MemberHasParent.Matcher create() {
273 return new Matcher();
274 }
275
276 private static final int POSITION_M = 0;
277
278 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(MemberHasParent.Matcher.class);
279
280 /**
281 * Initializes the pattern matcher within an existing VIATRA Query engine.
282 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
283 *
284 * @param engine the existing VIATRA Query engine in which this matcher will be created.
285 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
286 *
287 */
288 private Matcher() {
289 super(querySpecification());
290 }
291
292 /**
293 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
294 * @param pM the fixed value of pattern parameter m, or null if not bound.
295 * @return matches represented as a Match object.
296 *
297 */
298 public Collection<MemberHasParent.Match> getAllMatches(final Member pM) {
299 return rawStreamAllMatches(new Object[]{pM}).collect(Collectors.toSet());
300 }
301
302 /**
303 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
304 * </p>
305 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
306 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
307 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
308 * @param pM the fixed value of pattern parameter m, or null if not bound.
309 * @return a stream of matches represented as a Match object.
310 *
311 */
312 public Stream<MemberHasParent.Match> streamAllMatches(final Member pM) {
313 return rawStreamAllMatches(new Object[]{pM});
314 }
315
316 /**
317 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
318 * Neither determinism nor randomness of selection is guaranteed.
319 * @param pM the fixed value of pattern parameter m, or null if not bound.
320 * @return a match represented as a Match object, or null if no match is found.
321 *
322 */
323 public Optional<MemberHasParent.Match> getOneArbitraryMatch(final Member pM) {
324 return rawGetOneArbitraryMatch(new Object[]{pM});
325 }
326
327 /**
328 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
329 * under any possible substitution of the unspecified parameters (if any).
330 * @param pM the fixed value of pattern parameter m, or null if not bound.
331 * @return true if the input is a valid (partial) match of the pattern.
332 *
333 */
334 public boolean hasMatch(final Member pM) {
335 return rawHasMatch(new Object[]{pM});
336 }
337
338 /**
339 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
340 * @param pM the fixed value of pattern parameter m, or null if not bound.
341 * @return the number of pattern matches found.
342 *
343 */
344 public int countMatches(final Member pM) {
345 return rawCountMatches(new Object[]{pM});
346 }
347
348 /**
349 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
350 * Neither determinism nor randomness of selection is guaranteed.
351 * @param pM the fixed value of pattern parameter m, or null if not bound.
352 * @param processor the action that will process the selected match.
353 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
354 *
355 */
356 public boolean forOneArbitraryMatch(final Member pM, final Consumer<? super MemberHasParent.Match> processor) {
357 return rawForOneArbitraryMatch(new Object[]{pM}, processor);
358 }
359
360 /**
361 * Returns a new (partial) match.
362 * This can be used e.g. to call the matcher with a partial match.
363 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
364 * @param pM the fixed value of pattern parameter m, or null if not bound.
365 * @return the (partial) match object.
366 *
367 */
368 public MemberHasParent.Match newMatch(final Member pM) {
369 return MemberHasParent.Match.newMatch(pM);
370 }
371
372 /**
373 * Retrieve the set of values that occur in matches for m.
374 * @return the Set of all values or empty set if there are no matches
375 *
376 */
377 protected Stream<Member> rawStreamAllValuesOfm(final Object[] parameters) {
378 return rawStreamAllValues(POSITION_M, parameters).map(Member.class::cast);
379 }
380
381 /**
382 * Retrieve the set of values that occur in matches for m.
383 * @return the Set of all values or empty set if there are no matches
384 *
385 */
386 public Set<Member> getAllValuesOfm() {
387 return rawStreamAllValuesOfm(emptyArray()).collect(Collectors.toSet());
388 }
389
390 /**
391 * Retrieve the set of values that occur in matches for m.
392 * @return the Set of all values or empty set if there are no matches
393 *
394 */
395 public Stream<Member> streamAllValuesOfm() {
396 return rawStreamAllValuesOfm(emptyArray());
397 }
398
399 @Override
400 protected MemberHasParent.Match tupleToMatch(final Tuple t) {
401 try {
402 return MemberHasParent.Match.newMatch((Member) t.get(POSITION_M));
403 } catch(ClassCastException e) {
404 LOGGER.error("Element(s) in tuple not properly typed!",e);
405 return null;
406 }
407 }
408
409 @Override
410 protected MemberHasParent.Match arrayToMatch(final Object[] match) {
411 try {
412 return MemberHasParent.Match.newMatch((Member) match[POSITION_M]);
413 } catch(ClassCastException e) {
414 LOGGER.error("Element(s) in array not properly typed!",e);
415 return null;
416 }
417 }
418
419 @Override
420 protected MemberHasParent.Match arrayToMatchMutable(final Object[] match) {
421 try {
422 return MemberHasParent.Match.newMutableMatch((Member) match[POSITION_M]);
423 } catch(ClassCastException e) {
424 LOGGER.error("Element(s) in array not properly typed!",e);
425 return null;
426 }
427 }
428
429 /**
430 * @return the singleton instance of the query specification of this pattern
431 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
432 *
433 */
434 public static IQuerySpecification<MemberHasParent.Matcher> querySpecification() {
435 return MemberHasParent.instance();
436 }
437 }
438
439 private MemberHasParent() {
440 super(GeneratedPQuery.INSTANCE);
441 }
442
443 /**
444 * @return the singleton instance of the query specification
445 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
446 *
447 */
448 public static MemberHasParent instance() {
449 try{
450 return LazyHolder.INSTANCE;
451 } catch (ExceptionInInitializerError err) {
452 throw processInitializerError(err);
453 }
454 }
455
456 @Override
457 protected MemberHasParent.Matcher instantiate(final ViatraQueryEngine engine) {
458 return MemberHasParent.Matcher.on(engine);
459 }
460
461 @Override
462 public MemberHasParent.Matcher instantiate() {
463 return MemberHasParent.Matcher.create();
464 }
465
466 @Override
467 public MemberHasParent.Match newEmptyMatch() {
468 return MemberHasParent.Match.newEmptyMatch();
469 }
470
471 @Override
472 public MemberHasParent.Match newMatch(final Object... parameters) {
473 return MemberHasParent.Match.newMatch((familytree.Member) parameters[0]);
474 }
475
476 /**
477 * Inner class allowing the singleton instance of {@link MemberHasParent} to be created
478 * <b>not</b> at the class load time of the outer class,
479 * but rather at the first call to {@link MemberHasParent#instance()}.
480 *
481 * <p> This workaround is required e.g. to support recursion.
482 *
483 */
484 private static class LazyHolder {
485 private static final MemberHasParent INSTANCE = new MemberHasParent();
486
487 /**
488 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
489 * This initialization order is required to support indirect recursion.
490 *
491 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
492 *
493 */
494 private static final Object STATIC_INITIALIZER = ensureInitialized();
495
496 public static Object ensureInitialized() {
497 INSTANCE.ensureInitializedInternal();
498 return null;
499 }
500 }
501
502 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
503 private static final MemberHasParent.GeneratedPQuery INSTANCE = new GeneratedPQuery();
504
505 private final PParameter parameter_m = new PParameter("m", "familytree.Member", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/familytree", "Member")), PParameterDirection.INOUT);
506
507 private final List<PParameter> parameters = Arrays.asList(parameter_m);
508
509 private GeneratedPQuery() {
510 super(PVisibility.PUBLIC);
511 }
512
513 @Override
514 public String getFullyQualifiedName() {
515 return "queries.memberHasParent";
516 }
517
518 @Override
519 public List<String> getParameterNames() {
520 return Arrays.asList("m");
521 }
522
523 @Override
524 public List<PParameter> getParameters() {
525 return parameters;
526 }
527
528 @Override
529 public Set<PBody> doGetContainedBodies() {
530 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
531 Set<PBody> bodies = new LinkedHashSet<>();
532 {
533 PBody body = new PBody(this);
534 PVariable var_m = body.getOrCreateVariableByName("m");
535 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
536 new TypeConstraint(body, Tuples.flatTupleOf(var_m), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member")));
537 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
538 new ExportedParameter(body, var_m, parameter_m)
539 ));
540 // Member.parents(m, _)
541 new TypeConstraint(body, Tuples.flatTupleOf(var_m), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member")));
542 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
543 new TypeConstraint(body, Tuples.flatTupleOf(var_m, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/familytree", "Member", "parents")));
544 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member")));
545 new Equality(body, var__virtual_0_, var___0_);
546 bodies.add(body);
547 }
548 return bodies;
549 }
550 }
551}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/ParentTooYoung.java b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/ParentTooYoung.java
new file mode 100644
index 00000000..e90186e2
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/ParentTooYoung.java
@@ -0,0 +1,775 @@
1/**
2 * Generated from platform:/resource/case.study.familyTree.run/src/queries/familyTreeConstraints.vql
3 */
4package queries;
5
6import familytree.Member;
7import java.util.Arrays;
8import java.util.Collection;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Objects;
12import java.util.Optional;
13import java.util.Set;
14import java.util.function.Consumer;
15import java.util.stream.Collectors;
16import java.util.stream.Stream;
17import org.apache.log4j.Logger;
18import org.eclipse.emf.ecore.EClass;
19import org.eclipse.emf.ecore.EDataType;
20import org.eclipse.viatra.query.runtime.api.IPatternMatch;
21import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
22import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
25import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
26import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
27import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
28import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey;
29import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
30import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
31import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
32import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
33import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
34import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
35import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
36import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
39import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
40import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
42import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
43import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
44import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
45import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
46import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
47
48/**
49 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
50 *
51 * <p>Original source:
52 * <code><pre>
53 * {@literal @}Constraint(message="parentTooYoung", severity="error", key={m, p})
54 * pattern parentTooYoung(m: Member, p: Member) = {
55 * FamilyTree.members(_, m);
56 * Member.parents(m, p);
57 * Member.age(m, mAge);
58 * Member.age(p, pAge);
59 * check (mAge {@literal <}= (pAge + 12));
60 * }
61 * </pre></code>
62 *
63 * @see Matcher
64 * @see Match
65 *
66 */
67@SuppressWarnings("all")
68public final class ParentTooYoung extends BaseGeneratedEMFQuerySpecification<ParentTooYoung.Matcher> {
69 /**
70 * Pattern-specific match representation of the queries.parentTooYoung pattern,
71 * to be used in conjunction with {@link Matcher}.
72 *
73 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
74 * Each instance is a (possibly partial) substitution of pattern parameters,
75 * usable to represent a match of the pattern in the result of a query,
76 * or to specify the bound (fixed) input parameters when issuing a query.
77 *
78 * @see Matcher
79 *
80 */
81 public static abstract class Match extends BasePatternMatch {
82 private Member fM;
83
84 private Member fP;
85
86 private static List<String> parameterNames = makeImmutableList("m", "p");
87
88 private Match(final Member pM, final Member pP) {
89 this.fM = pM;
90 this.fP = pP;
91 }
92
93 @Override
94 public Object get(final String parameterName) {
95 switch(parameterName) {
96 case "m": return this.fM;
97 case "p": return this.fP;
98 default: return null;
99 }
100 }
101
102 @Override
103 public Object get(final int index) {
104 switch(index) {
105 case 0: return this.fM;
106 case 1: return this.fP;
107 default: return null;
108 }
109 }
110
111 public Member getM() {
112 return this.fM;
113 }
114
115 public Member getP() {
116 return this.fP;
117 }
118
119 @Override
120 public boolean set(final String parameterName, final Object newValue) {
121 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
122 if ("m".equals(parameterName) ) {
123 this.fM = (Member) newValue;
124 return true;
125 }
126 if ("p".equals(parameterName) ) {
127 this.fP = (Member) newValue;
128 return true;
129 }
130 return false;
131 }
132
133 public void setM(final Member pM) {
134 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
135 this.fM = pM;
136 }
137
138 public void setP(final Member pP) {
139 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
140 this.fP = pP;
141 }
142
143 @Override
144 public String patternName() {
145 return "queries.parentTooYoung";
146 }
147
148 @Override
149 public List<String> parameterNames() {
150 return ParentTooYoung.Match.parameterNames;
151 }
152
153 @Override
154 public Object[] toArray() {
155 return new Object[]{fM, fP};
156 }
157
158 @Override
159 public ParentTooYoung.Match toImmutable() {
160 return isMutable() ? newMatch(fM, fP) : this;
161 }
162
163 @Override
164 public String prettyPrint() {
165 StringBuilder result = new StringBuilder();
166 result.append("\"m\"=" + prettyPrintValue(fM) + ", ");
167 result.append("\"p\"=" + prettyPrintValue(fP));
168 return result.toString();
169 }
170
171 @Override
172 public int hashCode() {
173 return Objects.hash(fM, fP);
174 }
175
176 @Override
177 public boolean equals(final Object obj) {
178 if (this == obj)
179 return true;
180 if (obj == null) {
181 return false;
182 }
183 if ((obj instanceof ParentTooYoung.Match)) {
184 ParentTooYoung.Match other = (ParentTooYoung.Match) obj;
185 return Objects.equals(fM, other.fM) && Objects.equals(fP, other.fP);
186 } else {
187 // this should be infrequent
188 if (!(obj instanceof IPatternMatch)) {
189 return false;
190 }
191 IPatternMatch otherSig = (IPatternMatch) obj;
192 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
193 }
194 }
195
196 @Override
197 public ParentTooYoung specification() {
198 return ParentTooYoung.instance();
199 }
200
201 /**
202 * Returns an empty, mutable match.
203 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
204 *
205 * @return the empty match.
206 *
207 */
208 public static ParentTooYoung.Match newEmptyMatch() {
209 return new Mutable(null, null);
210 }
211
212 /**
213 * Returns a mutable (partial) match.
214 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
215 *
216 * @param pM the fixed value of pattern parameter m, or null if not bound.
217 * @param pP the fixed value of pattern parameter p, or null if not bound.
218 * @return the new, mutable (partial) match object.
219 *
220 */
221 public static ParentTooYoung.Match newMutableMatch(final Member pM, final Member pP) {
222 return new Mutable(pM, pP);
223 }
224
225 /**
226 * Returns a new (partial) match.
227 * This can be used e.g. to call the matcher with a partial match.
228 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
229 * @param pM the fixed value of pattern parameter m, or null if not bound.
230 * @param pP the fixed value of pattern parameter p, or null if not bound.
231 * @return the (partial) match object.
232 *
233 */
234 public static ParentTooYoung.Match newMatch(final Member pM, final Member pP) {
235 return new Immutable(pM, pP);
236 }
237
238 private static final class Mutable extends ParentTooYoung.Match {
239 Mutable(final Member pM, final Member pP) {
240 super(pM, pP);
241 }
242
243 @Override
244 public boolean isMutable() {
245 return true;
246 }
247 }
248
249 private static final class Immutable extends ParentTooYoung.Match {
250 Immutable(final Member pM, final Member pP) {
251 super(pM, pP);
252 }
253
254 @Override
255 public boolean isMutable() {
256 return false;
257 }
258 }
259 }
260
261 /**
262 * Generated pattern matcher API of the queries.parentTooYoung pattern,
263 * providing pattern-specific query methods.
264 *
265 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
266 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
267 *
268 * <p>Matches of the pattern will be represented as {@link Match}.
269 *
270 * <p>Original source:
271 * <code><pre>
272 * {@literal @}Constraint(message="parentTooYoung", severity="error", key={m, p})
273 * pattern parentTooYoung(m: Member, p: Member) = {
274 * FamilyTree.members(_, m);
275 * Member.parents(m, p);
276 * Member.age(m, mAge);
277 * Member.age(p, pAge);
278 * check (mAge {@literal <}= (pAge + 12));
279 * }
280 * </pre></code>
281 *
282 * @see Match
283 * @see ParentTooYoung
284 *
285 */
286 public static class Matcher extends BaseMatcher<ParentTooYoung.Match> {
287 /**
288 * Initializes the pattern matcher within an existing VIATRA Query engine.
289 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
290 *
291 * @param engine the existing VIATRA Query engine in which this matcher will be created.
292 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
293 *
294 */
295 public static ParentTooYoung.Matcher on(final ViatraQueryEngine engine) {
296 // check if matcher already exists
297 Matcher matcher = engine.getExistingMatcher(querySpecification());
298 if (matcher == null) {
299 matcher = (Matcher)engine.getMatcher(querySpecification());
300 }
301 return matcher;
302 }
303
304 /**
305 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
306 * @return an initialized matcher
307 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
308 *
309 */
310 public static ParentTooYoung.Matcher create() {
311 return new Matcher();
312 }
313
314 private static final int POSITION_M = 0;
315
316 private static final int POSITION_P = 1;
317
318 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ParentTooYoung.Matcher.class);
319
320 /**
321 * Initializes the pattern matcher within an existing VIATRA Query engine.
322 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
323 *
324 * @param engine the existing VIATRA Query engine in which this matcher will be created.
325 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
326 *
327 */
328 private Matcher() {
329 super(querySpecification());
330 }
331
332 /**
333 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
334 * @param pM the fixed value of pattern parameter m, or null if not bound.
335 * @param pP the fixed value of pattern parameter p, or null if not bound.
336 * @return matches represented as a Match object.
337 *
338 */
339 public Collection<ParentTooYoung.Match> getAllMatches(final Member pM, final Member pP) {
340 return rawStreamAllMatches(new Object[]{pM, pP}).collect(Collectors.toSet());
341 }
342
343 /**
344 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
345 * </p>
346 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
347 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
348 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
349 * @param pM the fixed value of pattern parameter m, or null if not bound.
350 * @param pP the fixed value of pattern parameter p, or null if not bound.
351 * @return a stream of matches represented as a Match object.
352 *
353 */
354 public Stream<ParentTooYoung.Match> streamAllMatches(final Member pM, final Member pP) {
355 return rawStreamAllMatches(new Object[]{pM, pP});
356 }
357
358 /**
359 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
360 * Neither determinism nor randomness of selection is guaranteed.
361 * @param pM the fixed value of pattern parameter m, or null if not bound.
362 * @param pP the fixed value of pattern parameter p, or null if not bound.
363 * @return a match represented as a Match object, or null if no match is found.
364 *
365 */
366 public Optional<ParentTooYoung.Match> getOneArbitraryMatch(final Member pM, final Member pP) {
367 return rawGetOneArbitraryMatch(new Object[]{pM, pP});
368 }
369
370 /**
371 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
372 * under any possible substitution of the unspecified parameters (if any).
373 * @param pM the fixed value of pattern parameter m, or null if not bound.
374 * @param pP the fixed value of pattern parameter p, or null if not bound.
375 * @return true if the input is a valid (partial) match of the pattern.
376 *
377 */
378 public boolean hasMatch(final Member pM, final Member pP) {
379 return rawHasMatch(new Object[]{pM, pP});
380 }
381
382 /**
383 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
384 * @param pM the fixed value of pattern parameter m, or null if not bound.
385 * @param pP the fixed value of pattern parameter p, or null if not bound.
386 * @return the number of pattern matches found.
387 *
388 */
389 public int countMatches(final Member pM, final Member pP) {
390 return rawCountMatches(new Object[]{pM, 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 pM the fixed value of pattern parameter m, or null if not bound.
397 * @param pP the fixed value of pattern parameter p, or null if not bound.
398 * @param processor the action that will process the selected match.
399 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
400 *
401 */
402 public boolean forOneArbitraryMatch(final Member pM, final Member pP, final Consumer<? super ParentTooYoung.Match> processor) {
403 return rawForOneArbitraryMatch(new Object[]{pM, pP}, processor);
404 }
405
406 /**
407 * Returns a new (partial) match.
408 * This can be used e.g. to call the matcher with a partial match.
409 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
410 * @param pM the fixed value of pattern parameter m, or null if not bound.
411 * @param pP the fixed value of pattern parameter p, or null if not bound.
412 * @return the (partial) match object.
413 *
414 */
415 public ParentTooYoung.Match newMatch(final Member pM, final Member pP) {
416 return ParentTooYoung.Match.newMatch(pM, pP);
417 }
418
419 /**
420 * Retrieve the set of values that occur in matches for m.
421 * @return the Set of all values or empty set if there are no matches
422 *
423 */
424 protected Stream<Member> rawStreamAllValuesOfm(final Object[] parameters) {
425 return rawStreamAllValues(POSITION_M, parameters).map(Member.class::cast);
426 }
427
428 /**
429 * Retrieve the set of values that occur in matches for m.
430 * @return the Set of all values or empty set if there are no matches
431 *
432 */
433 public Set<Member> getAllValuesOfm() {
434 return rawStreamAllValuesOfm(emptyArray()).collect(Collectors.toSet());
435 }
436
437 /**
438 * Retrieve the set of values that occur in matches for m.
439 * @return the Set of all values or empty set if there are no matches
440 *
441 */
442 public Stream<Member> streamAllValuesOfm() {
443 return rawStreamAllValuesOfm(emptyArray());
444 }
445
446 /**
447 * Retrieve the set of values that occur in matches for m.
448 * </p>
449 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
450 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
451 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
452 *
453 * @return the Stream of all values or empty set if there are no matches
454 *
455 */
456 public Stream<Member> streamAllValuesOfm(final ParentTooYoung.Match partialMatch) {
457 return rawStreamAllValuesOfm(partialMatch.toArray());
458 }
459
460 /**
461 * Retrieve the set of values that occur in matches for m.
462 * </p>
463 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
464 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
465 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
466 *
467 * @return the Stream of all values or empty set if there are no matches
468 *
469 */
470 public Stream<Member> streamAllValuesOfm(final Member pP) {
471 return rawStreamAllValuesOfm(new Object[]{null, pP});
472 }
473
474 /**
475 * Retrieve the set of values that occur in matches for m.
476 * @return the Set of all values or empty set if there are no matches
477 *
478 */
479 public Set<Member> getAllValuesOfm(final ParentTooYoung.Match partialMatch) {
480 return rawStreamAllValuesOfm(partialMatch.toArray()).collect(Collectors.toSet());
481 }
482
483 /**
484 * Retrieve the set of values that occur in matches for m.
485 * @return the Set of all values or empty set if there are no matches
486 *
487 */
488 public Set<Member> getAllValuesOfm(final Member pP) {
489 return rawStreamAllValuesOfm(new Object[]{null, pP}).collect(Collectors.toSet());
490 }
491
492 /**
493 * Retrieve the set of values that occur in matches for p.
494 * @return the Set of all values or empty set if there are no matches
495 *
496 */
497 protected Stream<Member> rawStreamAllValuesOfp(final Object[] parameters) {
498 return rawStreamAllValues(POSITION_P, parameters).map(Member.class::cast);
499 }
500
501 /**
502 * Retrieve the set of values that occur in matches for p.
503 * @return the Set of all values or empty set if there are no matches
504 *
505 */
506 public Set<Member> getAllValuesOfp() {
507 return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet());
508 }
509
510 /**
511 * Retrieve the set of values that occur in matches for p.
512 * @return the Set of all values or empty set if there are no matches
513 *
514 */
515 public Stream<Member> streamAllValuesOfp() {
516 return rawStreamAllValuesOfp(emptyArray());
517 }
518
519 /**
520 * Retrieve the set of values that occur in matches for p.
521 * </p>
522 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
523 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
524 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
525 *
526 * @return the Stream of all values or empty set if there are no matches
527 *
528 */
529 public Stream<Member> streamAllValuesOfp(final ParentTooYoung.Match partialMatch) {
530 return rawStreamAllValuesOfp(partialMatch.toArray());
531 }
532
533 /**
534 * Retrieve the set of values that occur in matches for p.
535 * </p>
536 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
537 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
538 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
539 *
540 * @return the Stream of all values or empty set if there are no matches
541 *
542 */
543 public Stream<Member> streamAllValuesOfp(final Member pM) {
544 return rawStreamAllValuesOfp(new Object[]{pM, null});
545 }
546
547 /**
548 * Retrieve the set of values that occur in matches for p.
549 * @return the Set of all values or empty set if there are no matches
550 *
551 */
552 public Set<Member> getAllValuesOfp(final ParentTooYoung.Match partialMatch) {
553 return rawStreamAllValuesOfp(partialMatch.toArray()).collect(Collectors.toSet());
554 }
555
556 /**
557 * Retrieve the set of values that occur in matches for p.
558 * @return the Set of all values or empty set if there are no matches
559 *
560 */
561 public Set<Member> getAllValuesOfp(final Member pM) {
562 return rawStreamAllValuesOfp(new Object[]{pM, null}).collect(Collectors.toSet());
563 }
564
565 @Override
566 protected ParentTooYoung.Match tupleToMatch(final Tuple t) {
567 try {
568 return ParentTooYoung.Match.newMatch((Member) t.get(POSITION_M), (Member) t.get(POSITION_P));
569 } catch(ClassCastException e) {
570 LOGGER.error("Element(s) in tuple not properly typed!",e);
571 return null;
572 }
573 }
574
575 @Override
576 protected ParentTooYoung.Match arrayToMatch(final Object[] match) {
577 try {
578 return ParentTooYoung.Match.newMatch((Member) match[POSITION_M], (Member) match[POSITION_P]);
579 } catch(ClassCastException e) {
580 LOGGER.error("Element(s) in array not properly typed!",e);
581 return null;
582 }
583 }
584
585 @Override
586 protected ParentTooYoung.Match arrayToMatchMutable(final Object[] match) {
587 try {
588 return ParentTooYoung.Match.newMutableMatch((Member) match[POSITION_M], (Member) match[POSITION_P]);
589 } catch(ClassCastException e) {
590 LOGGER.error("Element(s) in array not properly typed!",e);
591 return null;
592 }
593 }
594
595 /**
596 * @return the singleton instance of the query specification of this pattern
597 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
598 *
599 */
600 public static IQuerySpecification<ParentTooYoung.Matcher> querySpecification() {
601 return ParentTooYoung.instance();
602 }
603 }
604
605 private ParentTooYoung() {
606 super(GeneratedPQuery.INSTANCE);
607 }
608
609 /**
610 * @return the singleton instance of the query specification
611 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
612 *
613 */
614 public static ParentTooYoung instance() {
615 try{
616 return LazyHolder.INSTANCE;
617 } catch (ExceptionInInitializerError err) {
618 throw processInitializerError(err);
619 }
620 }
621
622 @Override
623 protected ParentTooYoung.Matcher instantiate(final ViatraQueryEngine engine) {
624 return ParentTooYoung.Matcher.on(engine);
625 }
626
627 @Override
628 public ParentTooYoung.Matcher instantiate() {
629 return ParentTooYoung.Matcher.create();
630 }
631
632 @Override
633 public ParentTooYoung.Match newEmptyMatch() {
634 return ParentTooYoung.Match.newEmptyMatch();
635 }
636
637 @Override
638 public ParentTooYoung.Match newMatch(final Object... parameters) {
639 return ParentTooYoung.Match.newMatch((familytree.Member) parameters[0], (familytree.Member) parameters[1]);
640 }
641
642 /**
643 * Inner class allowing the singleton instance of {@link ParentTooYoung} to be created
644 * <b>not</b> at the class load time of the outer class,
645 * but rather at the first call to {@link ParentTooYoung#instance()}.
646 *
647 * <p> This workaround is required e.g. to support recursion.
648 *
649 */
650 private static class LazyHolder {
651 private static final ParentTooYoung INSTANCE = new ParentTooYoung();
652
653 /**
654 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
655 * This initialization order is required to support indirect recursion.
656 *
657 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
658 *
659 */
660 private static final Object STATIC_INITIALIZER = ensureInitialized();
661
662 public static Object ensureInitialized() {
663 INSTANCE.ensureInitializedInternal();
664 return null;
665 }
666 }
667
668 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
669 private static final ParentTooYoung.GeneratedPQuery INSTANCE = new GeneratedPQuery();
670
671 private final PParameter parameter_m = new PParameter("m", "familytree.Member", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/familytree", "Member")), PParameterDirection.INOUT);
672
673 private final PParameter parameter_p = new PParameter("p", "familytree.Member", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/familytree", "Member")), PParameterDirection.INOUT);
674
675 private final List<PParameter> parameters = Arrays.asList(parameter_m, parameter_p);
676
677 private GeneratedPQuery() {
678 super(PVisibility.PUBLIC);
679 }
680
681 @Override
682 public String getFullyQualifiedName() {
683 return "queries.parentTooYoung";
684 }
685
686 @Override
687 public List<String> getParameterNames() {
688 return Arrays.asList("m","p");
689 }
690
691 @Override
692 public List<PParameter> getParameters() {
693 return parameters;
694 }
695
696 @Override
697 public Set<PBody> doGetContainedBodies() {
698 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
699 Set<PBody> bodies = new LinkedHashSet<>();
700 {
701 PBody body = new PBody(this);
702 PVariable var_m = body.getOrCreateVariableByName("m");
703 PVariable var_p = body.getOrCreateVariableByName("p");
704 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
705 PVariable var_mAge = body.getOrCreateVariableByName("mAge");
706 PVariable var_pAge = body.getOrCreateVariableByName("pAge");
707 new TypeConstraint(body, Tuples.flatTupleOf(var_m), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member")));
708 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member")));
709 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
710 new ExportedParameter(body, var_m, parameter_m),
711 new ExportedParameter(body, var_p, parameter_p)
712 ));
713 // FamilyTree.members(_, m)
714 new TypeConstraint(body, Tuples.flatTupleOf(var___0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "FamilyTree")));
715 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
716 new TypeConstraint(body, Tuples.flatTupleOf(var___0_, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/familytree", "FamilyTree", "members")));
717 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member")));
718 new Equality(body, var__virtual_0_, var_m);
719 // Member.parents(m, p)
720 new TypeConstraint(body, Tuples.flatTupleOf(var_m), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member")));
721 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
722 new TypeConstraint(body, Tuples.flatTupleOf(var_m, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/familytree", "Member", "parents")));
723 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member")));
724 new Equality(body, var__virtual_1_, var_p);
725 // Member.age(m, mAge)
726 new TypeConstraint(body, Tuples.flatTupleOf(var_m), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member")));
727 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
728 new TypeConstraint(body, Tuples.flatTupleOf(var_m, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/familytree", "Member", "age")));
729 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
730 new Equality(body, var__virtual_2_, var_mAge);
731 // Member.age(p, pAge)
732 new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member")));
733 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
734 new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/familytree", "Member", "age")));
735 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
736 new Equality(body, var__virtual_3_, var_pAge);
737 // check (mAge <= (pAge + 12))
738 new ExpressionEvaluation(body, new IExpressionEvaluator() {
739
740 @Override
741 public String getShortDescription() {
742 return "Expression evaluation from pattern parentTooYoung";
743 }
744
745 @Override
746 public Iterable<String> getInputParameterNames() {
747 return Arrays.asList("mAge", "pAge");}
748
749 @Override
750 public Object evaluateExpression(IValueProvider provider) throws Exception {
751 Integer mAge = (Integer) provider.getValue("mAge");
752 Integer pAge = (Integer) provider.getValue("pAge");
753 return evaluateExpression_1_1(mAge, pAge);
754 }
755 }, null);
756 bodies.add(body);
757 }
758 {
759 PAnnotation annotation = new PAnnotation("Constraint");
760 annotation.addAttribute("message", "parentTooYoung");
761 annotation.addAttribute("severity", "error");
762 annotation.addAttribute("key", Arrays.asList(new Object[] {
763 new ParameterReference("m"),
764 new ParameterReference("p")
765 }));
766 addAnnotation(annotation);
767 }
768 return bodies;
769 }
770 }
771
772 private static boolean evaluateExpression_1_1(final Integer mAge, final Integer pAge) {
773 return ((mAge).intValue() <= ((pAge).intValue() + 12));
774 }
775}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/TwoMembersHaveNoParent.java b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/TwoMembersHaveNoParent.java
new file mode 100644
index 00000000..58ad57a6
--- /dev/null
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src-gen/queries/TwoMembersHaveNoParent.java
@@ -0,0 +1,723 @@
1/**
2 * Generated from platform:/resource/case.study.familyTree.run/src/queries/familyTreeConstraints.vql
3 */
4package queries;
5
6import familytree.Member;
7import java.util.Arrays;
8import java.util.Collection;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Objects;
12import java.util.Optional;
13import java.util.Set;
14import java.util.function.Consumer;
15import java.util.stream.Collectors;
16import java.util.stream.Stream;
17import org.apache.log4j.Logger;
18import org.eclipse.emf.ecore.EClass;
19import org.eclipse.viatra.query.runtime.api.IPatternMatch;
20import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
21import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
22import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
24import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
25import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
26import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
27import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
28import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
29import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
30import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
31import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
38import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
39import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
40import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
41import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
42import queries.MemberHasParent;
43
44/**
45 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
46 *
47 * <p>Original source:
48 * <code><pre>
49 * {@literal @}Constraint(message="twoMembersHaveNoParent", severity="error", key={m1, m2})
50 * pattern twoMembersHaveNoParent(m1:Member, m2:Member) = {
51 * neg find memberHasParent(m1);
52 * neg find memberHasParent(m2);
53 * m1 != m2;
54 * }
55 * </pre></code>
56 *
57 * @see Matcher
58 * @see Match
59 *
60 */
61@SuppressWarnings("all")
62public final class TwoMembersHaveNoParent extends BaseGeneratedEMFQuerySpecification<TwoMembersHaveNoParent.Matcher> {
63 /**
64 * Pattern-specific match representation of the queries.twoMembersHaveNoParent pattern,
65 * to be used in conjunction with {@link Matcher}.
66 *
67 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
68 * Each instance is a (possibly partial) substitution of pattern parameters,
69 * usable to represent a match of the pattern in the result of a query,
70 * or to specify the bound (fixed) input parameters when issuing a query.
71 *
72 * @see Matcher
73 *
74 */
75 public static abstract class Match extends BasePatternMatch {
76 private Member fM1;
77
78 private Member fM2;
79
80 private static List<String> parameterNames = makeImmutableList("m1", "m2");
81
82 private Match(final Member pM1, final Member pM2) {
83 this.fM1 = pM1;
84 this.fM2 = pM2;
85 }
86
87 @Override
88 public Object get(final String parameterName) {
89 switch(parameterName) {
90 case "m1": return this.fM1;
91 case "m2": return this.fM2;
92 default: return null;
93 }
94 }
95
96 @Override
97 public Object get(final int index) {
98 switch(index) {
99 case 0: return this.fM1;
100 case 1: return this.fM2;
101 default: return null;
102 }
103 }
104
105 public Member getM1() {
106 return this.fM1;
107 }
108
109 public Member getM2() {
110 return this.fM2;
111 }
112
113 @Override
114 public boolean set(final String parameterName, final Object newValue) {
115 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
116 if ("m1".equals(parameterName) ) {
117 this.fM1 = (Member) newValue;
118 return true;
119 }
120 if ("m2".equals(parameterName) ) {
121 this.fM2 = (Member) newValue;
122 return true;
123 }
124 return false;
125 }
126
127 public void setM1(final Member pM1) {
128 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
129 this.fM1 = pM1;
130 }
131
132 public void setM2(final Member pM2) {
133 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
134 this.fM2 = pM2;
135 }
136
137 @Override
138 public String patternName() {
139 return "queries.twoMembersHaveNoParent";
140 }
141
142 @Override
143 public List<String> parameterNames() {
144 return TwoMembersHaveNoParent.Match.parameterNames;
145 }
146
147 @Override
148 public Object[] toArray() {
149 return new Object[]{fM1, fM2};
150 }
151
152 @Override
153 public TwoMembersHaveNoParent.Match toImmutable() {
154 return isMutable() ? newMatch(fM1, fM2) : this;
155 }
156
157 @Override
158 public String prettyPrint() {
159 StringBuilder result = new StringBuilder();
160 result.append("\"m1\"=" + prettyPrintValue(fM1) + ", ");
161 result.append("\"m2\"=" + prettyPrintValue(fM2));
162 return result.toString();
163 }
164
165 @Override
166 public int hashCode() {
167 return Objects.hash(fM1, fM2);
168 }
169
170 @Override
171 public boolean equals(final Object obj) {
172 if (this == obj)
173 return true;
174 if (obj == null) {
175 return false;
176 }
177 if ((obj instanceof TwoMembersHaveNoParent.Match)) {
178 TwoMembersHaveNoParent.Match other = (TwoMembersHaveNoParent.Match) obj;
179 return Objects.equals(fM1, other.fM1) && Objects.equals(fM2, other.fM2);
180 } else {
181 // this should be infrequent
182 if (!(obj instanceof IPatternMatch)) {
183 return false;
184 }
185 IPatternMatch otherSig = (IPatternMatch) obj;
186 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
187 }
188 }
189
190 @Override
191 public TwoMembersHaveNoParent specification() {
192 return TwoMembersHaveNoParent.instance();
193 }
194
195 /**
196 * Returns an empty, mutable match.
197 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
198 *
199 * @return the empty match.
200 *
201 */
202 public static TwoMembersHaveNoParent.Match newEmptyMatch() {
203 return new Mutable(null, null);
204 }
205
206 /**
207 * Returns a mutable (partial) match.
208 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
209 *
210 * @param pM1 the fixed value of pattern parameter m1, or null if not bound.
211 * @param pM2 the fixed value of pattern parameter m2, or null if not bound.
212 * @return the new, mutable (partial) match object.
213 *
214 */
215 public static TwoMembersHaveNoParent.Match newMutableMatch(final Member pM1, final Member pM2) {
216 return new Mutable(pM1, pM2);
217 }
218
219 /**
220 * Returns a new (partial) match.
221 * This can be used e.g. to call the matcher with a partial match.
222 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
223 * @param pM1 the fixed value of pattern parameter m1, or null if not bound.
224 * @param pM2 the fixed value of pattern parameter m2, or null if not bound.
225 * @return the (partial) match object.
226 *
227 */
228 public static TwoMembersHaveNoParent.Match newMatch(final Member pM1, final Member pM2) {
229 return new Immutable(pM1, pM2);
230 }
231
232 private static final class Mutable extends TwoMembersHaveNoParent.Match {
233 Mutable(final Member pM1, final Member pM2) {
234 super(pM1, pM2);
235 }
236
237 @Override
238 public boolean isMutable() {
239 return true;
240 }
241 }
242
243 private static final class Immutable extends TwoMembersHaveNoParent.Match {
244 Immutable(final Member pM1, final Member pM2) {
245 super(pM1, pM2);
246 }
247
248 @Override
249 public boolean isMutable() {
250 return false;
251 }
252 }
253 }
254
255 /**
256 * Generated pattern matcher API of the queries.twoMembersHaveNoParent pattern,
257 * providing pattern-specific query methods.
258 *
259 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
260 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
261 *
262 * <p>Matches of the pattern will be represented as {@link Match}.
263 *
264 * <p>Original source:
265 * <code><pre>
266 * {@literal @}Constraint(message="twoMembersHaveNoParent", severity="error", key={m1, m2})
267 * pattern twoMembersHaveNoParent(m1:Member, m2:Member) = {
268 * neg find memberHasParent(m1);
269 * neg find memberHasParent(m2);
270 * m1 != m2;
271 * }
272 * </pre></code>
273 *
274 * @see Match
275 * @see TwoMembersHaveNoParent
276 *
277 */
278 public static class Matcher extends BaseMatcher<TwoMembersHaveNoParent.Match> {
279 /**
280 * Initializes the pattern matcher within an existing VIATRA Query engine.
281 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
282 *
283 * @param engine the existing VIATRA Query engine in which this matcher will be created.
284 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
285 *
286 */
287 public static TwoMembersHaveNoParent.Matcher on(final ViatraQueryEngine engine) {
288 // check if matcher already exists
289 Matcher matcher = engine.getExistingMatcher(querySpecification());
290 if (matcher == null) {
291 matcher = (Matcher)engine.getMatcher(querySpecification());
292 }
293 return matcher;
294 }
295
296 /**
297 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
298 * @return an initialized matcher
299 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
300 *
301 */
302 public static TwoMembersHaveNoParent.Matcher create() {
303 return new Matcher();
304 }
305
306 private static final int POSITION_M1 = 0;
307
308 private static final int POSITION_M2 = 1;
309
310 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TwoMembersHaveNoParent.Matcher.class);
311
312 /**
313 * Initializes the pattern matcher within an existing VIATRA Query engine.
314 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
315 *
316 * @param engine the existing VIATRA Query engine in which this matcher will be created.
317 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
318 *
319 */
320 private Matcher() {
321 super(querySpecification());
322 }
323
324 /**
325 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
326 * @param pM1 the fixed value of pattern parameter m1, or null if not bound.
327 * @param pM2 the fixed value of pattern parameter m2, or null if not bound.
328 * @return matches represented as a Match object.
329 *
330 */
331 public Collection<TwoMembersHaveNoParent.Match> getAllMatches(final Member pM1, final Member pM2) {
332 return rawStreamAllMatches(new Object[]{pM1, pM2}).collect(Collectors.toSet());
333 }
334
335 /**
336 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
337 * </p>
338 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
339 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
340 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
341 * @param pM1 the fixed value of pattern parameter m1, or null if not bound.
342 * @param pM2 the fixed value of pattern parameter m2, or null if not bound.
343 * @return a stream of matches represented as a Match object.
344 *
345 */
346 public Stream<TwoMembersHaveNoParent.Match> streamAllMatches(final Member pM1, final Member pM2) {
347 return rawStreamAllMatches(new Object[]{pM1, pM2});
348 }
349
350 /**
351 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
352 * Neither determinism nor randomness of selection is guaranteed.
353 * @param pM1 the fixed value of pattern parameter m1, or null if not bound.
354 * @param pM2 the fixed value of pattern parameter m2, or null if not bound.
355 * @return a match represented as a Match object, or null if no match is found.
356 *
357 */
358 public Optional<TwoMembersHaveNoParent.Match> getOneArbitraryMatch(final Member pM1, final Member pM2) {
359 return rawGetOneArbitraryMatch(new Object[]{pM1, pM2});
360 }
361
362 /**
363 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
364 * under any possible substitution of the unspecified parameters (if any).
365 * @param pM1 the fixed value of pattern parameter m1, or null if not bound.
366 * @param pM2 the fixed value of pattern parameter m2, or null if not bound.
367 * @return true if the input is a valid (partial) match of the pattern.
368 *
369 */
370 public boolean hasMatch(final Member pM1, final Member pM2) {
371 return rawHasMatch(new Object[]{pM1, pM2});
372 }
373
374 /**
375 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
376 * @param pM1 the fixed value of pattern parameter m1, or null if not bound.
377 * @param pM2 the fixed value of pattern parameter m2, or null if not bound.
378 * @return the number of pattern matches found.
379 *
380 */
381 public int countMatches(final Member pM1, final Member pM2) {
382 return rawCountMatches(new Object[]{pM1, pM2});
383 }
384
385 /**
386 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
387 * Neither determinism nor randomness of selection is guaranteed.
388 * @param pM1 the fixed value of pattern parameter m1, or null if not bound.
389 * @param pM2 the fixed value of pattern parameter m2, or null if not bound.
390 * @param processor the action that will process the selected match.
391 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
392 *
393 */
394 public boolean forOneArbitraryMatch(final Member pM1, final Member pM2, final Consumer<? super TwoMembersHaveNoParent.Match> processor) {
395 return rawForOneArbitraryMatch(new Object[]{pM1, pM2}, processor);
396 }
397
398 /**
399 * Returns a new (partial) match.
400 * This can be used e.g. to call the matcher with a partial match.
401 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
402 * @param pM1 the fixed value of pattern parameter m1, or null if not bound.
403 * @param pM2 the fixed value of pattern parameter m2, or null if not bound.
404 * @return the (partial) match object.
405 *
406 */
407 public TwoMembersHaveNoParent.Match newMatch(final Member pM1, final Member pM2) {
408 return TwoMembersHaveNoParent.Match.newMatch(pM1, pM2);
409 }
410
411 /**
412 * Retrieve the set of values that occur in matches for m1.
413 * @return the Set of all values or empty set if there are no matches
414 *
415 */
416 protected Stream<Member> rawStreamAllValuesOfm1(final Object[] parameters) {
417 return rawStreamAllValues(POSITION_M1, parameters).map(Member.class::cast);
418 }
419
420 /**
421 * Retrieve the set of values that occur in matches for m1.
422 * @return the Set of all values or empty set if there are no matches
423 *
424 */
425 public Set<Member> getAllValuesOfm1() {
426 return rawStreamAllValuesOfm1(emptyArray()).collect(Collectors.toSet());
427 }
428
429 /**
430 * Retrieve the set of values that occur in matches for m1.
431 * @return the Set of all values or empty set if there are no matches
432 *
433 */
434 public Stream<Member> streamAllValuesOfm1() {
435 return rawStreamAllValuesOfm1(emptyArray());
436 }
437
438 /**
439 * Retrieve the set of values that occur in matches for m1.
440 * </p>
441 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
442 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
443 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
444 *
445 * @return the Stream of all values or empty set if there are no matches
446 *
447 */
448 public Stream<Member> streamAllValuesOfm1(final TwoMembersHaveNoParent.Match partialMatch) {
449 return rawStreamAllValuesOfm1(partialMatch.toArray());
450 }
451
452 /**
453 * Retrieve the set of values that occur in matches for m1.
454 * </p>
455 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
456 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
457 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
458 *
459 * @return the Stream of all values or empty set if there are no matches
460 *
461 */
462 public Stream<Member> streamAllValuesOfm1(final Member pM2) {
463 return rawStreamAllValuesOfm1(new Object[]{null, pM2});
464 }
465
466 /**
467 * Retrieve the set of values that occur in matches for m1.
468 * @return the Set of all values or empty set if there are no matches
469 *
470 */
471 public Set<Member> getAllValuesOfm1(final TwoMembersHaveNoParent.Match partialMatch) {
472 return rawStreamAllValuesOfm1(partialMatch.toArray()).collect(Collectors.toSet());
473 }
474
475 /**
476 * Retrieve the set of values that occur in matches for m1.
477 * @return the Set of all values or empty set if there are no matches
478 *
479 */
480 public Set<Member> getAllValuesOfm1(final Member pM2) {
481 return rawStreamAllValuesOfm1(new Object[]{null, pM2}).collect(Collectors.toSet());
482 }
483
484 /**
485 * Retrieve the set of values that occur in matches for m2.
486 * @return the Set of all values or empty set if there are no matches
487 *
488 */
489 protected Stream<Member> rawStreamAllValuesOfm2(final Object[] parameters) {
490 return rawStreamAllValues(POSITION_M2, parameters).map(Member.class::cast);
491 }
492
493 /**
494 * Retrieve the set of values that occur in matches for m2.
495 * @return the Set of all values or empty set if there are no matches
496 *
497 */
498 public Set<Member> getAllValuesOfm2() {
499 return rawStreamAllValuesOfm2(emptyArray()).collect(Collectors.toSet());
500 }
501
502 /**
503 * Retrieve the set of values that occur in matches for m2.
504 * @return the Set of all values or empty set if there are no matches
505 *
506 */
507 public Stream<Member> streamAllValuesOfm2() {
508 return rawStreamAllValuesOfm2(emptyArray());
509 }
510
511 /**
512 * Retrieve the set of values that occur in matches for m2.
513 * </p>
514 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
515 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
516 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
517 *
518 * @return the Stream of all values or empty set if there are no matches
519 *
520 */
521 public Stream<Member> streamAllValuesOfm2(final TwoMembersHaveNoParent.Match partialMatch) {
522 return rawStreamAllValuesOfm2(partialMatch.toArray());
523 }
524
525 /**
526 * Retrieve the set of values that occur in matches for m2.
527 * </p>
528 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
529 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
530 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
531 *
532 * @return the Stream of all values or empty set if there are no matches
533 *
534 */
535 public Stream<Member> streamAllValuesOfm2(final Member pM1) {
536 return rawStreamAllValuesOfm2(new Object[]{pM1, null});
537 }
538
539 /**
540 * Retrieve the set of values that occur in matches for m2.
541 * @return the Set of all values or empty set if there are no matches
542 *
543 */
544 public Set<Member> getAllValuesOfm2(final TwoMembersHaveNoParent.Match partialMatch) {
545 return rawStreamAllValuesOfm2(partialMatch.toArray()).collect(Collectors.toSet());
546 }
547
548 /**
549 * Retrieve the set of values that occur in matches for m2.
550 * @return the Set of all values or empty set if there are no matches
551 *
552 */
553 public Set<Member> getAllValuesOfm2(final Member pM1) {
554 return rawStreamAllValuesOfm2(new Object[]{pM1, null}).collect(Collectors.toSet());
555 }
556
557 @Override
558 protected TwoMembersHaveNoParent.Match tupleToMatch(final Tuple t) {
559 try {
560 return TwoMembersHaveNoParent.Match.newMatch((Member) t.get(POSITION_M1), (Member) t.get(POSITION_M2));
561 } catch(ClassCastException e) {
562 LOGGER.error("Element(s) in tuple not properly typed!",e);
563 return null;
564 }
565 }
566
567 @Override
568 protected TwoMembersHaveNoParent.Match arrayToMatch(final Object[] match) {
569 try {
570 return TwoMembersHaveNoParent.Match.newMatch((Member) match[POSITION_M1], (Member) match[POSITION_M2]);
571 } catch(ClassCastException e) {
572 LOGGER.error("Element(s) in array not properly typed!",e);
573 return null;
574 }
575 }
576
577 @Override
578 protected TwoMembersHaveNoParent.Match arrayToMatchMutable(final Object[] match) {
579 try {
580 return TwoMembersHaveNoParent.Match.newMutableMatch((Member) match[POSITION_M1], (Member) match[POSITION_M2]);
581 } catch(ClassCastException e) {
582 LOGGER.error("Element(s) in array not properly typed!",e);
583 return null;
584 }
585 }
586
587 /**
588 * @return the singleton instance of the query specification of this pattern
589 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
590 *
591 */
592 public static IQuerySpecification<TwoMembersHaveNoParent.Matcher> querySpecification() {
593 return TwoMembersHaveNoParent.instance();
594 }
595 }
596
597 private TwoMembersHaveNoParent() {
598 super(GeneratedPQuery.INSTANCE);
599 }
600
601 /**
602 * @return the singleton instance of the query specification
603 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
604 *
605 */
606 public static TwoMembersHaveNoParent instance() {
607 try{
608 return LazyHolder.INSTANCE;
609 } catch (ExceptionInInitializerError err) {
610 throw processInitializerError(err);
611 }
612 }
613
614 @Override
615 protected TwoMembersHaveNoParent.Matcher instantiate(final ViatraQueryEngine engine) {
616 return TwoMembersHaveNoParent.Matcher.on(engine);
617 }
618
619 @Override
620 public TwoMembersHaveNoParent.Matcher instantiate() {
621 return TwoMembersHaveNoParent.Matcher.create();
622 }
623
624 @Override
625 public TwoMembersHaveNoParent.Match newEmptyMatch() {
626 return TwoMembersHaveNoParent.Match.newEmptyMatch();
627 }
628
629 @Override
630 public TwoMembersHaveNoParent.Match newMatch(final Object... parameters) {
631 return TwoMembersHaveNoParent.Match.newMatch((familytree.Member) parameters[0], (familytree.Member) parameters[1]);
632 }
633
634 /**
635 * Inner class allowing the singleton instance of {@link TwoMembersHaveNoParent} to be created
636 * <b>not</b> at the class load time of the outer class,
637 * but rather at the first call to {@link TwoMembersHaveNoParent#instance()}.
638 *
639 * <p> This workaround is required e.g. to support recursion.
640 *
641 */
642 private static class LazyHolder {
643 private static final TwoMembersHaveNoParent INSTANCE = new TwoMembersHaveNoParent();
644
645 /**
646 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
647 * This initialization order is required to support indirect recursion.
648 *
649 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
650 *
651 */
652 private static final Object STATIC_INITIALIZER = ensureInitialized();
653
654 public static Object ensureInitialized() {
655 INSTANCE.ensureInitializedInternal();
656 return null;
657 }
658 }
659
660 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
661 private static final TwoMembersHaveNoParent.GeneratedPQuery INSTANCE = new GeneratedPQuery();
662
663 private final PParameter parameter_m1 = new PParameter("m1", "familytree.Member", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/familytree", "Member")), PParameterDirection.INOUT);
664
665 private final PParameter parameter_m2 = new PParameter("m2", "familytree.Member", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/familytree", "Member")), PParameterDirection.INOUT);
666
667 private final List<PParameter> parameters = Arrays.asList(parameter_m1, parameter_m2);
668
669 private GeneratedPQuery() {
670 super(PVisibility.PUBLIC);
671 }
672
673 @Override
674 public String getFullyQualifiedName() {
675 return "queries.twoMembersHaveNoParent";
676 }
677
678 @Override
679 public List<String> getParameterNames() {
680 return Arrays.asList("m1","m2");
681 }
682
683 @Override
684 public List<PParameter> getParameters() {
685 return parameters;
686 }
687
688 @Override
689 public Set<PBody> doGetContainedBodies() {
690 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
691 Set<PBody> bodies = new LinkedHashSet<>();
692 {
693 PBody body = new PBody(this);
694 PVariable var_m1 = body.getOrCreateVariableByName("m1");
695 PVariable var_m2 = body.getOrCreateVariableByName("m2");
696 new TypeConstraint(body, Tuples.flatTupleOf(var_m1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member")));
697 new TypeConstraint(body, Tuples.flatTupleOf(var_m2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/familytree", "Member")));
698 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
699 new ExportedParameter(body, var_m1, parameter_m1),
700 new ExportedParameter(body, var_m2, parameter_m2)
701 ));
702 // neg find memberHasParent(m1)
703 new NegativePatternCall(body, Tuples.flatTupleOf(var_m1), MemberHasParent.instance().getInternalQueryRepresentation());
704 // neg find memberHasParent(m2)
705 new NegativePatternCall(body, Tuples.flatTupleOf(var_m2), MemberHasParent.instance().getInternalQueryRepresentation());
706 // m1 != m2
707 new Inequality(body, var_m1, var_m2);
708 bodies.add(body);
709 }
710 {
711 PAnnotation annotation = new PAnnotation("Constraint");
712 annotation.addAttribute("message", "twoMembersHaveNoParent");
713 annotation.addAttribute("severity", "error");
714 annotation.addAttribute("key", Arrays.asList(new Object[] {
715 new ParameterReference("m1"),
716 new ParameterReference("m2")
717 }));
718 addAnnotation(annotation);
719 }
720 return bodies;
721 }
722 }
723}
diff --git a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src/queries/familyTreeConstraints.vql b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src/queries/familyTreeConstraints.vql
index 1b9b6659..a204443a 100644
--- a/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src/queries/familyTreeConstraints.vql
+++ b/Tests/MODELS2020-CaseStudies/case.study.familyTree.run/src/queries/familyTreeConstraints.vql
@@ -9,14 +9,25 @@ pattern memberIsItsOwnParent(m: Member) = {
9 m == p; 9 m == p;
10} 10}
11 11
12//@Constraint(message="parentTooYoung", severity="error", key={m, p}) 12@Constraint(message="twoMembersHaveNoParent", severity="error", key={m1, m2})
13//pattern parentTooYoung(m: Member, p: Member) = { 13pattern twoMembersHaveNoParent(m1:Member, m2:Member) = {
14// FamilyTree.members(_, m); 14 neg find memberHasParent(m1);
15// Member.parents(m, p); 15 neg find memberHasParent(m2);
16// Member.age(m, mAge); 16 m1 != m2;
17// Member.age(p, pAge); 17}
18// check (mAge <= (pAge + 12)); 18
19//} 19pattern memberHasParent(m: Member) = {
20 Member.parents(m, _);
21}
22
23@Constraint(message="parentTooYoung", severity="error", key={m, p})
24pattern parentTooYoung(m: Member, p: Member) = {
25 FamilyTree.members(_, m);
26 Member.parents(m, p);
27 Member.age(m, mAge);
28 Member.age(p, pAge);
29 check (mAge <= (pAge + 12));
30}
20 31
21 32
22 33