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