From 68a0667e862f0714410aafbb499a95a03f5bee23 Mon Sep 17 00:00:00 2001 From: ArenBabikian Date: Tue, 28 Apr 2020 00:29:00 -0400 Subject: Able to run Pledge Case Study --- .../case.study.pledge.queries/.classpath | 9 - .../case.study.pledge.queries/.project | 62 -- .../.settings/org.eclipse.core.resources.prefs | 2 - .../.settings/org.eclipse.jdt.core.prefs | 7 - .../.settings/org.eclipse.pde.core.prefs | 3 - .../case.study.pledge.queries/META-INF/MANIFEST.MF | 24 - .../case.study.pledge.queries/bin/.gitignore | 2 - .../bin/queries/.gitignore | 112 ---- .../bin/queries/NewOCLFileX.ocl | 45 -- .../bin/queries/case_study_A.vql | 334 ---------- .../bin/run/.RunGenerator.xtendbin | Bin 8709 -> 0 bytes .../case.study.pledge.queries/bin/run/.gitignore | 4 - .../case.study.pledge.queries/build.properties | 6 - .../case.study.pledge.queries/ocl/queries.ocl | 14 - .../case.study.pledge.queries/plugin.xml | 42 -- .../src-gen/queries/.gitignore | 112 ---- .../src-gen/queries/Case_study_A.java | 438 ------------- .../src-gen/queries/Inv03.java | 652 ------------------- .../src-gen/queries/Inv05.java | 701 -------------------- .../src-gen/queries/Inv06.java | 669 ------------------- .../src-gen/queries/Inv07.java | 612 ------------------ .../src-gen/queries/Inv08.java | 705 --------------------- .../src-gen/queries/Inv10.java | 616 ------------------ .../src-gen/queries/Inv11.java | 566 ----------------- .../src-gen/queries/Inv12.java | 596 ----------------- .../src-gen/queries/Inv13.java | 591 ----------------- .../src-gen/queries/Inv15.java | 567 ----------------- .../src-gen/queries/Inv17.java | 643 ------------------- .../src-gen/queries/Inv20.java | 587 ----------------- .../src-gen/queries/Inv33.java | 665 ------------------- .../src-gen/queries/Inv34.java | 639 ------------------- .../src-gen/queries/Inv35.java | 639 ------------------- .../src-gen/queries/Inv47.java | 636 ------------------- .../src-gen/queries/Inv48.java | 566 ----------------- .../src-gen/queries/Inv49.java | 561 ---------------- .../src-gen/queries/X_inv03_eligAll.java | 606 ------------------ .../src-gen/queries/X_inv03_hasAll.java | 551 ---------------- .../src-gen/queries/X_inv05_inRange.java | 630 ------------------ .../src-gen/queries/X_inv08_inRange.java | 630 ------------------ .../src-gen/queries/X_inv08_noType.java | 551 ---------------- .../src-gen/queries/X_inv08_notEI.java | 544 ---------------- .../src-gen/queries/X_inv11_incNotOver100.java | 684 -------------------- .../src-gen/queries/X_inv11_incOver100.java | 629 ------------------ .../src-gen/queries/X_inv12_notNonRes.java | 544 ---------------- .../src-gen/queries/X_inv12_notZZ.java | 555 ---------------- .../src-gen/queries/X_inv13.java | 544 ---------------- .../src-gen/queries/X_inv15.java | 637 ------------------- .../src-gen/queries/X_inv47.java | 569 ----------------- .../src-gen/queries/X_inv48_3.java | 555 ---------------- .../src-gen/queries/X_inv48_Dis.java | 610 ------------------ .../src-gen/queries/X_inv48_notDis.java | 569 ----------------- .../src-gen/queries/X_inv49_1.java | 579 ----------------- .../src-gen/queries/X_inv49_2.java | 544 ---------------- .../src/queries/NewOCLFileX.ocl | 45 -- .../src/queries/case_study_A.vql | 334 ---------- .../src/run/RunGenerator.xtend | 151 ----- .../xtend-gen/run/.RunGenerator.xtendbin | Bin 8709 -> 0 bytes .../xtend-gen/run/.gitignore | 4 - .../xtend-gen/run/GenerateScenarios.java | 165 ----- 59 files changed, 23657 deletions(-) delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.classpath delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.project delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.settings/org.eclipse.core.resources.prefs delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.settings/org.eclipse.jdt.core.prefs delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.settings/org.eclipse.pde.core.prefs delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/META-INF/MANIFEST.MF delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/.gitignore delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/queries/.gitignore delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/queries/NewOCLFileX.ocl delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/queries/case_study_A.vql delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/run/.RunGenerator.xtendbin delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/run/.gitignore delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/build.properties delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/ocl/queries.ocl delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/plugin.xml delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/.gitignore delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Case_study_A.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv03.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv05.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv06.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv07.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv08.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv10.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv11.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv12.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv13.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv15.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv17.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv20.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv33.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv34.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv35.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv47.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv48.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv49.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_eligAll.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_hasAll.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv05_inRange.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_inRange.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_noType.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_notEI.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incNotOver100.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incOver100.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notNonRes.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notZZ.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv13.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv15.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv47.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_3.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_Dis.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_notDis.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_1.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_2.java delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/NewOCLFileX.ocl delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/case_study_A.vql delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/run/RunGenerator.xtend delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.RunGenerator.xtendbin delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.gitignore delete mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/GenerateScenarios.java (limited to 'Tests/MODELS2020-CaseStudies/case.study.pledge.queries') diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.classpath b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.classpath deleted file mode 100644 index 29ba3981..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.classpath +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.project b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.project deleted file mode 100644 index 9080c4bb..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.project +++ /dev/null @@ -1,62 +0,0 @@ - - - case.study.pledge.run - - - - - - org.eclipse.ocl.pivot.ui.oclbuilder - - - disabledExtensions - *,essentialocl - - - disabledPaths - bin/**,target/** - - - enabledExtensions - ecore,ocl,oclinecore,oclstdlib,uml - - - enabledPaths - ** - - - - - org.eclipse.xtext.ui.shared.xtextBuilder - - - - - org.eclipse.viatra.query.tooling.ui.projectbuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - org.eclipse.xtext.ui.shared.xtextNature - org.eclipse.viatra.query.projectnature - org.eclipse.ocl.pivot.ui.oclnature - - diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.settings/org.eclipse.core.resources.prefs b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 4824b802..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding/=UTF-8 diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.settings/org.eclipse.jdt.core.prefs b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 295926d9..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.settings/org.eclipse.pde.core.prefs b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.settings/org.eclipse.pde.core.prefs deleted file mode 100644 index 13325c95..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/.settings/org.eclipse.pde.core.prefs +++ /dev/null @@ -1,3 +0,0 @@ -eclipse.preferences.version=1 -pluginProject.equinox=false -resolve.requirebundle=false diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/META-INF/MANIFEST.MF b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/META-INF/MANIFEST.MF deleted file mode 100644 index 1ab2d276..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/META-INF/MANIFEST.MF +++ /dev/null @@ -1,24 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: case.study.a.queries -Bundle-SymbolicName: case.study.pledge.run;singleton:=true -Bundle-Version: 0.0.1.qualifier -Export-Package: queries -Require-Bundle: org.eclipse.emf.ecore, - org.eclipse.viatra.query.runtime, - org.eclipse.viatra.query.runtime.rete, - org.eclipse.viatra.query.runtime.localsearch, - org.eclipse.viatra.addon.querybasedfeatures.runtime;bundle-version="2.3.0", - org.eclipse.xtext.xbase.lib, - case.study.pledge.model;bundle-version="1.0.0", - test;bundle-version="0.1.0", - hu.bme.mit.inf.dslreasoner.ecore2logic;bundle-version="1.0.0", - hu.bme.mit.inf.dslreasoner.logic.model;bundle-version="1.0.0", - hu.bme.mit.inf.dslreasoner.logic2ecore;bundle-version="1.0.0", - hu.bme.mit.inf.dslreasoner.viatra2logic;bundle-version="1.0.0", - hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatraquery;bundle-version="1.0.0", - hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage;bundle-version="1.0.0", - hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner;bundle-version="1.0.0", - hu.bme.mit.inf.dslreasoner.visualisation;bundle-version="1.0.0" -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Import-Package: org.apache.log4j diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/.gitignore b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/.gitignore deleted file mode 100644 index 3d70f0da..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/queries/ -/run/ diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/queries/.gitignore b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/queries/.gitignore deleted file mode 100644 index 527f3a0e..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/queries/.gitignore +++ /dev/null @@ -1,112 +0,0 @@ -/.Inv17.java._trace -/.Inv20.java._trace -/.Inv33_con.java._trace -/.Inv34.java._trace -/.Inv35.java._trace -/.Inv47.java._trace -/.Inv48.java._trace -/.Inv48_helper.java._trace -/.Case_study_A.java._trace -/.Inv49.java._trace -/.Inv49_con.java._trace -/.Inv49_helper.java._trace -/.H_inv49.java._trace -/.Ocl_inv49.java._trace -/.Vql_inv49.java._trace -/.Vql_inv492.java._trace -/.H1_inv48.java._trace -/.H2_inv48.java._trace -/.Vql_inv48.java._trace -/.H3_inv48.java._trace -/.H1_inv49.java._trace -/.H2_inv49.java._trace -/.H_inv47.java._trace -/.Inv35test.java._trace -/.Inv33.java._trace -/.X.java._trace -/.H_inv16_moreThan1.java._trace -/.H_inv48_1.java._trace -/.H_inv48_2.java._trace -/.H_inv48_3.java._trace -/.H_inv49_1.java._trace -/.H_inv49_2.java._trace -/.Inv16.java._trace -/.Inv15.java._trace -/.H_inv13.java._trace -/.Inv13.java._trace -/.Inv12.java._trace -/.H_inv12_notNonRes.java._trace -/.H_inv12_notZZ.java._trace -/.H_inv11_incOver100.java._trace -/.Inv11.java._trace -/.H_inv11_incNotOver100.java._trace -/.H_inv8_notEI.java._trace -/.Inv8.java._trace -/.H_inv08_notEI.java._trace -/.Inv08.java._trace -/.H_inv08_inRange.java._trace -/.X_inv08_inRange.java._trace -/.X_inv08_notEI.java._trace -/.X_inv11_incNotOver100.java._trace -/.X_inv11_incOver100.java._trace -/.X_inv12_notNonRes.java._trace -/.X_inv12_notZZ.java._trace -/.X_inv13.java._trace -/.X_inv47.java._trace -/.X_inv48_1.java._trace -/.X_inv48_2.java._trace -/.X_inv48_3.java._trace -/.X_inv49_1.java._trace -/.X_inv49_2.java._trace -/.X_inv48_Dis.java._trace -/.X_inv48_notDis.java._trace -/.X_inv08_noType.java._trace -/.X_inv08_invalidType.java._trace -/.Inv06.java._trace -/.X_inv06_inRange.java._trace -/.Inv05.java._trace -/.X_inv05_inRange.java._trace -/.Inv03.java._trace -/.X_inv03_noAll.java._trace -/.X_inv03_eligAll.java._trace -/.X_inv03_hasAll.java._trace -/.Inv07.java._trace -/.Inv10.java._trace -/.X_inv15.java._trace -/Inv03.java -/Inv05.java -/Inv06.java -/X_inv03_eligAll.java -/X_inv03_hasAll.java -/X_inv05_inRange.java -/Case_study_A.java -/Inv07.java -/Inv08.java -/Inv10.java -/Inv11.java -/Inv12.java -/Inv13.java -/Inv15.java -/Inv17.java -/Inv20.java -/Inv33.java -/Inv34.java -/Inv35.java -/Inv47.java -/Inv48.java -/Inv49.java -/X_inv08_inRange.java -/X_inv08_noType.java -/X_inv08_notEI.java -/X_inv11_incNotOver100.java -/X_inv11_incOver100.java -/X_inv12_notNonRes.java -/X_inv12_notZZ.java -/X_inv13.java -/X_inv15.java -/X_inv47.java -/X_inv48_3.java -/X_inv48_Dis.java -/X_inv48_notDis.java -/X_inv49_1.java -/X_inv49_2.java diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/queries/NewOCLFileX.ocl b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/queries/NewOCLFileX.ocl deleted file mode 100644 index 66ae728e..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/queries/NewOCLFileX.ocl +++ /dev/null @@ -1,45 +0,0 @@ -import 'file:/Users/Aren Babikian/git/VIATRA-Attributes/case.study.a.model/model/Taxation.ecore' - -package Taxation - ---context Income inv inv8: ---if(not self.income_type.oclIsTypeOf(Employment_Income)) then ---self.details->forAll(d| d.distance = 0) ---else ---self.details->forAll(d| d.distance >= 0.0 and d.distance <= 100) ---endif --- ---context Legal_Union_Record inv inv490: ---self.individual_A.oclIsKindOf(Tax_Payer) --- ---context Legal_Union_Record inv inv491: ---self.individual_B->forAll(i | i.oclIsKindOf(Physical_Person) ) --- ---context Legal_Union_Record inv inv492: ---self.individual_B->forAll(i | not i.oclIsTypeOf(Dependent) ) --- ---context Legal_Union_Record inv inv493: ---self.individual_A <> self.individual_B --- ---context Tax_Payer inv inv13: --- self.addresses->exists( hab_add:Address | hab_add.oclIsTypeOf(Habitual_Address) = true and hab_add.country=Country::ZZ) ---implies --- self.oclIsTypeOf(Resident_Tax_Payer) - - context Income inv inv7: -let val:Real =self.details->asOrderedSet()->first().distance in -self.details->forAll(d: Income_Detail|d.distance = val) - ---context External_Allowance inv inv15: ---let child:Dependent = self.person in ---let h:Household = Household.allInstances()->select(children->includes(child))->asOrderedSet()->first() in ---let t1:Set(Physical_Person) = Set{h.parents.individual_A}->union(h.parents.individual_B)->select(oclIsKindOf(Tax_Payer)) in ---if(t1->size()=1) then ---self.reciver = t1->asOrderedSet()->first() ---else ---self.reciver = t1->asOrderedSet()->at(2) or self.reciver = t1->asOrderedSet()->at(1) ---endif - - - -endpackage \ No newline at end of file diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/queries/case_study_A.vql b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/queries/case_study_A.vql deleted file mode 100644 index 5d46bf42..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/queries/case_study_A.vql +++ /dev/null @@ -1,334 +0,0 @@ -package queries - -import "http:///TaxCard.ecore" - -//AttributeRemoved -> DF - -//inv1-External_Allowance.amount is a derived feature (TODOcheck) -//inv2-Tax_Card.income.taxPayer.taxesDue is a derived feature (TODOcheck) - -//inv3-multiplicity adjusted -@Constraint(message = "inv03", severity = "error", key = {dep}) -pattern inv03(dep : Dependent) { - find x_inv03_eligAll(dep); - neg find x_inv03_hasAll(dep); -} or { - Dependent.birth_year(dep, by); - check(2018-by > 21); - Dependent.continued_studies(dep, false); - Dependent.allowances(dep, _); -} -pattern x_inv03_eligAll(dep : Dependent) { - Dependent.birth_year(dep, by); - check(2018-by <= 21); -} or { - Dependent.continued_studies(dep, true); -} -pattern x_inv03_hasAll(dep : Dependent) { - Dependent.allowances(dep, _); -} - -//inv5 - oclIsTypeOf - handled here -@Constraint(message = "inv05", severity = "error", key = {inc}) -pattern inv05(inc : Income) { - //income_type: None - neg find x_inv08_noType(inc); - Income.details.worked_days(inc, wd); - check(wd != 0); -} or { - //income_type: Not Employment_Income - Income.income_type(inc, type); - neg find x_inv08_notEI(type); - Income.details.worked_days(inc, wd); - check(wd != 0); -} or { - //income_type: Employment Income - Income.income_type(inc, type); - Employment_Income(type); - find x_inv05_inRange(inc); -} -pattern x_inv05_inRange(inc : Income) { - Income.details.worked_days(inc, wd); - check(wd < 1); -} or { - Income.details.worked_days(inc, wd); - check(wd > 25); -} - -//inv6-Does not make sens, but directly from OCL -//first part of or from definition of getAge() -@Constraint(message = "inv06", severity = "error", key = {tp}) -pattern inv06(tp : Tax_Payer) { - Tax_Payer.dependents(tp, _); - Tax_Payer.birth_year(tp, TPBy); - check(2018 - TPBy > 2018-16); -} or { - Tax_Payer.birth_year(tp, TPBy); - Tax_Payer.dependents(tp, dep); - Dependent.birth_year(dep, DepBy); - check(2018-DepBy <= 2018-TPBy-16); -} - -//inv7-OrderedSet -@Constraint(message = "inv07", severity = "error", key = {inc}) -pattern inv07(inc : Income) { - Income.details.distance(inc, d1); - Income.details.distance(inc, d2); - check(d1 != d2);//compare values -} - -//user_complete_details-AttributeRemoved - -//inv8 - oclIsTypeOf - handled here -@Constraint(message = "inv08", severity = "error", key = {inc}) -pattern inv08(inc : Income) { - //income_type: None - neg find x_inv08_noType(inc); - Income.details.distance(inc, dist); - check(dist != 0); -} or { - //income_type: Not Employment_Income - Income.income_type(inc, type); - neg find x_inv08_notEI(type); - Income.details.distance(inc, dist); - check(dist != 0); -} or { - //income_type: Employment Income - Income.income_type(inc, type); - Employment_Income(type); - find x_inv08_inRange(inc); -} -pattern x_inv08_notEI(type : Employment_Income) { - Employment_Income(type); -} -pattern x_inv08_noType(inc : Income) { - Income.income_type(inc, _); -} -pattern x_inv08_inRange(inc : Income) { - Income.details.distance(inc, dist); - check(dist < 0); -} or { - Income.details.distance(inc, dist); - check(dist > 100); -} -//inv9-DerivedFeature - -//inv10-Ordered Sets -@Constraint(message = "inv10", severity = "error", key = {inc}) -pattern inv10(inc : Income) { - Income.details.amount(inc, a1); - Income.details.amount(inc, a2); - check(a1 != a2);//compare values -} - -//inv11-attributes-handled by multiplicity -@Constraint(message = "inv11", severity = "error", key = {exp}) -pattern inv11(exp : Expense) { - find x_inv11_incOver100(exp); - find x_inv11_incNotOver100(exp); -} -pattern x_inv11_incOver100(exp : Expense) { - Expense.income.income_amount(exp, incVal); - check(incVal / 2 > 50); - -} or { - Expense.declared_amount(exp, decl); - check(decl != 50); -} -pattern x_inv11_incNotOver100(exp : Expense) { - Expense.income.income_amount(exp, incVal); - check(incVal / 2 <= 50); -} or { - Expense.declared_amount(exp, decl); - check(decl < 50); -} or { - Expense.income.income_amount(exp, incVal); - Expense.declared_amount(exp, decl); - check(decl > incVal/2); -} - -//inv12 -//exists - handled logically -@Constraint(message = "inv12", severity = "error", key = {tp}) -pattern inv12(tp : Tax_Payer) { - Tax_Payer.addresses(tp, hab_add); - Habitual_Address(hab_add); - neg find x_inv12_notZZ(hab_add); - Tax_Payer.incomes(tp, inc); - Local_Income(inc); - neg find x_inv12_notNonRes(tp); -} -pattern x_inv12_notNonRes(tp : Non_Resident_Tax_Payer) { - Non_Resident_Tax_Payer(tp); -} -pattern x_inv12_notZZ(hab_add : Habitual_Address) { - Address.country(hab_add, ::ZZ); -} - -//inv13 - Added new containment rel Phys_Pers->Address -//exists - handled logically -@Constraint(message = "inv13", severity = "error", key = {tp}) -pattern inv13(tp : Tax_Payer) { - Tax_Payer.addresses(tp, hab_add); - Habitual_Address(hab_add); - Address.country(hab_add, ::ZZ); - neg find x_inv13(tp); -} -pattern x_inv13(tp : Resident_Tax_Payer) { - Resident_Tax_Payer(tp); -} - -//inv14-MultiplicityChanged - -//inv15-Ordered Sets in assignment if block -//ERROR if no household object -@Constraint(message = "inv15", severity = "error", key = {ea}) -pattern inv15(ea : External_Allowance) { - neg find x_inv15(ea); -} -pattern x_inv15(ea : External_Allowance) { - External_Allowance.person(ea, child); - Household.children(h, child);//only one due to multiplicity - Household.parents.individual_A(h, iA); - Tax_Payer(iA); - External_Allowance.reciver(ea, iA); -} or { - External_Allowance.person(ea, child); - Household.children(h, child);//only one due to multiplicity - Household.parents.individual_B(h, iB); - Tax_Payer(iB); - External_Allowance.reciver(ea, iB); -} - -//inv16-Tax_Card.tax_card_type is a derived feature - -//inv17-attribute-handled by multiplicity -@Constraint(message = "inv17", severity = "error", key = {lur}) -pattern inv17(lur : Legal_Union_Record) { - Legal_Union_Record.start_year(lur, sy); - check(sy < 1950); -} or { - Legal_Union_Record.start_year(lur, sy); - check(sy > 2018); -} - -//inv18-MultiplicityChecked -//inv19-MultiplicityChecked - -//inv20-Useless constraint since both edges are containment (TODOCheck) -//OclIsUndefined-Handled by multiplicity -@Constraint(message = "inv20", severity = "error", key = {lur}) -pattern inv20(lur : Legal_Union_Record) { - Legal_Union_Record.individual_A(lur, iA); - Legal_Union_Record.individual_B(lur, iB); - iA == iB; -} -//inv21-MultiplicityChecked -//inv22-MultiplicityChecked -//inv23-MultiplicityChecked -//inv24-MultiplicityChecked -//inv25-MultiplicityChecked -//inv26-MultiplicityChanged -//inv27-dupOfInv24 -//inv28-dubOfInv23 -//inv29-MultiplicityChanged -//inv30-AttributeRemoved -//inv31-AttributeRemoved -//inv32-AttributeRemoved - -//inv33-attribute-handled by multiplicity -@Constraint(message = "inv33", severity = "error", key = {p}) -pattern inv33(p : Physical_Person) { - Physical_Person.birth_year(p, by); - check(2018-by < 0); -} or { - Physical_Person.birth_year(p, by); - check(2018-by > 100); -} - -//inv34-attribute-handled by multiplicity -@Constraint(message = "inv34", severity = "error", key = {p}) -pattern inv34(p : Physical_Person) { - Physical_Person.birth_month(p, birthMonth); - check(birthMonth < 1); -} or { - Physical_Person.birth_month(p, birthMonth); - check(birthMonth > 12); -} - -//inv35-attribute-handled by multiplicity -@Constraint(message = "inv35", severity = "error", key = {p}) -pattern inv35(p : Physical_Person) { - Physical_Person.birth_day(p, birthDay); - check(birthDay < 1); -} or { - Physical_Person.birth_day(p, birthDay); - check(birthDay > 28); -} - -//inv36-AttributeRemoved -//inv37-AttributeRemoved -//inv38-AttributeRemoved -//inv39-AttributeRemoved -//inv40-AttributeRemoved -//inv41-AttributeRemoved -//inv42-AttributeRemoved -//inv43-AttributeRemoved -//inv44-AttributeRemoved -//inv45-AttributeRemoved -//inv46-AttributeRemoved - -//inv47-attributes-handled by multiplicity -@Constraint(message = "inv47", severity = "error", key = {lur}) -pattern inv47(lur : Legal_Union_Record) { - Legal_Union_Record.end_year(lur, endY); - Legal_Union_Record.start_year(lur, startY); - neg find x_inv47(lur); - check(startY >= endY); -} -pattern x_inv47(lur : Legal_Union_Record) { - Legal_Union_Record.separation_cause(lur, ::NONE); - Legal_Union_Record.end_year(lur, -1); -} - -//inv48-attributes-handled by multiplicity -@Constraint(message = "inv48", severity = "error", key = {p}) -pattern inv48(p : Physical_Person) { - neg find x_inv48_notDis(p); - neg find x_inv48_Dis(p); -} -pattern x_inv48_notDis(p : Physical_Person) { - Physical_Person.disability_type(p, ::NONE); - Physical_Person.disability_percentage(p, 0.0); -} -pattern x_inv48_Dis(p : Physical_Person) { - neg find x_inv48_3(p); - Physical_Person.disability_percentage(p, disPer); - check(disPer > 0.0); - check(disPer <= 1.0); -} -pattern x_inv48_3(p : Physical_Person) { - Physical_Person.disability_type(p, ::NONE); -} - -//inv49-OclKindOf-handled by multiplicity -@Constraint(message = "inv49", severity = "error", key = {lur}) -pattern inv49(lur : Legal_Union_Record) { - neg find x_inv49_1(lur); -} -pattern x_inv49_1(lur : Legal_Union_Record) { - Legal_Union_Record.individual_A(lur, iA); - Legal_Union_Record.individual_B(lur, iB); - Tax_Payer(iA); - Physical_Person(iB); - neg find x_inv49_2(iB); - iA != iB; -} -pattern x_inv49_2(iB: Dependent) { - Dependent(iB); -} - -//inv50-MultiplicityChecked -//inv51-MultiplicityChecked -//inv52-MultiplicityChecked -//inv53-MultiplicityChecked \ No newline at end of file diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/run/.RunGenerator.xtendbin b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/run/.RunGenerator.xtendbin deleted file mode 100644 index e2021169..00000000 Binary files a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/run/.RunGenerator.xtendbin and /dev/null differ diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/run/.gitignore b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/run/.gitignore deleted file mode 100644 index 8e503b4a..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/bin/run/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/.GenerateScenarios.java._trace -/.checkQueries.java._trace -/.RunGenerator.xtendbin -/GenerateScenarios.java diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/build.properties b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/build.properties deleted file mode 100644 index 88d3713e..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/build.properties +++ /dev/null @@ -1,6 +0,0 @@ -bin.includes = META-INF/,\ - .,\ - plugin.xml -source.. = src/,\ - src-gen/ -output.. = bin/ diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/ocl/queries.ocl b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/ocl/queries.ocl deleted file mode 100644 index de770240..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/ocl/queries.ocl +++ /dev/null @@ -1,14 +0,0 @@ -import 'file:/Users/Aren Babikian/git/VIATRA-Attributes/original.PLEDGE.case.studies/model/CD_Case_A.uml' ---e.g., import 'file:/Users/User_X/CD_Case_A.uml' - -package Taxation - -context Income inv x: - let involved_details:Set(Income_Detail)=self.details->select(i:Income_Detail| i.is_worked=true) in - involved_details.amount->sum() - -context Expense inv inv11: -let max:Real = if((self.income.income_amount / 2)>50) then self.income.income_amount / 2 else 50 endif in -self.declared_amount >= 50 and self.declared_amount <= max - -endpackage \ No newline at end of file diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/plugin.xml b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/plugin.xml deleted file mode 100644 index 63aa0b02..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/plugin.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/.gitignore b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/.gitignore deleted file mode 100644 index 527f3a0e..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/.gitignore +++ /dev/null @@ -1,112 +0,0 @@ -/.Inv17.java._trace -/.Inv20.java._trace -/.Inv33_con.java._trace -/.Inv34.java._trace -/.Inv35.java._trace -/.Inv47.java._trace -/.Inv48.java._trace -/.Inv48_helper.java._trace -/.Case_study_A.java._trace -/.Inv49.java._trace -/.Inv49_con.java._trace -/.Inv49_helper.java._trace -/.H_inv49.java._trace -/.Ocl_inv49.java._trace -/.Vql_inv49.java._trace -/.Vql_inv492.java._trace -/.H1_inv48.java._trace -/.H2_inv48.java._trace -/.Vql_inv48.java._trace -/.H3_inv48.java._trace -/.H1_inv49.java._trace -/.H2_inv49.java._trace -/.H_inv47.java._trace -/.Inv35test.java._trace -/.Inv33.java._trace -/.X.java._trace -/.H_inv16_moreThan1.java._trace -/.H_inv48_1.java._trace -/.H_inv48_2.java._trace -/.H_inv48_3.java._trace -/.H_inv49_1.java._trace -/.H_inv49_2.java._trace -/.Inv16.java._trace -/.Inv15.java._trace -/.H_inv13.java._trace -/.Inv13.java._trace -/.Inv12.java._trace -/.H_inv12_notNonRes.java._trace -/.H_inv12_notZZ.java._trace -/.H_inv11_incOver100.java._trace -/.Inv11.java._trace -/.H_inv11_incNotOver100.java._trace -/.H_inv8_notEI.java._trace -/.Inv8.java._trace -/.H_inv08_notEI.java._trace -/.Inv08.java._trace -/.H_inv08_inRange.java._trace -/.X_inv08_inRange.java._trace -/.X_inv08_notEI.java._trace -/.X_inv11_incNotOver100.java._trace -/.X_inv11_incOver100.java._trace -/.X_inv12_notNonRes.java._trace -/.X_inv12_notZZ.java._trace -/.X_inv13.java._trace -/.X_inv47.java._trace -/.X_inv48_1.java._trace -/.X_inv48_2.java._trace -/.X_inv48_3.java._trace -/.X_inv49_1.java._trace -/.X_inv49_2.java._trace -/.X_inv48_Dis.java._trace -/.X_inv48_notDis.java._trace -/.X_inv08_noType.java._trace -/.X_inv08_invalidType.java._trace -/.Inv06.java._trace -/.X_inv06_inRange.java._trace -/.Inv05.java._trace -/.X_inv05_inRange.java._trace -/.Inv03.java._trace -/.X_inv03_noAll.java._trace -/.X_inv03_eligAll.java._trace -/.X_inv03_hasAll.java._trace -/.Inv07.java._trace -/.Inv10.java._trace -/.X_inv15.java._trace -/Inv03.java -/Inv05.java -/Inv06.java -/X_inv03_eligAll.java -/X_inv03_hasAll.java -/X_inv05_inRange.java -/Case_study_A.java -/Inv07.java -/Inv08.java -/Inv10.java -/Inv11.java -/Inv12.java -/Inv13.java -/Inv15.java -/Inv17.java -/Inv20.java -/Inv33.java -/Inv34.java -/Inv35.java -/Inv47.java -/Inv48.java -/Inv49.java -/X_inv08_inRange.java -/X_inv08_noType.java -/X_inv08_notEI.java -/X_inv11_incNotOver100.java -/X_inv11_incOver100.java -/X_inv12_notNonRes.java -/X_inv12_notZZ.java -/X_inv13.java -/X_inv15.java -/X_inv47.java -/X_inv48_3.java -/X_inv48_Dis.java -/X_inv48_notDis.java -/X_inv49_1.java -/X_inv49_2.java diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Case_study_A.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Case_study_A.java deleted file mode 100644 index 11c60d6f..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Case_study_A.java +++ /dev/null @@ -1,438 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; -import queries.Inv03; -import queries.Inv05; -import queries.Inv06; -import queries.Inv07; -import queries.Inv08; -import queries.Inv10; -import queries.Inv11; -import queries.Inv12; -import queries.Inv13; -import queries.Inv15; -import queries.Inv17; -import queries.Inv20; -import queries.Inv33; -import queries.Inv34; -import queries.Inv35; -import queries.Inv47; -import queries.Inv48; -import queries.Inv49; -import queries.X_inv03_eligAll; -import queries.X_inv03_hasAll; -import queries.X_inv05_inRange; -import queries.X_inv08_inRange; -import queries.X_inv08_noType; -import queries.X_inv08_notEI; -import queries.X_inv11_incNotOver100; -import queries.X_inv11_incOver100; -import queries.X_inv12_notNonRes; -import queries.X_inv12_notZZ; -import queries.X_inv13; -import queries.X_inv15; -import queries.X_inv47; -import queries.X_inv48_3; -import queries.X_inv48_Dis; -import queries.X_inv48_notDis; -import queries.X_inv49_1; -import queries.X_inv49_2; - -/** - * A pattern group formed of all public patterns defined in case_study_A.vql. - * - *

Use the static instance as any {@link interface org.eclipse.viatra.query.runtime.api.IQueryGroup}, to conveniently prepare - * a VIATRA Query engine for matching all patterns originally defined in file case_study_A.vql, - * in order to achieve better performance than one-by-one on-demand matcher initialization. - * - *

From package queries, the group contains the definition of the following patterns:

- * - * @see IQueryGroup - * - */ -@SuppressWarnings("all") -public final class Case_study_A extends BaseGeneratedPatternGroup { - /** - * Access the pattern group. - * - * @return the singleton instance of the group - * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications - * - */ - public static Case_study_A instance() { - if (INSTANCE == null) { - INSTANCE = new Case_study_A(); - } - return INSTANCE; - } - - private static Case_study_A INSTANCE; - - private Case_study_A() { - querySpecifications.add(Inv03.instance()); - querySpecifications.add(X_inv03_eligAll.instance()); - querySpecifications.add(X_inv03_hasAll.instance()); - querySpecifications.add(Inv05.instance()); - querySpecifications.add(X_inv05_inRange.instance()); - querySpecifications.add(Inv06.instance()); - querySpecifications.add(Inv07.instance()); - querySpecifications.add(Inv08.instance()); - querySpecifications.add(X_inv08_notEI.instance()); - querySpecifications.add(X_inv08_noType.instance()); - querySpecifications.add(X_inv08_inRange.instance()); - querySpecifications.add(Inv10.instance()); - querySpecifications.add(Inv11.instance()); - querySpecifications.add(X_inv11_incOver100.instance()); - querySpecifications.add(X_inv11_incNotOver100.instance()); - querySpecifications.add(Inv12.instance()); - querySpecifications.add(X_inv12_notNonRes.instance()); - querySpecifications.add(X_inv12_notZZ.instance()); - querySpecifications.add(Inv13.instance()); - querySpecifications.add(X_inv13.instance()); - querySpecifications.add(Inv15.instance()); - querySpecifications.add(X_inv15.instance()); - querySpecifications.add(Inv17.instance()); - querySpecifications.add(Inv20.instance()); - querySpecifications.add(Inv33.instance()); - querySpecifications.add(Inv34.instance()); - querySpecifications.add(Inv35.instance()); - querySpecifications.add(Inv47.instance()); - querySpecifications.add(X_inv47.instance()); - querySpecifications.add(Inv48.instance()); - querySpecifications.add(X_inv48_notDis.instance()); - querySpecifications.add(X_inv48_Dis.instance()); - querySpecifications.add(X_inv48_3.instance()); - querySpecifications.add(Inv49.instance()); - querySpecifications.add(X_inv49_1.instance()); - querySpecifications.add(X_inv49_2.instance()); - } - - public Inv03 getInv03() { - return Inv03.instance(); - } - - public Inv03.Matcher getInv03(final ViatraQueryEngine engine) { - return Inv03.Matcher.on(engine); - } - - public X_inv03_eligAll getX_inv03_eligAll() { - return X_inv03_eligAll.instance(); - } - - public X_inv03_eligAll.Matcher getX_inv03_eligAll(final ViatraQueryEngine engine) { - return X_inv03_eligAll.Matcher.on(engine); - } - - public X_inv03_hasAll getX_inv03_hasAll() { - return X_inv03_hasAll.instance(); - } - - public X_inv03_hasAll.Matcher getX_inv03_hasAll(final ViatraQueryEngine engine) { - return X_inv03_hasAll.Matcher.on(engine); - } - - public Inv05 getInv05() { - return Inv05.instance(); - } - - public Inv05.Matcher getInv05(final ViatraQueryEngine engine) { - return Inv05.Matcher.on(engine); - } - - public X_inv05_inRange getX_inv05_inRange() { - return X_inv05_inRange.instance(); - } - - public X_inv05_inRange.Matcher getX_inv05_inRange(final ViatraQueryEngine engine) { - return X_inv05_inRange.Matcher.on(engine); - } - - public Inv06 getInv06() { - return Inv06.instance(); - } - - public Inv06.Matcher getInv06(final ViatraQueryEngine engine) { - return Inv06.Matcher.on(engine); - } - - public Inv07 getInv07() { - return Inv07.instance(); - } - - public Inv07.Matcher getInv07(final ViatraQueryEngine engine) { - return Inv07.Matcher.on(engine); - } - - public Inv08 getInv08() { - return Inv08.instance(); - } - - public Inv08.Matcher getInv08(final ViatraQueryEngine engine) { - return Inv08.Matcher.on(engine); - } - - public X_inv08_notEI getX_inv08_notEI() { - return X_inv08_notEI.instance(); - } - - public X_inv08_notEI.Matcher getX_inv08_notEI(final ViatraQueryEngine engine) { - return X_inv08_notEI.Matcher.on(engine); - } - - public X_inv08_noType getX_inv08_noType() { - return X_inv08_noType.instance(); - } - - public X_inv08_noType.Matcher getX_inv08_noType(final ViatraQueryEngine engine) { - return X_inv08_noType.Matcher.on(engine); - } - - public X_inv08_inRange getX_inv08_inRange() { - return X_inv08_inRange.instance(); - } - - public X_inv08_inRange.Matcher getX_inv08_inRange(final ViatraQueryEngine engine) { - return X_inv08_inRange.Matcher.on(engine); - } - - public Inv10 getInv10() { - return Inv10.instance(); - } - - public Inv10.Matcher getInv10(final ViatraQueryEngine engine) { - return Inv10.Matcher.on(engine); - } - - public Inv11 getInv11() { - return Inv11.instance(); - } - - public Inv11.Matcher getInv11(final ViatraQueryEngine engine) { - return Inv11.Matcher.on(engine); - } - - public X_inv11_incOver100 getX_inv11_incOver100() { - return X_inv11_incOver100.instance(); - } - - public X_inv11_incOver100.Matcher getX_inv11_incOver100(final ViatraQueryEngine engine) { - return X_inv11_incOver100.Matcher.on(engine); - } - - public X_inv11_incNotOver100 getX_inv11_incNotOver100() { - return X_inv11_incNotOver100.instance(); - } - - public X_inv11_incNotOver100.Matcher getX_inv11_incNotOver100(final ViatraQueryEngine engine) { - return X_inv11_incNotOver100.Matcher.on(engine); - } - - public Inv12 getInv12() { - return Inv12.instance(); - } - - public Inv12.Matcher getInv12(final ViatraQueryEngine engine) { - return Inv12.Matcher.on(engine); - } - - public X_inv12_notNonRes getX_inv12_notNonRes() { - return X_inv12_notNonRes.instance(); - } - - public X_inv12_notNonRes.Matcher getX_inv12_notNonRes(final ViatraQueryEngine engine) { - return X_inv12_notNonRes.Matcher.on(engine); - } - - public X_inv12_notZZ getX_inv12_notZZ() { - return X_inv12_notZZ.instance(); - } - - public X_inv12_notZZ.Matcher getX_inv12_notZZ(final ViatraQueryEngine engine) { - return X_inv12_notZZ.Matcher.on(engine); - } - - public Inv13 getInv13() { - return Inv13.instance(); - } - - public Inv13.Matcher getInv13(final ViatraQueryEngine engine) { - return Inv13.Matcher.on(engine); - } - - public X_inv13 getX_inv13() { - return X_inv13.instance(); - } - - public X_inv13.Matcher getX_inv13(final ViatraQueryEngine engine) { - return X_inv13.Matcher.on(engine); - } - - public Inv15 getInv15() { - return Inv15.instance(); - } - - public Inv15.Matcher getInv15(final ViatraQueryEngine engine) { - return Inv15.Matcher.on(engine); - } - - public X_inv15 getX_inv15() { - return X_inv15.instance(); - } - - public X_inv15.Matcher getX_inv15(final ViatraQueryEngine engine) { - return X_inv15.Matcher.on(engine); - } - - public Inv17 getInv17() { - return Inv17.instance(); - } - - public Inv17.Matcher getInv17(final ViatraQueryEngine engine) { - return Inv17.Matcher.on(engine); - } - - public Inv20 getInv20() { - return Inv20.instance(); - } - - public Inv20.Matcher getInv20(final ViatraQueryEngine engine) { - return Inv20.Matcher.on(engine); - } - - public Inv33 getInv33() { - return Inv33.instance(); - } - - public Inv33.Matcher getInv33(final ViatraQueryEngine engine) { - return Inv33.Matcher.on(engine); - } - - public Inv34 getInv34() { - return Inv34.instance(); - } - - public Inv34.Matcher getInv34(final ViatraQueryEngine engine) { - return Inv34.Matcher.on(engine); - } - - public Inv35 getInv35() { - return Inv35.instance(); - } - - public Inv35.Matcher getInv35(final ViatraQueryEngine engine) { - return Inv35.Matcher.on(engine); - } - - public Inv47 getInv47() { - return Inv47.instance(); - } - - public Inv47.Matcher getInv47(final ViatraQueryEngine engine) { - return Inv47.Matcher.on(engine); - } - - public X_inv47 getX_inv47() { - return X_inv47.instance(); - } - - public X_inv47.Matcher getX_inv47(final ViatraQueryEngine engine) { - return X_inv47.Matcher.on(engine); - } - - public Inv48 getInv48() { - return Inv48.instance(); - } - - public Inv48.Matcher getInv48(final ViatraQueryEngine engine) { - return Inv48.Matcher.on(engine); - } - - public X_inv48_notDis getX_inv48_notDis() { - return X_inv48_notDis.instance(); - } - - public X_inv48_notDis.Matcher getX_inv48_notDis(final ViatraQueryEngine engine) { - return X_inv48_notDis.Matcher.on(engine); - } - - public X_inv48_Dis getX_inv48_Dis() { - return X_inv48_Dis.instance(); - } - - public X_inv48_Dis.Matcher getX_inv48_Dis(final ViatraQueryEngine engine) { - return X_inv48_Dis.Matcher.on(engine); - } - - public X_inv48_3 getX_inv48_3() { - return X_inv48_3.instance(); - } - - public X_inv48_3.Matcher getX_inv48_3(final ViatraQueryEngine engine) { - return X_inv48_3.Matcher.on(engine); - } - - public Inv49 getInv49() { - return Inv49.instance(); - } - - public Inv49.Matcher getInv49(final ViatraQueryEngine engine) { - return Inv49.Matcher.on(engine); - } - - public X_inv49_1 getX_inv49_1() { - return X_inv49_1.instance(); - } - - public X_inv49_1.Matcher getX_inv49_1(final ViatraQueryEngine engine) { - return X_inv49_1.Matcher.on(engine); - } - - public X_inv49_2 getX_inv49_2() { - return X_inv49_2.instance(); - } - - public X_inv49_2.Matcher getX_inv49_2(final ViatraQueryEngine engine) { - return X_inv49_2.Matcher.on(engine); - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv03.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv03.java deleted file mode 100644 index 9038ec4d..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv03.java +++ /dev/null @@ -1,652 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Dependent; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; -import queries.X_inv03_eligAll; -import queries.X_inv03_hasAll; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //AttributeRemoved -{@literal >} DF
- *         
- *         //inv1-External_Allowance.amount is a derived feature (TODOcheck)
- *         //inv2-Tax_Card.income.taxPayer.taxesDue is a derived feature (TODOcheck)
- *         
- *         //inv3-multiplicity adjusted
- *         {@literal @}Constraint(message = "inv03", severity = "error", key = {dep})
- *         pattern inv03(dep : Dependent) {
- *             find x_inv03_eligAll(dep);
- *             neg find x_inv03_hasAll(dep);
- *         } or {
- *         	Dependent.birth_year(dep, by);
- *             check(2018-by {@literal >} 21);
- *         	Dependent.continued_studies(dep, false);
- *             Dependent.allowances(dep, _);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv03 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv03 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Dependent fDep; - - private static List parameterNames = makeImmutableList("dep"); - - private Match(final Dependent pDep) { - this.fDep = pDep; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "dep": return this.fDep; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fDep; - default: return null; - } - } - - public Dependent getDep() { - return this.fDep; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("dep".equals(parameterName) ) { - this.fDep = (Dependent) newValue; - return true; - } - return false; - } - - public void setDep(final Dependent pDep) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fDep = pDep; - } - - @Override - public String patternName() { - return "queries.inv03"; - } - - @Override - public List parameterNames() { - return Inv03.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fDep}; - } - - @Override - public Inv03.Match toImmutable() { - return isMutable() ? newMatch(fDep) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"dep\"=" + prettyPrintValue(fDep)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fDep); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv03.Match)) { - Inv03.Match other = (Inv03.Match) obj; - return Objects.equals(fDep, other.fDep); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv03 specification() { - return Inv03.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv03.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv03.Match newMutableMatch(final Dependent pDep) { - return new Mutable(pDep); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv03.Match newMatch(final Dependent pDep) { - return new Immutable(pDep); - } - - private static final class Mutable extends Inv03.Match { - Mutable(final Dependent pDep) { - super(pDep); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv03.Match { - Immutable(final Dependent pDep) { - super(pDep); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv03 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //AttributeRemoved -{@literal >} DF
-   * 
-   * //inv1-External_Allowance.amount is a derived feature (TODOcheck)
-   * //inv2-Tax_Card.income.taxPayer.taxesDue is a derived feature (TODOcheck)
-   * 
-   * //inv3-multiplicity adjusted
-   * {@literal @}Constraint(message = "inv03", severity = "error", key = {dep})
-   * pattern inv03(dep : Dependent) {
-   *     find x_inv03_eligAll(dep);
-   *     neg find x_inv03_hasAll(dep);
-   * } or {
-   * 	Dependent.birth_year(dep, by);
-   *     check(2018-by {@literal >} 21);
-   * 	Dependent.continued_studies(dep, false);
-   *     Dependent.allowances(dep, _);
-   * }
-   * 
- * - * @see Match - * @see Inv03 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv03.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv03.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_DEP = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv03.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Dependent pDep) { - return rawStreamAllMatches(new Object[]{pDep}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Dependent pDep) { - return rawStreamAllMatches(new Object[]{pDep}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Dependent pDep) { - return rawGetOneArbitraryMatch(new Object[]{pDep}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Dependent pDep) { - return rawHasMatch(new Object[]{pDep}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Dependent pDep) { - return rawCountMatches(new Object[]{pDep}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Dependent pDep, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pDep}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv03.Match newMatch(final Dependent pDep) { - return Inv03.Match.newMatch(pDep); - } - - /** - * Retrieve the set of values that occur in matches for dep. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfdep(final Object[] parameters) { - return rawStreamAllValues(POSITION_DEP, parameters).map(Dependent.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for dep. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfdep() { - return rawStreamAllValuesOfdep(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for dep. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfdep() { - return rawStreamAllValuesOfdep(emptyArray()); - } - - @Override - protected Inv03.Match tupleToMatch(final Tuple t) { - try { - return Inv03.Match.newMatch((Dependent) t.get(POSITION_DEP)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv03.Match arrayToMatch(final Object[] match) { - try { - return Inv03.Match.newMatch((Dependent) match[POSITION_DEP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv03.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv03.Match.newMutableMatch((Dependent) match[POSITION_DEP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv03.instance(); - } - } - - private Inv03() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv03 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv03.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv03.Matcher.on(engine); - } - - @Override - public Inv03.Matcher instantiate() { - return Inv03.Matcher.create(); - } - - @Override - public Inv03.Match newEmptyMatch() { - return Inv03.Match.newEmptyMatch(); - } - - @Override - public Inv03.Match newMatch(final Object... parameters) { - return Inv03.Match.newMatch((Taxation.Dependent) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv03} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv03#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv03 INSTANCE = new Inv03(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv03.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_dep = new PParameter("dep", "Taxation.Dependent", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Dependent")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_dep); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv03"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("dep"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_dep = body.getOrCreateVariableByName("dep"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_dep, parameter_dep) - )); - // find x_inv03_eligAll(dep) - new PositivePatternCall(body, Tuples.flatTupleOf(var_dep), X_inv03_eligAll.instance().getInternalQueryRepresentation()); - // neg find x_inv03_hasAll(dep) - new NegativePatternCall(body, Tuples.flatTupleOf(var_dep), X_inv03_hasAll.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_dep = body.getOrCreateVariableByName("dep"); - PVariable var_by = body.getOrCreateVariableByName("by"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_dep, parameter_dep) - )); - // Dependent.birth_year(dep, by) - new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_0_, var_by); - // check(2018-by > 21) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv03"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("by");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer by = (Integer) provider.getValue("by"); - return evaluateExpression_2_1(by); - } - }, null); - // Dependent.continued_studies(dep, false) - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new ConstantValue(body, var__virtual_1_, false); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Dependent", "continued_studies"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EBoolean"))); - new Equality(body, var__virtual_2_, var__virtual_1_); - // Dependent.allowances(dep, _) - new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Dependent", "allowances"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance"))); - new Equality(body, var__virtual_3_, var___0_); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv03"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("dep") - })); - addAnnotation(annotation); - } - return bodies; - } - } - - private static boolean evaluateExpression_2_1(final Integer by) { - return ((2018 - (by).intValue()) > 21); - } - - private static boolean evaluateExpression_2_2() { - return false; - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv05.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv05.java deleted file mode 100644 index 2dee094d..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv05.java +++ /dev/null @@ -1,701 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Income; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; -import queries.X_inv05_inRange; -import queries.X_inv08_noType; -import queries.X_inv08_notEI; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv5 - oclIsTypeOf - handled here
- *         {@literal @}Constraint(message = "inv05", severity = "error", key = {inc})
- *         pattern inv05(inc : Income) {
- *         	//income_type: None
- *             neg find x_inv08_noType(inc);
- *             Income.details.worked_days(inc, wd);
- *             check(wd != 0);
- *         } or {
- *         	//income_type: Not Employment_Income
- *             Income.income_type(inc, type);
- *             neg find x_inv08_notEI(type);
- *             Income.details.worked_days(inc, wd);
- *             check(wd != 0);
- *         } or {
- *         	//income_type: Employment Income
- *         	Income.income_type(inc, type);
- *             Employment_Income(type);
- *             find x_inv05_inRange(inc);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv05 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv05 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Income fInc; - - private static List parameterNames = makeImmutableList("inc"); - - private Match(final Income pInc) { - this.fInc = pInc; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "inc": return this.fInc; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fInc; - default: return null; - } - } - - public Income getInc() { - return this.fInc; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("inc".equals(parameterName) ) { - this.fInc = (Income) newValue; - return true; - } - return false; - } - - public void setInc(final Income pInc) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fInc = pInc; - } - - @Override - public String patternName() { - return "queries.inv05"; - } - - @Override - public List parameterNames() { - return Inv05.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fInc}; - } - - @Override - public Inv05.Match toImmutable() { - return isMutable() ? newMatch(fInc) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"inc\"=" + prettyPrintValue(fInc)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fInc); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv05.Match)) { - Inv05.Match other = (Inv05.Match) obj; - return Objects.equals(fInc, other.fInc); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv05 specification() { - return Inv05.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv05.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv05.Match newMutableMatch(final Income pInc) { - return new Mutable(pInc); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv05.Match newMatch(final Income pInc) { - return new Immutable(pInc); - } - - private static final class Mutable extends Inv05.Match { - Mutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv05.Match { - Immutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv05 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv5 - oclIsTypeOf - handled here
-   * {@literal @}Constraint(message = "inv05", severity = "error", key = {inc})
-   * pattern inv05(inc : Income) {
-   * 	//income_type: None
-   *     neg find x_inv08_noType(inc);
-   *     Income.details.worked_days(inc, wd);
-   *     check(wd != 0);
-   * } or {
-   * 	//income_type: Not Employment_Income
-   *     Income.income_type(inc, type);
-   *     neg find x_inv08_notEI(type);
-   *     Income.details.worked_days(inc, wd);
-   *     check(wd != 0);
-   * } or {
-   * 	//income_type: Employment Income
-   * 	Income.income_type(inc, type);
-   *     Employment_Income(type);
-   *     find x_inv05_inRange(inc);
-   * }
-   * 
- * - * @see Match - * @see Inv05 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv05.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv05.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_INC = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv05.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Income pInc) { - return rawGetOneArbitraryMatch(new Object[]{pInc}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Income pInc) { - return rawHasMatch(new Object[]{pInc}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Income pInc) { - return rawCountMatches(new Object[]{pInc}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Income pInc, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pInc}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv05.Match newMatch(final Income pInc) { - return Inv05.Match.newMatch(pInc); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfinc(final Object[] parameters) { - return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()); - } - - @Override - protected Inv05.Match tupleToMatch(final Tuple t) { - try { - return Inv05.Match.newMatch((Income) t.get(POSITION_INC)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv05.Match arrayToMatch(final Object[] match) { - try { - return Inv05.Match.newMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv05.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv05.Match.newMutableMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv05.instance(); - } - } - - private Inv05() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv05 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv05.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv05.Matcher.on(engine); - } - - @Override - public Inv05.Matcher instantiate() { - return Inv05.Matcher.create(); - } - - @Override - public Inv05.Match newEmptyMatch() { - return Inv05.Match.newEmptyMatch(); - } - - @Override - public Inv05.Match newMatch(final Object... parameters) { - return Inv05.Match.newMatch((Taxation.Income) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv05} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv05#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv05 INSTANCE = new Inv05(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv05.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_inc); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv05"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("inc"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - PVariable var_wd = body.getOrCreateVariableByName("wd"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_inc, parameter_inc) - )); - // //income_type: None neg find x_inv08_noType(inc) - new NegativePatternCall(body, Tuples.flatTupleOf(var_inc), X_inv08_noType.instance().getInternalQueryRepresentation()); - // Income.details.worked_days(inc, wd) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "worked_days"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_1_, var_wd); - // check(wd != 0) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv05"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("wd");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer wd = (Integer) provider.getValue("wd"); - return evaluateExpression_1_1(wd); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - PVariable var_type = body.getOrCreateVariableByName("type"); - PVariable var_wd = body.getOrCreateVariableByName("wd"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_inc, parameter_inc) - )); - // //income_type: Not Employment_Income Income.income_type(inc, type) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_type"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Type"))); - new Equality(body, var__virtual_0_, var_type); - // neg find x_inv08_notEI(type) - new NegativePatternCall(body, Tuples.flatTupleOf(var_type), X_inv08_notEI.instance().getInternalQueryRepresentation()); - // Income.details.worked_days(inc, wd) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "worked_days"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_2_, var_wd); - // check(wd != 0) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv05"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("wd");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer wd = (Integer) provider.getValue("wd"); - return evaluateExpression_2_1(wd); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - PVariable var_type = body.getOrCreateVariableByName("type"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_inc, parameter_inc) - )); - // //income_type: Employment Income Income.income_type(inc, type) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_type"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Type"))); - new Equality(body, var__virtual_0_, var_type); - // Employment_Income(type) - new TypeConstraint(body, Tuples.flatTupleOf(var_type), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Employment_Income"))); - // find x_inv05_inRange(inc) - new PositivePatternCall(body, Tuples.flatTupleOf(var_inc), X_inv05_inRange.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv05"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("inc") - })); - addAnnotation(annotation); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Integer wd) { - return ((wd).intValue() != 0); - } - - private static boolean evaluateExpression_2_1(final Integer wd) { - return ((wd).intValue() != 0); - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv06.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv06.java deleted file mode 100644 index aafdbe41..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv06.java +++ /dev/null @@ -1,669 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Tax_Payer; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv6-Does not make sens, but directly from OCL
- *         //first part of or from definition of getAge()
- *         {@literal @}Constraint(message = "inv06", severity = "error", key = {tp})
- *         pattern inv06(tp : Tax_Payer) {
- *             Tax_Payer.dependents(tp, _);
- *         	Tax_Payer.birth_year(tp, TPBy);
- *         	check(2018 - TPBy {@literal >} 2018-16);
- *         } or {
- *         	Tax_Payer.birth_year(tp, TPBy);
- *             Tax_Payer.dependents(tp, dep);
- *             Dependent.birth_year(dep, DepBy);
- *             check(2018-DepBy {@literal <}= 2018-TPBy-16);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv06 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv06 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Tax_Payer fTp; - - private static List parameterNames = makeImmutableList("tp"); - - private Match(final Tax_Payer pTp) { - this.fTp = pTp; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "tp": return this.fTp; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fTp; - default: return null; - } - } - - public Tax_Payer getTp() { - return this.fTp; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("tp".equals(parameterName) ) { - this.fTp = (Tax_Payer) newValue; - return true; - } - return false; - } - - public void setTp(final Tax_Payer pTp) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTp = pTp; - } - - @Override - public String patternName() { - return "queries.inv06"; - } - - @Override - public List parameterNames() { - return Inv06.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fTp}; - } - - @Override - public Inv06.Match toImmutable() { - return isMutable() ? newMatch(fTp) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"tp\"=" + prettyPrintValue(fTp)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fTp); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv06.Match)) { - Inv06.Match other = (Inv06.Match) obj; - return Objects.equals(fTp, other.fTp); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv06 specification() { - return Inv06.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv06.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv06.Match newMutableMatch(final Tax_Payer pTp) { - return new Mutable(pTp); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv06.Match newMatch(final Tax_Payer pTp) { - return new Immutable(pTp); - } - - private static final class Mutable extends Inv06.Match { - Mutable(final Tax_Payer pTp) { - super(pTp); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv06.Match { - Immutable(final Tax_Payer pTp) { - super(pTp); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv06 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv6-Does not make sens, but directly from OCL
-   * //first part of or from definition of getAge()
-   * {@literal @}Constraint(message = "inv06", severity = "error", key = {tp})
-   * pattern inv06(tp : Tax_Payer) {
-   *     Tax_Payer.dependents(tp, _);
-   * 	Tax_Payer.birth_year(tp, TPBy);
-   * 	check(2018 - TPBy {@literal >} 2018-16);
-   * } or {
-   * 	Tax_Payer.birth_year(tp, TPBy);
-   *     Tax_Payer.dependents(tp, dep);
-   *     Dependent.birth_year(dep, DepBy);
-   *     check(2018-DepBy {@literal <}= 2018-TPBy-16);
-   * }
-   * 
- * - * @see Match - * @see Inv06 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv06.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv06.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_TP = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv06.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Tax_Payer pTp) { - return rawStreamAllMatches(new Object[]{pTp}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Tax_Payer pTp) { - return rawStreamAllMatches(new Object[]{pTp}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Tax_Payer pTp) { - return rawGetOneArbitraryMatch(new Object[]{pTp}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Tax_Payer pTp) { - return rawHasMatch(new Object[]{pTp}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Tax_Payer pTp) { - return rawCountMatches(new Object[]{pTp}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Tax_Payer pTp, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pTp}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv06.Match newMatch(final Tax_Payer pTp) { - return Inv06.Match.newMatch(pTp); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftp(final Object[] parameters) { - return rawStreamAllValues(POSITION_TP, parameters).map(Tax_Payer.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftp() { - return rawStreamAllValuesOftp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftp() { - return rawStreamAllValuesOftp(emptyArray()); - } - - @Override - protected Inv06.Match tupleToMatch(final Tuple t) { - try { - return Inv06.Match.newMatch((Tax_Payer) t.get(POSITION_TP)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv06.Match arrayToMatch(final Object[] match) { - try { - return Inv06.Match.newMatch((Tax_Payer) match[POSITION_TP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv06.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv06.Match.newMutableMatch((Tax_Payer) match[POSITION_TP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv06.instance(); - } - } - - private Inv06() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv06 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv06.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv06.Matcher.on(engine); - } - - @Override - public Inv06.Matcher instantiate() { - return Inv06.Matcher.create(); - } - - @Override - public Inv06.Match newEmptyMatch() { - return Inv06.Match.newEmptyMatch(); - } - - @Override - public Inv06.Match newMatch(final Object... parameters) { - return Inv06.Match.newMatch((Taxation.Tax_Payer) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv06} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv06#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv06 INSTANCE = new Inv06(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv06.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_tp = new PParameter("tp", "Taxation.Tax_Payer", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Tax_Payer")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_tp); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv06"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("tp"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_tp = body.getOrCreateVariableByName("tp"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - PVariable var_TPBy = body.getOrCreateVariableByName("TPBy"); - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_tp, parameter_tp) - )); - // Tax_Payer.dependents(tp, _) - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Tax_Payer", "dependents"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - new Equality(body, var__virtual_0_, var___0_); - // Tax_Payer.birth_year(tp, TPBy) - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_1_, var_TPBy); - // check(2018 - TPBy > 2018-16) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv06"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("TPBy");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer TPBy = (Integer) provider.getValue("TPBy"); - return evaluateExpression_1_1(TPBy); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_tp = body.getOrCreateVariableByName("tp"); - PVariable var_TPBy = body.getOrCreateVariableByName("TPBy"); - PVariable var_dep = body.getOrCreateVariableByName("dep"); - PVariable var_DepBy = body.getOrCreateVariableByName("DepBy"); - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_tp, parameter_tp) - )); - // Tax_Payer.birth_year(tp, TPBy) - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_0_, var_TPBy); - // Tax_Payer.dependents(tp, dep) - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Tax_Payer", "dependents"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - new Equality(body, var__virtual_1_, var_dep); - // Dependent.birth_year(dep, DepBy) - new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_2_, var_DepBy); - // check(2018-DepBy <= 2018-TPBy-16) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv06"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("DepBy", "TPBy");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer DepBy = (Integer) provider.getValue("DepBy"); - Integer TPBy = (Integer) provider.getValue("TPBy"); - return evaluateExpression_2_1(DepBy, TPBy); - } - }, null); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv06"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("tp") - })); - addAnnotation(annotation); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Integer TPBy) { - return ((2018 - (TPBy).intValue()) > (2018 - 16)); - } - - private static boolean evaluateExpression_2_1(final Integer DepBy, final Integer TPBy) { - return ((2018 - (DepBy).intValue()) <= ((2018 - (TPBy).intValue()) - 16)); - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv07.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv07.java deleted file mode 100644 index 81665825..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv07.java +++ /dev/null @@ -1,612 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Income; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv7-OrderedSet
- *         {@literal @}Constraint(message = "inv07", severity = "error", key = {inc})
- *         pattern inv07(inc : Income) {
- *         	Income.details.distance(inc, d1);
- *         	Income.details.distance(inc, d2);
- *         	check(d1 != d2);//compare values
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv07 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv07 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Income fInc; - - private static List parameterNames = makeImmutableList("inc"); - - private Match(final Income pInc) { - this.fInc = pInc; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "inc": return this.fInc; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fInc; - default: return null; - } - } - - public Income getInc() { - return this.fInc; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("inc".equals(parameterName) ) { - this.fInc = (Income) newValue; - return true; - } - return false; - } - - public void setInc(final Income pInc) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fInc = pInc; - } - - @Override - public String patternName() { - return "queries.inv07"; - } - - @Override - public List parameterNames() { - return Inv07.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fInc}; - } - - @Override - public Inv07.Match toImmutable() { - return isMutable() ? newMatch(fInc) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"inc\"=" + prettyPrintValue(fInc)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fInc); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv07.Match)) { - Inv07.Match other = (Inv07.Match) obj; - return Objects.equals(fInc, other.fInc); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv07 specification() { - return Inv07.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv07.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv07.Match newMutableMatch(final Income pInc) { - return new Mutable(pInc); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv07.Match newMatch(final Income pInc) { - return new Immutable(pInc); - } - - private static final class Mutable extends Inv07.Match { - Mutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv07.Match { - Immutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv07 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv7-OrderedSet
-   * {@literal @}Constraint(message = "inv07", severity = "error", key = {inc})
-   * pattern inv07(inc : Income) {
-   * 	Income.details.distance(inc, d1);
-   * 	Income.details.distance(inc, d2);
-   * 	check(d1 != d2);//compare values
-   * }
-   * 
- * - * @see Match - * @see Inv07 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv07.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv07.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_INC = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv07.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Income pInc) { - return rawGetOneArbitraryMatch(new Object[]{pInc}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Income pInc) { - return rawHasMatch(new Object[]{pInc}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Income pInc) { - return rawCountMatches(new Object[]{pInc}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Income pInc, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pInc}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv07.Match newMatch(final Income pInc) { - return Inv07.Match.newMatch(pInc); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfinc(final Object[] parameters) { - return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()); - } - - @Override - protected Inv07.Match tupleToMatch(final Tuple t) { - try { - return Inv07.Match.newMatch((Income) t.get(POSITION_INC)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv07.Match arrayToMatch(final Object[] match) { - try { - return Inv07.Match.newMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv07.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv07.Match.newMutableMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv07.instance(); - } - } - - private Inv07() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv07 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv07.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv07.Matcher.on(engine); - } - - @Override - public Inv07.Matcher instantiate() { - return Inv07.Matcher.create(); - } - - @Override - public Inv07.Match newEmptyMatch() { - return Inv07.Match.newEmptyMatch(); - } - - @Override - public Inv07.Match newMatch(final Object... parameters) { - return Inv07.Match.newMatch((Taxation.Income) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv07} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv07#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv07 INSTANCE = new Inv07(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv07.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_inc); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv07"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("inc"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - PVariable var_d1 = body.getOrCreateVariableByName("d1"); - PVariable var_d2 = body.getOrCreateVariableByName("d2"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_inc, parameter_inc) - )); - // Income.details.distance(inc, d1) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "distance"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_1_, var_d1); - // Income.details.distance(inc, d2) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail"))); - PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "distance"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_3_, var_d2); - // check(d1 != d2) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv07"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("d1", "d2");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Double d1 = (Double) provider.getValue("d1"); - Double d2 = (Double) provider.getValue("d2"); - return evaluateExpression_1_1(d1, d2); - } - }, null); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv07"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("inc") - })); - addAnnotation(annotation); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Double d1, final Double d2) { - boolean _notEquals = (!com.google.common.base.Objects.equal(d1, d2)); - return _notEquals; - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv08.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv08.java deleted file mode 100644 index 9ecadd34..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv08.java +++ /dev/null @@ -1,705 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Income; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; -import queries.X_inv08_inRange; -import queries.X_inv08_noType; -import queries.X_inv08_notEI; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //user_complete_details-AttributeRemoved
- *         
- *         //inv8 - oclIsTypeOf - handled here
- *         {@literal @}Constraint(message = "inv08", severity = "error", key = {inc})
- *         pattern inv08(inc : Income) {
- *         	//income_type: None
- *             neg find x_inv08_noType(inc);
- *             Income.details.distance(inc, dist);
- *             check(dist != 0);
- *         } or {
- *         	//income_type: Not Employment_Income
- *             Income.income_type(inc, type);
- *             neg find x_inv08_notEI(type);
- *             Income.details.distance(inc, dist);
- *             check(dist != 0);
- *         } or {
- *         	//income_type: Employment Income
- *         	Income.income_type(inc, type);
- *             Employment_Income(type);
- *             find x_inv08_inRange(inc);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv08 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv08 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Income fInc; - - private static List parameterNames = makeImmutableList("inc"); - - private Match(final Income pInc) { - this.fInc = pInc; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "inc": return this.fInc; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fInc; - default: return null; - } - } - - public Income getInc() { - return this.fInc; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("inc".equals(parameterName) ) { - this.fInc = (Income) newValue; - return true; - } - return false; - } - - public void setInc(final Income pInc) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fInc = pInc; - } - - @Override - public String patternName() { - return "queries.inv08"; - } - - @Override - public List parameterNames() { - return Inv08.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fInc}; - } - - @Override - public Inv08.Match toImmutable() { - return isMutable() ? newMatch(fInc) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"inc\"=" + prettyPrintValue(fInc)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fInc); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv08.Match)) { - Inv08.Match other = (Inv08.Match) obj; - return Objects.equals(fInc, other.fInc); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv08 specification() { - return Inv08.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv08.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv08.Match newMutableMatch(final Income pInc) { - return new Mutable(pInc); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv08.Match newMatch(final Income pInc) { - return new Immutable(pInc); - } - - private static final class Mutable extends Inv08.Match { - Mutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv08.Match { - Immutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv08 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //user_complete_details-AttributeRemoved
-   * 
-   * //inv8 - oclIsTypeOf - handled here
-   * {@literal @}Constraint(message = "inv08", severity = "error", key = {inc})
-   * pattern inv08(inc : Income) {
-   * 	//income_type: None
-   *     neg find x_inv08_noType(inc);
-   *     Income.details.distance(inc, dist);
-   *     check(dist != 0);
-   * } or {
-   * 	//income_type: Not Employment_Income
-   *     Income.income_type(inc, type);
-   *     neg find x_inv08_notEI(type);
-   *     Income.details.distance(inc, dist);
-   *     check(dist != 0);
-   * } or {
-   * 	//income_type: Employment Income
-   * 	Income.income_type(inc, type);
-   *     Employment_Income(type);
-   *     find x_inv08_inRange(inc);
-   * }
-   * 
- * - * @see Match - * @see Inv08 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv08.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv08.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_INC = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv08.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Income pInc) { - return rawGetOneArbitraryMatch(new Object[]{pInc}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Income pInc) { - return rawHasMatch(new Object[]{pInc}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Income pInc) { - return rawCountMatches(new Object[]{pInc}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Income pInc, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pInc}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv08.Match newMatch(final Income pInc) { - return Inv08.Match.newMatch(pInc); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfinc(final Object[] parameters) { - return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()); - } - - @Override - protected Inv08.Match tupleToMatch(final Tuple t) { - try { - return Inv08.Match.newMatch((Income) t.get(POSITION_INC)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv08.Match arrayToMatch(final Object[] match) { - try { - return Inv08.Match.newMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv08.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv08.Match.newMutableMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv08.instance(); - } - } - - private Inv08() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv08 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv08.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv08.Matcher.on(engine); - } - - @Override - public Inv08.Matcher instantiate() { - return Inv08.Matcher.create(); - } - - @Override - public Inv08.Match newEmptyMatch() { - return Inv08.Match.newEmptyMatch(); - } - - @Override - public Inv08.Match newMatch(final Object... parameters) { - return Inv08.Match.newMatch((Taxation.Income) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv08} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv08#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv08 INSTANCE = new Inv08(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv08.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_inc); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv08"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("inc"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - PVariable var_dist = body.getOrCreateVariableByName("dist"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_inc, parameter_inc) - )); - // //income_type: None neg find x_inv08_noType(inc) - new NegativePatternCall(body, Tuples.flatTupleOf(var_inc), X_inv08_noType.instance().getInternalQueryRepresentation()); - // Income.details.distance(inc, dist) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "distance"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_1_, var_dist); - // check(dist != 0) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv08"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("dist");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Double dist = (Double) provider.getValue("dist"); - return evaluateExpression_1_1(dist); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - PVariable var_type = body.getOrCreateVariableByName("type"); - PVariable var_dist = body.getOrCreateVariableByName("dist"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_inc, parameter_inc) - )); - // //income_type: Not Employment_Income Income.income_type(inc, type) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_type"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Type"))); - new Equality(body, var__virtual_0_, var_type); - // neg find x_inv08_notEI(type) - new NegativePatternCall(body, Tuples.flatTupleOf(var_type), X_inv08_notEI.instance().getInternalQueryRepresentation()); - // Income.details.distance(inc, dist) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "distance"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_2_, var_dist); - // check(dist != 0) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv08"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("dist");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Double dist = (Double) provider.getValue("dist"); - return evaluateExpression_2_1(dist); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - PVariable var_type = body.getOrCreateVariableByName("type"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_inc, parameter_inc) - )); - // //income_type: Employment Income Income.income_type(inc, type) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_type"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Type"))); - new Equality(body, var__virtual_0_, var_type); - // Employment_Income(type) - new TypeConstraint(body, Tuples.flatTupleOf(var_type), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Employment_Income"))); - // find x_inv08_inRange(inc) - new PositivePatternCall(body, Tuples.flatTupleOf(var_inc), X_inv08_inRange.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv08"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("inc") - })); - addAnnotation(annotation); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Double dist) { - return ((dist).doubleValue() != 0); - } - - private static boolean evaluateExpression_2_1(final Double dist) { - return ((dist).doubleValue() != 0); - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv10.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv10.java deleted file mode 100644 index 6ee0111e..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv10.java +++ /dev/null @@ -1,616 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Income; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv9-DerivedFeature
- *         
- *         //inv10-Ordered Sets
- *         {@literal @}Constraint(message = "inv10", severity = "error", key = {inc})
- *         pattern inv10(inc : Income) {
- *         	Income.details.amount(inc, a1);
- *         	Income.details.amount(inc, a2);
- *         	check(a1 != a2);//compare values
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv10 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv10 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Income fInc; - - private static List parameterNames = makeImmutableList("inc"); - - private Match(final Income pInc) { - this.fInc = pInc; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "inc": return this.fInc; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fInc; - default: return null; - } - } - - public Income getInc() { - return this.fInc; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("inc".equals(parameterName) ) { - this.fInc = (Income) newValue; - return true; - } - return false; - } - - public void setInc(final Income pInc) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fInc = pInc; - } - - @Override - public String patternName() { - return "queries.inv10"; - } - - @Override - public List parameterNames() { - return Inv10.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fInc}; - } - - @Override - public Inv10.Match toImmutable() { - return isMutable() ? newMatch(fInc) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"inc\"=" + prettyPrintValue(fInc)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fInc); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv10.Match)) { - Inv10.Match other = (Inv10.Match) obj; - return Objects.equals(fInc, other.fInc); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv10 specification() { - return Inv10.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv10.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv10.Match newMutableMatch(final Income pInc) { - return new Mutable(pInc); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv10.Match newMatch(final Income pInc) { - return new Immutable(pInc); - } - - private static final class Mutable extends Inv10.Match { - Mutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv10.Match { - Immutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv10 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv9-DerivedFeature
-   * 
-   * //inv10-Ordered Sets
-   * {@literal @}Constraint(message = "inv10", severity = "error", key = {inc})
-   * pattern inv10(inc : Income) {
-   * 	Income.details.amount(inc, a1);
-   * 	Income.details.amount(inc, a2);
-   * 	check(a1 != a2);//compare values
-   * }
-   * 
- * - * @see Match - * @see Inv10 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv10.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv10.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_INC = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv10.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Income pInc) { - return rawGetOneArbitraryMatch(new Object[]{pInc}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Income pInc) { - return rawHasMatch(new Object[]{pInc}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Income pInc) { - return rawCountMatches(new Object[]{pInc}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Income pInc, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pInc}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv10.Match newMatch(final Income pInc) { - return Inv10.Match.newMatch(pInc); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfinc(final Object[] parameters) { - return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()); - } - - @Override - protected Inv10.Match tupleToMatch(final Tuple t) { - try { - return Inv10.Match.newMatch((Income) t.get(POSITION_INC)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv10.Match arrayToMatch(final Object[] match) { - try { - return Inv10.Match.newMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv10.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv10.Match.newMutableMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv10.instance(); - } - } - - private Inv10() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv10 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv10.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv10.Matcher.on(engine); - } - - @Override - public Inv10.Matcher instantiate() { - return Inv10.Matcher.create(); - } - - @Override - public Inv10.Match newEmptyMatch() { - return Inv10.Match.newEmptyMatch(); - } - - @Override - public Inv10.Match newMatch(final Object... parameters) { - return Inv10.Match.newMatch((Taxation.Income) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv10} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv10#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv10 INSTANCE = new Inv10(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv10.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_inc); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv10"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("inc"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - PVariable var_a1 = body.getOrCreateVariableByName("a1"); - PVariable var_a2 = body.getOrCreateVariableByName("a2"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_inc, parameter_inc) - )); - // Income.details.amount(inc, a1) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "amount"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_1_, var_a1); - // Income.details.amount(inc, a2) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail"))); - PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "amount"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_3_, var_a2); - // check(a1 != a2) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv10"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("a1", "a2");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Double a1 = (Double) provider.getValue("a1"); - Double a2 = (Double) provider.getValue("a2"); - return evaluateExpression_1_1(a1, a2); - } - }, null); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv10"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("inc") - })); - addAnnotation(annotation); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Double a1, final Double a2) { - boolean _notEquals = (!com.google.common.base.Objects.equal(a1, a2)); - return _notEquals; - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv11.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv11.java deleted file mode 100644 index 5dc82fc9..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv11.java +++ /dev/null @@ -1,566 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Expense; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; -import queries.X_inv11_incNotOver100; -import queries.X_inv11_incOver100; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv11-attributes-handled by multiplicity
- *         {@literal @}Constraint(message = "inv11", severity = "error", key = {exp})
- *         pattern inv11(exp : Expense) {
- *             find x_inv11_incOver100(exp);
- *             find x_inv11_incNotOver100(exp);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv11 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv11 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Expense fExp; - - private static List parameterNames = makeImmutableList("exp"); - - private Match(final Expense pExp) { - this.fExp = pExp; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "exp": return this.fExp; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fExp; - default: return null; - } - } - - public Expense getExp() { - return this.fExp; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("exp".equals(parameterName) ) { - this.fExp = (Expense) newValue; - return true; - } - return false; - } - - public void setExp(final Expense pExp) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fExp = pExp; - } - - @Override - public String patternName() { - return "queries.inv11"; - } - - @Override - public List parameterNames() { - return Inv11.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fExp}; - } - - @Override - public Inv11.Match toImmutable() { - return isMutable() ? newMatch(fExp) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"exp\"=" + prettyPrintValue(fExp)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fExp); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv11.Match)) { - Inv11.Match other = (Inv11.Match) obj; - return Objects.equals(fExp, other.fExp); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv11 specification() { - return Inv11.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv11.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv11.Match newMutableMatch(final Expense pExp) { - return new Mutable(pExp); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv11.Match newMatch(final Expense pExp) { - return new Immutable(pExp); - } - - private static final class Mutable extends Inv11.Match { - Mutable(final Expense pExp) { - super(pExp); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv11.Match { - Immutable(final Expense pExp) { - super(pExp); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv11 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv11-attributes-handled by multiplicity
-   * {@literal @}Constraint(message = "inv11", severity = "error", key = {exp})
-   * pattern inv11(exp : Expense) {
-   *     find x_inv11_incOver100(exp);
-   *     find x_inv11_incNotOver100(exp);
-   * }
-   * 
- * - * @see Match - * @see Inv11 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv11.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv11.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_EXP = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv11.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Expense pExp) { - return rawStreamAllMatches(new Object[]{pExp}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Expense pExp) { - return rawStreamAllMatches(new Object[]{pExp}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Expense pExp) { - return rawGetOneArbitraryMatch(new Object[]{pExp}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Expense pExp) { - return rawHasMatch(new Object[]{pExp}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Expense pExp) { - return rawCountMatches(new Object[]{pExp}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Expense pExp, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pExp}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv11.Match newMatch(final Expense pExp) { - return Inv11.Match.newMatch(pExp); - } - - /** - * Retrieve the set of values that occur in matches for exp. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfexp(final Object[] parameters) { - return rawStreamAllValues(POSITION_EXP, parameters).map(Expense.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for exp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfexp() { - return rawStreamAllValuesOfexp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for exp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfexp() { - return rawStreamAllValuesOfexp(emptyArray()); - } - - @Override - protected Inv11.Match tupleToMatch(final Tuple t) { - try { - return Inv11.Match.newMatch((Expense) t.get(POSITION_EXP)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv11.Match arrayToMatch(final Object[] match) { - try { - return Inv11.Match.newMatch((Expense) match[POSITION_EXP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv11.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv11.Match.newMutableMatch((Expense) match[POSITION_EXP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv11.instance(); - } - } - - private Inv11() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv11 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv11.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv11.Matcher.on(engine); - } - - @Override - public Inv11.Matcher instantiate() { - return Inv11.Matcher.create(); - } - - @Override - public Inv11.Match newEmptyMatch() { - return Inv11.Match.newEmptyMatch(); - } - - @Override - public Inv11.Match newMatch(final Object... parameters) { - return Inv11.Match.newMatch((Taxation.Expense) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv11} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv11#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv11 INSTANCE = new Inv11(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv11.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_exp = new PParameter("exp", "Taxation.Expense", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Expense")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_exp); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv11"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("exp"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_exp = body.getOrCreateVariableByName("exp"); - new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_exp, parameter_exp) - )); - // find x_inv11_incOver100(exp) - new PositivePatternCall(body, Tuples.flatTupleOf(var_exp), X_inv11_incOver100.instance().getInternalQueryRepresentation()); - // find x_inv11_incNotOver100(exp) - new PositivePatternCall(body, Tuples.flatTupleOf(var_exp), X_inv11_incNotOver100.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv11"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("exp") - })); - addAnnotation(annotation); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv12.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv12.java deleted file mode 100644 index fc1b0c62..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv12.java +++ /dev/null @@ -1,596 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Tax_Payer; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; -import queries.X_inv12_notNonRes; -import queries.X_inv12_notZZ; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv12
- *         //exists - handled logically
- *         {@literal @}Constraint(message = "inv12", severity = "error", key = {tp})
- *         pattern inv12(tp : Tax_Payer) {
- *             Tax_Payer.addresses(tp, hab_add);
- *             Habitual_Address(hab_add);
- *             neg find x_inv12_notZZ(hab_add);
- *             Tax_Payer.incomes(tp, inc);
- *             Local_Income(inc);
- *             neg find x_inv12_notNonRes(tp);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv12 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv12 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Tax_Payer fTp; - - private static List parameterNames = makeImmutableList("tp"); - - private Match(final Tax_Payer pTp) { - this.fTp = pTp; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "tp": return this.fTp; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fTp; - default: return null; - } - } - - public Tax_Payer getTp() { - return this.fTp; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("tp".equals(parameterName) ) { - this.fTp = (Tax_Payer) newValue; - return true; - } - return false; - } - - public void setTp(final Tax_Payer pTp) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTp = pTp; - } - - @Override - public String patternName() { - return "queries.inv12"; - } - - @Override - public List parameterNames() { - return Inv12.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fTp}; - } - - @Override - public Inv12.Match toImmutable() { - return isMutable() ? newMatch(fTp) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"tp\"=" + prettyPrintValue(fTp)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fTp); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv12.Match)) { - Inv12.Match other = (Inv12.Match) obj; - return Objects.equals(fTp, other.fTp); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv12 specification() { - return Inv12.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv12.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv12.Match newMutableMatch(final Tax_Payer pTp) { - return new Mutable(pTp); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv12.Match newMatch(final Tax_Payer pTp) { - return new Immutable(pTp); - } - - private static final class Mutable extends Inv12.Match { - Mutable(final Tax_Payer pTp) { - super(pTp); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv12.Match { - Immutable(final Tax_Payer pTp) { - super(pTp); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv12 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv12
-   * //exists - handled logically
-   * {@literal @}Constraint(message = "inv12", severity = "error", key = {tp})
-   * pattern inv12(tp : Tax_Payer) {
-   *     Tax_Payer.addresses(tp, hab_add);
-   *     Habitual_Address(hab_add);
-   *     neg find x_inv12_notZZ(hab_add);
-   *     Tax_Payer.incomes(tp, inc);
-   *     Local_Income(inc);
-   *     neg find x_inv12_notNonRes(tp);
-   * }
-   * 
- * - * @see Match - * @see Inv12 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv12.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv12.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_TP = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv12.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Tax_Payer pTp) { - return rawStreamAllMatches(new Object[]{pTp}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Tax_Payer pTp) { - return rawStreamAllMatches(new Object[]{pTp}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Tax_Payer pTp) { - return rawGetOneArbitraryMatch(new Object[]{pTp}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Tax_Payer pTp) { - return rawHasMatch(new Object[]{pTp}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Tax_Payer pTp) { - return rawCountMatches(new Object[]{pTp}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Tax_Payer pTp, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pTp}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv12.Match newMatch(final Tax_Payer pTp) { - return Inv12.Match.newMatch(pTp); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftp(final Object[] parameters) { - return rawStreamAllValues(POSITION_TP, parameters).map(Tax_Payer.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftp() { - return rawStreamAllValuesOftp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftp() { - return rawStreamAllValuesOftp(emptyArray()); - } - - @Override - protected Inv12.Match tupleToMatch(final Tuple t) { - try { - return Inv12.Match.newMatch((Tax_Payer) t.get(POSITION_TP)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv12.Match arrayToMatch(final Object[] match) { - try { - return Inv12.Match.newMatch((Tax_Payer) match[POSITION_TP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv12.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv12.Match.newMutableMatch((Tax_Payer) match[POSITION_TP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv12.instance(); - } - } - - private Inv12() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv12 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv12.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv12.Matcher.on(engine); - } - - @Override - public Inv12.Matcher instantiate() { - return Inv12.Matcher.create(); - } - - @Override - public Inv12.Match newEmptyMatch() { - return Inv12.Match.newEmptyMatch(); - } - - @Override - public Inv12.Match newMatch(final Object... parameters) { - return Inv12.Match.newMatch((Taxation.Tax_Payer) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv12} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv12#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv12 INSTANCE = new Inv12(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv12.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_tp = new PParameter("tp", "Taxation.Tax_Payer", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Tax_Payer")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_tp); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv12"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("tp"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_tp = body.getOrCreateVariableByName("tp"); - PVariable var_hab_add = body.getOrCreateVariableByName("hab_add"); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_tp, parameter_tp) - )); - // Tax_Payer.addresses(tp, hab_add) - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "addresses"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Address"))); - new Equality(body, var__virtual_0_, var_hab_add); - // Habitual_Address(hab_add) - new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Habitual_Address"))); - // neg find x_inv12_notZZ(hab_add) - new NegativePatternCall(body, Tuples.flatTupleOf(var_hab_add), X_inv12_notZZ.instance().getInternalQueryRepresentation()); - // Tax_Payer.incomes(tp, inc) - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Tax_Payer", "incomes"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - new Equality(body, var__virtual_1_, var_inc); - // Local_Income(inc) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Local_Income"))); - // neg find x_inv12_notNonRes(tp) - new NegativePatternCall(body, Tuples.flatTupleOf(var_tp), X_inv12_notNonRes.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv12"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("tp") - })); - addAnnotation(annotation); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv13.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv13.java deleted file mode 100644 index a4aea47c..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv13.java +++ /dev/null @@ -1,591 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Tax_Payer; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; -import queries.X_inv13; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv13 - Added new containment rel Phys_Pers-{@literal >}Address
- *         //exists - handled logically
- *         {@literal @}Constraint(message = "inv13", severity = "error", key = {tp})
- *         pattern inv13(tp : Tax_Payer) {
- *             Tax_Payer.addresses(tp, hab_add);
- *             Habitual_Address(hab_add);
- *             Address.country(hab_add, ::ZZ);
- *             neg find x_inv13(tp);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv13 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv13 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Tax_Payer fTp; - - private static List parameterNames = makeImmutableList("tp"); - - private Match(final Tax_Payer pTp) { - this.fTp = pTp; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "tp": return this.fTp; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fTp; - default: return null; - } - } - - public Tax_Payer getTp() { - return this.fTp; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("tp".equals(parameterName) ) { - this.fTp = (Tax_Payer) newValue; - return true; - } - return false; - } - - public void setTp(final Tax_Payer pTp) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTp = pTp; - } - - @Override - public String patternName() { - return "queries.inv13"; - } - - @Override - public List parameterNames() { - return Inv13.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fTp}; - } - - @Override - public Inv13.Match toImmutable() { - return isMutable() ? newMatch(fTp) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"tp\"=" + prettyPrintValue(fTp)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fTp); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv13.Match)) { - Inv13.Match other = (Inv13.Match) obj; - return Objects.equals(fTp, other.fTp); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv13 specification() { - return Inv13.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv13.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv13.Match newMutableMatch(final Tax_Payer pTp) { - return new Mutable(pTp); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv13.Match newMatch(final Tax_Payer pTp) { - return new Immutable(pTp); - } - - private static final class Mutable extends Inv13.Match { - Mutable(final Tax_Payer pTp) { - super(pTp); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv13.Match { - Immutable(final Tax_Payer pTp) { - super(pTp); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv13 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv13 - Added new containment rel Phys_Pers-{@literal >}Address
-   * //exists - handled logically
-   * {@literal @}Constraint(message = "inv13", severity = "error", key = {tp})
-   * pattern inv13(tp : Tax_Payer) {
-   *     Tax_Payer.addresses(tp, hab_add);
-   *     Habitual_Address(hab_add);
-   *     Address.country(hab_add, ::ZZ);
-   *     neg find x_inv13(tp);
-   * }
-   * 
- * - * @see Match - * @see Inv13 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv13.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv13.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_TP = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv13.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Tax_Payer pTp) { - return rawStreamAllMatches(new Object[]{pTp}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Tax_Payer pTp) { - return rawStreamAllMatches(new Object[]{pTp}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Tax_Payer pTp) { - return rawGetOneArbitraryMatch(new Object[]{pTp}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Tax_Payer pTp) { - return rawHasMatch(new Object[]{pTp}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Tax_Payer pTp) { - return rawCountMatches(new Object[]{pTp}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Tax_Payer pTp, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pTp}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv13.Match newMatch(final Tax_Payer pTp) { - return Inv13.Match.newMatch(pTp); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftp(final Object[] parameters) { - return rawStreamAllValues(POSITION_TP, parameters).map(Tax_Payer.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftp() { - return rawStreamAllValuesOftp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftp() { - return rawStreamAllValuesOftp(emptyArray()); - } - - @Override - protected Inv13.Match tupleToMatch(final Tuple t) { - try { - return Inv13.Match.newMatch((Tax_Payer) t.get(POSITION_TP)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv13.Match arrayToMatch(final Object[] match) { - try { - return Inv13.Match.newMatch((Tax_Payer) match[POSITION_TP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv13.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv13.Match.newMutableMatch((Tax_Payer) match[POSITION_TP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv13.instance(); - } - } - - private Inv13() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv13 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv13.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv13.Matcher.on(engine); - } - - @Override - public Inv13.Matcher instantiate() { - return Inv13.Matcher.create(); - } - - @Override - public Inv13.Match newEmptyMatch() { - return Inv13.Match.newEmptyMatch(); - } - - @Override - public Inv13.Match newMatch(final Object... parameters) { - return Inv13.Match.newMatch((Taxation.Tax_Payer) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv13} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv13#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv13 INSTANCE = new Inv13(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv13.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_tp = new PParameter("tp", "Taxation.Tax_Payer", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Tax_Payer")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_tp); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv13"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("tp"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_tp = body.getOrCreateVariableByName("tp"); - PVariable var_hab_add = body.getOrCreateVariableByName("hab_add"); - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_tp, parameter_tp) - )); - // Tax_Payer.addresses(tp, hab_add) - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_tp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "addresses"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Address"))); - new Equality(body, var__virtual_0_, var_hab_add); - // Habitual_Address(hab_add) - new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Habitual_Address"))); - // Address.country(hab_add, ::ZZ) - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new ConstantValue(body, var__virtual_1_, getEnumLiteral("http:///TaxCard.ecore", "Country", "ZZ").getInstance()); - new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Address"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Address", "country"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http:///TaxCard.ecore", "Country"))); - new Equality(body, var__virtual_2_, var__virtual_1_); - // neg find x_inv13(tp) - new NegativePatternCall(body, Tuples.flatTupleOf(var_tp), X_inv13.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv13"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("tp") - })); - addAnnotation(annotation); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv15.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv15.java deleted file mode 100644 index 3bfab503..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv15.java +++ /dev/null @@ -1,567 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.External_Allowance; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; -import queries.X_inv15; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv14-MultiplicityChanged
- *         
- *         //inv15-Ordered Sets in assignment if block
- *         //ERROR if no household object
- *         {@literal @}Constraint(message = "inv15", severity = "error", key = {ea})
- *         pattern inv15(ea : External_Allowance) {
- *         	neg find x_inv15(ea);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv15 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv15 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private External_Allowance fEa; - - private static List parameterNames = makeImmutableList("ea"); - - private Match(final External_Allowance pEa) { - this.fEa = pEa; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "ea": return this.fEa; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fEa; - default: return null; - } - } - - public External_Allowance getEa() { - return this.fEa; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("ea".equals(parameterName) ) { - this.fEa = (External_Allowance) newValue; - return true; - } - return false; - } - - public void setEa(final External_Allowance pEa) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fEa = pEa; - } - - @Override - public String patternName() { - return "queries.inv15"; - } - - @Override - public List parameterNames() { - return Inv15.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fEa}; - } - - @Override - public Inv15.Match toImmutable() { - return isMutable() ? newMatch(fEa) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"ea\"=" + prettyPrintValue(fEa)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fEa); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv15.Match)) { - Inv15.Match other = (Inv15.Match) obj; - return Objects.equals(fEa, other.fEa); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv15 specification() { - return Inv15.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv15.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv15.Match newMutableMatch(final External_Allowance pEa) { - return new Mutable(pEa); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv15.Match newMatch(final External_Allowance pEa) { - return new Immutable(pEa); - } - - private static final class Mutable extends Inv15.Match { - Mutable(final External_Allowance pEa) { - super(pEa); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv15.Match { - Immutable(final External_Allowance pEa) { - super(pEa); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv15 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv14-MultiplicityChanged
-   * 
-   * //inv15-Ordered Sets in assignment if block
-   * //ERROR if no household object
-   * {@literal @}Constraint(message = "inv15", severity = "error", key = {ea})
-   * pattern inv15(ea : External_Allowance) {
-   * 	neg find x_inv15(ea);
-   * }
-   * 
- * - * @see Match - * @see Inv15 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv15.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv15.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_EA = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv15.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final External_Allowance pEa) { - return rawStreamAllMatches(new Object[]{pEa}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final External_Allowance pEa) { - return rawStreamAllMatches(new Object[]{pEa}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final External_Allowance pEa) { - return rawGetOneArbitraryMatch(new Object[]{pEa}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final External_Allowance pEa) { - return rawHasMatch(new Object[]{pEa}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final External_Allowance pEa) { - return rawCountMatches(new Object[]{pEa}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final External_Allowance pEa, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pEa}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv15.Match newMatch(final External_Allowance pEa) { - return Inv15.Match.newMatch(pEa); - } - - /** - * Retrieve the set of values that occur in matches for ea. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfea(final Object[] parameters) { - return rawStreamAllValues(POSITION_EA, parameters).map(External_Allowance.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for ea. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfea() { - return rawStreamAllValuesOfea(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for ea. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfea() { - return rawStreamAllValuesOfea(emptyArray()); - } - - @Override - protected Inv15.Match tupleToMatch(final Tuple t) { - try { - return Inv15.Match.newMatch((External_Allowance) t.get(POSITION_EA)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv15.Match arrayToMatch(final Object[] match) { - try { - return Inv15.Match.newMatch((External_Allowance) match[POSITION_EA]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv15.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv15.Match.newMutableMatch((External_Allowance) match[POSITION_EA]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv15.instance(); - } - } - - private Inv15() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv15 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv15.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv15.Matcher.on(engine); - } - - @Override - public Inv15.Matcher instantiate() { - return Inv15.Matcher.create(); - } - - @Override - public Inv15.Match newEmptyMatch() { - return Inv15.Match.newEmptyMatch(); - } - - @Override - public Inv15.Match newMatch(final Object... parameters) { - return Inv15.Match.newMatch((Taxation.External_Allowance) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv15} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv15#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv15 INSTANCE = new Inv15(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv15.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_ea = new PParameter("ea", "Taxation.External_Allowance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "External_Allowance")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_ea); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv15"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("ea"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_ea = body.getOrCreateVariableByName("ea"); - new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_ea, parameter_ea) - )); - // neg find x_inv15(ea) - new NegativePatternCall(body, Tuples.flatTupleOf(var_ea), X_inv15.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv15"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("ea") - })); - addAnnotation(annotation); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv17.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv17.java deleted file mode 100644 index 4a10d4f4..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv17.java +++ /dev/null @@ -1,643 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Legal_Union_Record; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv16-Tax_Card.tax_card_type is a derived feature
- *         
- *         //inv17-attribute-handled by multiplicity
- *         {@literal @}Constraint(message = "inv17", severity = "error", key = {lur})
- *         pattern inv17(lur : Legal_Union_Record) {
- *             Legal_Union_Record.start_year(lur, sy);
- *             check(sy {@literal <} 1950);
- *         } or {
- *         	Legal_Union_Record.start_year(lur, sy);
- *         	check(sy {@literal >} 2018);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv17 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv17 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Legal_Union_Record fLur; - - private static List parameterNames = makeImmutableList("lur"); - - private Match(final Legal_Union_Record pLur) { - this.fLur = pLur; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "lur": return this.fLur; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fLur; - default: return null; - } - } - - public Legal_Union_Record getLur() { - return this.fLur; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("lur".equals(parameterName) ) { - this.fLur = (Legal_Union_Record) newValue; - return true; - } - return false; - } - - public void setLur(final Legal_Union_Record pLur) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fLur = pLur; - } - - @Override - public String patternName() { - return "queries.inv17"; - } - - @Override - public List parameterNames() { - return Inv17.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fLur}; - } - - @Override - public Inv17.Match toImmutable() { - return isMutable() ? newMatch(fLur) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"lur\"=" + prettyPrintValue(fLur)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fLur); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv17.Match)) { - Inv17.Match other = (Inv17.Match) obj; - return Objects.equals(fLur, other.fLur); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv17 specification() { - return Inv17.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv17.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv17.Match newMutableMatch(final Legal_Union_Record pLur) { - return new Mutable(pLur); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv17.Match newMatch(final Legal_Union_Record pLur) { - return new Immutable(pLur); - } - - private static final class Mutable extends Inv17.Match { - Mutable(final Legal_Union_Record pLur) { - super(pLur); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv17.Match { - Immutable(final Legal_Union_Record pLur) { - super(pLur); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv17 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv16-Tax_Card.tax_card_type is a derived feature
-   * 
-   * //inv17-attribute-handled by multiplicity
-   * {@literal @}Constraint(message = "inv17", severity = "error", key = {lur})
-   * pattern inv17(lur : Legal_Union_Record) {
-   *     Legal_Union_Record.start_year(lur, sy);
-   *     check(sy {@literal <} 1950);
-   * } or {
-   * 	Legal_Union_Record.start_year(lur, sy);
-   * 	check(sy {@literal >} 2018);
-   * }
-   * 
- * - * @see Match - * @see Inv17 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv17.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv17.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_LUR = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv17.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Legal_Union_Record pLur) { - return rawStreamAllMatches(new Object[]{pLur}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Legal_Union_Record pLur) { - return rawStreamAllMatches(new Object[]{pLur}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Legal_Union_Record pLur) { - return rawGetOneArbitraryMatch(new Object[]{pLur}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Legal_Union_Record pLur) { - return rawHasMatch(new Object[]{pLur}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Legal_Union_Record pLur) { - return rawCountMatches(new Object[]{pLur}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Legal_Union_Record pLur, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pLur}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv17.Match newMatch(final Legal_Union_Record pLur) { - return Inv17.Match.newMatch(pLur); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOflur(final Object[] parameters) { - return rawStreamAllValues(POSITION_LUR, parameters).map(Legal_Union_Record.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOflur() { - return rawStreamAllValuesOflur(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOflur() { - return rawStreamAllValuesOflur(emptyArray()); - } - - @Override - protected Inv17.Match tupleToMatch(final Tuple t) { - try { - return Inv17.Match.newMatch((Legal_Union_Record) t.get(POSITION_LUR)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv17.Match arrayToMatch(final Object[] match) { - try { - return Inv17.Match.newMatch((Legal_Union_Record) match[POSITION_LUR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv17.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv17.Match.newMutableMatch((Legal_Union_Record) match[POSITION_LUR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv17.instance(); - } - } - - private Inv17() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv17 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv17.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv17.Matcher.on(engine); - } - - @Override - public Inv17.Matcher instantiate() { - return Inv17.Matcher.create(); - } - - @Override - public Inv17.Match newEmptyMatch() { - return Inv17.Match.newEmptyMatch(); - } - - @Override - public Inv17.Match newMatch(final Object... parameters) { - return Inv17.Match.newMatch((Taxation.Legal_Union_Record) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv17} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv17#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv17 INSTANCE = new Inv17(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv17.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_lur = new PParameter("lur", "Taxation.Legal_Union_Record", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Legal_Union_Record")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_lur); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv17"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("lur"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_lur = body.getOrCreateVariableByName("lur"); - PVariable var_sy = body.getOrCreateVariableByName("sy"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_lur, parameter_lur) - )); - // Legal_Union_Record.start_year(lur, sy) - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "start_year"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_0_, var_sy); - // check(sy < 1950) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv17"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("sy");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer sy = (Integer) provider.getValue("sy"); - return evaluateExpression_1_1(sy); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_lur = body.getOrCreateVariableByName("lur"); - PVariable var_sy = body.getOrCreateVariableByName("sy"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_lur, parameter_lur) - )); - // Legal_Union_Record.start_year(lur, sy) - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "start_year"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_0_, var_sy); - // check(sy > 2018) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv17"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("sy");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer sy = (Integer) provider.getValue("sy"); - return evaluateExpression_2_1(sy); - } - }, null); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv17"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("lur") - })); - addAnnotation(annotation); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Integer sy) { - return ((sy).intValue() < 1950); - } - - private static boolean evaluateExpression_2_1(final Integer sy) { - return ((sy).intValue() > 2018); - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv20.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv20.java deleted file mode 100644 index 6fcc3b7d..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv20.java +++ /dev/null @@ -1,587 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Legal_Union_Record; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv18-MultiplicityChecked
- *         //inv19-MultiplicityChecked
- *         
- *         //inv20-Useless constraint since both edges are containment (TODOCheck)
- *         //OclIsUndefined-Handled by multiplicity
- *         {@literal @}Constraint(message = "inv20", severity = "error", key = {lur})
- *         pattern inv20(lur : Legal_Union_Record) {
- *             Legal_Union_Record.individual_A(lur, iA);
- *             Legal_Union_Record.individual_B(lur, iB);
- *             iA == iB;
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv20 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv20 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Legal_Union_Record fLur; - - private static List parameterNames = makeImmutableList("lur"); - - private Match(final Legal_Union_Record pLur) { - this.fLur = pLur; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "lur": return this.fLur; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fLur; - default: return null; - } - } - - public Legal_Union_Record getLur() { - return this.fLur; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("lur".equals(parameterName) ) { - this.fLur = (Legal_Union_Record) newValue; - return true; - } - return false; - } - - public void setLur(final Legal_Union_Record pLur) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fLur = pLur; - } - - @Override - public String patternName() { - return "queries.inv20"; - } - - @Override - public List parameterNames() { - return Inv20.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fLur}; - } - - @Override - public Inv20.Match toImmutable() { - return isMutable() ? newMatch(fLur) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"lur\"=" + prettyPrintValue(fLur)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fLur); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv20.Match)) { - Inv20.Match other = (Inv20.Match) obj; - return Objects.equals(fLur, other.fLur); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv20 specification() { - return Inv20.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv20.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv20.Match newMutableMatch(final Legal_Union_Record pLur) { - return new Mutable(pLur); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv20.Match newMatch(final Legal_Union_Record pLur) { - return new Immutable(pLur); - } - - private static final class Mutable extends Inv20.Match { - Mutable(final Legal_Union_Record pLur) { - super(pLur); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv20.Match { - Immutable(final Legal_Union_Record pLur) { - super(pLur); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv20 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv18-MultiplicityChecked
-   * //inv19-MultiplicityChecked
-   * 
-   * //inv20-Useless constraint since both edges are containment (TODOCheck)
-   * //OclIsUndefined-Handled by multiplicity
-   * {@literal @}Constraint(message = "inv20", severity = "error", key = {lur})
-   * pattern inv20(lur : Legal_Union_Record) {
-   *     Legal_Union_Record.individual_A(lur, iA);
-   *     Legal_Union_Record.individual_B(lur, iB);
-   *     iA == iB;
-   * }
-   * 
- * - * @see Match - * @see Inv20 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv20.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv20.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_LUR = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv20.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Legal_Union_Record pLur) { - return rawStreamAllMatches(new Object[]{pLur}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Legal_Union_Record pLur) { - return rawStreamAllMatches(new Object[]{pLur}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Legal_Union_Record pLur) { - return rawGetOneArbitraryMatch(new Object[]{pLur}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Legal_Union_Record pLur) { - return rawHasMatch(new Object[]{pLur}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Legal_Union_Record pLur) { - return rawCountMatches(new Object[]{pLur}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Legal_Union_Record pLur, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pLur}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv20.Match newMatch(final Legal_Union_Record pLur) { - return Inv20.Match.newMatch(pLur); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOflur(final Object[] parameters) { - return rawStreamAllValues(POSITION_LUR, parameters).map(Legal_Union_Record.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOflur() { - return rawStreamAllValuesOflur(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOflur() { - return rawStreamAllValuesOflur(emptyArray()); - } - - @Override - protected Inv20.Match tupleToMatch(final Tuple t) { - try { - return Inv20.Match.newMatch((Legal_Union_Record) t.get(POSITION_LUR)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv20.Match arrayToMatch(final Object[] match) { - try { - return Inv20.Match.newMatch((Legal_Union_Record) match[POSITION_LUR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv20.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv20.Match.newMutableMatch((Legal_Union_Record) match[POSITION_LUR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv20.instance(); - } - } - - private Inv20() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv20 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv20.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv20.Matcher.on(engine); - } - - @Override - public Inv20.Matcher instantiate() { - return Inv20.Matcher.create(); - } - - @Override - public Inv20.Match newEmptyMatch() { - return Inv20.Match.newEmptyMatch(); - } - - @Override - public Inv20.Match newMatch(final Object... parameters) { - return Inv20.Match.newMatch((Taxation.Legal_Union_Record) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv20} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv20#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv20 INSTANCE = new Inv20(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv20.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_lur = new PParameter("lur", "Taxation.Legal_Union_Record", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Legal_Union_Record")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_lur); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv20"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("lur"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_lur = body.getOrCreateVariableByName("lur"); - PVariable var_iA = body.getOrCreateVariableByName("iA"); - PVariable var_iB = body.getOrCreateVariableByName("iB"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_lur, parameter_lur) - )); - // Legal_Union_Record.individual_A(lur, iA) - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "individual_A"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - new Equality(body, var__virtual_0_, var_iA); - // Legal_Union_Record.individual_B(lur, iB) - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "individual_B"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - new Equality(body, var__virtual_1_, var_iB); - // iA == iB - new Equality(body, var_iA, var_iB); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv20"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("lur") - })); - addAnnotation(annotation); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv33.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv33.java deleted file mode 100644 index 1672290c..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv33.java +++ /dev/null @@ -1,665 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Physical_Person; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv21-MultiplicityChecked
- *         //inv22-MultiplicityChecked
- *         //inv23-MultiplicityChecked
- *         //inv24-MultiplicityChecked
- *         //inv25-MultiplicityChecked
- *         //inv26-MultiplicityChanged
- *         //inv27-dupOfInv24
- *         //inv28-dubOfInv23
- *         //inv29-MultiplicityChanged
- *         //inv30-AttributeRemoved
- *         //inv31-AttributeRemoved
- *         //inv32-AttributeRemoved
- *         
- *         //inv33-attribute-handled by multiplicity
- *         {@literal @}Constraint(message = "inv33", severity = "error", key = {p})
- *         pattern inv33(p : Physical_Person) {
- *         	Physical_Person.birth_year(p, by); 
- *         	check(2018-by {@literal <} 0);
- *         } or {
- *         	Physical_Person.birth_year(p, by); 
- *         	check(2018-by {@literal >} 100);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv33 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv33 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Physical_Person fP; - - private static List parameterNames = makeImmutableList("p"); - - private Match(final Physical_Person pP) { - this.fP = pP; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "p": return this.fP; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fP; - default: return null; - } - } - - public Physical_Person getP() { - return this.fP; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("p".equals(parameterName) ) { - this.fP = (Physical_Person) newValue; - return true; - } - return false; - } - - public void setP(final Physical_Person pP) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fP = pP; - } - - @Override - public String patternName() { - return "queries.inv33"; - } - - @Override - public List parameterNames() { - return Inv33.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fP}; - } - - @Override - public Inv33.Match toImmutable() { - return isMutable() ? newMatch(fP) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"p\"=" + prettyPrintValue(fP)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fP); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv33.Match)) { - Inv33.Match other = (Inv33.Match) obj; - return Objects.equals(fP, other.fP); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv33 specification() { - return Inv33.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv33.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv33.Match newMutableMatch(final Physical_Person pP) { - return new Mutable(pP); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv33.Match newMatch(final Physical_Person pP) { - return new Immutable(pP); - } - - private static final class Mutable extends Inv33.Match { - Mutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv33.Match { - Immutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv33 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv21-MultiplicityChecked
-   * //inv22-MultiplicityChecked
-   * //inv23-MultiplicityChecked
-   * //inv24-MultiplicityChecked
-   * //inv25-MultiplicityChecked
-   * //inv26-MultiplicityChanged
-   * //inv27-dupOfInv24
-   * //inv28-dubOfInv23
-   * //inv29-MultiplicityChanged
-   * //inv30-AttributeRemoved
-   * //inv31-AttributeRemoved
-   * //inv32-AttributeRemoved
-   * 
-   * //inv33-attribute-handled by multiplicity
-   * {@literal @}Constraint(message = "inv33", severity = "error", key = {p})
-   * pattern inv33(p : Physical_Person) {
-   * 	Physical_Person.birth_year(p, by); 
-   * 	check(2018-by {@literal <} 0);
-   * } or {
-   * 	Physical_Person.birth_year(p, by); 
-   * 	check(2018-by {@literal >} 100);
-   * }
-   * 
- * - * @see Match - * @see Inv33 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv33.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv33.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_P = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv33.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Physical_Person pP) { - return rawGetOneArbitraryMatch(new Object[]{pP}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Physical_Person pP) { - return rawHasMatch(new Object[]{pP}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Physical_Person pP) { - return rawCountMatches(new Object[]{pP}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pP}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv33.Match newMatch(final Physical_Person pP) { - return Inv33.Match.newMatch(pP); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfp(final Object[] parameters) { - return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()); - } - - @Override - protected Inv33.Match tupleToMatch(final Tuple t) { - try { - return Inv33.Match.newMatch((Physical_Person) t.get(POSITION_P)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv33.Match arrayToMatch(final Object[] match) { - try { - return Inv33.Match.newMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv33.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv33.Match.newMutableMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv33.instance(); - } - } - - private Inv33() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv33 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv33.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv33.Matcher.on(engine); - } - - @Override - public Inv33.Matcher instantiate() { - return Inv33.Matcher.create(); - } - - @Override - public Inv33.Match newEmptyMatch() { - return Inv33.Match.newEmptyMatch(); - } - - @Override - public Inv33.Match newMatch(final Object... parameters) { - return Inv33.Match.newMatch((Taxation.Physical_Person) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv33} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv33#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv33 INSTANCE = new Inv33(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv33.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_p); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv33"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("p"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_p = body.getOrCreateVariableByName("p"); - PVariable var_by = body.getOrCreateVariableByName("by"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_p, parameter_p) - )); - // Physical_Person.birth_year(p, by) - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_0_, var_by); - // check(2018-by < 0) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv33"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("by");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer by = (Integer) provider.getValue("by"); - return evaluateExpression_1_1(by); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_p = body.getOrCreateVariableByName("p"); - PVariable var_by = body.getOrCreateVariableByName("by"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_p, parameter_p) - )); - // Physical_Person.birth_year(p, by) - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_0_, var_by); - // check(2018-by > 100) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv33"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("by");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer by = (Integer) provider.getValue("by"); - return evaluateExpression_2_1(by); - } - }, null); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv33"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("p") - })); - addAnnotation(annotation); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Integer by) { - return ((2018 - (by).intValue()) < 0); - } - - private static boolean evaluateExpression_2_1(final Integer by) { - return ((2018 - (by).intValue()) > 100); - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv34.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv34.java deleted file mode 100644 index b9b28986..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv34.java +++ /dev/null @@ -1,639 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Physical_Person; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv34-attribute-handled by multiplicity
- *         {@literal @}Constraint(message = "inv34", severity = "error", key = {p})
- *         pattern inv34(p : Physical_Person) {
- *             Physical_Person.birth_month(p, birthMonth);
- *             check(birthMonth {@literal <} 1);    
- *         } or {
- *         	Physical_Person.birth_month(p, birthMonth);
- *             check(birthMonth {@literal >} 12);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv34 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv34 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Physical_Person fP; - - private static List parameterNames = makeImmutableList("p"); - - private Match(final Physical_Person pP) { - this.fP = pP; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "p": return this.fP; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fP; - default: return null; - } - } - - public Physical_Person getP() { - return this.fP; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("p".equals(parameterName) ) { - this.fP = (Physical_Person) newValue; - return true; - } - return false; - } - - public void setP(final Physical_Person pP) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fP = pP; - } - - @Override - public String patternName() { - return "queries.inv34"; - } - - @Override - public List parameterNames() { - return Inv34.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fP}; - } - - @Override - public Inv34.Match toImmutable() { - return isMutable() ? newMatch(fP) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"p\"=" + prettyPrintValue(fP)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fP); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv34.Match)) { - Inv34.Match other = (Inv34.Match) obj; - return Objects.equals(fP, other.fP); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv34 specification() { - return Inv34.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv34.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv34.Match newMutableMatch(final Physical_Person pP) { - return new Mutable(pP); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv34.Match newMatch(final Physical_Person pP) { - return new Immutable(pP); - } - - private static final class Mutable extends Inv34.Match { - Mutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv34.Match { - Immutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv34 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv34-attribute-handled by multiplicity
-   * {@literal @}Constraint(message = "inv34", severity = "error", key = {p})
-   * pattern inv34(p : Physical_Person) {
-   *     Physical_Person.birth_month(p, birthMonth);
-   *     check(birthMonth {@literal <} 1);    
-   * } or {
-   * 	Physical_Person.birth_month(p, birthMonth);
-   *     check(birthMonth {@literal >} 12);
-   * }
-   * 
- * - * @see Match - * @see Inv34 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv34.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv34.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_P = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv34.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Physical_Person pP) { - return rawGetOneArbitraryMatch(new Object[]{pP}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Physical_Person pP) { - return rawHasMatch(new Object[]{pP}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Physical_Person pP) { - return rawCountMatches(new Object[]{pP}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pP}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv34.Match newMatch(final Physical_Person pP) { - return Inv34.Match.newMatch(pP); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfp(final Object[] parameters) { - return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()); - } - - @Override - protected Inv34.Match tupleToMatch(final Tuple t) { - try { - return Inv34.Match.newMatch((Physical_Person) t.get(POSITION_P)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv34.Match arrayToMatch(final Object[] match) { - try { - return Inv34.Match.newMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv34.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv34.Match.newMutableMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv34.instance(); - } - } - - private Inv34() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv34 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv34.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv34.Matcher.on(engine); - } - - @Override - public Inv34.Matcher instantiate() { - return Inv34.Matcher.create(); - } - - @Override - public Inv34.Match newEmptyMatch() { - return Inv34.Match.newEmptyMatch(); - } - - @Override - public Inv34.Match newMatch(final Object... parameters) { - return Inv34.Match.newMatch((Taxation.Physical_Person) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv34} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv34#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv34 INSTANCE = new Inv34(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv34.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_p); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv34"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("p"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_p = body.getOrCreateVariableByName("p"); - PVariable var_birthMonth = body.getOrCreateVariableByName("birthMonth"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_p, parameter_p) - )); - // Physical_Person.birth_month(p, birthMonth) - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_month"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_0_, var_birthMonth); - // check(birthMonth < 1) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv34"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("birthMonth");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer birthMonth = (Integer) provider.getValue("birthMonth"); - return evaluateExpression_1_1(birthMonth); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_p = body.getOrCreateVariableByName("p"); - PVariable var_birthMonth = body.getOrCreateVariableByName("birthMonth"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_p, parameter_p) - )); - // Physical_Person.birth_month(p, birthMonth) - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_month"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_0_, var_birthMonth); - // check(birthMonth > 12) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv34"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("birthMonth");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer birthMonth = (Integer) provider.getValue("birthMonth"); - return evaluateExpression_2_1(birthMonth); - } - }, null); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv34"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("p") - })); - addAnnotation(annotation); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Integer birthMonth) { - return ((birthMonth).intValue() < 1); - } - - private static boolean evaluateExpression_2_1(final Integer birthMonth) { - return ((birthMonth).intValue() > 12); - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv35.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv35.java deleted file mode 100644 index c67325ac..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv35.java +++ /dev/null @@ -1,639 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Physical_Person; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv35-attribute-handled by multiplicity
- *         {@literal @}Constraint(message = "inv35", severity = "error", key = {p})
- *         pattern inv35(p : Physical_Person) {
- *             Physical_Person.birth_day(p, birthDay);
- *             check(birthDay {@literal <} 1);    
- *         } or {
- *         	Physical_Person.birth_day(p, birthDay);
- *             check(birthDay {@literal >} 28);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv35 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv35 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Physical_Person fP; - - private static List parameterNames = makeImmutableList("p"); - - private Match(final Physical_Person pP) { - this.fP = pP; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "p": return this.fP; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fP; - default: return null; - } - } - - public Physical_Person getP() { - return this.fP; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("p".equals(parameterName) ) { - this.fP = (Physical_Person) newValue; - return true; - } - return false; - } - - public void setP(final Physical_Person pP) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fP = pP; - } - - @Override - public String patternName() { - return "queries.inv35"; - } - - @Override - public List parameterNames() { - return Inv35.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fP}; - } - - @Override - public Inv35.Match toImmutable() { - return isMutable() ? newMatch(fP) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"p\"=" + prettyPrintValue(fP)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fP); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv35.Match)) { - Inv35.Match other = (Inv35.Match) obj; - return Objects.equals(fP, other.fP); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv35 specification() { - return Inv35.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv35.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv35.Match newMutableMatch(final Physical_Person pP) { - return new Mutable(pP); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv35.Match newMatch(final Physical_Person pP) { - return new Immutable(pP); - } - - private static final class Mutable extends Inv35.Match { - Mutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv35.Match { - Immutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv35 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv35-attribute-handled by multiplicity
-   * {@literal @}Constraint(message = "inv35", severity = "error", key = {p})
-   * pattern inv35(p : Physical_Person) {
-   *     Physical_Person.birth_day(p, birthDay);
-   *     check(birthDay {@literal <} 1);    
-   * } or {
-   * 	Physical_Person.birth_day(p, birthDay);
-   *     check(birthDay {@literal >} 28);
-   * }
-   * 
- * - * @see Match - * @see Inv35 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv35.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv35.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_P = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv35.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Physical_Person pP) { - return rawGetOneArbitraryMatch(new Object[]{pP}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Physical_Person pP) { - return rawHasMatch(new Object[]{pP}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Physical_Person pP) { - return rawCountMatches(new Object[]{pP}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pP}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv35.Match newMatch(final Physical_Person pP) { - return Inv35.Match.newMatch(pP); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfp(final Object[] parameters) { - return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()); - } - - @Override - protected Inv35.Match tupleToMatch(final Tuple t) { - try { - return Inv35.Match.newMatch((Physical_Person) t.get(POSITION_P)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv35.Match arrayToMatch(final Object[] match) { - try { - return Inv35.Match.newMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv35.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv35.Match.newMutableMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv35.instance(); - } - } - - private Inv35() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv35 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv35.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv35.Matcher.on(engine); - } - - @Override - public Inv35.Matcher instantiate() { - return Inv35.Matcher.create(); - } - - @Override - public Inv35.Match newEmptyMatch() { - return Inv35.Match.newEmptyMatch(); - } - - @Override - public Inv35.Match newMatch(final Object... parameters) { - return Inv35.Match.newMatch((Taxation.Physical_Person) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv35} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv35#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv35 INSTANCE = new Inv35(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv35.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_p); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv35"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("p"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_p = body.getOrCreateVariableByName("p"); - PVariable var_birthDay = body.getOrCreateVariableByName("birthDay"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_p, parameter_p) - )); - // Physical_Person.birth_day(p, birthDay) - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_day"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_0_, var_birthDay); - // check(birthDay < 1) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv35"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("birthDay");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer birthDay = (Integer) provider.getValue("birthDay"); - return evaluateExpression_1_1(birthDay); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_p = body.getOrCreateVariableByName("p"); - PVariable var_birthDay = body.getOrCreateVariableByName("birthDay"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_p, parameter_p) - )); - // Physical_Person.birth_day(p, birthDay) - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_day"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_0_, var_birthDay); - // check(birthDay > 28) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv35"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("birthDay");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer birthDay = (Integer) provider.getValue("birthDay"); - return evaluateExpression_2_1(birthDay); - } - }, null); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv35"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("p") - })); - addAnnotation(annotation); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Integer birthDay) { - return ((birthDay).intValue() < 1); - } - - private static boolean evaluateExpression_2_1(final Integer birthDay) { - return ((birthDay).intValue() > 28); - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv47.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv47.java deleted file mode 100644 index 10ba19d6..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv47.java +++ /dev/null @@ -1,636 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Legal_Union_Record; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; -import queries.X_inv47; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv36-AttributeRemoved
- *         //inv37-AttributeRemoved
- *         //inv38-AttributeRemoved
- *         //inv39-AttributeRemoved
- *         //inv40-AttributeRemoved
- *         //inv41-AttributeRemoved
- *         //inv42-AttributeRemoved
- *         //inv43-AttributeRemoved
- *         //inv44-AttributeRemoved
- *         //inv45-AttributeRemoved
- *         //inv46-AttributeRemoved
- *         
- *         //inv47-attributes-handled by multiplicity
- *         {@literal @}Constraint(message = "inv47", severity = "error", key = {lur})
- *         pattern inv47(lur : Legal_Union_Record) {
- *             Legal_Union_Record.end_year(lur, endY);
- *             Legal_Union_Record.start_year(lur, startY);
- *             neg find x_inv47(lur);
- *             check(startY {@literal >}= endY);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv47 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv47 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Legal_Union_Record fLur; - - private static List parameterNames = makeImmutableList("lur"); - - private Match(final Legal_Union_Record pLur) { - this.fLur = pLur; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "lur": return this.fLur; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fLur; - default: return null; - } - } - - public Legal_Union_Record getLur() { - return this.fLur; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("lur".equals(parameterName) ) { - this.fLur = (Legal_Union_Record) newValue; - return true; - } - return false; - } - - public void setLur(final Legal_Union_Record pLur) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fLur = pLur; - } - - @Override - public String patternName() { - return "queries.inv47"; - } - - @Override - public List parameterNames() { - return Inv47.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fLur}; - } - - @Override - public Inv47.Match toImmutable() { - return isMutable() ? newMatch(fLur) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"lur\"=" + prettyPrintValue(fLur)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fLur); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv47.Match)) { - Inv47.Match other = (Inv47.Match) obj; - return Objects.equals(fLur, other.fLur); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv47 specification() { - return Inv47.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv47.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv47.Match newMutableMatch(final Legal_Union_Record pLur) { - return new Mutable(pLur); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv47.Match newMatch(final Legal_Union_Record pLur) { - return new Immutable(pLur); - } - - private static final class Mutable extends Inv47.Match { - Mutable(final Legal_Union_Record pLur) { - super(pLur); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv47.Match { - Immutable(final Legal_Union_Record pLur) { - super(pLur); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv47 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv36-AttributeRemoved
-   * //inv37-AttributeRemoved
-   * //inv38-AttributeRemoved
-   * //inv39-AttributeRemoved
-   * //inv40-AttributeRemoved
-   * //inv41-AttributeRemoved
-   * //inv42-AttributeRemoved
-   * //inv43-AttributeRemoved
-   * //inv44-AttributeRemoved
-   * //inv45-AttributeRemoved
-   * //inv46-AttributeRemoved
-   * 
-   * //inv47-attributes-handled by multiplicity
-   * {@literal @}Constraint(message = "inv47", severity = "error", key = {lur})
-   * pattern inv47(lur : Legal_Union_Record) {
-   *     Legal_Union_Record.end_year(lur, endY);
-   *     Legal_Union_Record.start_year(lur, startY);
-   *     neg find x_inv47(lur);
-   *     check(startY {@literal >}= endY);
-   * }
-   * 
- * - * @see Match - * @see Inv47 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv47.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv47.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_LUR = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv47.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Legal_Union_Record pLur) { - return rawStreamAllMatches(new Object[]{pLur}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Legal_Union_Record pLur) { - return rawStreamAllMatches(new Object[]{pLur}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Legal_Union_Record pLur) { - return rawGetOneArbitraryMatch(new Object[]{pLur}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Legal_Union_Record pLur) { - return rawHasMatch(new Object[]{pLur}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Legal_Union_Record pLur) { - return rawCountMatches(new Object[]{pLur}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Legal_Union_Record pLur, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pLur}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv47.Match newMatch(final Legal_Union_Record pLur) { - return Inv47.Match.newMatch(pLur); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOflur(final Object[] parameters) { - return rawStreamAllValues(POSITION_LUR, parameters).map(Legal_Union_Record.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOflur() { - return rawStreamAllValuesOflur(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOflur() { - return rawStreamAllValuesOflur(emptyArray()); - } - - @Override - protected Inv47.Match tupleToMatch(final Tuple t) { - try { - return Inv47.Match.newMatch((Legal_Union_Record) t.get(POSITION_LUR)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv47.Match arrayToMatch(final Object[] match) { - try { - return Inv47.Match.newMatch((Legal_Union_Record) match[POSITION_LUR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv47.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv47.Match.newMutableMatch((Legal_Union_Record) match[POSITION_LUR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv47.instance(); - } - } - - private Inv47() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv47 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv47.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv47.Matcher.on(engine); - } - - @Override - public Inv47.Matcher instantiate() { - return Inv47.Matcher.create(); - } - - @Override - public Inv47.Match newEmptyMatch() { - return Inv47.Match.newEmptyMatch(); - } - - @Override - public Inv47.Match newMatch(final Object... parameters) { - return Inv47.Match.newMatch((Taxation.Legal_Union_Record) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv47} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv47#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv47 INSTANCE = new Inv47(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv47.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_lur = new PParameter("lur", "Taxation.Legal_Union_Record", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Legal_Union_Record")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_lur); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv47"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("lur"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_lur = body.getOrCreateVariableByName("lur"); - PVariable var_endY = body.getOrCreateVariableByName("endY"); - PVariable var_startY = body.getOrCreateVariableByName("startY"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_lur, parameter_lur) - )); - // Legal_Union_Record.end_year(lur, endY) - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "end_year"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_0_, var_endY); - // Legal_Union_Record.start_year(lur, startY) - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "start_year"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_1_, var_startY); - // neg find x_inv47(lur) - new NegativePatternCall(body, Tuples.flatTupleOf(var_lur), X_inv47.instance().getInternalQueryRepresentation()); - // check(startY >= endY) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern inv47"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("endY", "startY");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer endY = (Integer) provider.getValue("endY"); - Integer startY = (Integer) provider.getValue("startY"); - return evaluateExpression_1_1(endY, startY); - } - }, null); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv47"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("lur") - })); - addAnnotation(annotation); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Integer endY, final Integer startY) { - boolean _greaterEqualsThan = (startY.compareTo(endY) >= 0); - return _greaterEqualsThan; - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv48.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv48.java deleted file mode 100644 index 67133328..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv48.java +++ /dev/null @@ -1,566 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Physical_Person; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; -import queries.X_inv48_Dis; -import queries.X_inv48_notDis; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv48-attributes-handled by multiplicity
- *         {@literal @}Constraint(message = "inv48", severity = "error", key = {p})
- *         pattern inv48(p : Physical_Person) {
- *         	neg find x_inv48_notDis(p);
- *         	neg find x_inv48_Dis(p);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv48 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv48 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Physical_Person fP; - - private static List parameterNames = makeImmutableList("p"); - - private Match(final Physical_Person pP) { - this.fP = pP; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "p": return this.fP; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fP; - default: return null; - } - } - - public Physical_Person getP() { - return this.fP; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("p".equals(parameterName) ) { - this.fP = (Physical_Person) newValue; - return true; - } - return false; - } - - public void setP(final Physical_Person pP) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fP = pP; - } - - @Override - public String patternName() { - return "queries.inv48"; - } - - @Override - public List parameterNames() { - return Inv48.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fP}; - } - - @Override - public Inv48.Match toImmutable() { - return isMutable() ? newMatch(fP) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"p\"=" + prettyPrintValue(fP)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fP); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv48.Match)) { - Inv48.Match other = (Inv48.Match) obj; - return Objects.equals(fP, other.fP); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv48 specification() { - return Inv48.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv48.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv48.Match newMutableMatch(final Physical_Person pP) { - return new Mutable(pP); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv48.Match newMatch(final Physical_Person pP) { - return new Immutable(pP); - } - - private static final class Mutable extends Inv48.Match { - Mutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv48.Match { - Immutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv48 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv48-attributes-handled by multiplicity
-   * {@literal @}Constraint(message = "inv48", severity = "error", key = {p})
-   * pattern inv48(p : Physical_Person) {
-   * 	neg find x_inv48_notDis(p);
-   * 	neg find x_inv48_Dis(p);
-   * }
-   * 
- * - * @see Match - * @see Inv48 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv48.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv48.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_P = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv48.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Physical_Person pP) { - return rawGetOneArbitraryMatch(new Object[]{pP}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Physical_Person pP) { - return rawHasMatch(new Object[]{pP}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Physical_Person pP) { - return rawCountMatches(new Object[]{pP}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pP}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv48.Match newMatch(final Physical_Person pP) { - return Inv48.Match.newMatch(pP); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfp(final Object[] parameters) { - return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()); - } - - @Override - protected Inv48.Match tupleToMatch(final Tuple t) { - try { - return Inv48.Match.newMatch((Physical_Person) t.get(POSITION_P)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv48.Match arrayToMatch(final Object[] match) { - try { - return Inv48.Match.newMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv48.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv48.Match.newMutableMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv48.instance(); - } - } - - private Inv48() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv48 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv48.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv48.Matcher.on(engine); - } - - @Override - public Inv48.Matcher instantiate() { - return Inv48.Matcher.create(); - } - - @Override - public Inv48.Match newEmptyMatch() { - return Inv48.Match.newEmptyMatch(); - } - - @Override - public Inv48.Match newMatch(final Object... parameters) { - return Inv48.Match.newMatch((Taxation.Physical_Person) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv48} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv48#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv48 INSTANCE = new Inv48(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv48.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_p); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv48"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("p"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_p = body.getOrCreateVariableByName("p"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_p, parameter_p) - )); - // neg find x_inv48_notDis(p) - new NegativePatternCall(body, Tuples.flatTupleOf(var_p), X_inv48_notDis.instance().getInternalQueryRepresentation()); - // neg find x_inv48_Dis(p) - new NegativePatternCall(body, Tuples.flatTupleOf(var_p), X_inv48_Dis.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv48"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("p") - })); - addAnnotation(annotation); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv49.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv49.java deleted file mode 100644 index 66bca24a..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/Inv49.java +++ /dev/null @@ -1,561 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Legal_Union_Record; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; -import queries.X_inv49_1; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         //inv49-OclKindOf-handled by multiplicity
- *         {@literal @}Constraint(message = "inv49", severity = "error", key = {lur})
- *         pattern inv49(lur : Legal_Union_Record) {
- *             neg find x_inv49_1(lur);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Inv49 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.inv49 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Legal_Union_Record fLur; - - private static List parameterNames = makeImmutableList("lur"); - - private Match(final Legal_Union_Record pLur) { - this.fLur = pLur; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "lur": return this.fLur; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fLur; - default: return null; - } - } - - public Legal_Union_Record getLur() { - return this.fLur; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("lur".equals(parameterName) ) { - this.fLur = (Legal_Union_Record) newValue; - return true; - } - return false; - } - - public void setLur(final Legal_Union_Record pLur) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fLur = pLur; - } - - @Override - public String patternName() { - return "queries.inv49"; - } - - @Override - public List parameterNames() { - return Inv49.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fLur}; - } - - @Override - public Inv49.Match toImmutable() { - return isMutable() ? newMatch(fLur) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"lur\"=" + prettyPrintValue(fLur)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fLur); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Inv49.Match)) { - Inv49.Match other = (Inv49.Match) obj; - return Objects.equals(fLur, other.fLur); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Inv49 specification() { - return Inv49.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Inv49.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Inv49.Match newMutableMatch(final Legal_Union_Record pLur) { - return new Mutable(pLur); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the (partial) match object. - * - */ - public static Inv49.Match newMatch(final Legal_Union_Record pLur) { - return new Immutable(pLur); - } - - private static final class Mutable extends Inv49.Match { - Mutable(final Legal_Union_Record pLur) { - super(pLur); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Inv49.Match { - Immutable(final Legal_Union_Record pLur) { - super(pLur); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.inv49 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * //inv49-OclKindOf-handled by multiplicity
-   * {@literal @}Constraint(message = "inv49", severity = "error", key = {lur})
-   * pattern inv49(lur : Legal_Union_Record) {
-   *     neg find x_inv49_1(lur);
-   * }
-   * 
- * - * @see Match - * @see Inv49 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Inv49.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Inv49.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_LUR = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Inv49.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Legal_Union_Record pLur) { - return rawStreamAllMatches(new Object[]{pLur}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Legal_Union_Record pLur) { - return rawStreamAllMatches(new Object[]{pLur}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Legal_Union_Record pLur) { - return rawGetOneArbitraryMatch(new Object[]{pLur}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Legal_Union_Record pLur) { - return rawHasMatch(new Object[]{pLur}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Legal_Union_Record pLur) { - return rawCountMatches(new Object[]{pLur}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Legal_Union_Record pLur, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pLur}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the (partial) match object. - * - */ - public Inv49.Match newMatch(final Legal_Union_Record pLur) { - return Inv49.Match.newMatch(pLur); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOflur(final Object[] parameters) { - return rawStreamAllValues(POSITION_LUR, parameters).map(Legal_Union_Record.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOflur() { - return rawStreamAllValuesOflur(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOflur() { - return rawStreamAllValuesOflur(emptyArray()); - } - - @Override - protected Inv49.Match tupleToMatch(final Tuple t) { - try { - return Inv49.Match.newMatch((Legal_Union_Record) t.get(POSITION_LUR)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Inv49.Match arrayToMatch(final Object[] match) { - try { - return Inv49.Match.newMatch((Legal_Union_Record) match[POSITION_LUR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Inv49.Match arrayToMatchMutable(final Object[] match) { - try { - return Inv49.Match.newMutableMatch((Legal_Union_Record) match[POSITION_LUR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Inv49.instance(); - } - } - - private Inv49() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Inv49 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Inv49.Matcher instantiate(final ViatraQueryEngine engine) { - return Inv49.Matcher.on(engine); - } - - @Override - public Inv49.Matcher instantiate() { - return Inv49.Matcher.create(); - } - - @Override - public Inv49.Match newEmptyMatch() { - return Inv49.Match.newEmptyMatch(); - } - - @Override - public Inv49.Match newMatch(final Object... parameters) { - return Inv49.Match.newMatch((Taxation.Legal_Union_Record) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Inv49} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Inv49#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Inv49 INSTANCE = new Inv49(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Inv49.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_lur = new PParameter("lur", "Taxation.Legal_Union_Record", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Legal_Union_Record")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_lur); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.inv49"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("lur"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_lur = body.getOrCreateVariableByName("lur"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_lur, parameter_lur) - )); - // neg find x_inv49_1(lur) - new NegativePatternCall(body, Tuples.flatTupleOf(var_lur), X_inv49_1.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PAnnotation annotation = new PAnnotation("Constraint"); - annotation.addAttribute("message", "inv49"); - annotation.addAttribute("severity", "error"); - annotation.addAttribute("key", Arrays.asList(new Object[] { - new ParameterReference("lur") - })); - addAnnotation(annotation); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_eligAll.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_eligAll.java deleted file mode 100644 index 0bfffe93..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_eligAll.java +++ /dev/null @@ -1,606 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Dependent; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv03_eligAll(dep : Dependent) {
- *             Dependent.birth_year(dep, by);
- *             check(2018-by {@literal <}= 21);
- *         } or {
- *         	Dependent.continued_studies(dep, true);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv03_eligAll extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv03_eligAll pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Dependent fDep; - - private static List parameterNames = makeImmutableList("dep"); - - private Match(final Dependent pDep) { - this.fDep = pDep; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "dep": return this.fDep; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fDep; - default: return null; - } - } - - public Dependent getDep() { - return this.fDep; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("dep".equals(parameterName) ) { - this.fDep = (Dependent) newValue; - return true; - } - return false; - } - - public void setDep(final Dependent pDep) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fDep = pDep; - } - - @Override - public String patternName() { - return "queries.x_inv03_eligAll"; - } - - @Override - public List parameterNames() { - return X_inv03_eligAll.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fDep}; - } - - @Override - public X_inv03_eligAll.Match toImmutable() { - return isMutable() ? newMatch(fDep) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"dep\"=" + prettyPrintValue(fDep)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fDep); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv03_eligAll.Match)) { - X_inv03_eligAll.Match other = (X_inv03_eligAll.Match) obj; - return Objects.equals(fDep, other.fDep); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv03_eligAll specification() { - return X_inv03_eligAll.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv03_eligAll.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv03_eligAll.Match newMutableMatch(final Dependent pDep) { - return new Mutable(pDep); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv03_eligAll.Match newMatch(final Dependent pDep) { - return new Immutable(pDep); - } - - private static final class Mutable extends X_inv03_eligAll.Match { - Mutable(final Dependent pDep) { - super(pDep); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv03_eligAll.Match { - Immutable(final Dependent pDep) { - super(pDep); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv03_eligAll pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv03_eligAll(dep : Dependent) {
-   *     Dependent.birth_year(dep, by);
-   *     check(2018-by {@literal <}= 21);
-   * } or {
-   * 	Dependent.continued_studies(dep, true);
-   * }
-   * 
- * - * @see Match - * @see X_inv03_eligAll - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv03_eligAll.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv03_eligAll.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_DEP = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv03_eligAll.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Dependent pDep) { - return rawStreamAllMatches(new Object[]{pDep}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Dependent pDep) { - return rawStreamAllMatches(new Object[]{pDep}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Dependent pDep) { - return rawGetOneArbitraryMatch(new Object[]{pDep}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Dependent pDep) { - return rawHasMatch(new Object[]{pDep}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Dependent pDep) { - return rawCountMatches(new Object[]{pDep}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Dependent pDep, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pDep}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv03_eligAll.Match newMatch(final Dependent pDep) { - return X_inv03_eligAll.Match.newMatch(pDep); - } - - /** - * Retrieve the set of values that occur in matches for dep. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfdep(final Object[] parameters) { - return rawStreamAllValues(POSITION_DEP, parameters).map(Dependent.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for dep. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfdep() { - return rawStreamAllValuesOfdep(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for dep. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfdep() { - return rawStreamAllValuesOfdep(emptyArray()); - } - - @Override - protected X_inv03_eligAll.Match tupleToMatch(final Tuple t) { - try { - return X_inv03_eligAll.Match.newMatch((Dependent) t.get(POSITION_DEP)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv03_eligAll.Match arrayToMatch(final Object[] match) { - try { - return X_inv03_eligAll.Match.newMatch((Dependent) match[POSITION_DEP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv03_eligAll.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv03_eligAll.Match.newMutableMatch((Dependent) match[POSITION_DEP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv03_eligAll.instance(); - } - } - - private X_inv03_eligAll() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv03_eligAll instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv03_eligAll.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv03_eligAll.Matcher.on(engine); - } - - @Override - public X_inv03_eligAll.Matcher instantiate() { - return X_inv03_eligAll.Matcher.create(); - } - - @Override - public X_inv03_eligAll.Match newEmptyMatch() { - return X_inv03_eligAll.Match.newEmptyMatch(); - } - - @Override - public X_inv03_eligAll.Match newMatch(final Object... parameters) { - return X_inv03_eligAll.Match.newMatch((Taxation.Dependent) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv03_eligAll} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv03_eligAll#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv03_eligAll INSTANCE = new X_inv03_eligAll(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv03_eligAll.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_dep = new PParameter("dep", "Taxation.Dependent", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Dependent")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_dep); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv03_eligAll"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("dep"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_dep = body.getOrCreateVariableByName("dep"); - PVariable var_by = body.getOrCreateVariableByName("by"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_dep, parameter_dep) - )); - // Dependent.birth_year(dep, by) - new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "birth_year"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_0_, var_by); - // check(2018-by <= 21) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern x_inv03_eligAll"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("by");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer by = (Integer) provider.getValue("by"); - return evaluateExpression_1_1(by); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_dep = body.getOrCreateVariableByName("dep"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_dep, parameter_dep) - )); - // Dependent.continued_studies(dep, true) - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new ConstantValue(body, var__virtual_0_, true); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Dependent", "continued_studies"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EBoolean"))); - new Equality(body, var__virtual_1_, var__virtual_0_); - bodies.add(body); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Integer by) { - return ((2018 - (by).intValue()) <= 21); - } - - private static boolean evaluateExpression_2_1() { - return true; - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_hasAll.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_hasAll.java deleted file mode 100644 index 90deb92d..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv03_hasAll.java +++ /dev/null @@ -1,551 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Dependent; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv03_hasAll(dep : Dependent) {
- *             Dependent.allowances(dep, _);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv03_hasAll extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv03_hasAll pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Dependent fDep; - - private static List parameterNames = makeImmutableList("dep"); - - private Match(final Dependent pDep) { - this.fDep = pDep; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "dep": return this.fDep; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fDep; - default: return null; - } - } - - public Dependent getDep() { - return this.fDep; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("dep".equals(parameterName) ) { - this.fDep = (Dependent) newValue; - return true; - } - return false; - } - - public void setDep(final Dependent pDep) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fDep = pDep; - } - - @Override - public String patternName() { - return "queries.x_inv03_hasAll"; - } - - @Override - public List parameterNames() { - return X_inv03_hasAll.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fDep}; - } - - @Override - public X_inv03_hasAll.Match toImmutable() { - return isMutable() ? newMatch(fDep) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"dep\"=" + prettyPrintValue(fDep)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fDep); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv03_hasAll.Match)) { - X_inv03_hasAll.Match other = (X_inv03_hasAll.Match) obj; - return Objects.equals(fDep, other.fDep); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv03_hasAll specification() { - return X_inv03_hasAll.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv03_hasAll.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv03_hasAll.Match newMutableMatch(final Dependent pDep) { - return new Mutable(pDep); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv03_hasAll.Match newMatch(final Dependent pDep) { - return new Immutable(pDep); - } - - private static final class Mutable extends X_inv03_hasAll.Match { - Mutable(final Dependent pDep) { - super(pDep); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv03_hasAll.Match { - Immutable(final Dependent pDep) { - super(pDep); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv03_hasAll pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv03_hasAll(dep : Dependent) {
-   *     Dependent.allowances(dep, _);
-   * }
-   * 
- * - * @see Match - * @see X_inv03_hasAll - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv03_hasAll.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv03_hasAll.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_DEP = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv03_hasAll.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Dependent pDep) { - return rawStreamAllMatches(new Object[]{pDep}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Dependent pDep) { - return rawStreamAllMatches(new Object[]{pDep}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Dependent pDep) { - return rawGetOneArbitraryMatch(new Object[]{pDep}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Dependent pDep) { - return rawHasMatch(new Object[]{pDep}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Dependent pDep) { - return rawCountMatches(new Object[]{pDep}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Dependent pDep, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pDep}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pDep the fixed value of pattern parameter dep, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv03_hasAll.Match newMatch(final Dependent pDep) { - return X_inv03_hasAll.Match.newMatch(pDep); - } - - /** - * Retrieve the set of values that occur in matches for dep. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfdep(final Object[] parameters) { - return rawStreamAllValues(POSITION_DEP, parameters).map(Dependent.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for dep. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfdep() { - return rawStreamAllValuesOfdep(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for dep. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfdep() { - return rawStreamAllValuesOfdep(emptyArray()); - } - - @Override - protected X_inv03_hasAll.Match tupleToMatch(final Tuple t) { - try { - return X_inv03_hasAll.Match.newMatch((Dependent) t.get(POSITION_DEP)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv03_hasAll.Match arrayToMatch(final Object[] match) { - try { - return X_inv03_hasAll.Match.newMatch((Dependent) match[POSITION_DEP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv03_hasAll.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv03_hasAll.Match.newMutableMatch((Dependent) match[POSITION_DEP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv03_hasAll.instance(); - } - } - - private X_inv03_hasAll() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv03_hasAll instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv03_hasAll.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv03_hasAll.Matcher.on(engine); - } - - @Override - public X_inv03_hasAll.Matcher instantiate() { - return X_inv03_hasAll.Matcher.create(); - } - - @Override - public X_inv03_hasAll.Match newEmptyMatch() { - return X_inv03_hasAll.Match.newEmptyMatch(); - } - - @Override - public X_inv03_hasAll.Match newMatch(final Object... parameters) { - return X_inv03_hasAll.Match.newMatch((Taxation.Dependent) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv03_hasAll} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv03_hasAll#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv03_hasAll INSTANCE = new X_inv03_hasAll(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv03_hasAll.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_dep = new PParameter("dep", "Taxation.Dependent", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Dependent")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_dep); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv03_hasAll"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("dep"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_dep = body.getOrCreateVariableByName("dep"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_dep, parameter_dep) - )); - // Dependent.allowances(dep, _) - new TypeConstraint(body, Tuples.flatTupleOf(var_dep), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dep, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Dependent", "allowances"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance"))); - new Equality(body, var__virtual_0_, var___0_); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv05_inRange.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv05_inRange.java deleted file mode 100644 index aea94873..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv05_inRange.java +++ /dev/null @@ -1,630 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Income; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv05_inRange(inc : Income) {
- *             Income.details.worked_days(inc, wd);
- *             check(wd {@literal <} 1);
- *         } or {
- *             Income.details.worked_days(inc, wd);
- *             check(wd {@literal >} 25);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv05_inRange extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv05_inRange pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Income fInc; - - private static List parameterNames = makeImmutableList("inc"); - - private Match(final Income pInc) { - this.fInc = pInc; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "inc": return this.fInc; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fInc; - default: return null; - } - } - - public Income getInc() { - return this.fInc; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("inc".equals(parameterName) ) { - this.fInc = (Income) newValue; - return true; - } - return false; - } - - public void setInc(final Income pInc) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fInc = pInc; - } - - @Override - public String patternName() { - return "queries.x_inv05_inRange"; - } - - @Override - public List parameterNames() { - return X_inv05_inRange.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fInc}; - } - - @Override - public X_inv05_inRange.Match toImmutable() { - return isMutable() ? newMatch(fInc) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"inc\"=" + prettyPrintValue(fInc)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fInc); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv05_inRange.Match)) { - X_inv05_inRange.Match other = (X_inv05_inRange.Match) obj; - return Objects.equals(fInc, other.fInc); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv05_inRange specification() { - return X_inv05_inRange.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv05_inRange.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv05_inRange.Match newMutableMatch(final Income pInc) { - return new Mutable(pInc); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv05_inRange.Match newMatch(final Income pInc) { - return new Immutable(pInc); - } - - private static final class Mutable extends X_inv05_inRange.Match { - Mutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv05_inRange.Match { - Immutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv05_inRange pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv05_inRange(inc : Income) {
-   *     Income.details.worked_days(inc, wd);
-   *     check(wd {@literal <} 1);
-   * } or {
-   *     Income.details.worked_days(inc, wd);
-   *     check(wd {@literal >} 25);
-   * }
-   * 
- * - * @see Match - * @see X_inv05_inRange - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv05_inRange.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv05_inRange.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_INC = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv05_inRange.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Income pInc) { - return rawGetOneArbitraryMatch(new Object[]{pInc}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Income pInc) { - return rawHasMatch(new Object[]{pInc}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Income pInc) { - return rawCountMatches(new Object[]{pInc}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Income pInc, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pInc}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv05_inRange.Match newMatch(final Income pInc) { - return X_inv05_inRange.Match.newMatch(pInc); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfinc(final Object[] parameters) { - return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()); - } - - @Override - protected X_inv05_inRange.Match tupleToMatch(final Tuple t) { - try { - return X_inv05_inRange.Match.newMatch((Income) t.get(POSITION_INC)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv05_inRange.Match arrayToMatch(final Object[] match) { - try { - return X_inv05_inRange.Match.newMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv05_inRange.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv05_inRange.Match.newMutableMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv05_inRange.instance(); - } - } - - private X_inv05_inRange() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv05_inRange instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv05_inRange.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv05_inRange.Matcher.on(engine); - } - - @Override - public X_inv05_inRange.Matcher instantiate() { - return X_inv05_inRange.Matcher.create(); - } - - @Override - public X_inv05_inRange.Match newEmptyMatch() { - return X_inv05_inRange.Match.newEmptyMatch(); - } - - @Override - public X_inv05_inRange.Match newMatch(final Object... parameters) { - return X_inv05_inRange.Match.newMatch((Taxation.Income) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv05_inRange} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv05_inRange#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv05_inRange INSTANCE = new X_inv05_inRange(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv05_inRange.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_inc); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv05_inRange"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("inc"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - PVariable var_wd = body.getOrCreateVariableByName("wd"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_inc, parameter_inc) - )); - // Income.details.worked_days(inc, wd) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "worked_days"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_1_, var_wd); - // check(wd < 1) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern x_inv05_inRange"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("wd");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer wd = (Integer) provider.getValue("wd"); - return evaluateExpression_1_1(wd); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - PVariable var_wd = body.getOrCreateVariableByName("wd"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_inc, parameter_inc) - )); - // Income.details.worked_days(inc, wd) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "worked_days"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_1_, var_wd); - // check(wd > 25) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern x_inv05_inRange"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("wd");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer wd = (Integer) provider.getValue("wd"); - return evaluateExpression_2_1(wd); - } - }, null); - bodies.add(body); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Integer wd) { - return ((wd).intValue() < 1); - } - - private static boolean evaluateExpression_2_1(final Integer wd) { - return ((wd).intValue() > 25); - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_inRange.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_inRange.java deleted file mode 100644 index b3efea21..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_inRange.java +++ /dev/null @@ -1,630 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Income; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv08_inRange(inc : Income) {
- *             Income.details.distance(inc, dist);
- *             check(dist {@literal <} 0);
- *         } or {
- *             Income.details.distance(inc, dist);
- *             check(dist {@literal >} 100);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv08_inRange extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv08_inRange pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Income fInc; - - private static List parameterNames = makeImmutableList("inc"); - - private Match(final Income pInc) { - this.fInc = pInc; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "inc": return this.fInc; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fInc; - default: return null; - } - } - - public Income getInc() { - return this.fInc; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("inc".equals(parameterName) ) { - this.fInc = (Income) newValue; - return true; - } - return false; - } - - public void setInc(final Income pInc) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fInc = pInc; - } - - @Override - public String patternName() { - return "queries.x_inv08_inRange"; - } - - @Override - public List parameterNames() { - return X_inv08_inRange.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fInc}; - } - - @Override - public X_inv08_inRange.Match toImmutable() { - return isMutable() ? newMatch(fInc) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"inc\"=" + prettyPrintValue(fInc)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fInc); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv08_inRange.Match)) { - X_inv08_inRange.Match other = (X_inv08_inRange.Match) obj; - return Objects.equals(fInc, other.fInc); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv08_inRange specification() { - return X_inv08_inRange.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv08_inRange.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv08_inRange.Match newMutableMatch(final Income pInc) { - return new Mutable(pInc); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv08_inRange.Match newMatch(final Income pInc) { - return new Immutable(pInc); - } - - private static final class Mutable extends X_inv08_inRange.Match { - Mutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv08_inRange.Match { - Immutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv08_inRange pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv08_inRange(inc : Income) {
-   *     Income.details.distance(inc, dist);
-   *     check(dist {@literal <} 0);
-   * } or {
-   *     Income.details.distance(inc, dist);
-   *     check(dist {@literal >} 100);
-   * }
-   * 
- * - * @see Match - * @see X_inv08_inRange - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv08_inRange.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv08_inRange.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_INC = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv08_inRange.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Income pInc) { - return rawGetOneArbitraryMatch(new Object[]{pInc}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Income pInc) { - return rawHasMatch(new Object[]{pInc}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Income pInc) { - return rawCountMatches(new Object[]{pInc}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Income pInc, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pInc}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv08_inRange.Match newMatch(final Income pInc) { - return X_inv08_inRange.Match.newMatch(pInc); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfinc(final Object[] parameters) { - return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()); - } - - @Override - protected X_inv08_inRange.Match tupleToMatch(final Tuple t) { - try { - return X_inv08_inRange.Match.newMatch((Income) t.get(POSITION_INC)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv08_inRange.Match arrayToMatch(final Object[] match) { - try { - return X_inv08_inRange.Match.newMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv08_inRange.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv08_inRange.Match.newMutableMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv08_inRange.instance(); - } - } - - private X_inv08_inRange() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv08_inRange instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv08_inRange.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv08_inRange.Matcher.on(engine); - } - - @Override - public X_inv08_inRange.Matcher instantiate() { - return X_inv08_inRange.Matcher.create(); - } - - @Override - public X_inv08_inRange.Match newEmptyMatch() { - return X_inv08_inRange.Match.newEmptyMatch(); - } - - @Override - public X_inv08_inRange.Match newMatch(final Object... parameters) { - return X_inv08_inRange.Match.newMatch((Taxation.Income) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv08_inRange} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv08_inRange#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv08_inRange INSTANCE = new X_inv08_inRange(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv08_inRange.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_inc); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv08_inRange"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("inc"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - PVariable var_dist = body.getOrCreateVariableByName("dist"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_inc, parameter_inc) - )); - // Income.details.distance(inc, dist) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "distance"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_1_, var_dist); - // check(dist < 0) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern x_inv08_inRange"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("dist");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Double dist = (Double) provider.getValue("dist"); - return evaluateExpression_1_1(dist); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - PVariable var_dist = body.getOrCreateVariableByName("dist"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_inc, parameter_inc) - )); - // Income.details.distance(inc, dist) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "details"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Detail"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income_Detail", "distance"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_1_, var_dist); - // check(dist > 100) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern x_inv08_inRange"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("dist");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Double dist = (Double) provider.getValue("dist"); - return evaluateExpression_2_1(dist); - } - }, null); - bodies.add(body); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Double dist) { - return ((dist).doubleValue() < 0); - } - - private static boolean evaluateExpression_2_1(final Double dist) { - return ((dist).doubleValue() > 100); - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_noType.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_noType.java deleted file mode 100644 index 451d7d66..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_noType.java +++ /dev/null @@ -1,551 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Income; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv08_noType(inc : Income) {
- *             Income.income_type(inc, _);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv08_noType extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv08_noType pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Income fInc; - - private static List parameterNames = makeImmutableList("inc"); - - private Match(final Income pInc) { - this.fInc = pInc; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "inc": return this.fInc; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fInc; - default: return null; - } - } - - public Income getInc() { - return this.fInc; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("inc".equals(parameterName) ) { - this.fInc = (Income) newValue; - return true; - } - return false; - } - - public void setInc(final Income pInc) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fInc = pInc; - } - - @Override - public String patternName() { - return "queries.x_inv08_noType"; - } - - @Override - public List parameterNames() { - return X_inv08_noType.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fInc}; - } - - @Override - public X_inv08_noType.Match toImmutable() { - return isMutable() ? newMatch(fInc) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"inc\"=" + prettyPrintValue(fInc)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fInc); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv08_noType.Match)) { - X_inv08_noType.Match other = (X_inv08_noType.Match) obj; - return Objects.equals(fInc, other.fInc); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv08_noType specification() { - return X_inv08_noType.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv08_noType.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv08_noType.Match newMutableMatch(final Income pInc) { - return new Mutable(pInc); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv08_noType.Match newMatch(final Income pInc) { - return new Immutable(pInc); - } - - private static final class Mutable extends X_inv08_noType.Match { - Mutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv08_noType.Match { - Immutable(final Income pInc) { - super(pInc); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv08_noType pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv08_noType(inc : Income) {
-   *     Income.income_type(inc, _);
-   * }
-   * 
- * - * @see Match - * @see X_inv08_noType - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv08_noType.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv08_noType.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_INC = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv08_noType.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Income pInc) { - return rawStreamAllMatches(new Object[]{pInc}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Income pInc) { - return rawGetOneArbitraryMatch(new Object[]{pInc}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Income pInc) { - return rawHasMatch(new Object[]{pInc}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Income pInc) { - return rawCountMatches(new Object[]{pInc}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Income pInc, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pInc}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pInc the fixed value of pattern parameter inc, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv08_noType.Match newMatch(final Income pInc) { - return X_inv08_noType.Match.newMatch(pInc); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfinc(final Object[] parameters) { - return rawStreamAllValues(POSITION_INC, parameters).map(Income.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for inc. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfinc() { - return rawStreamAllValuesOfinc(emptyArray()); - } - - @Override - protected X_inv08_noType.Match tupleToMatch(final Tuple t) { - try { - return X_inv08_noType.Match.newMatch((Income) t.get(POSITION_INC)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv08_noType.Match arrayToMatch(final Object[] match) { - try { - return X_inv08_noType.Match.newMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv08_noType.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv08_noType.Match.newMutableMatch((Income) match[POSITION_INC]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv08_noType.instance(); - } - } - - private X_inv08_noType() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv08_noType instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv08_noType.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv08_noType.Matcher.on(engine); - } - - @Override - public X_inv08_noType.Matcher instantiate() { - return X_inv08_noType.Matcher.create(); - } - - @Override - public X_inv08_noType.Match newEmptyMatch() { - return X_inv08_noType.Match.newEmptyMatch(); - } - - @Override - public X_inv08_noType.Match newMatch(final Object... parameters) { - return X_inv08_noType.Match.newMatch((Taxation.Income) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv08_noType} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv08_noType#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv08_noType INSTANCE = new X_inv08_noType(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv08_noType.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_inc = new PParameter("inc", "Taxation.Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Income")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_inc); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv08_noType"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("inc"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_inc = body.getOrCreateVariableByName("inc"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_inc, parameter_inc) - )); - // Income.income_type(inc, _) - new TypeConstraint(body, Tuples.flatTupleOf(var_inc), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_inc, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_type"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income_Type"))); - new Equality(body, var__virtual_0_, var___0_); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_notEI.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_notEI.java deleted file mode 100644 index 07236028..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv08_notEI.java +++ /dev/null @@ -1,544 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Employment_Income; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv08_notEI(type : Employment_Income) {
- *             Employment_Income(type);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv08_notEI extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv08_notEI pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Employment_Income fType; - - private static List parameterNames = makeImmutableList("type"); - - private Match(final Employment_Income pType) { - this.fType = pType; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "type": return this.fType; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fType; - default: return null; - } - } - - public Employment_Income getType() { - return this.fType; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("type".equals(parameterName) ) { - this.fType = (Employment_Income) newValue; - return true; - } - return false; - } - - public void setType(final Employment_Income pType) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fType = pType; - } - - @Override - public String patternName() { - return "queries.x_inv08_notEI"; - } - - @Override - public List parameterNames() { - return X_inv08_notEI.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fType}; - } - - @Override - public X_inv08_notEI.Match toImmutable() { - return isMutable() ? newMatch(fType) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"type\"=" + prettyPrintValue(fType)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fType); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv08_notEI.Match)) { - X_inv08_notEI.Match other = (X_inv08_notEI.Match) obj; - return Objects.equals(fType, other.fType); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv08_notEI specification() { - return X_inv08_notEI.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv08_notEI.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv08_notEI.Match newMutableMatch(final Employment_Income pType) { - return new Mutable(pType); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv08_notEI.Match newMatch(final Employment_Income pType) { - return new Immutable(pType); - } - - private static final class Mutable extends X_inv08_notEI.Match { - Mutable(final Employment_Income pType) { - super(pType); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv08_notEI.Match { - Immutable(final Employment_Income pType) { - super(pType); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv08_notEI pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv08_notEI(type : Employment_Income) {
-   *     Employment_Income(type);
-   * }
-   * 
- * - * @see Match - * @see X_inv08_notEI - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv08_notEI.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv08_notEI.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_TYPE = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv08_notEI.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Employment_Income pType) { - return rawStreamAllMatches(new Object[]{pType}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Employment_Income pType) { - return rawStreamAllMatches(new Object[]{pType}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Employment_Income pType) { - return rawGetOneArbitraryMatch(new Object[]{pType}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Employment_Income pType) { - return rawHasMatch(new Object[]{pType}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Employment_Income pType) { - return rawCountMatches(new Object[]{pType}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Employment_Income pType, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pType}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv08_notEI.Match newMatch(final Employment_Income pType) { - return X_inv08_notEI.Match.newMatch(pType); - } - - /** - * Retrieve the set of values that occur in matches for type. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftype(final Object[] parameters) { - return rawStreamAllValues(POSITION_TYPE, parameters).map(Employment_Income.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for type. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftype() { - return rawStreamAllValuesOftype(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for type. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftype() { - return rawStreamAllValuesOftype(emptyArray()); - } - - @Override - protected X_inv08_notEI.Match tupleToMatch(final Tuple t) { - try { - return X_inv08_notEI.Match.newMatch((Employment_Income) t.get(POSITION_TYPE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv08_notEI.Match arrayToMatch(final Object[] match) { - try { - return X_inv08_notEI.Match.newMatch((Employment_Income) match[POSITION_TYPE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv08_notEI.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv08_notEI.Match.newMutableMatch((Employment_Income) match[POSITION_TYPE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv08_notEI.instance(); - } - } - - private X_inv08_notEI() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv08_notEI instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv08_notEI.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv08_notEI.Matcher.on(engine); - } - - @Override - public X_inv08_notEI.Matcher instantiate() { - return X_inv08_notEI.Matcher.create(); - } - - @Override - public X_inv08_notEI.Match newEmptyMatch() { - return X_inv08_notEI.Match.newEmptyMatch(); - } - - @Override - public X_inv08_notEI.Match newMatch(final Object... parameters) { - return X_inv08_notEI.Match.newMatch((Taxation.Employment_Income) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv08_notEI} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv08_notEI#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv08_notEI INSTANCE = new X_inv08_notEI(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv08_notEI.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_type = new PParameter("type", "Taxation.Employment_Income", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Employment_Income")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_type); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv08_notEI"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("type"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_type = body.getOrCreateVariableByName("type"); - new TypeConstraint(body, Tuples.flatTupleOf(var_type), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Employment_Income"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_type, parameter_type) - )); - // Employment_Income(type) - new TypeConstraint(body, Tuples.flatTupleOf(var_type), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Employment_Income"))); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incNotOver100.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incNotOver100.java deleted file mode 100644 index 995946eb..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incNotOver100.java +++ /dev/null @@ -1,684 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Expense; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv11_incNotOver100(exp : Expense) {
- *             Expense.income.income_amount(exp, incVal);
- *             check(incVal / 2 {@literal <}= 50);
- *         } or {
- *         	Expense.declared_amount(exp, decl);
- *             check(decl {@literal <} 50);
- *         } or {
- *         	Expense.income.income_amount(exp, incVal);
- *         	Expense.declared_amount(exp, decl);
- *         	check(decl {@literal >} incVal/2);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv11_incNotOver100 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv11_incNotOver100 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Expense fExp; - - private static List parameterNames = makeImmutableList("exp"); - - private Match(final Expense pExp) { - this.fExp = pExp; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "exp": return this.fExp; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fExp; - default: return null; - } - } - - public Expense getExp() { - return this.fExp; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("exp".equals(parameterName) ) { - this.fExp = (Expense) newValue; - return true; - } - return false; - } - - public void setExp(final Expense pExp) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fExp = pExp; - } - - @Override - public String patternName() { - return "queries.x_inv11_incNotOver100"; - } - - @Override - public List parameterNames() { - return X_inv11_incNotOver100.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fExp}; - } - - @Override - public X_inv11_incNotOver100.Match toImmutable() { - return isMutable() ? newMatch(fExp) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"exp\"=" + prettyPrintValue(fExp)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fExp); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv11_incNotOver100.Match)) { - X_inv11_incNotOver100.Match other = (X_inv11_incNotOver100.Match) obj; - return Objects.equals(fExp, other.fExp); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv11_incNotOver100 specification() { - return X_inv11_incNotOver100.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv11_incNotOver100.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv11_incNotOver100.Match newMutableMatch(final Expense pExp) { - return new Mutable(pExp); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv11_incNotOver100.Match newMatch(final Expense pExp) { - return new Immutable(pExp); - } - - private static final class Mutable extends X_inv11_incNotOver100.Match { - Mutable(final Expense pExp) { - super(pExp); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv11_incNotOver100.Match { - Immutable(final Expense pExp) { - super(pExp); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv11_incNotOver100 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv11_incNotOver100(exp : Expense) {
-   *     Expense.income.income_amount(exp, incVal);
-   *     check(incVal / 2 {@literal <}= 50);
-   * } or {
-   * 	Expense.declared_amount(exp, decl);
-   *     check(decl {@literal <} 50);
-   * } or {
-   * 	Expense.income.income_amount(exp, incVal);
-   * 	Expense.declared_amount(exp, decl);
-   * 	check(decl {@literal >} incVal/2);
-   * }
-   * 
- * - * @see Match - * @see X_inv11_incNotOver100 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv11_incNotOver100.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv11_incNotOver100.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_EXP = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv11_incNotOver100.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Expense pExp) { - return rawStreamAllMatches(new Object[]{pExp}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Expense pExp) { - return rawStreamAllMatches(new Object[]{pExp}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Expense pExp) { - return rawGetOneArbitraryMatch(new Object[]{pExp}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Expense pExp) { - return rawHasMatch(new Object[]{pExp}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Expense pExp) { - return rawCountMatches(new Object[]{pExp}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Expense pExp, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pExp}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv11_incNotOver100.Match newMatch(final Expense pExp) { - return X_inv11_incNotOver100.Match.newMatch(pExp); - } - - /** - * Retrieve the set of values that occur in matches for exp. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfexp(final Object[] parameters) { - return rawStreamAllValues(POSITION_EXP, parameters).map(Expense.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for exp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfexp() { - return rawStreamAllValuesOfexp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for exp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfexp() { - return rawStreamAllValuesOfexp(emptyArray()); - } - - @Override - protected X_inv11_incNotOver100.Match tupleToMatch(final Tuple t) { - try { - return X_inv11_incNotOver100.Match.newMatch((Expense) t.get(POSITION_EXP)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv11_incNotOver100.Match arrayToMatch(final Object[] match) { - try { - return X_inv11_incNotOver100.Match.newMatch((Expense) match[POSITION_EXP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv11_incNotOver100.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv11_incNotOver100.Match.newMutableMatch((Expense) match[POSITION_EXP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv11_incNotOver100.instance(); - } - } - - private X_inv11_incNotOver100() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv11_incNotOver100 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv11_incNotOver100.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv11_incNotOver100.Matcher.on(engine); - } - - @Override - public X_inv11_incNotOver100.Matcher instantiate() { - return X_inv11_incNotOver100.Matcher.create(); - } - - @Override - public X_inv11_incNotOver100.Match newEmptyMatch() { - return X_inv11_incNotOver100.Match.newEmptyMatch(); - } - - @Override - public X_inv11_incNotOver100.Match newMatch(final Object... parameters) { - return X_inv11_incNotOver100.Match.newMatch((Taxation.Expense) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv11_incNotOver100} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv11_incNotOver100#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv11_incNotOver100 INSTANCE = new X_inv11_incNotOver100(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv11_incNotOver100.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_exp = new PParameter("exp", "Taxation.Expense", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Expense")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_exp); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv11_incNotOver100"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("exp"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_exp = body.getOrCreateVariableByName("exp"); - PVariable var_incVal = body.getOrCreateVariableByName("incVal"); - new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_exp, parameter_exp) - )); - // Expense.income.income_amount(exp, incVal) - new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_exp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Expense", "income"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_amount"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_1_, var_incVal); - // check(incVal / 2 <= 50) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern x_inv11_incNotOver100"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("incVal");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Double incVal = (Double) provider.getValue("incVal"); - return evaluateExpression_1_1(incVal); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_exp = body.getOrCreateVariableByName("exp"); - PVariable var_decl = body.getOrCreateVariableByName("decl"); - new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_exp, parameter_exp) - )); - // Expense.declared_amount(exp, decl) - new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_exp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Expense", "declared_amount"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_0_, var_decl); - // check(decl < 50) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern x_inv11_incNotOver100"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("decl");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Double decl = (Double) provider.getValue("decl"); - return evaluateExpression_2_1(decl); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_exp = body.getOrCreateVariableByName("exp"); - PVariable var_incVal = body.getOrCreateVariableByName("incVal"); - PVariable var_decl = body.getOrCreateVariableByName("decl"); - new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_exp, parameter_exp) - )); - // Expense.income.income_amount(exp, incVal) - new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_exp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Expense", "income"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_amount"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_1_, var_incVal); - // Expense.declared_amount(exp, decl) - new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_exp, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Expense", "declared_amount"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_2_, var_decl); - // check(decl > incVal/2) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern x_inv11_incNotOver100"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("decl", "incVal");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Double decl = (Double) provider.getValue("decl"); - Double incVal = (Double) provider.getValue("incVal"); - return evaluateExpression_3_1(decl, incVal); - } - }, null); - bodies.add(body); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Double incVal) { - return (((incVal).doubleValue() / 2) <= 50); - } - - private static boolean evaluateExpression_2_1(final Double decl) { - return ((decl).doubleValue() < 50); - } - - private static boolean evaluateExpression_3_1(final Double decl, final Double incVal) { - return ((decl).doubleValue() > ((incVal).doubleValue() / 2)); - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incOver100.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incOver100.java deleted file mode 100644 index 65ae5dd6..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv11_incOver100.java +++ /dev/null @@ -1,629 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Expense; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv11_incOver100(exp : Expense) {
- *             Expense.income.income_amount(exp, incVal);
- *             check(incVal / 2 {@literal >} 50);
- *         
- *         } or {
- *         	Expense.declared_amount(exp, decl);
- *             check(decl != 50);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv11_incOver100 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv11_incOver100 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Expense fExp; - - private static List parameterNames = makeImmutableList("exp"); - - private Match(final Expense pExp) { - this.fExp = pExp; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "exp": return this.fExp; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fExp; - default: return null; - } - } - - public Expense getExp() { - return this.fExp; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("exp".equals(parameterName) ) { - this.fExp = (Expense) newValue; - return true; - } - return false; - } - - public void setExp(final Expense pExp) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fExp = pExp; - } - - @Override - public String patternName() { - return "queries.x_inv11_incOver100"; - } - - @Override - public List parameterNames() { - return X_inv11_incOver100.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fExp}; - } - - @Override - public X_inv11_incOver100.Match toImmutable() { - return isMutable() ? newMatch(fExp) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"exp\"=" + prettyPrintValue(fExp)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fExp); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv11_incOver100.Match)) { - X_inv11_incOver100.Match other = (X_inv11_incOver100.Match) obj; - return Objects.equals(fExp, other.fExp); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv11_incOver100 specification() { - return X_inv11_incOver100.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv11_incOver100.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv11_incOver100.Match newMutableMatch(final Expense pExp) { - return new Mutable(pExp); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv11_incOver100.Match newMatch(final Expense pExp) { - return new Immutable(pExp); - } - - private static final class Mutable extends X_inv11_incOver100.Match { - Mutable(final Expense pExp) { - super(pExp); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv11_incOver100.Match { - Immutable(final Expense pExp) { - super(pExp); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv11_incOver100 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv11_incOver100(exp : Expense) {
-   *     Expense.income.income_amount(exp, incVal);
-   *     check(incVal / 2 {@literal >} 50);
-   * 
-   * } or {
-   * 	Expense.declared_amount(exp, decl);
-   *     check(decl != 50);
-   * }
-   * 
- * - * @see Match - * @see X_inv11_incOver100 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv11_incOver100.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv11_incOver100.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_EXP = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv11_incOver100.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Expense pExp) { - return rawStreamAllMatches(new Object[]{pExp}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Expense pExp) { - return rawStreamAllMatches(new Object[]{pExp}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Expense pExp) { - return rawGetOneArbitraryMatch(new Object[]{pExp}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Expense pExp) { - return rawHasMatch(new Object[]{pExp}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Expense pExp) { - return rawCountMatches(new Object[]{pExp}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Expense pExp, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pExp}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pExp the fixed value of pattern parameter exp, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv11_incOver100.Match newMatch(final Expense pExp) { - return X_inv11_incOver100.Match.newMatch(pExp); - } - - /** - * Retrieve the set of values that occur in matches for exp. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfexp(final Object[] parameters) { - return rawStreamAllValues(POSITION_EXP, parameters).map(Expense.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for exp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfexp() { - return rawStreamAllValuesOfexp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for exp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfexp() { - return rawStreamAllValuesOfexp(emptyArray()); - } - - @Override - protected X_inv11_incOver100.Match tupleToMatch(final Tuple t) { - try { - return X_inv11_incOver100.Match.newMatch((Expense) t.get(POSITION_EXP)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv11_incOver100.Match arrayToMatch(final Object[] match) { - try { - return X_inv11_incOver100.Match.newMatch((Expense) match[POSITION_EXP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv11_incOver100.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv11_incOver100.Match.newMutableMatch((Expense) match[POSITION_EXP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv11_incOver100.instance(); - } - } - - private X_inv11_incOver100() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv11_incOver100 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv11_incOver100.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv11_incOver100.Matcher.on(engine); - } - - @Override - public X_inv11_incOver100.Matcher instantiate() { - return X_inv11_incOver100.Matcher.create(); - } - - @Override - public X_inv11_incOver100.Match newEmptyMatch() { - return X_inv11_incOver100.Match.newEmptyMatch(); - } - - @Override - public X_inv11_incOver100.Match newMatch(final Object... parameters) { - return X_inv11_incOver100.Match.newMatch((Taxation.Expense) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv11_incOver100} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv11_incOver100#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv11_incOver100 INSTANCE = new X_inv11_incOver100(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv11_incOver100.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_exp = new PParameter("exp", "Taxation.Expense", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Expense")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_exp); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv11_incOver100"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("exp"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_exp = body.getOrCreateVariableByName("exp"); - PVariable var_incVal = body.getOrCreateVariableByName("incVal"); - new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_exp, parameter_exp) - )); - // Expense.income.income_amount(exp, incVal) - new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_exp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Expense", "income"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Income"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Income", "income_amount"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_1_, var_incVal); - // check(incVal / 2 > 50) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern x_inv11_incOver100"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("incVal");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Double incVal = (Double) provider.getValue("incVal"); - return evaluateExpression_1_1(incVal); - } - }, null); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_exp = body.getOrCreateVariableByName("exp"); - PVariable var_decl = body.getOrCreateVariableByName("decl"); - new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_exp, parameter_exp) - )); - // Expense.declared_amount(exp, decl) - new TypeConstraint(body, Tuples.flatTupleOf(var_exp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Expense"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_exp, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Expense", "declared_amount"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_0_, var_decl); - // check(decl != 50) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern x_inv11_incOver100"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("decl");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Double decl = (Double) provider.getValue("decl"); - return evaluateExpression_2_1(decl); - } - }, null); - bodies.add(body); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Double incVal) { - return (((incVal).doubleValue() / 2) > 50); - } - - private static boolean evaluateExpression_2_1(final Double decl) { - return ((decl).doubleValue() != 50); - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notNonRes.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notNonRes.java deleted file mode 100644 index 96aea5e8..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notNonRes.java +++ /dev/null @@ -1,544 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Non_Resident_Tax_Payer; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv12_notNonRes(tp : Non_Resident_Tax_Payer) {
- *             Non_Resident_Tax_Payer(tp);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv12_notNonRes extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv12_notNonRes pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Non_Resident_Tax_Payer fTp; - - private static List parameterNames = makeImmutableList("tp"); - - private Match(final Non_Resident_Tax_Payer pTp) { - this.fTp = pTp; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "tp": return this.fTp; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fTp; - default: return null; - } - } - - public Non_Resident_Tax_Payer getTp() { - return this.fTp; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("tp".equals(parameterName) ) { - this.fTp = (Non_Resident_Tax_Payer) newValue; - return true; - } - return false; - } - - public void setTp(final Non_Resident_Tax_Payer pTp) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTp = pTp; - } - - @Override - public String patternName() { - return "queries.x_inv12_notNonRes"; - } - - @Override - public List parameterNames() { - return X_inv12_notNonRes.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fTp}; - } - - @Override - public X_inv12_notNonRes.Match toImmutable() { - return isMutable() ? newMatch(fTp) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"tp\"=" + prettyPrintValue(fTp)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fTp); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv12_notNonRes.Match)) { - X_inv12_notNonRes.Match other = (X_inv12_notNonRes.Match) obj; - return Objects.equals(fTp, other.fTp); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv12_notNonRes specification() { - return X_inv12_notNonRes.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv12_notNonRes.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv12_notNonRes.Match newMutableMatch(final Non_Resident_Tax_Payer pTp) { - return new Mutable(pTp); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv12_notNonRes.Match newMatch(final Non_Resident_Tax_Payer pTp) { - return new Immutable(pTp); - } - - private static final class Mutable extends X_inv12_notNonRes.Match { - Mutable(final Non_Resident_Tax_Payer pTp) { - super(pTp); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv12_notNonRes.Match { - Immutable(final Non_Resident_Tax_Payer pTp) { - super(pTp); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv12_notNonRes pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv12_notNonRes(tp : Non_Resident_Tax_Payer) {
-   *     Non_Resident_Tax_Payer(tp);
-   * }
-   * 
- * - * @see Match - * @see X_inv12_notNonRes - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv12_notNonRes.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv12_notNonRes.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_TP = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv12_notNonRes.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Non_Resident_Tax_Payer pTp) { - return rawStreamAllMatches(new Object[]{pTp}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Non_Resident_Tax_Payer pTp) { - return rawStreamAllMatches(new Object[]{pTp}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Non_Resident_Tax_Payer pTp) { - return rawGetOneArbitraryMatch(new Object[]{pTp}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Non_Resident_Tax_Payer pTp) { - return rawHasMatch(new Object[]{pTp}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Non_Resident_Tax_Payer pTp) { - return rawCountMatches(new Object[]{pTp}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Non_Resident_Tax_Payer pTp, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pTp}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv12_notNonRes.Match newMatch(final Non_Resident_Tax_Payer pTp) { - return X_inv12_notNonRes.Match.newMatch(pTp); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftp(final Object[] parameters) { - return rawStreamAllValues(POSITION_TP, parameters).map(Non_Resident_Tax_Payer.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftp() { - return rawStreamAllValuesOftp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftp() { - return rawStreamAllValuesOftp(emptyArray()); - } - - @Override - protected X_inv12_notNonRes.Match tupleToMatch(final Tuple t) { - try { - return X_inv12_notNonRes.Match.newMatch((Non_Resident_Tax_Payer) t.get(POSITION_TP)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv12_notNonRes.Match arrayToMatch(final Object[] match) { - try { - return X_inv12_notNonRes.Match.newMatch((Non_Resident_Tax_Payer) match[POSITION_TP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv12_notNonRes.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv12_notNonRes.Match.newMutableMatch((Non_Resident_Tax_Payer) match[POSITION_TP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv12_notNonRes.instance(); - } - } - - private X_inv12_notNonRes() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv12_notNonRes instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv12_notNonRes.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv12_notNonRes.Matcher.on(engine); - } - - @Override - public X_inv12_notNonRes.Matcher instantiate() { - return X_inv12_notNonRes.Matcher.create(); - } - - @Override - public X_inv12_notNonRes.Match newEmptyMatch() { - return X_inv12_notNonRes.Match.newEmptyMatch(); - } - - @Override - public X_inv12_notNonRes.Match newMatch(final Object... parameters) { - return X_inv12_notNonRes.Match.newMatch((Taxation.Non_Resident_Tax_Payer) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv12_notNonRes} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv12_notNonRes#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv12_notNonRes INSTANCE = new X_inv12_notNonRes(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv12_notNonRes.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_tp = new PParameter("tp", "Taxation.Non_Resident_Tax_Payer", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Non_Resident_Tax_Payer")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_tp); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv12_notNonRes"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("tp"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_tp = body.getOrCreateVariableByName("tp"); - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Non_Resident_Tax_Payer"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_tp, parameter_tp) - )); - // Non_Resident_Tax_Payer(tp) - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Non_Resident_Tax_Payer"))); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notZZ.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notZZ.java deleted file mode 100644 index f8e7da17..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv12_notZZ.java +++ /dev/null @@ -1,555 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Habitual_Address; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv12_notZZ(hab_add : Habitual_Address) {
- *             Address.country(hab_add, ::ZZ);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv12_notZZ extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv12_notZZ pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Habitual_Address fHab_add; - - private static List parameterNames = makeImmutableList("hab_add"); - - private Match(final Habitual_Address pHab_add) { - this.fHab_add = pHab_add; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "hab_add": return this.fHab_add; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fHab_add; - default: return null; - } - } - - public Habitual_Address getHab_add() { - return this.fHab_add; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("hab_add".equals(parameterName) ) { - this.fHab_add = (Habitual_Address) newValue; - return true; - } - return false; - } - - public void setHab_add(final Habitual_Address pHab_add) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fHab_add = pHab_add; - } - - @Override - public String patternName() { - return "queries.x_inv12_notZZ"; - } - - @Override - public List parameterNames() { - return X_inv12_notZZ.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fHab_add}; - } - - @Override - public X_inv12_notZZ.Match toImmutable() { - return isMutable() ? newMatch(fHab_add) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"hab_add\"=" + prettyPrintValue(fHab_add)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fHab_add); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv12_notZZ.Match)) { - X_inv12_notZZ.Match other = (X_inv12_notZZ.Match) obj; - return Objects.equals(fHab_add, other.fHab_add); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv12_notZZ specification() { - return X_inv12_notZZ.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv12_notZZ.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv12_notZZ.Match newMutableMatch(final Habitual_Address pHab_add) { - return new Mutable(pHab_add); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv12_notZZ.Match newMatch(final Habitual_Address pHab_add) { - return new Immutable(pHab_add); - } - - private static final class Mutable extends X_inv12_notZZ.Match { - Mutable(final Habitual_Address pHab_add) { - super(pHab_add); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv12_notZZ.Match { - Immutable(final Habitual_Address pHab_add) { - super(pHab_add); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv12_notZZ pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv12_notZZ(hab_add : Habitual_Address) {
-   *     Address.country(hab_add, ::ZZ);
-   * }
-   * 
- * - * @see Match - * @see X_inv12_notZZ - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv12_notZZ.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv12_notZZ.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_HAB_ADD = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv12_notZZ.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Habitual_Address pHab_add) { - return rawStreamAllMatches(new Object[]{pHab_add}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Habitual_Address pHab_add) { - return rawStreamAllMatches(new Object[]{pHab_add}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Habitual_Address pHab_add) { - return rawGetOneArbitraryMatch(new Object[]{pHab_add}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Habitual_Address pHab_add) { - return rawHasMatch(new Object[]{pHab_add}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Habitual_Address pHab_add) { - return rawCountMatches(new Object[]{pHab_add}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Habitual_Address pHab_add, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pHab_add}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pHab_add the fixed value of pattern parameter hab_add, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv12_notZZ.Match newMatch(final Habitual_Address pHab_add) { - return X_inv12_notZZ.Match.newMatch(pHab_add); - } - - /** - * Retrieve the set of values that occur in matches for hab_add. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfhab_add(final Object[] parameters) { - return rawStreamAllValues(POSITION_HAB_ADD, parameters).map(Habitual_Address.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for hab_add. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfhab_add() { - return rawStreamAllValuesOfhab_add(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for hab_add. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfhab_add() { - return rawStreamAllValuesOfhab_add(emptyArray()); - } - - @Override - protected X_inv12_notZZ.Match tupleToMatch(final Tuple t) { - try { - return X_inv12_notZZ.Match.newMatch((Habitual_Address) t.get(POSITION_HAB_ADD)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv12_notZZ.Match arrayToMatch(final Object[] match) { - try { - return X_inv12_notZZ.Match.newMatch((Habitual_Address) match[POSITION_HAB_ADD]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv12_notZZ.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv12_notZZ.Match.newMutableMatch((Habitual_Address) match[POSITION_HAB_ADD]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv12_notZZ.instance(); - } - } - - private X_inv12_notZZ() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv12_notZZ instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv12_notZZ.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv12_notZZ.Matcher.on(engine); - } - - @Override - public X_inv12_notZZ.Matcher instantiate() { - return X_inv12_notZZ.Matcher.create(); - } - - @Override - public X_inv12_notZZ.Match newEmptyMatch() { - return X_inv12_notZZ.Match.newEmptyMatch(); - } - - @Override - public X_inv12_notZZ.Match newMatch(final Object... parameters) { - return X_inv12_notZZ.Match.newMatch((Taxation.Habitual_Address) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv12_notZZ} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv12_notZZ#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv12_notZZ INSTANCE = new X_inv12_notZZ(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv12_notZZ.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_hab_add = new PParameter("hab_add", "Taxation.Habitual_Address", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Habitual_Address")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_hab_add); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv12_notZZ"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("hab_add"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_hab_add = body.getOrCreateVariableByName("hab_add"); - new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Habitual_Address"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_hab_add, parameter_hab_add) - )); - // Address.country(hab_add, ::ZZ) - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new ConstantValue(body, var__virtual_0_, getEnumLiteral("http:///TaxCard.ecore", "Country", "ZZ").getInstance()); - new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Address"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_hab_add, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Address", "country"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http:///TaxCard.ecore", "Country"))); - new Equality(body, var__virtual_1_, var__virtual_0_); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv13.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv13.java deleted file mode 100644 index 42afdd70..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv13.java +++ /dev/null @@ -1,544 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Resident_Tax_Payer; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv13(tp : Resident_Tax_Payer) {
- *             Resident_Tax_Payer(tp);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv13 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv13 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Resident_Tax_Payer fTp; - - private static List parameterNames = makeImmutableList("tp"); - - private Match(final Resident_Tax_Payer pTp) { - this.fTp = pTp; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "tp": return this.fTp; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fTp; - default: return null; - } - } - - public Resident_Tax_Payer getTp() { - return this.fTp; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("tp".equals(parameterName) ) { - this.fTp = (Resident_Tax_Payer) newValue; - return true; - } - return false; - } - - public void setTp(final Resident_Tax_Payer pTp) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTp = pTp; - } - - @Override - public String patternName() { - return "queries.x_inv13"; - } - - @Override - public List parameterNames() { - return X_inv13.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fTp}; - } - - @Override - public X_inv13.Match toImmutable() { - return isMutable() ? newMatch(fTp) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"tp\"=" + prettyPrintValue(fTp)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fTp); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv13.Match)) { - X_inv13.Match other = (X_inv13.Match) obj; - return Objects.equals(fTp, other.fTp); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv13 specification() { - return X_inv13.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv13.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv13.Match newMutableMatch(final Resident_Tax_Payer pTp) { - return new Mutable(pTp); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv13.Match newMatch(final Resident_Tax_Payer pTp) { - return new Immutable(pTp); - } - - private static final class Mutable extends X_inv13.Match { - Mutable(final Resident_Tax_Payer pTp) { - super(pTp); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv13.Match { - Immutable(final Resident_Tax_Payer pTp) { - super(pTp); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv13 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv13(tp : Resident_Tax_Payer) {
-   *     Resident_Tax_Payer(tp);
-   * }
-   * 
- * - * @see Match - * @see X_inv13 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv13.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv13.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_TP = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv13.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Resident_Tax_Payer pTp) { - return rawStreamAllMatches(new Object[]{pTp}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Resident_Tax_Payer pTp) { - return rawStreamAllMatches(new Object[]{pTp}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Resident_Tax_Payer pTp) { - return rawGetOneArbitraryMatch(new Object[]{pTp}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Resident_Tax_Payer pTp) { - return rawHasMatch(new Object[]{pTp}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Resident_Tax_Payer pTp) { - return rawCountMatches(new Object[]{pTp}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Resident_Tax_Payer pTp, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pTp}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pTp the fixed value of pattern parameter tp, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv13.Match newMatch(final Resident_Tax_Payer pTp) { - return X_inv13.Match.newMatch(pTp); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftp(final Object[] parameters) { - return rawStreamAllValues(POSITION_TP, parameters).map(Resident_Tax_Payer.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftp() { - return rawStreamAllValuesOftp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for tp. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftp() { - return rawStreamAllValuesOftp(emptyArray()); - } - - @Override - protected X_inv13.Match tupleToMatch(final Tuple t) { - try { - return X_inv13.Match.newMatch((Resident_Tax_Payer) t.get(POSITION_TP)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv13.Match arrayToMatch(final Object[] match) { - try { - return X_inv13.Match.newMatch((Resident_Tax_Payer) match[POSITION_TP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv13.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv13.Match.newMutableMatch((Resident_Tax_Payer) match[POSITION_TP]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv13.instance(); - } - } - - private X_inv13() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv13 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv13.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv13.Matcher.on(engine); - } - - @Override - public X_inv13.Matcher instantiate() { - return X_inv13.Matcher.create(); - } - - @Override - public X_inv13.Match newEmptyMatch() { - return X_inv13.Match.newEmptyMatch(); - } - - @Override - public X_inv13.Match newMatch(final Object... parameters) { - return X_inv13.Match.newMatch((Taxation.Resident_Tax_Payer) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv13} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv13#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv13 INSTANCE = new X_inv13(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv13.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_tp = new PParameter("tp", "Taxation.Resident_Tax_Payer", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Resident_Tax_Payer")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_tp); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv13"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("tp"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_tp = body.getOrCreateVariableByName("tp"); - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Resident_Tax_Payer"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_tp, parameter_tp) - )); - // Resident_Tax_Payer(tp) - new TypeConstraint(body, Tuples.flatTupleOf(var_tp), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Resident_Tax_Payer"))); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv15.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv15.java deleted file mode 100644 index d162542d..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv15.java +++ /dev/null @@ -1,637 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.External_Allowance; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv15(ea : External_Allowance) {
- *             External_Allowance.person(ea, child);
- *             Household.children(h, child);//only one due to multiplicity
- *             Household.parents.individual_A(h, iA);
- *             Tax_Payer(iA);
- *             External_Allowance.reciver(ea, iA);
- *         } or {
- *             External_Allowance.person(ea, child);
- *             Household.children(h, child);//only one due to multiplicity
- *             Household.parents.individual_B(h, iB);
- *             Tax_Payer(iB);
- *             External_Allowance.reciver(ea, iB);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv15 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv15 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private External_Allowance fEa; - - private static List parameterNames = makeImmutableList("ea"); - - private Match(final External_Allowance pEa) { - this.fEa = pEa; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "ea": return this.fEa; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fEa; - default: return null; - } - } - - public External_Allowance getEa() { - return this.fEa; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("ea".equals(parameterName) ) { - this.fEa = (External_Allowance) newValue; - return true; - } - return false; - } - - public void setEa(final External_Allowance pEa) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fEa = pEa; - } - - @Override - public String patternName() { - return "queries.x_inv15"; - } - - @Override - public List parameterNames() { - return X_inv15.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fEa}; - } - - @Override - public X_inv15.Match toImmutable() { - return isMutable() ? newMatch(fEa) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"ea\"=" + prettyPrintValue(fEa)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fEa); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv15.Match)) { - X_inv15.Match other = (X_inv15.Match) obj; - return Objects.equals(fEa, other.fEa); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv15 specification() { - return X_inv15.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv15.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv15.Match newMutableMatch(final External_Allowance pEa) { - return new Mutable(pEa); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv15.Match newMatch(final External_Allowance pEa) { - return new Immutable(pEa); - } - - private static final class Mutable extends X_inv15.Match { - Mutable(final External_Allowance pEa) { - super(pEa); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv15.Match { - Immutable(final External_Allowance pEa) { - super(pEa); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv15 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv15(ea : External_Allowance) {
-   *     External_Allowance.person(ea, child);
-   *     Household.children(h, child);//only one due to multiplicity
-   *     Household.parents.individual_A(h, iA);
-   *     Tax_Payer(iA);
-   *     External_Allowance.reciver(ea, iA);
-   * } or {
-   *     External_Allowance.person(ea, child);
-   *     Household.children(h, child);//only one due to multiplicity
-   *     Household.parents.individual_B(h, iB);
-   *     Tax_Payer(iB);
-   *     External_Allowance.reciver(ea, iB);
-   * }
-   * 
- * - * @see Match - * @see X_inv15 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv15.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv15.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_EA = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv15.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final External_Allowance pEa) { - return rawStreamAllMatches(new Object[]{pEa}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final External_Allowance pEa) { - return rawStreamAllMatches(new Object[]{pEa}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final External_Allowance pEa) { - return rawGetOneArbitraryMatch(new Object[]{pEa}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final External_Allowance pEa) { - return rawHasMatch(new Object[]{pEa}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final External_Allowance pEa) { - return rawCountMatches(new Object[]{pEa}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final External_Allowance pEa, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pEa}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pEa the fixed value of pattern parameter ea, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv15.Match newMatch(final External_Allowance pEa) { - return X_inv15.Match.newMatch(pEa); - } - - /** - * Retrieve the set of values that occur in matches for ea. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfea(final Object[] parameters) { - return rawStreamAllValues(POSITION_EA, parameters).map(External_Allowance.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for ea. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfea() { - return rawStreamAllValuesOfea(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for ea. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfea() { - return rawStreamAllValuesOfea(emptyArray()); - } - - @Override - protected X_inv15.Match tupleToMatch(final Tuple t) { - try { - return X_inv15.Match.newMatch((External_Allowance) t.get(POSITION_EA)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv15.Match arrayToMatch(final Object[] match) { - try { - return X_inv15.Match.newMatch((External_Allowance) match[POSITION_EA]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv15.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv15.Match.newMutableMatch((External_Allowance) match[POSITION_EA]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv15.instance(); - } - } - - private X_inv15() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv15 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv15.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv15.Matcher.on(engine); - } - - @Override - public X_inv15.Matcher instantiate() { - return X_inv15.Matcher.create(); - } - - @Override - public X_inv15.Match newEmptyMatch() { - return X_inv15.Match.newEmptyMatch(); - } - - @Override - public X_inv15.Match newMatch(final Object... parameters) { - return X_inv15.Match.newMatch((Taxation.External_Allowance) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv15} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv15#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv15 INSTANCE = new X_inv15(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv15.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_ea = new PParameter("ea", "Taxation.External_Allowance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "External_Allowance")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_ea); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv15"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("ea"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_ea = body.getOrCreateVariableByName("ea"); - PVariable var_child = body.getOrCreateVariableByName("child"); - PVariable var_h = body.getOrCreateVariableByName("h"); - PVariable var_iA = body.getOrCreateVariableByName("iA"); - new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_ea, parameter_ea) - )); - // External_Allowance.person(ea, child) - new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_ea, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "External_Allowance", "person"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - new Equality(body, var__virtual_0_, var_child); - // Household.children(h, child) - new TypeConstraint(body, Tuples.flatTupleOf(var_h), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Household"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_h, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Household", "children"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - new Equality(body, var__virtual_1_, var_child); - // //only one due to multiplicity Household.parents.individual_A(h, iA) - new TypeConstraint(body, Tuples.flatTupleOf(var_h), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Household"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_h, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Household", "parents"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "individual_A"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - new Equality(body, var__virtual_3_, var_iA); - // Tax_Payer(iA) - new TypeConstraint(body, Tuples.flatTupleOf(var_iA), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - // External_Allowance.reciver(ea, iA) - new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance"))); - PVariable var__virtual_4_ = body.getOrCreateVariableByName(".virtual{4}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_ea, var__virtual_4_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "External_Allowance", "reciver"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - new Equality(body, var__virtual_4_, var_iA); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_ea = body.getOrCreateVariableByName("ea"); - PVariable var_child = body.getOrCreateVariableByName("child"); - PVariable var_h = body.getOrCreateVariableByName("h"); - PVariable var_iB = body.getOrCreateVariableByName("iB"); - new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_ea, parameter_ea) - )); - // External_Allowance.person(ea, child) - new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_ea, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "External_Allowance", "person"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - new Equality(body, var__virtual_0_, var_child); - // Household.children(h, child) - new TypeConstraint(body, Tuples.flatTupleOf(var_h), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Household"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_h, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Household", "children"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - new Equality(body, var__virtual_1_, var_child); - // //only one due to multiplicity Household.parents.individual_B(h, iB) - new TypeConstraint(body, Tuples.flatTupleOf(var_h), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Household"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_h, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Household", "parents"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "individual_B"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - new Equality(body, var__virtual_3_, var_iB); - // Tax_Payer(iB) - new TypeConstraint(body, Tuples.flatTupleOf(var_iB), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - // External_Allowance.reciver(ea, iB) - new TypeConstraint(body, Tuples.flatTupleOf(var_ea), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "External_Allowance"))); - PVariable var__virtual_4_ = body.getOrCreateVariableByName(".virtual{4}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_ea, var__virtual_4_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "External_Allowance", "reciver"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - new Equality(body, var__virtual_4_, var_iB); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv47.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv47.java deleted file mode 100644 index c602f8d4..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv47.java +++ /dev/null @@ -1,569 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Legal_Union_Record; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv47(lur : Legal_Union_Record) {
- *             Legal_Union_Record.separation_cause(lur, ::NONE);
- *             Legal_Union_Record.end_year(lur, -1);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv47 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv47 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Legal_Union_Record fLur; - - private static List parameterNames = makeImmutableList("lur"); - - private Match(final Legal_Union_Record pLur) { - this.fLur = pLur; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "lur": return this.fLur; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fLur; - default: return null; - } - } - - public Legal_Union_Record getLur() { - return this.fLur; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("lur".equals(parameterName) ) { - this.fLur = (Legal_Union_Record) newValue; - return true; - } - return false; - } - - public void setLur(final Legal_Union_Record pLur) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fLur = pLur; - } - - @Override - public String patternName() { - return "queries.x_inv47"; - } - - @Override - public List parameterNames() { - return X_inv47.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fLur}; - } - - @Override - public X_inv47.Match toImmutable() { - return isMutable() ? newMatch(fLur) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"lur\"=" + prettyPrintValue(fLur)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fLur); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv47.Match)) { - X_inv47.Match other = (X_inv47.Match) obj; - return Objects.equals(fLur, other.fLur); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv47 specification() { - return X_inv47.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv47.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv47.Match newMutableMatch(final Legal_Union_Record pLur) { - return new Mutable(pLur); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv47.Match newMatch(final Legal_Union_Record pLur) { - return new Immutable(pLur); - } - - private static final class Mutable extends X_inv47.Match { - Mutable(final Legal_Union_Record pLur) { - super(pLur); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv47.Match { - Immutable(final Legal_Union_Record pLur) { - super(pLur); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv47 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv47(lur : Legal_Union_Record) {
-   *     Legal_Union_Record.separation_cause(lur, ::NONE);
-   *     Legal_Union_Record.end_year(lur, -1);
-   * }
-   * 
- * - * @see Match - * @see X_inv47 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv47.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv47.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_LUR = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv47.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Legal_Union_Record pLur) { - return rawStreamAllMatches(new Object[]{pLur}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Legal_Union_Record pLur) { - return rawStreamAllMatches(new Object[]{pLur}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Legal_Union_Record pLur) { - return rawGetOneArbitraryMatch(new Object[]{pLur}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Legal_Union_Record pLur) { - return rawHasMatch(new Object[]{pLur}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Legal_Union_Record pLur) { - return rawCountMatches(new Object[]{pLur}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Legal_Union_Record pLur, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pLur}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv47.Match newMatch(final Legal_Union_Record pLur) { - return X_inv47.Match.newMatch(pLur); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOflur(final Object[] parameters) { - return rawStreamAllValues(POSITION_LUR, parameters).map(Legal_Union_Record.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOflur() { - return rawStreamAllValuesOflur(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOflur() { - return rawStreamAllValuesOflur(emptyArray()); - } - - @Override - protected X_inv47.Match tupleToMatch(final Tuple t) { - try { - return X_inv47.Match.newMatch((Legal_Union_Record) t.get(POSITION_LUR)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv47.Match arrayToMatch(final Object[] match) { - try { - return X_inv47.Match.newMatch((Legal_Union_Record) match[POSITION_LUR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv47.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv47.Match.newMutableMatch((Legal_Union_Record) match[POSITION_LUR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv47.instance(); - } - } - - private X_inv47() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv47 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv47.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv47.Matcher.on(engine); - } - - @Override - public X_inv47.Matcher instantiate() { - return X_inv47.Matcher.create(); - } - - @Override - public X_inv47.Match newEmptyMatch() { - return X_inv47.Match.newEmptyMatch(); - } - - @Override - public X_inv47.Match newMatch(final Object... parameters) { - return X_inv47.Match.newMatch((Taxation.Legal_Union_Record) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv47} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv47#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv47 INSTANCE = new X_inv47(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv47.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_lur = new PParameter("lur", "Taxation.Legal_Union_Record", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Legal_Union_Record")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_lur); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv47"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("lur"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_lur = body.getOrCreateVariableByName("lur"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_lur, parameter_lur) - )); - // Legal_Union_Record.separation_cause(lur, ::NONE) - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new ConstantValue(body, var__virtual_0_, getEnumLiteral("http:///TaxCard.ecore", "Separation_Causes", "NONE").getInstance()); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "separation_cause"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http:///TaxCard.ecore", "Separation_Causes"))); - new Equality(body, var__virtual_1_, var__virtual_0_); - // Legal_Union_Record.end_year(lur, -1) - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new ConstantValue(body, var__virtual_2_, -1); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "end_year"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); - new Equality(body, var__virtual_3_, var__virtual_2_); - bodies.add(body); - } - return bodies; - } - } - - private static int evaluateExpression_1_1() { - return 1; - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_3.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_3.java deleted file mode 100644 index 913e9c7e..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_3.java +++ /dev/null @@ -1,555 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Physical_Person; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv48_3(p : Physical_Person) {
- *             Physical_Person.disability_type(p, ::NONE);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv48_3 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv48_3 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Physical_Person fP; - - private static List parameterNames = makeImmutableList("p"); - - private Match(final Physical_Person pP) { - this.fP = pP; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "p": return this.fP; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fP; - default: return null; - } - } - - public Physical_Person getP() { - return this.fP; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("p".equals(parameterName) ) { - this.fP = (Physical_Person) newValue; - return true; - } - return false; - } - - public void setP(final Physical_Person pP) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fP = pP; - } - - @Override - public String patternName() { - return "queries.x_inv48_3"; - } - - @Override - public List parameterNames() { - return X_inv48_3.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fP}; - } - - @Override - public X_inv48_3.Match toImmutable() { - return isMutable() ? newMatch(fP) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"p\"=" + prettyPrintValue(fP)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fP); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv48_3.Match)) { - X_inv48_3.Match other = (X_inv48_3.Match) obj; - return Objects.equals(fP, other.fP); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv48_3 specification() { - return X_inv48_3.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv48_3.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv48_3.Match newMutableMatch(final Physical_Person pP) { - return new Mutable(pP); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv48_3.Match newMatch(final Physical_Person pP) { - return new Immutable(pP); - } - - private static final class Mutable extends X_inv48_3.Match { - Mutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv48_3.Match { - Immutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv48_3 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv48_3(p : Physical_Person) {
-   *     Physical_Person.disability_type(p, ::NONE);
-   * }
-   * 
- * - * @see Match - * @see X_inv48_3 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv48_3.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv48_3.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_P = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv48_3.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Physical_Person pP) { - return rawGetOneArbitraryMatch(new Object[]{pP}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Physical_Person pP) { - return rawHasMatch(new Object[]{pP}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Physical_Person pP) { - return rawCountMatches(new Object[]{pP}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pP}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv48_3.Match newMatch(final Physical_Person pP) { - return X_inv48_3.Match.newMatch(pP); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfp(final Object[] parameters) { - return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()); - } - - @Override - protected X_inv48_3.Match tupleToMatch(final Tuple t) { - try { - return X_inv48_3.Match.newMatch((Physical_Person) t.get(POSITION_P)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv48_3.Match arrayToMatch(final Object[] match) { - try { - return X_inv48_3.Match.newMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv48_3.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv48_3.Match.newMutableMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv48_3.instance(); - } - } - - private X_inv48_3() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv48_3 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv48_3.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv48_3.Matcher.on(engine); - } - - @Override - public X_inv48_3.Matcher instantiate() { - return X_inv48_3.Matcher.create(); - } - - @Override - public X_inv48_3.Match newEmptyMatch() { - return X_inv48_3.Match.newEmptyMatch(); - } - - @Override - public X_inv48_3.Match newMatch(final Object... parameters) { - return X_inv48_3.Match.newMatch((Taxation.Physical_Person) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv48_3} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv48_3#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv48_3 INSTANCE = new X_inv48_3(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv48_3.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_p); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv48_3"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("p"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_p = body.getOrCreateVariableByName("p"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_p, parameter_p) - )); - // Physical_Person.disability_type(p, ::NONE) - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new ConstantValue(body, var__virtual_0_, getEnumLiteral("http:///TaxCard.ecore", "Disability_Types", "NONE").getInstance()); - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "disability_type"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http:///TaxCard.ecore", "Disability_Types"))); - new Equality(body, var__virtual_1_, var__virtual_0_); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_Dis.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_Dis.java deleted file mode 100644 index 08de1250..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_Dis.java +++ /dev/null @@ -1,610 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Physical_Person; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; -import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; -import queries.X_inv48_3; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv48_Dis(p : Physical_Person) {
- *         	neg find x_inv48_3(p);
- *         	Physical_Person.disability_percentage(p, disPer);
- *             check(disPer {@literal >} 0.0);
- *             check(disPer {@literal <}= 1.0);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv48_Dis extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv48_Dis pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Physical_Person fP; - - private static List parameterNames = makeImmutableList("p"); - - private Match(final Physical_Person pP) { - this.fP = pP; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "p": return this.fP; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fP; - default: return null; - } - } - - public Physical_Person getP() { - return this.fP; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("p".equals(parameterName) ) { - this.fP = (Physical_Person) newValue; - return true; - } - return false; - } - - public void setP(final Physical_Person pP) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fP = pP; - } - - @Override - public String patternName() { - return "queries.x_inv48_Dis"; - } - - @Override - public List parameterNames() { - return X_inv48_Dis.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fP}; - } - - @Override - public X_inv48_Dis.Match toImmutable() { - return isMutable() ? newMatch(fP) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"p\"=" + prettyPrintValue(fP)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fP); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv48_Dis.Match)) { - X_inv48_Dis.Match other = (X_inv48_Dis.Match) obj; - return Objects.equals(fP, other.fP); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv48_Dis specification() { - return X_inv48_Dis.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv48_Dis.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv48_Dis.Match newMutableMatch(final Physical_Person pP) { - return new Mutable(pP); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv48_Dis.Match newMatch(final Physical_Person pP) { - return new Immutable(pP); - } - - private static final class Mutable extends X_inv48_Dis.Match { - Mutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv48_Dis.Match { - Immutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv48_Dis pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv48_Dis(p : Physical_Person) {
-   * 	neg find x_inv48_3(p);
-   * 	Physical_Person.disability_percentage(p, disPer);
-   *     check(disPer {@literal >} 0.0);
-   *     check(disPer {@literal <}= 1.0);
-   * }
-   * 
- * - * @see Match - * @see X_inv48_Dis - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv48_Dis.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv48_Dis.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_P = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv48_Dis.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Physical_Person pP) { - return rawGetOneArbitraryMatch(new Object[]{pP}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Physical_Person pP) { - return rawHasMatch(new Object[]{pP}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Physical_Person pP) { - return rawCountMatches(new Object[]{pP}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pP}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv48_Dis.Match newMatch(final Physical_Person pP) { - return X_inv48_Dis.Match.newMatch(pP); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfp(final Object[] parameters) { - return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()); - } - - @Override - protected X_inv48_Dis.Match tupleToMatch(final Tuple t) { - try { - return X_inv48_Dis.Match.newMatch((Physical_Person) t.get(POSITION_P)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv48_Dis.Match arrayToMatch(final Object[] match) { - try { - return X_inv48_Dis.Match.newMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv48_Dis.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv48_Dis.Match.newMutableMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv48_Dis.instance(); - } - } - - private X_inv48_Dis() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv48_Dis instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv48_Dis.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv48_Dis.Matcher.on(engine); - } - - @Override - public X_inv48_Dis.Matcher instantiate() { - return X_inv48_Dis.Matcher.create(); - } - - @Override - public X_inv48_Dis.Match newEmptyMatch() { - return X_inv48_Dis.Match.newEmptyMatch(); - } - - @Override - public X_inv48_Dis.Match newMatch(final Object... parameters) { - return X_inv48_Dis.Match.newMatch((Taxation.Physical_Person) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv48_Dis} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv48_Dis#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv48_Dis INSTANCE = new X_inv48_Dis(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv48_Dis.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_p); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv48_Dis"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("p"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_p = body.getOrCreateVariableByName("p"); - PVariable var_disPer = body.getOrCreateVariableByName("disPer"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_p, parameter_p) - )); - // neg find x_inv48_3(p) - new NegativePatternCall(body, Tuples.flatTupleOf(var_p), X_inv48_3.instance().getInternalQueryRepresentation()); - // Physical_Person.disability_percentage(p, disPer) - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "disability_percentage"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_0_, var_disPer); - // check(disPer > 0.0) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern x_inv48_Dis"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("disPer");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Double disPer = (Double) provider.getValue("disPer"); - return evaluateExpression_1_1(disPer); - } - }, null); - // check(disPer <= 1.0) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern x_inv48_Dis"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("disPer");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Double disPer = (Double) provider.getValue("disPer"); - return evaluateExpression_1_2(disPer); - } - }, null); - bodies.add(body); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Double disPer) { - return ((disPer).doubleValue() > 0.0); - } - - private static boolean evaluateExpression_1_2(final Double disPer) { - return ((disPer).doubleValue() <= 1.0); - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_notDis.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_notDis.java deleted file mode 100644 index 21dcc068..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv48_notDis.java +++ /dev/null @@ -1,569 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Physical_Person; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv48_notDis(p : Physical_Person) {
- *             Physical_Person.disability_type(p, ::NONE);
- *             Physical_Person.disability_percentage(p, 0.0);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv48_notDis extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv48_notDis pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Physical_Person fP; - - private static List parameterNames = makeImmutableList("p"); - - private Match(final Physical_Person pP) { - this.fP = pP; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "p": return this.fP; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fP; - default: return null; - } - } - - public Physical_Person getP() { - return this.fP; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("p".equals(parameterName) ) { - this.fP = (Physical_Person) newValue; - return true; - } - return false; - } - - public void setP(final Physical_Person pP) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fP = pP; - } - - @Override - public String patternName() { - return "queries.x_inv48_notDis"; - } - - @Override - public List parameterNames() { - return X_inv48_notDis.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fP}; - } - - @Override - public X_inv48_notDis.Match toImmutable() { - return isMutable() ? newMatch(fP) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"p\"=" + prettyPrintValue(fP)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fP); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv48_notDis.Match)) { - X_inv48_notDis.Match other = (X_inv48_notDis.Match) obj; - return Objects.equals(fP, other.fP); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv48_notDis specification() { - return X_inv48_notDis.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv48_notDis.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv48_notDis.Match newMutableMatch(final Physical_Person pP) { - return new Mutable(pP); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv48_notDis.Match newMatch(final Physical_Person pP) { - return new Immutable(pP); - } - - private static final class Mutable extends X_inv48_notDis.Match { - Mutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv48_notDis.Match { - Immutable(final Physical_Person pP) { - super(pP); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv48_notDis pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv48_notDis(p : Physical_Person) {
-   *     Physical_Person.disability_type(p, ::NONE);
-   *     Physical_Person.disability_percentage(p, 0.0);
-   * }
-   * 
- * - * @see Match - * @see X_inv48_notDis - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv48_notDis.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv48_notDis.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_P = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv48_notDis.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Physical_Person pP) { - return rawStreamAllMatches(new Object[]{pP}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Physical_Person pP) { - return rawGetOneArbitraryMatch(new Object[]{pP}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Physical_Person pP) { - return rawHasMatch(new Object[]{pP}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Physical_Person pP) { - return rawCountMatches(new Object[]{pP}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Physical_Person pP, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pP}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pP the fixed value of pattern parameter p, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv48_notDis.Match newMatch(final Physical_Person pP) { - return X_inv48_notDis.Match.newMatch(pP); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfp(final Object[] parameters) { - return rawStreamAllValues(POSITION_P, parameters).map(Physical_Person.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for p. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfp() { - return rawStreamAllValuesOfp(emptyArray()); - } - - @Override - protected X_inv48_notDis.Match tupleToMatch(final Tuple t) { - try { - return X_inv48_notDis.Match.newMatch((Physical_Person) t.get(POSITION_P)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv48_notDis.Match arrayToMatch(final Object[] match) { - try { - return X_inv48_notDis.Match.newMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv48_notDis.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv48_notDis.Match.newMutableMatch((Physical_Person) match[POSITION_P]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv48_notDis.instance(); - } - } - - private X_inv48_notDis() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv48_notDis instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv48_notDis.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv48_notDis.Matcher.on(engine); - } - - @Override - public X_inv48_notDis.Matcher instantiate() { - return X_inv48_notDis.Matcher.create(); - } - - @Override - public X_inv48_notDis.Match newEmptyMatch() { - return X_inv48_notDis.Match.newEmptyMatch(); - } - - @Override - public X_inv48_notDis.Match newMatch(final Object... parameters) { - return X_inv48_notDis.Match.newMatch((Taxation.Physical_Person) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv48_notDis} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv48_notDis#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv48_notDis INSTANCE = new X_inv48_notDis(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv48_notDis.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_p = new PParameter("p", "Taxation.Physical_Person", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Physical_Person")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_p); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv48_notDis"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("p"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_p = body.getOrCreateVariableByName("p"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_p, parameter_p) - )); - // Physical_Person.disability_type(p, ::NONE) - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new ConstantValue(body, var__virtual_0_, getEnumLiteral("http:///TaxCard.ecore", "Disability_Types", "NONE").getInstance()); - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "disability_type"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http:///TaxCard.ecore", "Disability_Types"))); - new Equality(body, var__virtual_1_, var__virtual_0_); - // Physical_Person.disability_percentage(p, 0.0) - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new ConstantValue(body, var__virtual_2_, 0.0); - new TypeConstraint(body, Tuples.flatTupleOf(var_p), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_p, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Physical_Person", "disability_percentage"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EDouble"))); - new Equality(body, var__virtual_3_, var__virtual_2_); - bodies.add(body); - } - return bodies; - } - } - - private static double evaluateExpression_1_1() { - return 0.0; - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_1.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_1.java deleted file mode 100644 index 67915440..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_1.java +++ /dev/null @@ -1,579 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Legal_Union_Record; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; -import queries.X_inv49_2; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv49_1(lur : Legal_Union_Record) {
- *         	Legal_Union_Record.individual_A(lur, iA);
- *         	Legal_Union_Record.individual_B(lur, iB);
- *             Tax_Payer(iA);
- *             Physical_Person(iB);
- *             neg find x_inv49_2(iB);
- *             iA != iB;
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv49_1 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv49_1 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Legal_Union_Record fLur; - - private static List parameterNames = makeImmutableList("lur"); - - private Match(final Legal_Union_Record pLur) { - this.fLur = pLur; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "lur": return this.fLur; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fLur; - default: return null; - } - } - - public Legal_Union_Record getLur() { - return this.fLur; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("lur".equals(parameterName) ) { - this.fLur = (Legal_Union_Record) newValue; - return true; - } - return false; - } - - public void setLur(final Legal_Union_Record pLur) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fLur = pLur; - } - - @Override - public String patternName() { - return "queries.x_inv49_1"; - } - - @Override - public List parameterNames() { - return X_inv49_1.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fLur}; - } - - @Override - public X_inv49_1.Match toImmutable() { - return isMutable() ? newMatch(fLur) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"lur\"=" + prettyPrintValue(fLur)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fLur); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv49_1.Match)) { - X_inv49_1.Match other = (X_inv49_1.Match) obj; - return Objects.equals(fLur, other.fLur); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv49_1 specification() { - return X_inv49_1.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv49_1.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv49_1.Match newMutableMatch(final Legal_Union_Record pLur) { - return new Mutable(pLur); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv49_1.Match newMatch(final Legal_Union_Record pLur) { - return new Immutable(pLur); - } - - private static final class Mutable extends X_inv49_1.Match { - Mutable(final Legal_Union_Record pLur) { - super(pLur); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv49_1.Match { - Immutable(final Legal_Union_Record pLur) { - super(pLur); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv49_1 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv49_1(lur : Legal_Union_Record) {
-   * 	Legal_Union_Record.individual_A(lur, iA);
-   * 	Legal_Union_Record.individual_B(lur, iB);
-   *     Tax_Payer(iA);
-   *     Physical_Person(iB);
-   *     neg find x_inv49_2(iB);
-   *     iA != iB;
-   * }
-   * 
- * - * @see Match - * @see X_inv49_1 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv49_1.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv49_1.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_LUR = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv49_1.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Legal_Union_Record pLur) { - return rawStreamAllMatches(new Object[]{pLur}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Legal_Union_Record pLur) { - return rawStreamAllMatches(new Object[]{pLur}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Legal_Union_Record pLur) { - return rawGetOneArbitraryMatch(new Object[]{pLur}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Legal_Union_Record pLur) { - return rawHasMatch(new Object[]{pLur}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Legal_Union_Record pLur) { - return rawCountMatches(new Object[]{pLur}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Legal_Union_Record pLur, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pLur}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pLur the fixed value of pattern parameter lur, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv49_1.Match newMatch(final Legal_Union_Record pLur) { - return X_inv49_1.Match.newMatch(pLur); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOflur(final Object[] parameters) { - return rawStreamAllValues(POSITION_LUR, parameters).map(Legal_Union_Record.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOflur() { - return rawStreamAllValuesOflur(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for lur. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOflur() { - return rawStreamAllValuesOflur(emptyArray()); - } - - @Override - protected X_inv49_1.Match tupleToMatch(final Tuple t) { - try { - return X_inv49_1.Match.newMatch((Legal_Union_Record) t.get(POSITION_LUR)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv49_1.Match arrayToMatch(final Object[] match) { - try { - return X_inv49_1.Match.newMatch((Legal_Union_Record) match[POSITION_LUR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv49_1.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv49_1.Match.newMutableMatch((Legal_Union_Record) match[POSITION_LUR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv49_1.instance(); - } - } - - private X_inv49_1() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv49_1 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv49_1.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv49_1.Matcher.on(engine); - } - - @Override - public X_inv49_1.Matcher instantiate() { - return X_inv49_1.Matcher.create(); - } - - @Override - public X_inv49_1.Match newEmptyMatch() { - return X_inv49_1.Match.newEmptyMatch(); - } - - @Override - public X_inv49_1.Match newMatch(final Object... parameters) { - return X_inv49_1.Match.newMatch((Taxation.Legal_Union_Record) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv49_1} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv49_1#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv49_1 INSTANCE = new X_inv49_1(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv49_1.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_lur = new PParameter("lur", "Taxation.Legal_Union_Record", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Legal_Union_Record")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_lur); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv49_1"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("lur"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_lur = body.getOrCreateVariableByName("lur"); - PVariable var_iA = body.getOrCreateVariableByName("iA"); - PVariable var_iB = body.getOrCreateVariableByName("iB"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_lur, parameter_lur) - )); - // Legal_Union_Record.individual_A(lur, iA) - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "individual_A"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - new Equality(body, var__virtual_0_, var_iA); - // Legal_Union_Record.individual_B(lur, iB) - new TypeConstraint(body, Tuples.flatTupleOf(var_lur), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Legal_Union_Record"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_lur, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http:///TaxCard.ecore", "Legal_Union_Record", "individual_B"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - new Equality(body, var__virtual_1_, var_iB); - // Tax_Payer(iA) - new TypeConstraint(body, Tuples.flatTupleOf(var_iA), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Tax_Payer"))); - // Physical_Person(iB) - new TypeConstraint(body, Tuples.flatTupleOf(var_iB), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Physical_Person"))); - // neg find x_inv49_2(iB) - new NegativePatternCall(body, Tuples.flatTupleOf(var_iB), X_inv49_2.instance().getInternalQueryRepresentation()); - // iA != iB - new Inequality(body, var_iA, var_iB); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_2.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_2.java deleted file mode 100644 index 66decdb4..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src-gen/queries/X_inv49_2.java +++ /dev/null @@ -1,544 +0,0 @@ -/** - * Generated from platform:/resource/case.study.pledge.run/src/queries/case_study_A.vql - */ -package queries; - -import Taxation.Dependent; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; -import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; -import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern x_inv49_2(iB: Dependent) {
- *             Dependent(iB);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class X_inv49_2 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the queries.x_inv49_2 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Dependent fIB; - - private static List parameterNames = makeImmutableList("iB"); - - private Match(final Dependent pIB) { - this.fIB = pIB; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "iB": return this.fIB; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fIB; - default: return null; - } - } - - public Dependent getIB() { - return this.fIB; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("iB".equals(parameterName) ) { - this.fIB = (Dependent) newValue; - return true; - } - return false; - } - - public void setIB(final Dependent pIB) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fIB = pIB; - } - - @Override - public String patternName() { - return "queries.x_inv49_2"; - } - - @Override - public List parameterNames() { - return X_inv49_2.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fIB}; - } - - @Override - public X_inv49_2.Match toImmutable() { - return isMutable() ? newMatch(fIB) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"iB\"=" + prettyPrintValue(fIB)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fIB); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof X_inv49_2.Match)) { - X_inv49_2.Match other = (X_inv49_2.Match) obj; - return Objects.equals(fIB, other.fIB); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public X_inv49_2 specification() { - return X_inv49_2.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static X_inv49_2.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pIB the fixed value of pattern parameter iB, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static X_inv49_2.Match newMutableMatch(final Dependent pIB) { - return new Mutable(pIB); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pIB the fixed value of pattern parameter iB, or null if not bound. - * @return the (partial) match object. - * - */ - public static X_inv49_2.Match newMatch(final Dependent pIB) { - return new Immutable(pIB); - } - - private static final class Mutable extends X_inv49_2.Match { - Mutable(final Dependent pIB) { - super(pIB); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends X_inv49_2.Match { - Immutable(final Dependent pIB) { - super(pIB); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the queries.x_inv49_2 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern x_inv49_2(iB: Dependent) {
-   *     Dependent(iB);
-   * }
-   * 
- * - * @see Match - * @see X_inv49_2 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static X_inv49_2.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static X_inv49_2.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_IB = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(X_inv49_2.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pIB the fixed value of pattern parameter iB, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Dependent pIB) { - return rawStreamAllMatches(new Object[]{pIB}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pIB the fixed value of pattern parameter iB, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Dependent pIB) { - return rawStreamAllMatches(new Object[]{pIB}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pIB the fixed value of pattern parameter iB, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Dependent pIB) { - return rawGetOneArbitraryMatch(new Object[]{pIB}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pIB the fixed value of pattern parameter iB, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Dependent pIB) { - return rawHasMatch(new Object[]{pIB}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pIB the fixed value of pattern parameter iB, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Dependent pIB) { - return rawCountMatches(new Object[]{pIB}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pIB the fixed value of pattern parameter iB, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Dependent pIB, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pIB}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pIB the fixed value of pattern parameter iB, or null if not bound. - * @return the (partial) match object. - * - */ - public X_inv49_2.Match newMatch(final Dependent pIB) { - return X_inv49_2.Match.newMatch(pIB); - } - - /** - * Retrieve the set of values that occur in matches for iB. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfiB(final Object[] parameters) { - return rawStreamAllValues(POSITION_IB, parameters).map(Dependent.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for iB. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfiB() { - return rawStreamAllValuesOfiB(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for iB. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfiB() { - return rawStreamAllValuesOfiB(emptyArray()); - } - - @Override - protected X_inv49_2.Match tupleToMatch(final Tuple t) { - try { - return X_inv49_2.Match.newMatch((Dependent) t.get(POSITION_IB)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected X_inv49_2.Match arrayToMatch(final Object[] match) { - try { - return X_inv49_2.Match.newMatch((Dependent) match[POSITION_IB]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected X_inv49_2.Match arrayToMatchMutable(final Object[] match) { - try { - return X_inv49_2.Match.newMutableMatch((Dependent) match[POSITION_IB]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return X_inv49_2.instance(); - } - } - - private X_inv49_2() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static X_inv49_2 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected X_inv49_2.Matcher instantiate(final ViatraQueryEngine engine) { - return X_inv49_2.Matcher.on(engine); - } - - @Override - public X_inv49_2.Matcher instantiate() { - return X_inv49_2.Matcher.create(); - } - - @Override - public X_inv49_2.Match newEmptyMatch() { - return X_inv49_2.Match.newEmptyMatch(); - } - - @Override - public X_inv49_2.Match newMatch(final Object... parameters) { - return X_inv49_2.Match.newMatch((Taxation.Dependent) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link X_inv49_2} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link X_inv49_2#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final X_inv49_2 INSTANCE = new X_inv49_2(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final X_inv49_2.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_iB = new PParameter("iB", "Taxation.Dependent", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http:///TaxCard.ecore", "Dependent")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_iB); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "queries.x_inv49_2"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("iB"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_iB = body.getOrCreateVariableByName("iB"); - new TypeConstraint(body, Tuples.flatTupleOf(var_iB), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_iB, parameter_iB) - )); - // Dependent(iB) - new TypeConstraint(body, Tuples.flatTupleOf(var_iB), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http:///TaxCard.ecore", "Dependent"))); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/NewOCLFileX.ocl b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/NewOCLFileX.ocl deleted file mode 100644 index 66ae728e..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/NewOCLFileX.ocl +++ /dev/null @@ -1,45 +0,0 @@ -import 'file:/Users/Aren Babikian/git/VIATRA-Attributes/case.study.a.model/model/Taxation.ecore' - -package Taxation - ---context Income inv inv8: ---if(not self.income_type.oclIsTypeOf(Employment_Income)) then ---self.details->forAll(d| d.distance = 0) ---else ---self.details->forAll(d| d.distance >= 0.0 and d.distance <= 100) ---endif --- ---context Legal_Union_Record inv inv490: ---self.individual_A.oclIsKindOf(Tax_Payer) --- ---context Legal_Union_Record inv inv491: ---self.individual_B->forAll(i | i.oclIsKindOf(Physical_Person) ) --- ---context Legal_Union_Record inv inv492: ---self.individual_B->forAll(i | not i.oclIsTypeOf(Dependent) ) --- ---context Legal_Union_Record inv inv493: ---self.individual_A <> self.individual_B --- ---context Tax_Payer inv inv13: --- self.addresses->exists( hab_add:Address | hab_add.oclIsTypeOf(Habitual_Address) = true and hab_add.country=Country::ZZ) ---implies --- self.oclIsTypeOf(Resident_Tax_Payer) - - context Income inv inv7: -let val:Real =self.details->asOrderedSet()->first().distance in -self.details->forAll(d: Income_Detail|d.distance = val) - ---context External_Allowance inv inv15: ---let child:Dependent = self.person in ---let h:Household = Household.allInstances()->select(children->includes(child))->asOrderedSet()->first() in ---let t1:Set(Physical_Person) = Set{h.parents.individual_A}->union(h.parents.individual_B)->select(oclIsKindOf(Tax_Payer)) in ---if(t1->size()=1) then ---self.reciver = t1->asOrderedSet()->first() ---else ---self.reciver = t1->asOrderedSet()->at(2) or self.reciver = t1->asOrderedSet()->at(1) ---endif - - - -endpackage \ No newline at end of file diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/case_study_A.vql b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/case_study_A.vql deleted file mode 100644 index 5d46bf42..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/case_study_A.vql +++ /dev/null @@ -1,334 +0,0 @@ -package queries - -import "http:///TaxCard.ecore" - -//AttributeRemoved -> DF - -//inv1-External_Allowance.amount is a derived feature (TODOcheck) -//inv2-Tax_Card.income.taxPayer.taxesDue is a derived feature (TODOcheck) - -//inv3-multiplicity adjusted -@Constraint(message = "inv03", severity = "error", key = {dep}) -pattern inv03(dep : Dependent) { - find x_inv03_eligAll(dep); - neg find x_inv03_hasAll(dep); -} or { - Dependent.birth_year(dep, by); - check(2018-by > 21); - Dependent.continued_studies(dep, false); - Dependent.allowances(dep, _); -} -pattern x_inv03_eligAll(dep : Dependent) { - Dependent.birth_year(dep, by); - check(2018-by <= 21); -} or { - Dependent.continued_studies(dep, true); -} -pattern x_inv03_hasAll(dep : Dependent) { - Dependent.allowances(dep, _); -} - -//inv5 - oclIsTypeOf - handled here -@Constraint(message = "inv05", severity = "error", key = {inc}) -pattern inv05(inc : Income) { - //income_type: None - neg find x_inv08_noType(inc); - Income.details.worked_days(inc, wd); - check(wd != 0); -} or { - //income_type: Not Employment_Income - Income.income_type(inc, type); - neg find x_inv08_notEI(type); - Income.details.worked_days(inc, wd); - check(wd != 0); -} or { - //income_type: Employment Income - Income.income_type(inc, type); - Employment_Income(type); - find x_inv05_inRange(inc); -} -pattern x_inv05_inRange(inc : Income) { - Income.details.worked_days(inc, wd); - check(wd < 1); -} or { - Income.details.worked_days(inc, wd); - check(wd > 25); -} - -//inv6-Does not make sens, but directly from OCL -//first part of or from definition of getAge() -@Constraint(message = "inv06", severity = "error", key = {tp}) -pattern inv06(tp : Tax_Payer) { - Tax_Payer.dependents(tp, _); - Tax_Payer.birth_year(tp, TPBy); - check(2018 - TPBy > 2018-16); -} or { - Tax_Payer.birth_year(tp, TPBy); - Tax_Payer.dependents(tp, dep); - Dependent.birth_year(dep, DepBy); - check(2018-DepBy <= 2018-TPBy-16); -} - -//inv7-OrderedSet -@Constraint(message = "inv07", severity = "error", key = {inc}) -pattern inv07(inc : Income) { - Income.details.distance(inc, d1); - Income.details.distance(inc, d2); - check(d1 != d2);//compare values -} - -//user_complete_details-AttributeRemoved - -//inv8 - oclIsTypeOf - handled here -@Constraint(message = "inv08", severity = "error", key = {inc}) -pattern inv08(inc : Income) { - //income_type: None - neg find x_inv08_noType(inc); - Income.details.distance(inc, dist); - check(dist != 0); -} or { - //income_type: Not Employment_Income - Income.income_type(inc, type); - neg find x_inv08_notEI(type); - Income.details.distance(inc, dist); - check(dist != 0); -} or { - //income_type: Employment Income - Income.income_type(inc, type); - Employment_Income(type); - find x_inv08_inRange(inc); -} -pattern x_inv08_notEI(type : Employment_Income) { - Employment_Income(type); -} -pattern x_inv08_noType(inc : Income) { - Income.income_type(inc, _); -} -pattern x_inv08_inRange(inc : Income) { - Income.details.distance(inc, dist); - check(dist < 0); -} or { - Income.details.distance(inc, dist); - check(dist > 100); -} -//inv9-DerivedFeature - -//inv10-Ordered Sets -@Constraint(message = "inv10", severity = "error", key = {inc}) -pattern inv10(inc : Income) { - Income.details.amount(inc, a1); - Income.details.amount(inc, a2); - check(a1 != a2);//compare values -} - -//inv11-attributes-handled by multiplicity -@Constraint(message = "inv11", severity = "error", key = {exp}) -pattern inv11(exp : Expense) { - find x_inv11_incOver100(exp); - find x_inv11_incNotOver100(exp); -} -pattern x_inv11_incOver100(exp : Expense) { - Expense.income.income_amount(exp, incVal); - check(incVal / 2 > 50); - -} or { - Expense.declared_amount(exp, decl); - check(decl != 50); -} -pattern x_inv11_incNotOver100(exp : Expense) { - Expense.income.income_amount(exp, incVal); - check(incVal / 2 <= 50); -} or { - Expense.declared_amount(exp, decl); - check(decl < 50); -} or { - Expense.income.income_amount(exp, incVal); - Expense.declared_amount(exp, decl); - check(decl > incVal/2); -} - -//inv12 -//exists - handled logically -@Constraint(message = "inv12", severity = "error", key = {tp}) -pattern inv12(tp : Tax_Payer) { - Tax_Payer.addresses(tp, hab_add); - Habitual_Address(hab_add); - neg find x_inv12_notZZ(hab_add); - Tax_Payer.incomes(tp, inc); - Local_Income(inc); - neg find x_inv12_notNonRes(tp); -} -pattern x_inv12_notNonRes(tp : Non_Resident_Tax_Payer) { - Non_Resident_Tax_Payer(tp); -} -pattern x_inv12_notZZ(hab_add : Habitual_Address) { - Address.country(hab_add, ::ZZ); -} - -//inv13 - Added new containment rel Phys_Pers->Address -//exists - handled logically -@Constraint(message = "inv13", severity = "error", key = {tp}) -pattern inv13(tp : Tax_Payer) { - Tax_Payer.addresses(tp, hab_add); - Habitual_Address(hab_add); - Address.country(hab_add, ::ZZ); - neg find x_inv13(tp); -} -pattern x_inv13(tp : Resident_Tax_Payer) { - Resident_Tax_Payer(tp); -} - -//inv14-MultiplicityChanged - -//inv15-Ordered Sets in assignment if block -//ERROR if no household object -@Constraint(message = "inv15", severity = "error", key = {ea}) -pattern inv15(ea : External_Allowance) { - neg find x_inv15(ea); -} -pattern x_inv15(ea : External_Allowance) { - External_Allowance.person(ea, child); - Household.children(h, child);//only one due to multiplicity - Household.parents.individual_A(h, iA); - Tax_Payer(iA); - External_Allowance.reciver(ea, iA); -} or { - External_Allowance.person(ea, child); - Household.children(h, child);//only one due to multiplicity - Household.parents.individual_B(h, iB); - Tax_Payer(iB); - External_Allowance.reciver(ea, iB); -} - -//inv16-Tax_Card.tax_card_type is a derived feature - -//inv17-attribute-handled by multiplicity -@Constraint(message = "inv17", severity = "error", key = {lur}) -pattern inv17(lur : Legal_Union_Record) { - Legal_Union_Record.start_year(lur, sy); - check(sy < 1950); -} or { - Legal_Union_Record.start_year(lur, sy); - check(sy > 2018); -} - -//inv18-MultiplicityChecked -//inv19-MultiplicityChecked - -//inv20-Useless constraint since both edges are containment (TODOCheck) -//OclIsUndefined-Handled by multiplicity -@Constraint(message = "inv20", severity = "error", key = {lur}) -pattern inv20(lur : Legal_Union_Record) { - Legal_Union_Record.individual_A(lur, iA); - Legal_Union_Record.individual_B(lur, iB); - iA == iB; -} -//inv21-MultiplicityChecked -//inv22-MultiplicityChecked -//inv23-MultiplicityChecked -//inv24-MultiplicityChecked -//inv25-MultiplicityChecked -//inv26-MultiplicityChanged -//inv27-dupOfInv24 -//inv28-dubOfInv23 -//inv29-MultiplicityChanged -//inv30-AttributeRemoved -//inv31-AttributeRemoved -//inv32-AttributeRemoved - -//inv33-attribute-handled by multiplicity -@Constraint(message = "inv33", severity = "error", key = {p}) -pattern inv33(p : Physical_Person) { - Physical_Person.birth_year(p, by); - check(2018-by < 0); -} or { - Physical_Person.birth_year(p, by); - check(2018-by > 100); -} - -//inv34-attribute-handled by multiplicity -@Constraint(message = "inv34", severity = "error", key = {p}) -pattern inv34(p : Physical_Person) { - Physical_Person.birth_month(p, birthMonth); - check(birthMonth < 1); -} or { - Physical_Person.birth_month(p, birthMonth); - check(birthMonth > 12); -} - -//inv35-attribute-handled by multiplicity -@Constraint(message = "inv35", severity = "error", key = {p}) -pattern inv35(p : Physical_Person) { - Physical_Person.birth_day(p, birthDay); - check(birthDay < 1); -} or { - Physical_Person.birth_day(p, birthDay); - check(birthDay > 28); -} - -//inv36-AttributeRemoved -//inv37-AttributeRemoved -//inv38-AttributeRemoved -//inv39-AttributeRemoved -//inv40-AttributeRemoved -//inv41-AttributeRemoved -//inv42-AttributeRemoved -//inv43-AttributeRemoved -//inv44-AttributeRemoved -//inv45-AttributeRemoved -//inv46-AttributeRemoved - -//inv47-attributes-handled by multiplicity -@Constraint(message = "inv47", severity = "error", key = {lur}) -pattern inv47(lur : Legal_Union_Record) { - Legal_Union_Record.end_year(lur, endY); - Legal_Union_Record.start_year(lur, startY); - neg find x_inv47(lur); - check(startY >= endY); -} -pattern x_inv47(lur : Legal_Union_Record) { - Legal_Union_Record.separation_cause(lur, ::NONE); - Legal_Union_Record.end_year(lur, -1); -} - -//inv48-attributes-handled by multiplicity -@Constraint(message = "inv48", severity = "error", key = {p}) -pattern inv48(p : Physical_Person) { - neg find x_inv48_notDis(p); - neg find x_inv48_Dis(p); -} -pattern x_inv48_notDis(p : Physical_Person) { - Physical_Person.disability_type(p, ::NONE); - Physical_Person.disability_percentage(p, 0.0); -} -pattern x_inv48_Dis(p : Physical_Person) { - neg find x_inv48_3(p); - Physical_Person.disability_percentage(p, disPer); - check(disPer > 0.0); - check(disPer <= 1.0); -} -pattern x_inv48_3(p : Physical_Person) { - Physical_Person.disability_type(p, ::NONE); -} - -//inv49-OclKindOf-handled by multiplicity -@Constraint(message = "inv49", severity = "error", key = {lur}) -pattern inv49(lur : Legal_Union_Record) { - neg find x_inv49_1(lur); -} -pattern x_inv49_1(lur : Legal_Union_Record) { - Legal_Union_Record.individual_A(lur, iA); - Legal_Union_Record.individual_B(lur, iB); - Tax_Payer(iA); - Physical_Person(iB); - neg find x_inv49_2(iB); - iA != iB; -} -pattern x_inv49_2(iB: Dependent) { - Dependent(iB); -} - -//inv50-MultiplicityChecked -//inv51-MultiplicityChecked -//inv52-MultiplicityChecked -//inv53-MultiplicityChecked \ No newline at end of file diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/run/RunGenerator.xtend b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/run/RunGenerator.xtend deleted file mode 100644 index 8bd70919..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/run/RunGenerator.xtend +++ /dev/null @@ -1,151 +0,0 @@ -package run - -import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic -import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration -import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace -import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor -import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type -import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult -import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.impl.ModelResultImpl -import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore -import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic -import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration -import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor -import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic -import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner -import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration -import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace -import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace -import java.io.PrintWriter -import java.text.SimpleDateFormat -import java.util.Date -import java.util.HashMap -import java.util.List -import java.util.Map -import org.eclipse.emf.ecore.EAttribute -import org.eclipse.emf.ecore.EClass -import org.eclipse.emf.ecore.EEnum -import org.eclipse.emf.ecore.EEnumLiteral -import org.eclipse.emf.ecore.EObject -import org.eclipse.emf.ecore.EPackage -import org.eclipse.emf.ecore.EReference -import org.eclipse.emf.ecore.resource.Resource -import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl -import org.eclipse.viatra.query.runtime.api.IQueryGroup -import Taxation.TaxationPackage - -class GenerateScenarios { - def static void main(String[] args) { - val Ecore2Logic ecore2Logic = new Ecore2Logic -// val Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic) -// val Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic) -// val InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic - // Workspace setup - val Date date = new Date(System.currentTimeMillis) - val SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); - val formattedDate = format.format(date) - - val workspace = new FileSystemWorkspace('''output/''' + formattedDate + '''/''', "") - workspace.initAndClear - - // Logicproblem writing setup - val reg = Resource.Factory.Registry.INSTANCE - val map = reg.extensionToFactoryMap - map.put("logicproblem", new XMIResourceFactoryImpl) - - println("Input and output workspaces are created") - - print(TaxationPackage.eINSTANCE.getEClassifiers.filter(EClass).toList.get(0)) - - val metamodel = loadMetamodel(TaxationPackage.eINSTANCE) -// val partialModel = loadPartialModel(inputs, "yakindu/Yakindu.xmi") -// val queries = loadQueries(metamodel, Patterns.instance) - println("DSL loaded") - - val SIZE = 10 - var REPS = 1 - - val RUNTIME = 300 - - val modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, new Ecore2LogicConfiguration()) -// var modelExtensionProblem = instanceModel2Logic.transform(modelGenerationProblem, partialModel) -// var validModelExtensionProblem = viatra2Logic.transformQueries(queries, modelExtensionProblem, -// new Viatra2LogicConfiguration) - var problem = modelGenerationProblem.output - workspace.writeModel(problem, "scenario.logicproblem") - println("Problem created") - - for (var i = 0; i <= REPS; i++) { - - var ViatraReasoner reasoner = new ViatraReasoner - - // ///////////////////////////////////////////////////// - // Define Config File - val solverConfig = new ViatraReasonerConfiguration => [ - // add configuration things, in config file first -// it.documentationLevel = DocumentationLevel::FULL -// it.iteration = iter - it.runtimeLimit = RUNTIME - it.typeScopes.maxNewElements = SIZE - it.typeScopes.minNewElements = SIZE - ] - - var solution = reasoner.solve(problem, solverConfig, workspace) - print("Problem Solved") - - // Run Garbage Collector - val Runtime r = Runtime.getRuntime(); - r.gc(); - r.gc(); - r.gc(); - Thread.sleep(3000) - } - - } - - def static Map getTypeMap(Map classMap, EcoreMetamodelDescriptor metamodel, - Ecore2Logic e2l, Ecore2Logic_Trace trace) { - val typeMap = new HashMap - val listMap = metamodel.classes.toMap[s|s.name] - - for (Class elem : classMap.keySet) { - typeMap.put(e2l.TypeofEClass( - trace, - listMap.get(elem.simpleName) - ), classMap.get(elem)) - } - return typeMap - } - - def static loadMetamodel(EPackage pckg) { - val List classes = pckg.getEClassifiers.filter(EClass).toList - val List enums = pckg.getEClassifiers.filter(EEnum).toList - val List literals = enums.map[getELiterals].flatten.toList - val List references = classes.map[getEReferences].flatten.toList - val List attributes = classes.map[getEAttributes].flatten.toList - return new EcoreMetamodelDescriptor(classes, #{}, false, enums, literals, references, attributes) - } - - def static loadPartialModel(ReasonerWorkspace inputs, String path) { - Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()) - inputs.readModel(EObject, path).eResource.contents -// inputs.readModel(EObject,"FamInstance.xmi").eResource.allContents.toList - } - - def static loadQueries(EcoreMetamodelDescriptor metamodel, IQueryGroup i) { - val patterns = i.specifications.toList - val wfPatterns = patterns.filter[it.allAnnotations.exists[it.name == "Constraint"]].toSet - val derivedFeatures = emptyMap - // NO DERIVED FEATURES -// val derivedFeatures = new LinkedHashMap -// derivedFeatures.put(i.type,metamodel.attributes.filter[it.name == "type"].head) -// derivedFeatures.put(i.model,metamodel.references.filter[it.name == "model"].head) - val res = new ViatraQuerySetDescriptor( - patterns, - wfPatterns, - derivedFeatures - ) - return res - } - -} diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.RunGenerator.xtendbin b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.RunGenerator.xtendbin deleted file mode 100644 index e2021169..00000000 Binary files a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.RunGenerator.xtendbin and /dev/null differ diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.gitignore b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.gitignore deleted file mode 100644 index 8e503b4a..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/.GenerateScenarios.java._trace -/.checkQueries.java._trace -/.RunGenerator.xtendbin -/GenerateScenarios.java diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/GenerateScenarios.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/GenerateScenarios.java deleted file mode 100644 index 7ec45124..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/GenerateScenarios.java +++ /dev/null @@ -1,165 +0,0 @@ -package run; - -import Taxation.TaxationPackage; -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; -import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration; -import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; -import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor; -import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput; -import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; -import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem; -import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult; -import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor; -import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner; -import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration; -import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace; -import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace; -import java.text.SimpleDateFormat; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EEnum; -import org.eclipse.emf.ecore.EEnumLiteral; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; -import org.eclipse.viatra.query.runtime.api.IQueryGroup; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.InputOutput; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.ListExtensions; -import org.eclipse.xtext.xbase.lib.ObjectExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - -@SuppressWarnings("all") -public class GenerateScenarios { - public static void main(final String[] args) { - try { - final Ecore2Logic ecore2Logic = new Ecore2Logic(); - long _currentTimeMillis = System.currentTimeMillis(); - final Date date = new Date(_currentTimeMillis); - final SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); - final String formattedDate = format.format(date); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("output/"); - String _plus = (_builder.toString() + formattedDate); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("/"); - String _plus_1 = (_plus + _builder_1); - final FileSystemWorkspace workspace = new FileSystemWorkspace(_plus_1, ""); - workspace.initAndClear(); - final Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; - final Map map = reg.getExtensionToFactoryMap(); - XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); - map.put("logicproblem", _xMIResourceFactoryImpl); - InputOutput.println("Input and output workspaces are created"); - InputOutput.print(IterableExtensions.toList(Iterables.filter(TaxationPackage.eINSTANCE.getEClassifiers(), EClass.class)).get(0)); - final EcoreMetamodelDescriptor metamodel = GenerateScenarios.loadMetamodel(TaxationPackage.eINSTANCE); - InputOutput.println("DSL loaded"); - final int SIZE = 10; - int REPS = 1; - final int RUNTIME = 300; - Ecore2LogicConfiguration _ecore2LogicConfiguration = new Ecore2LogicConfiguration(); - final TracedOutput modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, _ecore2LogicConfiguration); - LogicProblem problem = modelGenerationProblem.getOutput(); - workspace.writeModel(problem, "scenario.logicproblem"); - InputOutput.println("Problem created"); - for (int i = 0; (i <= REPS); i++) { - { - ViatraReasoner reasoner = new ViatraReasoner(); - ViatraReasonerConfiguration _viatraReasonerConfiguration = new ViatraReasonerConfiguration(); - final Procedure1 _function = (ViatraReasonerConfiguration it) -> { - it.runtimeLimit = RUNTIME; - it.typeScopes.maxNewElements = SIZE; - it.typeScopes.minNewElements = SIZE; - }; - final ViatraReasonerConfiguration solverConfig = ObjectExtensions.operator_doubleArrow(_viatraReasonerConfiguration, _function); - LogicResult solution = reasoner.solve(problem, solverConfig, workspace); - InputOutput.print("Problem Solved"); - final Runtime r = Runtime.getRuntime(); - r.gc(); - r.gc(); - r.gc(); - Thread.sleep(3000); - } - } - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - public static Map getTypeMap(final Map classMap, final EcoreMetamodelDescriptor metamodel, final Ecore2Logic e2l, final Ecore2Logic_Trace trace) { - final HashMap typeMap = new HashMap(); - final Function1 _function = (EClass s) -> { - return s.getName(); - }; - final Map listMap = IterableExtensions.toMap(metamodel.getClasses(), _function); - Set _keySet = classMap.keySet(); - for (final Class elem : _keySet) { - typeMap.put( - e2l.TypeofEClass(trace, - listMap.get(elem.getSimpleName())), classMap.get(elem)); - } - return typeMap; - } - - public static EcoreMetamodelDescriptor loadMetamodel(final EPackage pckg) { - final List classes = IterableExtensions.toList(Iterables.filter(pckg.getEClassifiers(), EClass.class)); - final List enums = IterableExtensions.toList(Iterables.filter(pckg.getEClassifiers(), EEnum.class)); - final Function1> _function = (EEnum it) -> { - return it.getELiterals(); - }; - final List literals = IterableExtensions.toList(Iterables.concat(ListExtensions.>map(enums, _function))); - final Function1> _function_1 = (EClass it) -> { - return it.getEReferences(); - }; - final List references = IterableExtensions.toList(Iterables.concat(ListExtensions.>map(classes, _function_1))); - final Function1> _function_2 = (EClass it) -> { - return it.getEAttributes(); - }; - final List attributes = IterableExtensions.toList(Iterables.concat(ListExtensions.>map(classes, _function_2))); - return new EcoreMetamodelDescriptor(classes, Collections.unmodifiableSet(CollectionLiterals.newHashSet()), false, enums, literals, references, attributes); - } - - public static EList loadPartialModel(final ReasonerWorkspace inputs, final String path) { - EList _xblockexpression = null; - { - Map _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); - XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); - _extensionToFactoryMap.put("*", _xMIResourceFactoryImpl); - _xblockexpression = inputs.readModel(EObject.class, path).eResource().getContents(); - } - return _xblockexpression; - } - - public static ViatraQuerySetDescriptor loadQueries(final EcoreMetamodelDescriptor metamodel, final IQueryGroup i) { - final List> patterns = IterableExtensions.>toList(i.getSpecifications()); - final Function1, Boolean> _function = (IQuerySpecification it) -> { - final Function1 _function_1 = (PAnnotation it_1) -> { - String _name = it_1.getName(); - return Boolean.valueOf(Objects.equal(_name, "Constraint")); - }; - return Boolean.valueOf(IterableExtensions.exists(it.getAllAnnotations(), _function_1)); - }; - final Set> wfPatterns = IterableExtensions.>toSet(IterableExtensions.>filter(patterns, _function)); - final Map, EStructuralFeature> derivedFeatures = CollectionLiterals., EStructuralFeature>emptyMap(); - final ViatraQuerySetDescriptor res = new ViatraQuerySetDescriptor(patterns, wfPatterns, derivedFeatures); - return res; - } -} -- cgit v1.2.3-70-g09d2