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