diff options
author | 2020-06-25 19:55:10 +0200 | |
---|---|---|
committer | 2020-06-25 19:55:10 +0200 | |
commit | c3a6d4b9cf3657070d180aa65ddbf0459e880329 (patch) | |
tree | 780c4fc61578dcb309af53fb0c164c7627e51676 /Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java | |
parent | New configuration language parser WIP (diff) | |
parent | Scope unsat benchmarks (diff) | |
download | VIATRA-Generator-c3a6d4b9cf3657070d180aa65ddbf0459e880329.tar.gz VIATRA-Generator-c3a6d4b9cf3657070d180aa65ddbf0459e880329.tar.zst VIATRA-Generator-c3a6d4b9cf3657070d180aa65ddbf0459e880329.zip |
Merge branch 'kris'
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java')
-rw-r--r-- | Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java | 589 |
1 files changed, 589 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java new file mode 100644 index 00000000..6e52bee8 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java | |||
@@ -0,0 +1,589 @@ | |||
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 | */ | ||
4 | package hu.bme.mit.inf.dslreasoner.domains.cps.queries; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory; | ||
8 | import java.util.Arrays; | ||
9 | import java.util.Collection; | ||
10 | import java.util.LinkedHashSet; | ||
11 | import java.util.List; | ||
12 | import java.util.Objects; | ||
13 | import java.util.Optional; | ||
14 | import java.util.Set; | ||
15 | import java.util.function.Consumer; | ||
16 | import java.util.stream.Collectors; | ||
17 | import java.util.stream.Stream; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
42 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
43 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
44 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
45 | |||
46 | /** | ||
47 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
48 | * | ||
49 | * <p>Original source: | ||
50 | * <code><pre> | ||
51 | * {@literal @}Constraint(severity = "error", key = {Host}, | ||
52 | * message = "Insufficient memory available on host.") | ||
53 | * pattern notEnoughAvailableMemory(Host : HostInstance) { | ||
54 | * find availableMemory(Host, Memory); | ||
55 | * check(Memory {@literal <} 0); | ||
56 | * } | ||
57 | * </pre></code> | ||
58 | * | ||
59 | * @see Matcher | ||
60 | * @see Match | ||
61 | * | ||
62 | */ | ||
63 | @SuppressWarnings("all") | ||
64 | public final class NotEnoughAvailableMemory extends BaseGeneratedEMFQuerySpecification<NotEnoughAvailableMemory.Matcher> { | ||
65 | /** | ||
66 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory pattern, | ||
67 | * to be used in conjunction with {@link Matcher}. | ||
68 | * | ||
69 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
70 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
71 | * usable to represent a match of the pattern in the result of a query, | ||
72 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
73 | * | ||
74 | * @see Matcher | ||
75 | * | ||
76 | */ | ||
77 | public static abstract class Match extends BasePatternMatch { | ||
78 | private HostInstance fHost; | ||
79 | |||
80 | private static List<String> parameterNames = makeImmutableList("Host"); | ||
81 | |||
82 | private Match(final HostInstance pHost) { | ||
83 | this.fHost = pHost; | ||
84 | } | ||
85 | |||
86 | @Override | ||
87 | public Object get(final String parameterName) { | ||
88 | switch(parameterName) { | ||
89 | case "Host": return this.fHost; | ||
90 | default: return null; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | @Override | ||
95 | public Object get(final int index) { | ||
96 | switch(index) { | ||
97 | case 0: return this.fHost; | ||
98 | default: return null; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | public HostInstance getHost() { | ||
103 | return this.fHost; | ||
104 | } | ||
105 | |||
106 | @Override | ||
107 | public boolean set(final String parameterName, final Object newValue) { | ||
108 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
109 | if ("Host".equals(parameterName) ) { | ||
110 | this.fHost = (HostInstance) newValue; | ||
111 | return true; | ||
112 | } | ||
113 | return false; | ||
114 | } | ||
115 | |||
116 | public void setHost(final HostInstance pHost) { | ||
117 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
118 | this.fHost = pHost; | ||
119 | } | ||
120 | |||
121 | @Override | ||
122 | public String patternName() { | ||
123 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory"; | ||
124 | } | ||
125 | |||
126 | @Override | ||
127 | public List<String> parameterNames() { | ||
128 | return NotEnoughAvailableMemory.Match.parameterNames; | ||
129 | } | ||
130 | |||
131 | @Override | ||
132 | public Object[] toArray() { | ||
133 | return new Object[]{fHost}; | ||
134 | } | ||
135 | |||
136 | @Override | ||
137 | public NotEnoughAvailableMemory.Match toImmutable() { | ||
138 | return isMutable() ? newMatch(fHost) : this; | ||
139 | } | ||
140 | |||
141 | @Override | ||
142 | public String prettyPrint() { | ||
143 | StringBuilder result = new StringBuilder(); | ||
144 | result.append("\"Host\"=" + prettyPrintValue(fHost)); | ||
145 | return result.toString(); | ||
146 | } | ||
147 | |||
148 | @Override | ||
149 | public int hashCode() { | ||
150 | return Objects.hash(fHost); | ||
151 | } | ||
152 | |||
153 | @Override | ||
154 | public boolean equals(final Object obj) { | ||
155 | if (this == obj) | ||
156 | return true; | ||
157 | if (obj == null) { | ||
158 | return false; | ||
159 | } | ||
160 | if ((obj instanceof NotEnoughAvailableMemory.Match)) { | ||
161 | NotEnoughAvailableMemory.Match other = (NotEnoughAvailableMemory.Match) obj; | ||
162 | return Objects.equals(fHost, other.fHost); | ||
163 | } else { | ||
164 | // this should be infrequent | ||
165 | if (!(obj instanceof IPatternMatch)) { | ||
166 | return false; | ||
167 | } | ||
168 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
169 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | @Override | ||
174 | public NotEnoughAvailableMemory specification() { | ||
175 | return NotEnoughAvailableMemory.instance(); | ||
176 | } | ||
177 | |||
178 | /** | ||
179 | * Returns an empty, mutable match. | ||
180 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
181 | * | ||
182 | * @return the empty match. | ||
183 | * | ||
184 | */ | ||
185 | public static NotEnoughAvailableMemory.Match newEmptyMatch() { | ||
186 | return new Mutable(null); | ||
187 | } | ||
188 | |||
189 | /** | ||
190 | * Returns a mutable (partial) match. | ||
191 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
192 | * | ||
193 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
194 | * @return the new, mutable (partial) match object. | ||
195 | * | ||
196 | */ | ||
197 | public static NotEnoughAvailableMemory.Match newMutableMatch(final HostInstance pHost) { | ||
198 | return new Mutable(pHost); | ||
199 | } | ||
200 | |||
201 | /** | ||
202 | * Returns a new (partial) match. | ||
203 | * This can be used e.g. to call the matcher with a partial match. | ||
204 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
205 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
206 | * @return the (partial) match object. | ||
207 | * | ||
208 | */ | ||
209 | public static NotEnoughAvailableMemory.Match newMatch(final HostInstance pHost) { | ||
210 | return new Immutable(pHost); | ||
211 | } | ||
212 | |||
213 | private static final class Mutable extends NotEnoughAvailableMemory.Match { | ||
214 | Mutable(final HostInstance pHost) { | ||
215 | super(pHost); | ||
216 | } | ||
217 | |||
218 | @Override | ||
219 | public boolean isMutable() { | ||
220 | return true; | ||
221 | } | ||
222 | } | ||
223 | |||
224 | private static final class Immutable extends NotEnoughAvailableMemory.Match { | ||
225 | Immutable(final HostInstance pHost) { | ||
226 | super(pHost); | ||
227 | } | ||
228 | |||
229 | @Override | ||
230 | public boolean isMutable() { | ||
231 | return false; | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | |||
236 | /** | ||
237 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory pattern, | ||
238 | * providing pattern-specific query methods. | ||
239 | * | ||
240 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
241 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
242 | * | ||
243 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
244 | * | ||
245 | * <p>Original source: | ||
246 | * <code><pre> | ||
247 | * {@literal @}Constraint(severity = "error", key = {Host}, | ||
248 | * message = "Insufficient memory available on host.") | ||
249 | * pattern notEnoughAvailableMemory(Host : HostInstance) { | ||
250 | * find availableMemory(Host, Memory); | ||
251 | * check(Memory {@literal <} 0); | ||
252 | * } | ||
253 | * </pre></code> | ||
254 | * | ||
255 | * @see Match | ||
256 | * @see NotEnoughAvailableMemory | ||
257 | * | ||
258 | */ | ||
259 | public static class Matcher extends BaseMatcher<NotEnoughAvailableMemory.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 NotEnoughAvailableMemory.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 NotEnoughAvailableMemory.Matcher create() { | ||
284 | return new Matcher(); | ||
285 | } | ||
286 | |||
287 | private static final int POSITION_HOST = 0; | ||
288 | |||
289 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NotEnoughAvailableMemory.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 pHost the fixed value of pattern parameter Host, or null if not bound. | ||
306 | * @return matches represented as a Match object. | ||
307 | * | ||
308 | */ | ||
309 | public Collection<NotEnoughAvailableMemory.Match> getAllMatches(final HostInstance pHost) { | ||
310 | return rawStreamAllMatches(new Object[]{pHost}).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 pHost the fixed value of pattern parameter Host, or null if not bound. | ||
320 | * @return a stream of matches represented as a Match object. | ||
321 | * | ||
322 | */ | ||
323 | public Stream<NotEnoughAvailableMemory.Match> streamAllMatches(final HostInstance pHost) { | ||
324 | return rawStreamAllMatches(new Object[]{pHost}); | ||
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 pHost the fixed value of pattern parameter Host, 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<NotEnoughAvailableMemory.Match> getOneArbitraryMatch(final HostInstance pHost) { | ||
335 | return rawGetOneArbitraryMatch(new Object[]{pHost}); | ||
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 pHost the fixed value of pattern parameter Host, 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 HostInstance pHost) { | ||
346 | return rawHasMatch(new Object[]{pHost}); | ||
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 pHost the fixed value of pattern parameter Host, or null if not bound. | ||
352 | * @return the number of pattern matches found. | ||
353 | * | ||
354 | */ | ||
355 | public int countMatches(final HostInstance pHost) { | ||
356 | return rawCountMatches(new Object[]{pHost}); | ||
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 pHost the fixed value of pattern parameter Host, 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 HostInstance pHost, final Consumer<? super NotEnoughAvailableMemory.Match> processor) { | ||
368 | return rawForOneArbitraryMatch(new Object[]{pHost}, 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 pHost the fixed value of pattern parameter Host, or null if not bound. | ||
376 | * @return the (partial) match object. | ||
377 | * | ||
378 | */ | ||
379 | public NotEnoughAvailableMemory.Match newMatch(final HostInstance pHost) { | ||
380 | return NotEnoughAvailableMemory.Match.newMatch(pHost); | ||
381 | } | ||
382 | |||
383 | /** | ||
384 | * Retrieve the set of values that occur in matches for Host. | ||
385 | * @return the Set of all values or empty set if there are no matches | ||
386 | * | ||
387 | */ | ||
388 | protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) { | ||
389 | return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast); | ||
390 | } | ||
391 | |||
392 | /** | ||
393 | * Retrieve the set of values that occur in matches for Host. | ||
394 | * @return the Set of all values or empty set if there are no matches | ||
395 | * | ||
396 | */ | ||
397 | public Set<HostInstance> getAllValuesOfHost() { | ||
398 | return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet()); | ||
399 | } | ||
400 | |||
401 | /** | ||
402 | * Retrieve the set of values that occur in matches for Host. | ||
403 | * @return the Set of all values or empty set if there are no matches | ||
404 | * | ||
405 | */ | ||
406 | public Stream<HostInstance> streamAllValuesOfHost() { | ||
407 | return rawStreamAllValuesOfHost(emptyArray()); | ||
408 | } | ||
409 | |||
410 | @Override | ||
411 | protected NotEnoughAvailableMemory.Match tupleToMatch(final Tuple t) { | ||
412 | try { | ||
413 | return NotEnoughAvailableMemory.Match.newMatch((HostInstance) t.get(POSITION_HOST)); | ||
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 NotEnoughAvailableMemory.Match arrayToMatch(final Object[] match) { | ||
422 | try { | ||
423 | return NotEnoughAvailableMemory.Match.newMatch((HostInstance) match[POSITION_HOST]); | ||
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 NotEnoughAvailableMemory.Match arrayToMatchMutable(final Object[] match) { | ||
432 | try { | ||
433 | return NotEnoughAvailableMemory.Match.newMutableMatch((HostInstance) match[POSITION_HOST]); | ||
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<NotEnoughAvailableMemory.Matcher> querySpecification() { | ||
446 | return NotEnoughAvailableMemory.instance(); | ||
447 | } | ||
448 | } | ||
449 | |||
450 | private NotEnoughAvailableMemory() { | ||
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 NotEnoughAvailableMemory instance() { | ||
460 | try{ | ||
461 | return LazyHolder.INSTANCE; | ||
462 | } catch (ExceptionInInitializerError err) { | ||
463 | throw processInitializerError(err); | ||
464 | } | ||
465 | } | ||
466 | |||
467 | @Override | ||
468 | protected NotEnoughAvailableMemory.Matcher instantiate(final ViatraQueryEngine engine) { | ||
469 | return NotEnoughAvailableMemory.Matcher.on(engine); | ||
470 | } | ||
471 | |||
472 | @Override | ||
473 | public NotEnoughAvailableMemory.Matcher instantiate() { | ||
474 | return NotEnoughAvailableMemory.Matcher.create(); | ||
475 | } | ||
476 | |||
477 | @Override | ||
478 | public NotEnoughAvailableMemory.Match newEmptyMatch() { | ||
479 | return NotEnoughAvailableMemory.Match.newEmptyMatch(); | ||
480 | } | ||
481 | |||
482 | @Override | ||
483 | public NotEnoughAvailableMemory.Match newMatch(final Object... parameters) { | ||
484 | return NotEnoughAvailableMemory.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0]); | ||
485 | } | ||
486 | |||
487 | /** | ||
488 | * Inner class allowing the singleton instance of {@link NotEnoughAvailableMemory} 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 NotEnoughAvailableMemory#instance()}. | ||
491 | * | ||
492 | * <p> This workaround is required e.g. to support recursion. | ||
493 | * | ||
494 | */ | ||
495 | private static class LazyHolder { | ||
496 | private static final NotEnoughAvailableMemory INSTANCE = new NotEnoughAvailableMemory(); | ||
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 NotEnoughAvailableMemory.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
515 | |||
516 | private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT); | ||
517 | |||
518 | private final List<PParameter> parameters = Arrays.asList(parameter_Host); | ||
519 | |||
520 | private GeneratedPQuery() { | ||
521 | super(PVisibility.PUBLIC); | ||
522 | } | ||
523 | |||
524 | @Override | ||
525 | public String getFullyQualifiedName() { | ||
526 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory"; | ||
527 | } | ||
528 | |||
529 | @Override | ||
530 | public List<String> getParameterNames() { | ||
531 | return Arrays.asList("Host"); | ||
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_Host = body.getOrCreateVariableByName("Host"); | ||
546 | PVariable var_Memory = body.getOrCreateVariableByName("Memory"); | ||
547 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
548 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
549 | new ExportedParameter(body, var_Host, parameter_Host) | ||
550 | )); | ||
551 | // find availableMemory(Host, Memory) | ||
552 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Memory), AvailableMemory.instance().getInternalQueryRepresentation()); | ||
553 | // check(Memory < 0) | ||
554 | new ExpressionEvaluation(body, new IExpressionEvaluator() { | ||
555 | |||
556 | @Override | ||
557 | public String getShortDescription() { | ||
558 | return "Expression evaluation from pattern notEnoughAvailableMemory"; | ||
559 | } | ||
560 | |||
561 | @Override | ||
562 | public Iterable<String> getInputParameterNames() { | ||
563 | return Arrays.asList("Memory");} | ||
564 | |||
565 | @Override | ||
566 | public Object evaluateExpression(IValueProvider provider) throws Exception { | ||
567 | Integer Memory = (Integer) provider.getValue("Memory"); | ||
568 | return evaluateExpression_1_1(Memory); | ||
569 | } | ||
570 | }, null); | ||
571 | bodies.add(body); | ||
572 | } | ||
573 | { | ||
574 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
575 | annotation.addAttribute("severity", "error"); | ||
576 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
577 | new ParameterReference("Host") | ||
578 | })); | ||
579 | annotation.addAttribute("message", "Insufficient memory available on host."); | ||
580 | addAnnotation(annotation); | ||
581 | } | ||
582 | return bodies; | ||
583 | } | ||
584 | } | ||
585 | |||
586 | private static boolean evaluateExpression_1_1(final Integer Memory) { | ||
587 | return ((Memory).intValue() < 0); | ||
588 | } | ||
589 | } | ||