diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2020-05-07 19:12:45 +0200 |
---|---|---|
committer | Kristóf Marussy <marussy@mit.bme.hu> | 2020-05-07 19:22:45 +0200 |
commit | 89235248d109ec015cc483188a7c4167c0deef77 (patch) | |
tree | a2f0901b664df37992f5b88213bd117ebdfffdb5 /Domains/hu.bme.mit.inf.dslreasoner.domains.alloyexamples/src-gen/hu/bme/mit/inf/dslreasoner/domains/alloyexamples/DirectSupertype.java | |
parent | multiple object additions fixes (diff) | |
download | VIATRA-Generator-89235248d109ec015cc483188a7c4167c0deef77.tar.gz VIATRA-Generator-89235248d109ec015cc483188a7c4167c0deef77.tar.zst VIATRA-Generator-89235248d109ec015cc483188a7c4167c0deef77.zip |
Rebuild with Eclipse 2020-03
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.alloyexamples/src-gen/hu/bme/mit/inf/dslreasoner/domains/alloyexamples/DirectSupertype.java')
-rw-r--r-- | Domains/hu.bme.mit.inf.dslreasoner.domains.alloyexamples/src-gen/hu/bme/mit/inf/dslreasoner/domains/alloyexamples/DirectSupertype.java | 703 |
1 files changed, 703 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.alloyexamples/src-gen/hu/bme/mit/inf/dslreasoner/domains/alloyexamples/DirectSupertype.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.alloyexamples/src-gen/hu/bme/mit/inf/dslreasoner/domains/alloyexamples/DirectSupertype.java new file mode 100644 index 00000000..72c31e34 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.alloyexamples/src-gen/hu/bme/mit/inf/dslreasoner/domains/alloyexamples/DirectSupertype.java | |||
@@ -0,0 +1,703 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.alloyexamples/patterns/hu/bme/mit/inf/dslreasoner/domains/alloyexamples/Ecore.vql | ||
3 | */ | ||
4 | package hu.bme.mit.inf.dslreasoner.domains.alloyexamples; | ||
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 directSupertype(a: EClass, b:EClass) { | ||
46 | * EClass.eSuperTypes(a,b); | ||
47 | * } | ||
48 | * </pre></code> | ||
49 | * | ||
50 | * @see Matcher | ||
51 | * @see Match | ||
52 | * | ||
53 | */ | ||
54 | @SuppressWarnings("all") | ||
55 | public final class DirectSupertype extends BaseGeneratedEMFQuerySpecification<DirectSupertype.Matcher> { | ||
56 | /** | ||
57 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.alloyexamples.directSupertype 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 fA; | ||
70 | |||
71 | private EClass fB; | ||
72 | |||
73 | private static List<String> parameterNames = makeImmutableList("a", "b"); | ||
74 | |||
75 | private Match(final EClass pA, final EClass pB) { | ||
76 | this.fA = pA; | ||
77 | this.fB = pB; | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | public Object get(final String parameterName) { | ||
82 | switch(parameterName) { | ||
83 | case "a": return this.fA; | ||
84 | case "b": return this.fB; | ||
85 | default: return null; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | @Override | ||
90 | public Object get(final int index) { | ||
91 | switch(index) { | ||
92 | case 0: return this.fA; | ||
93 | case 1: return this.fB; | ||
94 | default: return null; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | public EClass getA() { | ||
99 | return this.fA; | ||
100 | } | ||
101 | |||
102 | public EClass getB() { | ||
103 | return this.fB; | ||
104 | } | ||
105 | |||
106 | @Override | ||
107 | public boolean set(final String parameterName, final Object newValue) { | ||
108 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
109 | if ("a".equals(parameterName) ) { | ||
110 | this.fA = (EClass) newValue; | ||
111 | return true; | ||
112 | } | ||
113 | if ("b".equals(parameterName) ) { | ||
114 | this.fB = (EClass) newValue; | ||
115 | return true; | ||
116 | } | ||
117 | return false; | ||
118 | } | ||
119 | |||
120 | public void setA(final EClass pA) { | ||
121 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
122 | this.fA = pA; | ||
123 | } | ||
124 | |||
125 | public void setB(final EClass pB) { | ||
126 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
127 | this.fB = pB; | ||
128 | } | ||
129 | |||
130 | @Override | ||
131 | public String patternName() { | ||
132 | return "hu.bme.mit.inf.dslreasoner.domains.alloyexamples.directSupertype"; | ||
133 | } | ||
134 | |||
135 | @Override | ||
136 | public List<String> parameterNames() { | ||
137 | return DirectSupertype.Match.parameterNames; | ||
138 | } | ||
139 | |||
140 | @Override | ||
141 | public Object[] toArray() { | ||
142 | return new Object[]{fA, fB}; | ||
143 | } | ||
144 | |||
145 | @Override | ||
146 | public DirectSupertype.Match toImmutable() { | ||
147 | return isMutable() ? newMatch(fA, fB) : this; | ||
148 | } | ||
149 | |||
150 | @Override | ||
151 | public String prettyPrint() { | ||
152 | StringBuilder result = new StringBuilder(); | ||
153 | result.append("\"a\"=" + prettyPrintValue(fA) + ", "); | ||
154 | result.append("\"b\"=" + prettyPrintValue(fB)); | ||
155 | return result.toString(); | ||
156 | } | ||
157 | |||
158 | @Override | ||
159 | public int hashCode() { | ||
160 | return Objects.hash(fA, fB); | ||
161 | } | ||
162 | |||
163 | @Override | ||
164 | public boolean equals(final Object obj) { | ||
165 | if (this == obj) | ||
166 | return true; | ||
167 | if (obj == null) { | ||
168 | return false; | ||
169 | } | ||
170 | if ((obj instanceof DirectSupertype.Match)) { | ||
171 | DirectSupertype.Match other = (DirectSupertype.Match) obj; | ||
172 | return Objects.equals(fA, other.fA) && Objects.equals(fB, other.fB); | ||
173 | } else { | ||
174 | // this should be infrequent | ||
175 | if (!(obj instanceof IPatternMatch)) { | ||
176 | return false; | ||
177 | } | ||
178 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
179 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
180 | } | ||
181 | } | ||
182 | |||
183 | @Override | ||
184 | public DirectSupertype specification() { | ||
185 | return DirectSupertype.instance(); | ||
186 | } | ||
187 | |||
188 | /** | ||
189 | * Returns an empty, mutable match. | ||
190 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
191 | * | ||
192 | * @return the empty match. | ||
193 | * | ||
194 | */ | ||
195 | public static DirectSupertype.Match newEmptyMatch() { | ||
196 | return new Mutable(null, null); | ||
197 | } | ||
198 | |||
199 | /** | ||
200 | * Returns a mutable (partial) match. | ||
201 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
202 | * | ||
203 | * @param pA the fixed value of pattern parameter a, or null if not bound. | ||
204 | * @param pB the fixed value of pattern parameter b, or null if not bound. | ||
205 | * @return the new, mutable (partial) match object. | ||
206 | * | ||
207 | */ | ||
208 | public static DirectSupertype.Match newMutableMatch(final EClass pA, final EClass pB) { | ||
209 | return new Mutable(pA, pB); | ||
210 | } | ||
211 | |||
212 | /** | ||
213 | * Returns a new (partial) match. | ||
214 | * This can be used e.g. to call the matcher with a partial match. | ||
215 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
216 | * @param pA the fixed value of pattern parameter a, or null if not bound. | ||
217 | * @param pB the fixed value of pattern parameter b, or null if not bound. | ||
218 | * @return the (partial) match object. | ||
219 | * | ||
220 | */ | ||
221 | public static DirectSupertype.Match newMatch(final EClass pA, final EClass pB) { | ||
222 | return new Immutable(pA, pB); | ||
223 | } | ||
224 | |||
225 | private static final class Mutable extends DirectSupertype.Match { | ||
226 | Mutable(final EClass pA, final EClass pB) { | ||
227 | super(pA, pB); | ||
228 | } | ||
229 | |||
230 | @Override | ||
231 | public boolean isMutable() { | ||
232 | return true; | ||
233 | } | ||
234 | } | ||
235 | |||
236 | private static final class Immutable extends DirectSupertype.Match { | ||
237 | Immutable(final EClass pA, final EClass pB) { | ||
238 | super(pA, pB); | ||
239 | } | ||
240 | |||
241 | @Override | ||
242 | public boolean isMutable() { | ||
243 | return false; | ||
244 | } | ||
245 | } | ||
246 | } | ||
247 | |||
248 | /** | ||
249 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.alloyexamples.directSupertype pattern, | ||
250 | * providing pattern-specific query methods. | ||
251 | * | ||
252 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
253 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
254 | * | ||
255 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
256 | * | ||
257 | * <p>Original source: | ||
258 | * <code><pre> | ||
259 | * pattern directSupertype(a: EClass, b:EClass) { | ||
260 | * EClass.eSuperTypes(a,b); | ||
261 | * } | ||
262 | * </pre></code> | ||
263 | * | ||
264 | * @see Match | ||
265 | * @see DirectSupertype | ||
266 | * | ||
267 | */ | ||
268 | public static class Matcher extends BaseMatcher<DirectSupertype.Match> { | ||
269 | /** | ||
270 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
271 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
272 | * | ||
273 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
274 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
275 | * | ||
276 | */ | ||
277 | public static DirectSupertype.Matcher on(final ViatraQueryEngine engine) { | ||
278 | // check if matcher already exists | ||
279 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
280 | if (matcher == null) { | ||
281 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
282 | } | ||
283 | return matcher; | ||
284 | } | ||
285 | |||
286 | /** | ||
287 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
288 | * @return an initialized matcher | ||
289 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
290 | * | ||
291 | */ | ||
292 | public static DirectSupertype.Matcher create() { | ||
293 | return new Matcher(); | ||
294 | } | ||
295 | |||
296 | private static final int POSITION_A = 0; | ||
297 | |||
298 | private static final int POSITION_B = 1; | ||
299 | |||
300 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(DirectSupertype.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 pA the fixed value of pattern parameter a, or null if not bound. | ||
317 | * @param pB the fixed value of pattern parameter b, or null if not bound. | ||
318 | * @return matches represented as a Match object. | ||
319 | * | ||
320 | */ | ||
321 | public Collection<DirectSupertype.Match> getAllMatches(final EClass pA, final EClass pB) { | ||
322 | return rawStreamAllMatches(new Object[]{pA, pB}).collect(Collectors.toSet()); | ||
323 | } | ||
324 | |||
325 | /** | ||
326 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
327 | * </p> | ||
328 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
329 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
330 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
331 | * @param pA the fixed value of pattern parameter a, or null if not bound. | ||
332 | * @param pB the fixed value of pattern parameter b, or null if not bound. | ||
333 | * @return a stream of matches represented as a Match object. | ||
334 | * | ||
335 | */ | ||
336 | public Stream<DirectSupertype.Match> streamAllMatches(final EClass pA, final EClass pB) { | ||
337 | return rawStreamAllMatches(new Object[]{pA, pB}); | ||
338 | } | ||
339 | |||
340 | /** | ||
341 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
342 | * Neither determinism nor randomness of selection is guaranteed. | ||
343 | * @param pA the fixed value of pattern parameter a, or null if not bound. | ||
344 | * @param pB the fixed value of pattern parameter b, or null if not bound. | ||
345 | * @return a match represented as a Match object, or null if no match is found. | ||
346 | * | ||
347 | */ | ||
348 | public Optional<DirectSupertype.Match> getOneArbitraryMatch(final EClass pA, final EClass pB) { | ||
349 | return rawGetOneArbitraryMatch(new Object[]{pA, pB}); | ||
350 | } | ||
351 | |||
352 | /** | ||
353 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
354 | * under any possible substitution of the unspecified parameters (if any). | ||
355 | * @param pA the fixed value of pattern parameter a, or null if not bound. | ||
356 | * @param pB the fixed value of pattern parameter b, or null if not bound. | ||
357 | * @return true if the input is a valid (partial) match of the pattern. | ||
358 | * | ||
359 | */ | ||
360 | public boolean hasMatch(final EClass pA, final EClass pB) { | ||
361 | return rawHasMatch(new Object[]{pA, pB}); | ||
362 | } | ||
363 | |||
364 | /** | ||
365 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
366 | * @param pA the fixed value of pattern parameter a, or null if not bound. | ||
367 | * @param pB the fixed value of pattern parameter b, or null if not bound. | ||
368 | * @return the number of pattern matches found. | ||
369 | * | ||
370 | */ | ||
371 | public int countMatches(final EClass pA, final EClass pB) { | ||
372 | return rawCountMatches(new Object[]{pA, pB}); | ||
373 | } | ||
374 | |||
375 | /** | ||
376 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
377 | * Neither determinism nor randomness of selection is guaranteed. | ||
378 | * @param pA the fixed value of pattern parameter a, or null if not bound. | ||
379 | * @param pB the fixed value of pattern parameter b, or null if not bound. | ||
380 | * @param processor the action that will process the selected match. | ||
381 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
382 | * | ||
383 | */ | ||
384 | public boolean forOneArbitraryMatch(final EClass pA, final EClass pB, final Consumer<? super DirectSupertype.Match> processor) { | ||
385 | return rawForOneArbitraryMatch(new Object[]{pA, pB}, processor); | ||
386 | } | ||
387 | |||
388 | /** | ||
389 | * Returns a new (partial) match. | ||
390 | * This can be used e.g. to call the matcher with a partial match. | ||
391 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
392 | * @param pA the fixed value of pattern parameter a, or null if not bound. | ||
393 | * @param pB the fixed value of pattern parameter b, or null if not bound. | ||
394 | * @return the (partial) match object. | ||
395 | * | ||
396 | */ | ||
397 | public DirectSupertype.Match newMatch(final EClass pA, final EClass pB) { | ||
398 | return DirectSupertype.Match.newMatch(pA, pB); | ||
399 | } | ||
400 | |||
401 | /** | ||
402 | * Retrieve the set of values that occur in matches for a. | ||
403 | * @return the Set of all values or empty set if there are no matches | ||
404 | * | ||
405 | */ | ||
406 | protected Stream<EClass> rawStreamAllValuesOfa(final Object[] parameters) { | ||
407 | return rawStreamAllValues(POSITION_A, parameters).map(EClass.class::cast); | ||
408 | } | ||
409 | |||
410 | /** | ||
411 | * Retrieve the set of values that occur in matches for a. | ||
412 | * @return the Set of all values or empty set if there are no matches | ||
413 | * | ||
414 | */ | ||
415 | public Set<EClass> getAllValuesOfa() { | ||
416 | return rawStreamAllValuesOfa(emptyArray()).collect(Collectors.toSet()); | ||
417 | } | ||
418 | |||
419 | /** | ||
420 | * Retrieve the set of values that occur in matches for a. | ||
421 | * @return the Set of all values or empty set if there are no matches | ||
422 | * | ||
423 | */ | ||
424 | public Stream<EClass> streamAllValuesOfa() { | ||
425 | return rawStreamAllValuesOfa(emptyArray()); | ||
426 | } | ||
427 | |||
428 | /** | ||
429 | * Retrieve the set of values that occur in matches for a. | ||
430 | * </p> | ||
431 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
432 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
433 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
434 | * | ||
435 | * @return the Stream of all values or empty set if there are no matches | ||
436 | * | ||
437 | */ | ||
438 | public Stream<EClass> streamAllValuesOfa(final DirectSupertype.Match partialMatch) { | ||
439 | return rawStreamAllValuesOfa(partialMatch.toArray()); | ||
440 | } | ||
441 | |||
442 | /** | ||
443 | * Retrieve the set of values that occur in matches for a. | ||
444 | * </p> | ||
445 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
446 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
447 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
448 | * | ||
449 | * @return the Stream of all values or empty set if there are no matches | ||
450 | * | ||
451 | */ | ||
452 | public Stream<EClass> streamAllValuesOfa(final EClass pB) { | ||
453 | return rawStreamAllValuesOfa(new Object[]{null, pB}); | ||
454 | } | ||
455 | |||
456 | /** | ||
457 | * Retrieve the set of values that occur in matches for a. | ||
458 | * @return the Set of all values or empty set if there are no matches | ||
459 | * | ||
460 | */ | ||
461 | public Set<EClass> getAllValuesOfa(final DirectSupertype.Match partialMatch) { | ||
462 | return rawStreamAllValuesOfa(partialMatch.toArray()).collect(Collectors.toSet()); | ||
463 | } | ||
464 | |||
465 | /** | ||
466 | * Retrieve the set of values that occur in matches for a. | ||
467 | * @return the Set of all values or empty set if there are no matches | ||
468 | * | ||
469 | */ | ||
470 | public Set<EClass> getAllValuesOfa(final EClass pB) { | ||
471 | return rawStreamAllValuesOfa(new Object[]{null, pB}).collect(Collectors.toSet()); | ||
472 | } | ||
473 | |||
474 | /** | ||
475 | * Retrieve the set of values that occur in matches for b. | ||
476 | * @return the Set of all values or empty set if there are no matches | ||
477 | * | ||
478 | */ | ||
479 | protected Stream<EClass> rawStreamAllValuesOfb(final Object[] parameters) { | ||
480 | return rawStreamAllValues(POSITION_B, parameters).map(EClass.class::cast); | ||
481 | } | ||
482 | |||
483 | /** | ||
484 | * Retrieve the set of values that occur in matches for b. | ||
485 | * @return the Set of all values or empty set if there are no matches | ||
486 | * | ||
487 | */ | ||
488 | public Set<EClass> getAllValuesOfb() { | ||
489 | return rawStreamAllValuesOfb(emptyArray()).collect(Collectors.toSet()); | ||
490 | } | ||
491 | |||
492 | /** | ||
493 | * Retrieve the set of values that occur in matches for b. | ||
494 | * @return the Set of all values or empty set if there are no matches | ||
495 | * | ||
496 | */ | ||
497 | public Stream<EClass> streamAllValuesOfb() { | ||
498 | return rawStreamAllValuesOfb(emptyArray()); | ||
499 | } | ||
500 | |||
501 | /** | ||
502 | * Retrieve the set of values that occur in matches for b. | ||
503 | * </p> | ||
504 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
505 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
506 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
507 | * | ||
508 | * @return the Stream of all values or empty set if there are no matches | ||
509 | * | ||
510 | */ | ||
511 | public Stream<EClass> streamAllValuesOfb(final DirectSupertype.Match partialMatch) { | ||
512 | return rawStreamAllValuesOfb(partialMatch.toArray()); | ||
513 | } | ||
514 | |||
515 | /** | ||
516 | * Retrieve the set of values that occur in matches for b. | ||
517 | * </p> | ||
518 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
519 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
520 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
521 | * | ||
522 | * @return the Stream of all values or empty set if there are no matches | ||
523 | * | ||
524 | */ | ||
525 | public Stream<EClass> streamAllValuesOfb(final EClass pA) { | ||
526 | return rawStreamAllValuesOfb(new Object[]{pA, null}); | ||
527 | } | ||
528 | |||
529 | /** | ||
530 | * Retrieve the set of values that occur in matches for b. | ||
531 | * @return the Set of all values or empty set if there are no matches | ||
532 | * | ||
533 | */ | ||
534 | public Set<EClass> getAllValuesOfb(final DirectSupertype.Match partialMatch) { | ||
535 | return rawStreamAllValuesOfb(partialMatch.toArray()).collect(Collectors.toSet()); | ||
536 | } | ||
537 | |||
538 | /** | ||
539 | * Retrieve the set of values that occur in matches for b. | ||
540 | * @return the Set of all values or empty set if there are no matches | ||
541 | * | ||
542 | */ | ||
543 | public Set<EClass> getAllValuesOfb(final EClass pA) { | ||
544 | return rawStreamAllValuesOfb(new Object[]{pA, null}).collect(Collectors.toSet()); | ||
545 | } | ||
546 | |||
547 | @Override | ||
548 | protected DirectSupertype.Match tupleToMatch(final Tuple t) { | ||
549 | try { | ||
550 | return DirectSupertype.Match.newMatch((EClass) t.get(POSITION_A), (EClass) t.get(POSITION_B)); | ||
551 | } catch(ClassCastException e) { | ||
552 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
553 | return null; | ||
554 | } | ||
555 | } | ||
556 | |||
557 | @Override | ||
558 | protected DirectSupertype.Match arrayToMatch(final Object[] match) { | ||
559 | try { | ||
560 | return DirectSupertype.Match.newMatch((EClass) match[POSITION_A], (EClass) match[POSITION_B]); | ||
561 | } catch(ClassCastException e) { | ||
562 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
563 | return null; | ||
564 | } | ||
565 | } | ||
566 | |||
567 | @Override | ||
568 | protected DirectSupertype.Match arrayToMatchMutable(final Object[] match) { | ||
569 | try { | ||
570 | return DirectSupertype.Match.newMutableMatch((EClass) match[POSITION_A], (EClass) match[POSITION_B]); | ||
571 | } catch(ClassCastException e) { | ||
572 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
573 | return null; | ||
574 | } | ||
575 | } | ||
576 | |||
577 | /** | ||
578 | * @return the singleton instance of the query specification of this pattern | ||
579 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
580 | * | ||
581 | */ | ||
582 | public static IQuerySpecification<DirectSupertype.Matcher> querySpecification() { | ||
583 | return DirectSupertype.instance(); | ||
584 | } | ||
585 | } | ||
586 | |||
587 | private DirectSupertype() { | ||
588 | super(GeneratedPQuery.INSTANCE); | ||
589 | } | ||
590 | |||
591 | /** | ||
592 | * @return the singleton instance of the query specification | ||
593 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
594 | * | ||
595 | */ | ||
596 | public static DirectSupertype instance() { | ||
597 | try{ | ||
598 | return LazyHolder.INSTANCE; | ||
599 | } catch (ExceptionInInitializerError err) { | ||
600 | throw processInitializerError(err); | ||
601 | } | ||
602 | } | ||
603 | |||
604 | @Override | ||
605 | protected DirectSupertype.Matcher instantiate(final ViatraQueryEngine engine) { | ||
606 | return DirectSupertype.Matcher.on(engine); | ||
607 | } | ||
608 | |||
609 | @Override | ||
610 | public DirectSupertype.Matcher instantiate() { | ||
611 | return DirectSupertype.Matcher.create(); | ||
612 | } | ||
613 | |||
614 | @Override | ||
615 | public DirectSupertype.Match newEmptyMatch() { | ||
616 | return DirectSupertype.Match.newEmptyMatch(); | ||
617 | } | ||
618 | |||
619 | @Override | ||
620 | public DirectSupertype.Match newMatch(final Object... parameters) { | ||
621 | return DirectSupertype.Match.newMatch((org.eclipse.emf.ecore.EClass) parameters[0], (org.eclipse.emf.ecore.EClass) parameters[1]); | ||
622 | } | ||
623 | |||
624 | /** | ||
625 | * Inner class allowing the singleton instance of {@link DirectSupertype} to be created | ||
626 | * <b>not</b> at the class load time of the outer class, | ||
627 | * but rather at the first call to {@link DirectSupertype#instance()}. | ||
628 | * | ||
629 | * <p> This workaround is required e.g. to support recursion. | ||
630 | * | ||
631 | */ | ||
632 | private static class LazyHolder { | ||
633 | private static final DirectSupertype INSTANCE = new DirectSupertype(); | ||
634 | |||
635 | /** | ||
636 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
637 | * This initialization order is required to support indirect recursion. | ||
638 | * | ||
639 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
640 | * | ||
641 | */ | ||
642 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
643 | |||
644 | public static Object ensureInitialized() { | ||
645 | INSTANCE.ensureInitializedInternal(); | ||
646 | return null; | ||
647 | } | ||
648 | } | ||
649 | |||
650 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
651 | private static final DirectSupertype.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
652 | |||
653 | private final PParameter parameter_a = new PParameter("a", "org.eclipse.emf.ecore.EClass", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.eclipse.org/emf/2002/Ecore", "EClass")), PParameterDirection.INOUT); | ||
654 | |||
655 | private final PParameter parameter_b = new PParameter("b", "org.eclipse.emf.ecore.EClass", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.eclipse.org/emf/2002/Ecore", "EClass")), PParameterDirection.INOUT); | ||
656 | |||
657 | private final List<PParameter> parameters = Arrays.asList(parameter_a, parameter_b); | ||
658 | |||
659 | private GeneratedPQuery() { | ||
660 | super(PVisibility.PUBLIC); | ||
661 | } | ||
662 | |||
663 | @Override | ||
664 | public String getFullyQualifiedName() { | ||
665 | return "hu.bme.mit.inf.dslreasoner.domains.alloyexamples.directSupertype"; | ||
666 | } | ||
667 | |||
668 | @Override | ||
669 | public List<String> getParameterNames() { | ||
670 | return Arrays.asList("a","b"); | ||
671 | } | ||
672 | |||
673 | @Override | ||
674 | public List<PParameter> getParameters() { | ||
675 | return parameters; | ||
676 | } | ||
677 | |||
678 | @Override | ||
679 | public Set<PBody> doGetContainedBodies() { | ||
680 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
681 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
682 | { | ||
683 | PBody body = new PBody(this); | ||
684 | PVariable var_a = body.getOrCreateVariableByName("a"); | ||
685 | PVariable var_b = body.getOrCreateVariableByName("b"); | ||
686 | new TypeConstraint(body, Tuples.flatTupleOf(var_a), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EClass"))); | ||
687 | new TypeConstraint(body, Tuples.flatTupleOf(var_b), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EClass"))); | ||
688 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
689 | new ExportedParameter(body, var_a, parameter_a), | ||
690 | new ExportedParameter(body, var_b, parameter_b) | ||
691 | )); | ||
692 | // EClass.eSuperTypes(a,b) | ||
693 | new TypeConstraint(body, Tuples.flatTupleOf(var_a), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EClass"))); | ||
694 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
695 | new TypeConstraint(body, Tuples.flatTupleOf(var_a, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.eclipse.org/emf/2002/Ecore", "EClass", "eSuperTypes"))); | ||
696 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EClass"))); | ||
697 | new Equality(body, var__virtual_0_, var_b); | ||
698 | bodies.add(body); | ||
699 | } | ||
700 | return bodies; | ||
701 | } | ||
702 | } | ||
703 | } | ||