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