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