diff options
Diffstat (limited to 'Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Unreachable.java')
-rw-r--r-- | Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Unreachable.java | 714 |
1 files changed, 714 insertions, 0 deletions
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Unreachable.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Unreachable.java new file mode 100644 index 00000000..a1b76f83 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Unreachable.java | |||
@@ -0,0 +1,714 @@ | |||
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.Reachable; | ||
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.annotations.PAnnotation; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
41 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
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(message = "unreachable", severity = "error", key = { S1, S2 }) | ||
49 | * pattern unreachable(S1 : Segment, S2 : Segment) { | ||
50 | * neg find reachable(S1, S2); | ||
51 | * } | ||
52 | * </pre></code> | ||
53 | * | ||
54 | * @see Matcher | ||
55 | * @see Match | ||
56 | * | ||
57 | */ | ||
58 | @SuppressWarnings("all") | ||
59 | public final class Unreachable extends BaseGeneratedEMFQuerySpecification<Unreachable.Matcher> { | ||
60 | /** | ||
61 | * Pattern-specific match representation of the modes3.queries.unreachable 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.unreachable"; | ||
137 | } | ||
138 | |||
139 | @Override | ||
140 | public List<String> parameterNames() { | ||
141 | return Unreachable.Match.parameterNames; | ||
142 | } | ||
143 | |||
144 | @Override | ||
145 | public Object[] toArray() { | ||
146 | return new Object[]{fS1, fS2}; | ||
147 | } | ||
148 | |||
149 | @Override | ||
150 | public Unreachable.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 Unreachable.Match)) { | ||
175 | Unreachable.Match other = (Unreachable.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 Unreachable specification() { | ||
189 | return Unreachable.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 Unreachable.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 Unreachable.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 Unreachable.Match newMatch(final Segment pS1, final Segment pS2) { | ||
226 | return new Immutable(pS1, pS2); | ||
227 | } | ||
228 | |||
229 | private static final class Mutable extends Unreachable.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 Unreachable.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.unreachable 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 | * {@literal @}Constraint(message = "unreachable", severity = "error", key = { S1, S2 }) | ||
264 | * pattern unreachable(S1 : Segment, S2 : Segment) { | ||
265 | * neg find reachable(S1, S2); | ||
266 | * } | ||
267 | * </pre></code> | ||
268 | * | ||
269 | * @see Match | ||
270 | * @see Unreachable | ||
271 | * | ||
272 | */ | ||
273 | public static class Matcher extends BaseMatcher<Unreachable.Match> { | ||
274 | /** | ||
275 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
276 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
277 | * | ||
278 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
279 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
280 | * | ||
281 | */ | ||
282 | public static Unreachable.Matcher on(final ViatraQueryEngine engine) { | ||
283 | // check if matcher already exists | ||
284 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
285 | if (matcher == null) { | ||
286 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
287 | } | ||
288 | return matcher; | ||
289 | } | ||
290 | |||
291 | /** | ||
292 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
293 | * @return an initialized matcher | ||
294 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
295 | * | ||
296 | */ | ||
297 | public static Unreachable.Matcher create() { | ||
298 | return new Matcher(); | ||
299 | } | ||
300 | |||
301 | private static final int POSITION_S1 = 0; | ||
302 | |||
303 | private static final int POSITION_S2 = 1; | ||
304 | |||
305 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Unreachable.Matcher.class); | ||
306 | |||
307 | /** | ||
308 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
309 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
310 | * | ||
311 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
312 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
313 | * | ||
314 | */ | ||
315 | private Matcher() { | ||
316 | super(querySpecification()); | ||
317 | } | ||
318 | |||
319 | /** | ||
320 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
321 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
322 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
323 | * @return matches represented as a Match object. | ||
324 | * | ||
325 | */ | ||
326 | public Collection<Unreachable.Match> getAllMatches(final Segment pS1, final Segment pS2) { | ||
327 | return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet()); | ||
328 | } | ||
329 | |||
330 | /** | ||
331 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
332 | * </p> | ||
333 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
334 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
335 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
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 a stream of matches represented as a Match object. | ||
339 | * | ||
340 | */ | ||
341 | public Stream<Unreachable.Match> streamAllMatches(final Segment pS1, final Segment pS2) { | ||
342 | return rawStreamAllMatches(new Object[]{pS1, pS2}); | ||
343 | } | ||
344 | |||
345 | /** | ||
346 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
347 | * Neither determinism nor randomness of selection is guaranteed. | ||
348 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
349 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
350 | * @return a match represented as a Match object, or null if no match is found. | ||
351 | * | ||
352 | */ | ||
353 | public Optional<Unreachable.Match> getOneArbitraryMatch(final Segment pS1, final Segment pS2) { | ||
354 | return rawGetOneArbitraryMatch(new Object[]{pS1, pS2}); | ||
355 | } | ||
356 | |||
357 | /** | ||
358 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
359 | * under any possible substitution of the unspecified parameters (if any). | ||
360 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
361 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
362 | * @return true if the input is a valid (partial) match of the pattern. | ||
363 | * | ||
364 | */ | ||
365 | public boolean hasMatch(final Segment pS1, final Segment pS2) { | ||
366 | return rawHasMatch(new Object[]{pS1, pS2}); | ||
367 | } | ||
368 | |||
369 | /** | ||
370 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
371 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
372 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
373 | * @return the number of pattern matches found. | ||
374 | * | ||
375 | */ | ||
376 | public int countMatches(final Segment pS1, final Segment pS2) { | ||
377 | return rawCountMatches(new Object[]{pS1, pS2}); | ||
378 | } | ||
379 | |||
380 | /** | ||
381 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
382 | * Neither determinism nor randomness of selection is guaranteed. | ||
383 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
384 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
385 | * @param processor the action that will process the selected match. | ||
386 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
387 | * | ||
388 | */ | ||
389 | public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer<? super Unreachable.Match> processor) { | ||
390 | return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor); | ||
391 | } | ||
392 | |||
393 | /** | ||
394 | * Returns a new (partial) match. | ||
395 | * This can be used e.g. to call the matcher with a partial match. | ||
396 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
397 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
398 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
399 | * @return the (partial) match object. | ||
400 | * | ||
401 | */ | ||
402 | public Unreachable.Match newMatch(final Segment pS1, final Segment pS2) { | ||
403 | return Unreachable.Match.newMatch(pS1, pS2); | ||
404 | } | ||
405 | |||
406 | /** | ||
407 | * Retrieve the set of values that occur in matches for S1. | ||
408 | * @return the Set of all values or empty set if there are no matches | ||
409 | * | ||
410 | */ | ||
411 | protected Stream<Segment> rawStreamAllValuesOfS1(final Object[] parameters) { | ||
412 | return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast); | ||
413 | } | ||
414 | |||
415 | /** | ||
416 | * Retrieve the set of values that occur in matches for S1. | ||
417 | * @return the Set of all values or empty set if there are no matches | ||
418 | * | ||
419 | */ | ||
420 | public Set<Segment> getAllValuesOfS1() { | ||
421 | return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet()); | ||
422 | } | ||
423 | |||
424 | /** | ||
425 | * Retrieve the set of values that occur in matches for S1. | ||
426 | * @return the Set of all values or empty set if there are no matches | ||
427 | * | ||
428 | */ | ||
429 | public Stream<Segment> streamAllValuesOfS1() { | ||
430 | return rawStreamAllValuesOfS1(emptyArray()); | ||
431 | } | ||
432 | |||
433 | /** | ||
434 | * Retrieve the set of values that occur in matches for S1. | ||
435 | * </p> | ||
436 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
437 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
438 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
439 | * | ||
440 | * @return the Stream of all values or empty set if there are no matches | ||
441 | * | ||
442 | */ | ||
443 | public Stream<Segment> streamAllValuesOfS1(final Unreachable.Match partialMatch) { | ||
444 | return rawStreamAllValuesOfS1(partialMatch.toArray()); | ||
445 | } | ||
446 | |||
447 | /** | ||
448 | * Retrieve the set of values that occur in matches for S1. | ||
449 | * </p> | ||
450 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
451 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
452 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
453 | * | ||
454 | * @return the Stream of all values or empty set if there are no matches | ||
455 | * | ||
456 | */ | ||
457 | public Stream<Segment> streamAllValuesOfS1(final Segment pS2) { | ||
458 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}); | ||
459 | } | ||
460 | |||
461 | /** | ||
462 | * Retrieve the set of values that occur in matches for S1. | ||
463 | * @return the Set of all values or empty set if there are no matches | ||
464 | * | ||
465 | */ | ||
466 | public Set<Segment> getAllValuesOfS1(final Unreachable.Match partialMatch) { | ||
467 | return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet()); | ||
468 | } | ||
469 | |||
470 | /** | ||
471 | * Retrieve the set of values that occur in matches for S1. | ||
472 | * @return the Set of all values or empty set if there are no matches | ||
473 | * | ||
474 | */ | ||
475 | public Set<Segment> getAllValuesOfS1(final Segment pS2) { | ||
476 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet()); | ||
477 | } | ||
478 | |||
479 | /** | ||
480 | * Retrieve the set of values that occur in matches for S2. | ||
481 | * @return the Set of all values or empty set if there are no matches | ||
482 | * | ||
483 | */ | ||
484 | protected Stream<Segment> rawStreamAllValuesOfS2(final Object[] parameters) { | ||
485 | return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast); | ||
486 | } | ||
487 | |||
488 | /** | ||
489 | * Retrieve the set of values that occur in matches for S2. | ||
490 | * @return the Set of all values or empty set if there are no matches | ||
491 | * | ||
492 | */ | ||
493 | public Set<Segment> getAllValuesOfS2() { | ||
494 | return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet()); | ||
495 | } | ||
496 | |||
497 | /** | ||
498 | * Retrieve the set of values that occur in matches for S2. | ||
499 | * @return the Set of all values or empty set if there are no matches | ||
500 | * | ||
501 | */ | ||
502 | public Stream<Segment> streamAllValuesOfS2() { | ||
503 | return rawStreamAllValuesOfS2(emptyArray()); | ||
504 | } | ||
505 | |||
506 | /** | ||
507 | * Retrieve the set of values that occur in matches for S2. | ||
508 | * </p> | ||
509 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
510 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
511 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
512 | * | ||
513 | * @return the Stream of all values or empty set if there are no matches | ||
514 | * | ||
515 | */ | ||
516 | public Stream<Segment> streamAllValuesOfS2(final Unreachable.Match partialMatch) { | ||
517 | return rawStreamAllValuesOfS2(partialMatch.toArray()); | ||
518 | } | ||
519 | |||
520 | /** | ||
521 | * Retrieve the set of values that occur in matches for S2. | ||
522 | * </p> | ||
523 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
524 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
525 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
526 | * | ||
527 | * @return the Stream of all values or empty set if there are no matches | ||
528 | * | ||
529 | */ | ||
530 | public Stream<Segment> streamAllValuesOfS2(final Segment pS1) { | ||
531 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}); | ||
532 | } | ||
533 | |||
534 | /** | ||
535 | * Retrieve the set of values that occur in matches for S2. | ||
536 | * @return the Set of all values or empty set if there are no matches | ||
537 | * | ||
538 | */ | ||
539 | public Set<Segment> getAllValuesOfS2(final Unreachable.Match partialMatch) { | ||
540 | return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet()); | ||
541 | } | ||
542 | |||
543 | /** | ||
544 | * Retrieve the set of values that occur in matches for S2. | ||
545 | * @return the Set of all values or empty set if there are no matches | ||
546 | * | ||
547 | */ | ||
548 | public Set<Segment> getAllValuesOfS2(final Segment pS1) { | ||
549 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet()); | ||
550 | } | ||
551 | |||
552 | @Override | ||
553 | protected Unreachable.Match tupleToMatch(final Tuple t) { | ||
554 | try { | ||
555 | return Unreachable.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2)); | ||
556 | } catch(ClassCastException e) { | ||
557 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
558 | return null; | ||
559 | } | ||
560 | } | ||
561 | |||
562 | @Override | ||
563 | protected Unreachable.Match arrayToMatch(final Object[] match) { | ||
564 | try { | ||
565 | return Unreachable.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
566 | } catch(ClassCastException e) { | ||
567 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
568 | return null; | ||
569 | } | ||
570 | } | ||
571 | |||
572 | @Override | ||
573 | protected Unreachable.Match arrayToMatchMutable(final Object[] match) { | ||
574 | try { | ||
575 | return Unreachable.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
576 | } catch(ClassCastException e) { | ||
577 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
578 | return null; | ||
579 | } | ||
580 | } | ||
581 | |||
582 | /** | ||
583 | * @return the singleton instance of the query specification of this pattern | ||
584 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
585 | * | ||
586 | */ | ||
587 | public static IQuerySpecification<Unreachable.Matcher> querySpecification() { | ||
588 | return Unreachable.instance(); | ||
589 | } | ||
590 | } | ||
591 | |||
592 | private Unreachable() { | ||
593 | super(GeneratedPQuery.INSTANCE); | ||
594 | } | ||
595 | |||
596 | /** | ||
597 | * @return the singleton instance of the query specification | ||
598 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
599 | * | ||
600 | */ | ||
601 | public static Unreachable instance() { | ||
602 | try{ | ||
603 | return LazyHolder.INSTANCE; | ||
604 | } catch (ExceptionInInitializerError err) { | ||
605 | throw processInitializerError(err); | ||
606 | } | ||
607 | } | ||
608 | |||
609 | @Override | ||
610 | protected Unreachable.Matcher instantiate(final ViatraQueryEngine engine) { | ||
611 | return Unreachable.Matcher.on(engine); | ||
612 | } | ||
613 | |||
614 | @Override | ||
615 | public Unreachable.Matcher instantiate() { | ||
616 | return Unreachable.Matcher.create(); | ||
617 | } | ||
618 | |||
619 | @Override | ||
620 | public Unreachable.Match newEmptyMatch() { | ||
621 | return Unreachable.Match.newEmptyMatch(); | ||
622 | } | ||
623 | |||
624 | @Override | ||
625 | public Unreachable.Match newMatch(final Object... parameters) { | ||
626 | return Unreachable.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]); | ||
627 | } | ||
628 | |||
629 | /** | ||
630 | * Inner class allowing the singleton instance of {@link Unreachable} to be created | ||
631 | * <b>not</b> at the class load time of the outer class, | ||
632 | * but rather at the first call to {@link Unreachable#instance()}. | ||
633 | * | ||
634 | * <p> This workaround is required e.g. to support recursion. | ||
635 | * | ||
636 | */ | ||
637 | private static class LazyHolder { | ||
638 | private static final Unreachable INSTANCE = new Unreachable(); | ||
639 | |||
640 | /** | ||
641 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
642 | * This initialization order is required to support indirect recursion. | ||
643 | * | ||
644 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
645 | * | ||
646 | */ | ||
647 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
648 | |||
649 | public static Object ensureInitialized() { | ||
650 | INSTANCE.ensureInitializedInternal(); | ||
651 | return null; | ||
652 | } | ||
653 | } | ||
654 | |||
655 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
656 | private static final Unreachable.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
657 | |||
658 | private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
659 | |||
660 | private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
661 | |||
662 | private final List<PParameter> parameters = Arrays.asList(parameter_S1, parameter_S2); | ||
663 | |||
664 | private GeneratedPQuery() { | ||
665 | super(PVisibility.PUBLIC); | ||
666 | } | ||
667 | |||
668 | @Override | ||
669 | public String getFullyQualifiedName() { | ||
670 | return "modes3.queries.unreachable"; | ||
671 | } | ||
672 | |||
673 | @Override | ||
674 | public List<String> getParameterNames() { | ||
675 | return Arrays.asList("S1","S2"); | ||
676 | } | ||
677 | |||
678 | @Override | ||
679 | public List<PParameter> getParameters() { | ||
680 | return parameters; | ||
681 | } | ||
682 | |||
683 | @Override | ||
684 | public Set<PBody> doGetContainedBodies() { | ||
685 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
686 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
687 | { | ||
688 | PBody body = new PBody(this); | ||
689 | PVariable var_S1 = body.getOrCreateVariableByName("S1"); | ||
690 | PVariable var_S2 = body.getOrCreateVariableByName("S2"); | ||
691 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
692 | new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
693 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
694 | new ExportedParameter(body, var_S1, parameter_S1), | ||
695 | new ExportedParameter(body, var_S2, parameter_S2) | ||
696 | )); | ||
697 | // neg find reachable(S1, S2) | ||
698 | new NegativePatternCall(body, Tuples.flatTupleOf(var_S1, var_S2), Reachable.instance().getInternalQueryRepresentation()); | ||
699 | bodies.add(body); | ||
700 | } | ||
701 | { | ||
702 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
703 | annotation.addAttribute("message", "unreachable"); | ||
704 | annotation.addAttribute("severity", "error"); | ||
705 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
706 | new ParameterReference("S1"), | ||
707 | new ParameterReference("S2") | ||
708 | })); | ||
709 | addAnnotation(annotation); | ||
710 | } | ||
711 | return bodies; | ||
712 | } | ||
713 | } | ||
714 | } | ||