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