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