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