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