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