diff options
Diffstat (limited to 'Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/LookupHandler.xtend')
-rw-r--r-- | Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/LookupHandler.xtend | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/LookupHandler.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/LookupHandler.xtend deleted file mode 100644 index 3a06dcc3..00000000 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/LookupHandler.xtend +++ /dev/null | |||
@@ -1,47 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.LookupDefinition | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.MappingDefinition | ||
5 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | ||
6 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher | ||
7 | |||
8 | class LookupHandler { | ||
9 | val int[] argumentIndices | ||
10 | val ViatraQueryMatcher<? extends IPatternMatch> lookedUpMatcher | ||
11 | |||
12 | new(MappingDefinition mappingDefinition, LookupDefinition lookupDefinition, | ||
13 | ViatraQueryMatcher<? extends IPatternMatch> lookedUpMatcher) { | ||
14 | if (lookupDefinition.eContainer != mappingDefinition) { | ||
15 | throw new IllegalArgumentException("lookupDefinition must be contained in mappingDefinition") | ||
16 | } | ||
17 | val argumentCount = lookupDefinition.arguments.size | ||
18 | if (argumentCount != lookedUpMatcher.parameterNames.length) { | ||
19 | throw new IllegalArgumentException( | ||
20 | "lookupDefinition (name: " + lookupDefinition.mapping?.pattern?.name + | ||
21 | ") must have as many arguments as lookedUpMatcher (name: " + lookedUpMatcher.patternName + ")") | ||
22 | } | ||
23 | argumentIndices = newIntArrayOfSize(argumentCount) | ||
24 | for (var int i = 0; i < argumentCount; i++) { | ||
25 | val argument = lookupDefinition.arguments.get(i) | ||
26 | val argumentIndex = mappingDefinition.parameters.indexOf(argument) | ||
27 | argumentIndices.set(i, argumentIndex) | ||
28 | } | ||
29 | this.lookedUpMatcher = lookedUpMatcher | ||
30 | } | ||
31 | |||
32 | def lookupForMatch(ComponentFaultTreeTrace faultTreeTrace, IPatternMatch match) { | ||
33 | val lookedUpMatch = createLookedUpMatch(match) | ||
34 | faultTreeTrace.lookup(lookedUpMatch) | ||
35 | } | ||
36 | |||
37 | private def createLookedUpMatch(IPatternMatch match) { | ||
38 | val lookedUpMatch = lookedUpMatcher.newEmptyMatch | ||
39 | val argumentCount = argumentIndices.length | ||
40 | for (var int i = 0; i < argumentCount; i++) { | ||
41 | val argumentIndex = argumentIndices.get(i) | ||
42 | var argumentValue = match.get(argumentIndex) | ||
43 | lookedUpMatch.set(i, argumentValue) | ||
44 | } | ||
45 | lookedUpMatch | ||
46 | } | ||
47 | } | ||