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