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