diff options
author | 2019-08-01 14:49:53 +0200 | |
---|---|---|
committer | 2019-08-01 14:49:53 +0200 | |
commit | 972baab642bd889d2c3476c0c9e17a6929e0c318 (patch) | |
tree | 8f724cb348c60e4fc45d446d8532988ed8e40748 /Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageScopeProvider.xtend | |
parent | Counting scope propagator (simpler than BasicTypeHierarchy) (diff) | |
download | VIATRA-Generator-972baab642bd889d2c3476c0c9e17a6929e0c318.tar.gz VIATRA-Generator-972baab642bd889d2c3476c0c9e17a6929e0c318.tar.zst VIATRA-Generator-972baab642bd889d2c3476c0c9e17a6929e0c318.zip |
[Stochastic] Remove fault tree support for now
Diffstat (limited to 'Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageScopeProvider.xtend')
-rw-r--r-- | Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageScopeProvider.xtend | 147 |
1 files changed, 0 insertions, 147 deletions
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageScopeProvider.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageScopeProvider.xtend deleted file mode 100644 index f295f116..00000000 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageScopeProvider.xtend +++ /dev/null | |||
@@ -1,147 +0,0 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.16.0 | ||
3 | */ | ||
4 | package hu.bme.mit.inf.dslreasoner.faulttree.components.scoping | ||
5 | |||
6 | import com.google.common.collect.Lists | ||
7 | import com.google.inject.Inject | ||
8 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.ComponentInstance | ||
9 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.EventReference | ||
10 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.LookupDefinition | ||
11 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.MappingDefinition | ||
12 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.TransformationDefinition | ||
13 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.Variable | ||
14 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.impl.MappingDefinitionImpl | ||
15 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.ComponentDefinition | ||
16 | import org.eclipse.emf.common.notify.Notifier | ||
17 | import org.eclipse.emf.ecore.EObject | ||
18 | import org.eclipse.emf.ecore.EReference | ||
19 | import org.eclipse.xtext.EcoreUtil2 | ||
20 | import org.eclipse.xtext.resource.EObjectDescription | ||
21 | import org.eclipse.xtext.resource.IResourceDescriptions | ||
22 | import org.eclipse.xtext.resource.IResourceDescriptionsProvider | ||
23 | import org.eclipse.xtext.scoping.IScope | ||
24 | import org.eclipse.xtext.scoping.Scopes | ||
25 | import org.eclipse.xtext.scoping.impl.SimpleScope | ||
26 | |||
27 | import static hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.CftLanguagePackage.Literals.* | ||
28 | |||
29 | /** | ||
30 | * This class contains custom scoping description. | ||
31 | * | ||
32 | * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping | ||
33 | * on how and when to use it. | ||
34 | */ | ||
35 | class CftLanguageScopeProvider extends AbstractCftLanguageScopeProvider { | ||
36 | public static val SINGLETON_VARIABLE_PREFIX = "_" | ||
37 | |||
38 | @Inject IResourceDescriptionsProvider resourceDescriptionsProvider | ||
39 | @Inject CftLanguageImportedNamespaceAwareLocalScopeProvider importedNamespaceProvider | ||
40 | |||
41 | override getScope(EObject context, EReference reference) { | ||
42 | switch (reference) { | ||
43 | case LOOKUP_DEFINITION__MAPPING: | ||
44 | getRuleDefinitionsScope(context, reference) | ||
45 | case LOOKUP_DEFINITION__ARGUMENTS: | ||
46 | getMappingParametersScope(context) | ||
47 | case EVENT_REFERENCE__COMPONENT: | ||
48 | getComponentInstancesScope(context) | ||
49 | case EVENT_REFERENCE__EVENT: | ||
50 | getEventDeclarationsScope(context) | ||
51 | default: | ||
52 | super.getScope(context, reference) | ||
53 | } | ||
54 | } | ||
55 | |||
56 | protected def getRuleDefinitionsScope(EObject context, EReference referece) { | ||
57 | val transformationDefinition = EcoreUtil2.getContainerOfType(context, TransformationDefinition) | ||
58 | if (transformationDefinition === null) { | ||
59 | return IScope.NULLSCOPE | ||
60 | } | ||
61 | val resourceDescriptions = getResourceDescriptions(transformationDefinition) | ||
62 | val mappingDefinitionDescriptions = toMappingDefinitionDescriptions(resourceDescriptions, | ||
63 | transformationDefinition.mappingDefinitions) | ||
64 | val ruleDefinitionsScope = new SimpleScope(IScope.NULLSCOPE, mappingDefinitionDescriptions) | ||
65 | importedNamespaceProvider.createImportNormalizedScope(ruleDefinitionsScope, context, referece) | ||
66 | } | ||
67 | |||
68 | protected def toMappingDefinitionDescriptions(IResourceDescriptions resourceDescriptions, | ||
69 | Iterable<? extends MappingDefinition> ruleDefinitions) { | ||
70 | val mappingDefinitionDescriptions = Lists.newArrayListWithExpectedSize(ruleDefinitions.size) | ||
71 | for (ruleDefinition : ruleDefinitions) { | ||
72 | val pattern = ruleDefinition.safelyGetPattern | ||
73 | if (pattern !== null) { | ||
74 | val patternName = resourceDescriptions.getExportedObjectsByObject(pattern).head?.qualifiedName | ||
75 | if (patternName !== null) { | ||
76 | mappingDefinitionDescriptions += EObjectDescription.create(patternName, ruleDefinition) | ||
77 | } | ||
78 | } | ||
79 | |||
80 | } | ||
81 | mappingDefinitionDescriptions | ||
82 | } | ||
83 | |||
84 | private def safelyGetPattern(MappingDefinition mappingDefinition) { | ||
85 | switch (mappingDefinition) { | ||
86 | MappingDefinitionImpl: mappingDefinition.basicGetPattern | ||
87 | case null: null | ||
88 | default: mappingDefinition.pattern | ||
89 | } | ||
90 | } | ||
91 | |||
92 | private def getResourceDescriptions(Notifier notifier) { | ||
93 | val resourceSet = EcoreUtil2.getResourceSet(notifier) | ||
94 | if (resourceSet === null) { | ||
95 | new IResourceDescriptions.NullImpl | ||
96 | } else { | ||
97 | resourceDescriptionsProvider.getResourceDescriptions(resourceSet) | ||
98 | } | ||
99 | } | ||
100 | |||
101 | protected def getMappingParametersScope(EObject context) { | ||
102 | val mappingDefinition = EcoreUtil2.getContainerOfType(context, MappingDefinition) | ||
103 | if (mappingDefinition === null) { | ||
104 | return IScope.NULLSCOPE | ||
105 | } | ||
106 | val variables = mappingDefinition.parameters.filter [ | ||
107 | !name.startsWith(SINGLETON_VARIABLE_PREFIX) | ||
108 | ] | ||
109 | Scopes.scopeFor(variables) | ||
110 | } | ||
111 | |||
112 | protected def getComponentInstancesScope(EObject context) { | ||
113 | val mappingDefinition = EcoreUtil2.getContainerOfType(context, MappingDefinition) | ||
114 | if (mappingDefinition === null) { | ||
115 | return IScope.NULLSCOPE | ||
116 | } | ||
117 | val componentInstances = <Variable>newArrayList | ||
118 | componentInstances.addAll(mappingDefinition.lookupDefinitions) | ||
119 | if (mappingDefinition.componentInstance !== null) { | ||
120 | componentInstances += mappingDefinition.componentInstance | ||
121 | } | ||
122 | Scopes.scopeFor(componentInstances) | ||
123 | } | ||
124 | |||
125 | protected def getEventDeclarationsScope(EObject context) { | ||
126 | val variable = EcoreUtil2.getContainerOfType(context, EventReference)?.component | ||
127 | val events = switch (variable) { | ||
128 | ComponentInstance: | ||
129 | variable.componentType?.allEventDeclarations | ||
130 | LookupDefinition: | ||
131 | variable.mapping?.componentInstance?.componentType?.allEventDeclarations | ||
132 | default: | ||
133 | null | ||
134 | } | ||
135 | if (events === null) { | ||
136 | return IScope.NULLSCOPE | ||
137 | } | ||
138 | Scopes.scopeFor(events) | ||
139 | } | ||
140 | |||
141 | private def getAllEventDeclarations(ComponentDefinition componentDefinition) { | ||
142 | val eventDeclarations = newArrayList | ||
143 | eventDeclarations.addAll(componentDefinition.inputEvents) | ||
144 | eventDeclarations.addAll(componentDefinition.eventDefinitions) | ||
145 | eventDeclarations | ||
146 | } | ||
147 | } | ||