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