diff options
author | 2019-03-20 16:09:09 +0100 | |
---|---|---|
committer | 2019-03-20 16:09:09 +0100 | |
commit | 3f5aaab5025b8eb243f414b1c789085327df04f4 (patch) | |
tree | 156d9d95888fce6b003d73f509b9155e6b24555f /Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme | |
parent | Fix ParseUtil to avoid breaking the .vql editor in Eclipse (diff) | |
download | VIATRA-Generator-3f5aaab5025b8eb243f414b1c789085327df04f4.tar.gz VIATRA-Generator-3f5aaab5025b8eb243f414b1c789085327df04f4.tar.zst VIATRA-Generator-3f5aaab5025b8eb243f414b1c789085327df04f4.zip |
Fault tree transformation for partial models WIP
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme')
4 files changed, 215 insertions, 231 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/ApplicationConfiguration.xtext b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/ApplicationConfiguration.xtext index 6af31723..44ef8fd1 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/ApplicationConfiguration.xtext +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/ApplicationConfiguration.xtext | |||
@@ -2,6 +2,7 @@ grammar hu.bme.mit.inf.dslreasoner.application.ApplicationConfiguration with org | |||
2 | 2 | ||
3 | import "http://www.eclipse.org/emf/2002/Ecore" as ecore | 3 | import "http://www.eclipse.org/emf/2002/Ecore" as ecore |
4 | import "http://www.eclipse.org/viatra/query/patternlanguage/emf/PatternLanguage" as viatra | 4 | import "http://www.eclipse.org/viatra/query/patternlanguage/emf/PatternLanguage" as viatra |
5 | import "http://www.bme.hu/mit/inf/dslreasoner/faulttree/components/CftLanguage" as cftLanguage | ||
5 | generate applicationConfiguration "http://www.bme.hu/mit/inf/dslreasoner/application/ApplicationConfiguration" | 6 | generate applicationConfiguration "http://www.bme.hu/mit/inf/dslreasoner/application/ApplicationConfiguration" |
6 | 7 | ||
7 | ConfigurationScript: | 8 | ConfigurationScript: |
@@ -22,10 +23,11 @@ INTLiteral returns ecore::EInt: '-'? INT; | |||
22 | // Imports | 23 | // Imports |
23 | /////////////////////////////////////////////////// | 24 | /////////////////////////////////////////////////// |
24 | 25 | ||
25 | Import: EPackageImport | ViatraImport; | 26 | Import: EPackageImport | ViatraImport | CftImport; |
26 | 27 | ||
27 | EPackageImport: "import" "epackage" importedPackage=[ecore::EPackage|STRING]; | 28 | EPackageImport: "import" "epackage" importedPackage=[ecore::EPackage|STRING]; |
28 | ViatraImport: "import" "viatra" importedViatra=[viatra::PatternModel|STRING]; | 29 | ViatraImport: "import" "viatra" importedViatra=[viatra::PatternModel|STRING]; |
30 | CftImport: "import" "reliability" importedCft=[cftLanguage::CftModel|STRING]; | ||
29 | 31 | ||
30 | /////////////////////////////////////////////////// | 32 | /////////////////////////////////////////////////// |
31 | // Declaration | 33 | // Declaration |
@@ -38,6 +40,7 @@ Declaration : | |||
38 | | GraphPatternDeclaration | 40 | | GraphPatternDeclaration |
39 | | ConfigDeclaration | 41 | | ConfigDeclaration |
40 | | ScopeDeclaration | 42 | | ScopeDeclaration |
43 | | ObjectiveDeclaration | ||
41 | ; | 44 | ; |
42 | 45 | ||
43 | /////////////////////////////////////////////////// | 46 | /////////////////////////////////////////////////// |
@@ -89,6 +92,23 @@ GraphPatternReference: referred = [GraphPatternDeclaration]; | |||
89 | GraphPattern: GraphPatternReference|PatternSpecification; | 92 | GraphPattern: GraphPatternReference|PatternSpecification; |
90 | 93 | ||
91 | /////////////////////////////////////////////////// | 94 | /////////////////////////////////////////////////// |
95 | // Objectives | ||
96 | /////////////////////////////////////////////////// | ||
97 | |||
98 | ObjectiveSpecification: '{' entries += ObjectiveEntry (',' entries += ObjectiveEntry)* '}'; | ||
99 | ObjectiveEntry: OptimizationEntry | ThresholdEntry; | ||
100 | enum OptimizationDirection: MINIMIZE='minimize' | MAXIMIZE='maximize'; | ||
101 | OptimizationEntry: direction=OptimizationDirection function=ObjectiveFunction; | ||
102 | enum ComparisonOperator: LESS_EQUALS='<=' | GREATER_EQUALS='>='; | ||
103 | ThresholdEntry: function=ObjectiveFunction operator=ComparisonOperator threshold=REALLiteral; | ||
104 | ObjectiveFunction: ReliabiltiyFunction; | ||
105 | ReliabiltiyFunction: 'reliability' (package=[cftLanguage::CftModel|QualifiedName] '::')? transformation = [cftLanguage::TransformationDefinition]; | ||
106 | |||
107 | ObjectiveDeclaration: 'objectives' name = ID specification = ObjectiveSpecification; | ||
108 | ObjectiveReference: referred = [ObjectiveDeclaration]; | ||
109 | Objective: ObjectiveReference|ObjectiveSpecification; | ||
110 | |||
111 | /////////////////////////////////////////////////// | ||
92 | // SolverConfig | 112 | // SolverConfig |
93 | /////////////////////////////////////////////////// | 113 | /////////////////////////////////////////////////// |
94 | 114 | ||
@@ -99,7 +119,8 @@ ConfigDeclaration : | |||
99 | 'config' name = ID specification = ConfigSpecification | 119 | 'config' name = ID specification = ConfigSpecification |
100 | ; | 120 | ; |
101 | ConfigEntry: DocumentationEntry | RuntimeEntry | MemoryEntry | CustomEntry; | 121 | ConfigEntry: DocumentationEntry | RuntimeEntry | MemoryEntry | CustomEntry; |
102 | DocumentationEntry: "log-level" '=' level = DocumentLevelSpecification; enum DocumentLevelSpecification: none | normal | full; | 122 | DocumentationEntry: "log-level" '=' level = DocumentLevelSpecification; |
123 | enum DocumentLevelSpecification: none | normal | full; | ||
103 | RuntimeEntry: "runtime" "=" millisecLimit = INT; | 124 | RuntimeEntry: "runtime" "=" millisecLimit = INT; |
104 | MemoryEntry: "memory" "=" megabyteLimit = INT; | 125 | MemoryEntry: "memory" "=" megabyteLimit = INT; |
105 | CustomEntry: key = STRING "=" value = STRING; | 126 | CustomEntry: key = STRING "=" value = STRING; |
@@ -160,6 +181,7 @@ GenerationTask: 'generate' {GenerationTask} '{'( | |||
160 | ('metamodel' '=' metamodel = Metamodel)? & | 181 | ('metamodel' '=' metamodel = Metamodel)? & |
161 | ('partial-model' '=' partialModel = PartialModel)? & | 182 | ('partial-model' '=' partialModel = PartialModel)? & |
162 | ('constraints' '=' patterns = GraphPattern)? & | 183 | ('constraints' '=' patterns = GraphPattern)? & |
184 | ('objectives' '=' objectives = Objective)? & | ||
163 | 185 | ||
164 | // model set | 186 | // model set |
165 | ('scope' '=' scope = Scope)? & | 187 | ('scope' '=' scope = Scope)? & |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/GenerateApplicationConfiguration.mwe2 b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/GenerateApplicationConfiguration.mwe2 index 13cc78a8..3983cd10 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/GenerateApplicationConfiguration.mwe2 +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/GenerateApplicationConfiguration.mwe2 | |||
@@ -31,6 +31,7 @@ Workflow { | |||
31 | name = "hu.bme.mit.inf.dslreasoner.application.ApplicationConfiguration" | 31 | name = "hu.bme.mit.inf.dslreasoner.application.ApplicationConfiguration" |
32 | referencedResource = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel" | 32 | referencedResource = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel" |
33 | referencedResource = "platform:/resource/org.eclipse.viatra.query.patternlanguage.emf/model/PatternLanguage.genmodel" | 33 | referencedResource = "platform:/resource/org.eclipse.viatra.query.patternlanguage.emf/model/PatternLanguage.genmodel" |
34 | referencedResource = "platform:/resource/hu.bme.mit.inf.dslreasoner.faulttree.components/model/generated/CftLanguage.genmodel" | ||
34 | fileExtensions = "vsconfig" | 35 | fileExtensions = "vsconfig" |
35 | serializer = { | 36 | serializer = { |
36 | generateStub = false | 37 | generateStub = false |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend index fc4b721a..ec79ac89 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend | |||
@@ -2,6 +2,7 @@ package hu.bme.mit.inf.dslreasoner.application.linking | |||
2 | 2 | ||
3 | import com.google.inject.Inject | 3 | import com.google.inject.Inject |
4 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ApplicationConfigurationPackage | 4 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ApplicationConfigurationPackage |
5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.CftImport | ||
5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript | 6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript |
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.EPackageImport | 7 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.EPackageImport |
7 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternEntry | 8 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternEntry |
@@ -11,8 +12,10 @@ import java.util.List | |||
11 | import java.util.Optional | 12 | import java.util.Optional |
12 | import org.eclipse.emf.common.util.URI | 13 | import org.eclipse.emf.common.util.URI |
13 | import org.eclipse.emf.ecore.EObject | 14 | import org.eclipse.emf.ecore.EObject |
15 | import org.eclipse.emf.ecore.EPackage | ||
14 | import org.eclipse.emf.ecore.EReference | 16 | import org.eclipse.emf.ecore.EReference |
15 | import org.eclipse.emf.ecore.resource.Resource | 17 | import org.eclipse.emf.ecore.resource.Resource |
18 | import org.eclipse.emf.ecore.resource.ResourceSet | ||
16 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider | 19 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider |
17 | import org.eclipse.xtext.EcoreUtil2 | 20 | import org.eclipse.xtext.EcoreUtil2 |
18 | import org.eclipse.xtext.conversion.IValueConverterService | 21 | import org.eclipse.xtext.conversion.IValueConverterService |
@@ -20,105 +23,98 @@ import org.eclipse.xtext.conversion.ValueConverterException | |||
20 | import org.eclipse.xtext.linking.impl.DefaultLinkingService | 23 | import org.eclipse.xtext.linking.impl.DefaultLinkingService |
21 | import org.eclipse.xtext.nodemodel.ILeafNode | 24 | import org.eclipse.xtext.nodemodel.ILeafNode |
22 | import org.eclipse.xtext.nodemodel.INode | 25 | import org.eclipse.xtext.nodemodel.INode |
23 | import org.eclipse.emf.ecore.resource.ResourceSet | ||
24 | import org.eclipse.emf.ecore.EPackage | ||
25 | 26 | ||
26 | class ApplicationConfigurationLinkingService extends DefaultLinkingService{ | 27 | class ApplicationConfigurationLinkingService extends DefaultLinkingService { |
28 | @Inject IValueConverterService valueConverterService | ||
29 | @Inject IMetamodelProvider metamodelProvider | ||
27 | 30 | ||
28 | //@Inject Logger logger | 31 | public static extension ApplicationConfigurationPackage pac = ApplicationConfigurationPackage.eINSTANCE |
29 | 32 | ||
30 | @Inject IValueConverterService valueConverterService | 33 | override getLinkedObjects(EObject context, EReference ref, INode node) { |
31 | @Inject IMetamodelProvider metamodelProvider | 34 | if (context instanceof EPackageImport) { |
32 | 35 | if (ref == EPackageImport_ImportedPackage && node instanceof ILeafNode) { | |
33 | public static extension ApplicationConfigurationPackage pac = ApplicationConfigurationPackage.eINSTANCE | 36 | return getEPackage(context, node as ILeafNode) |
37 | } | ||
38 | } else if (context instanceof ViatraImport) { | ||
39 | if (ref == viatraImport_ImportedViatra) { | ||
40 | return getViatra(context, node) | ||
41 | } | ||
42 | } else if (context instanceof CftImport) { | ||
43 | if (ref == cftImport_ImportedCft) { | ||
44 | return getCftModel(context, node) | ||
45 | } | ||
46 | } | ||
47 | return super.getLinkedObjects(context, ref, node) | ||
48 | } | ||
49 | |||
50 | private def getEPackage(EPackageImport packageImport, ILeafNode node) { | ||
51 | val x = getNSUri(node) | ||
52 | if (x.isPresent) { | ||
53 | val uriString = x.get | ||
54 | val epackageByMetamodelProvider = metamodelProvider.loadEPackage(uriString, | ||
55 | packageImport.eResource.resourceSet) | ||
56 | val epackageByMe = ePackageByMe(packageImport.eResource.resourceSet, uriString) | ||
57 | if (epackageByMetamodelProvider !== null) { | ||
58 | return Collections.singletonList(epackageByMetamodelProvider as EObject) | ||
59 | } else if (epackageByMe !== null) { | ||
60 | return Collections.singletonList(epackageByMe as EObject) | ||
61 | } else { | ||
62 | emptyList | ||
63 | } | ||
64 | } else { | ||
65 | return emptyList | ||
66 | } | ||
67 | } | ||
34 | 68 | ||
35 | override getLinkedObjects(EObject context, EReference ref, INode node) { | 69 | private def ePackageByMe(ResourceSet rs, String uri) { |
36 | if(context instanceof EPackageImport) { | 70 | try { |
37 | if(ref == EPackageImport_ImportedPackage && node instanceof ILeafNode) { | 71 | val resource = rs.getResource(URI.createURI(uri), true); |
38 | return getEPackage(context as EPackageImport, node as ILeafNode) | 72 | return resource.contents.head as EPackage |
39 | } | 73 | } catch (Exception e) { |
40 | } else if(context instanceof ViatraImport) { | 74 | return null |
41 | if(ref == viatraImport_ImportedViatra) { | 75 | } |
42 | return getViatra(context as ViatraImport, node) | 76 | } |
43 | } | 77 | |
44 | } else if(context instanceof PatternEntry) { | 78 | private def getViatra(ViatraImport viatraImport, INode node) { |
45 | if(ref === patternEntry_Package) { | 79 | getByUri(viatraImport, viatraImport_ImportedViatra, node) |
46 | return getViatraPackage(context as PatternEntry,node) | 80 | } |
47 | } | ||
48 | } | ||
49 | return super.getLinkedObjects(context, ref, node) | ||
50 | } | ||
51 | 81 | ||
52 | def getViatraPackage(PatternEntry entry, INode node) { | 82 | private def getByUri(EObject context, EReference ref, INode node) { |
53 | val document = EcoreUtil2.getContainerOfType(entry,ConfigurationScript) | 83 | val uri = getNSUri(node) |
54 | val nodeString = valueConverterService.toValue(node.text, | 84 | if (uri.present) { |
55 | linkingHelper.getRuleNameFrom(node.grammarElement), node).toString.replaceAll("\\s","") | 85 | var URI createdURI |
56 | val patternModels = document.imports.filter(ViatraImport).map[it.importedViatra].filterNull | 86 | try { |
57 | val List<EObject> patternModelsWithSameNamespace = patternModels.filter[nodeString.equals(it.packageName)].filter(EObject).toList | 87 | createdURI = URI.createURI(uri.get) |
58 | return patternModelsWithSameNamespace | 88 | } catch (IllegalArgumentException e) { |
89 | return super.getLinkedObjects(context, ref, node) | ||
90 | } | ||
91 | var Resource res | ||
92 | try { | ||
93 | res = context.eResource.resourceSet.getResource(createdURI, true); | ||
94 | } catch (RuntimeException e) { | ||
95 | return super.getLinkedObjects(context, ref, node) | ||
96 | } | ||
97 | if (res !== null && res.contents !== null) { | ||
98 | return res.contents.filter[ref.EType.isInstance(it)].toList | ||
99 | } else { | ||
100 | return super.getLinkedObjects(context, ref, node) | ||
101 | } | ||
102 | } else { | ||
103 | return super.getLinkedObjects(context, ref, node) | ||
104 | } | ||
59 | } | 105 | } |
60 | 106 | ||
61 | private def getEPackage(EPackageImport packageImport, ILeafNode node) { | 107 | private def getNSUri(INode node) { |
62 | val x = getNSUri(node) | 108 | try { |
63 | if(x.isPresent) { | 109 | val convertedValue = valueConverterService.toValue(node.text, |
64 | val uriString = x.get | 110 | linkingHelper.getRuleNameFrom(node.grammarElement), node) |
65 | val epackageByMetamodelProvider = metamodelProvider.loadEPackage(uriString, packageImport.eResource.resourceSet) | 111 | Optional.of(convertedValue as String) |
66 | val epackageByMe = ePackageByMe(packageImport.eResource.resourceSet,uriString) | 112 | } catch (ValueConverterException e) { |
67 | //println(epackageByMetamodelProvider) | 113 | Optional.empty |
68 | //println(epackageByMe) | 114 | } |
69 | if(epackageByMetamodelProvider!==null) { | 115 | } |
70 | return Collections.singletonList(epackageByMetamodelProvider as EObject) | 116 | |
71 | } else if(epackageByMe !== null) { | 117 | private def getCftModel(CftImport context, INode node) { |
72 | return Collections.singletonList(epackageByMe as EObject) | 118 | getByUri(context, cftImport_ImportedCft, node) |
73 | } else { | 119 | } |
74 | emptyList | 120 | } |
75 | } | ||
76 | } else { | ||
77 | return emptyList | ||
78 | } | ||
79 | } | ||
80 | |||
81 | private def ePackageByMe(ResourceSet rs, String uri) { | ||
82 | try { | ||
83 | val resource = rs.getResource(URI.createURI(uri), true); | ||
84 | return resource.contents.head as EPackage | ||
85 | } catch (Exception e) { | ||
86 | return null | ||
87 | } | ||
88 | } | ||
89 | |||
90 | private def getViatra(ViatraImport viatraImport, INode node) { | ||
91 | val uri = getNSUri(node) | ||
92 | if(uri.present) { | ||
93 | var URI createdURI | ||
94 | try{ | ||
95 | createdURI = URI.createURI(uri.get) | ||
96 | }catch(IllegalArgumentException e) { | ||
97 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | ||
98 | } | ||
99 | var Resource res | ||
100 | try{ | ||
101 | res = viatraImport.eResource.resourceSet.getResource(createdURI,true); | ||
102 | } catch(RuntimeException e){ | ||
103 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | ||
104 | } | ||
105 | if(res!==null && !res.contents.nullOrEmpty) { | ||
106 | return #[res.contents.head] | ||
107 | } else { | ||
108 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | ||
109 | } | ||
110 | } else { | ||
111 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | ||
112 | } | ||
113 | } | ||
114 | |||
115 | private def getNSUri(INode node) { | ||
116 | try { | ||
117 | val convertedValue = valueConverterService.toValue(node.text, | ||
118 | linkingHelper.getRuleNameFrom(node.grammarElement), node) | ||
119 | Optional.of(convertedValue as String) | ||
120 | } catch (ValueConverterException e) { | ||
121 | Optional.empty | ||
122 | } | ||
123 | } | ||
124 | } \ No newline at end of file | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/scoping/ApplicationConfigurationScopeProvider.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/scoping/ApplicationConfigurationScopeProvider.xtend index 36948c2d..b049b4c9 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/scoping/ApplicationConfigurationScopeProvider.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/scoping/ApplicationConfigurationScopeProvider.xtend | |||
@@ -3,28 +3,27 @@ | |||
3 | */ | 3 | */ |
4 | package hu.bme.mit.inf.dslreasoner.application.scoping | 4 | package hu.bme.mit.inf.dslreasoner.application.scoping |
5 | 5 | ||
6 | import com.google.common.base.Function | 6 | import com.google.inject.Inject |
7 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.AllPackageEntry | 7 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.CftImport |
8 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.AllPatternEntry | ||
9 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ApplicationConfigurationPackage | ||
10 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ClassReference | ||
11 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript | 8 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript |
12 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.EPackageImport | 9 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.EPackageImport |
13 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelElement | 10 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelElement |
14 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelSpecification | 11 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelEntry |
15 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternElement | 12 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternEntry |
16 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternSpecification | 13 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ReliabiltiyFunction |
17 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ViatraImport | 14 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ViatraImport |
15 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.CftModel | ||
18 | import org.eclipse.emf.ecore.EClass | 16 | import org.eclipse.emf.ecore.EClass |
19 | import org.eclipse.emf.ecore.EEnum | 17 | import org.eclipse.emf.ecore.EEnum |
20 | import org.eclipse.emf.ecore.EObject | 18 | import org.eclipse.emf.ecore.EObject |
21 | import org.eclipse.emf.ecore.EReference | 19 | import org.eclipse.emf.ecore.EReference |
22 | import org.eclipse.viatra.query.patternlanguage.emf.vql.PatternModel | 20 | import org.eclipse.viatra.query.patternlanguage.emf.vql.PatternModel |
23 | import org.eclipse.xtext.EcoreUtil2 | 21 | import org.eclipse.xtext.EcoreUtil2 |
24 | import org.eclipse.xtext.naming.QualifiedName | 22 | import org.eclipse.xtext.naming.IQualifiedNameConverter |
25 | import org.eclipse.xtext.scoping.IScope | ||
26 | import org.eclipse.xtext.scoping.Scopes | 23 | import org.eclipse.xtext.scoping.Scopes |
27 | 24 | ||
25 | import static hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ApplicationConfigurationPackage.Literals.* | ||
26 | |||
28 | /** | 27 | /** |
29 | * This class contains custom scoping description. | 28 | * This class contains custom scoping description. |
30 | * | 29 | * |
@@ -32,150 +31,116 @@ import org.eclipse.xtext.scoping.Scopes | |||
32 | * on how and when to use it. | 31 | * on how and when to use it. |
33 | */ | 32 | */ |
34 | class ApplicationConfigurationScopeProvider extends AbstractApplicationConfigurationScopeProvider { | 33 | class ApplicationConfigurationScopeProvider extends AbstractApplicationConfigurationScopeProvider { |
35 | 34 | ||
36 | private val language = ApplicationConfigurationPackage.eINSTANCE | 35 | @Inject IQualifiedNameConverter qualifiedNameConverter |
37 | protected val nameConverter = new Function<PatternModel,QualifiedName>() { | 36 | |
38 | override apply(PatternModel input) { | ||
39 | println(input) | ||
40 | val res = QualifiedName.create(input.packageName.split("\\.")) | ||
41 | println(res.toString) | ||
42 | return res | ||
43 | } | ||
44 | } | ||
45 | |||
46 | override getScope(EObject context, EReference reference) { | 37 | override getScope(EObject context, EReference reference) { |
47 | val document = EcoreUtil2.getContainerOfType(context,ConfigurationScript) | 38 | val document = EcoreUtil2.getContainerOfType(context, ConfigurationScript) |
48 | if(context instanceof MetamodelElement) { | 39 | switch (reference) { |
49 | return context.scopeForMetamodelElement(reference,document) | 40 | case METAMODEL_ENTRY__PACKAGE: |
50 | } else if(context instanceof MetamodelSpecification) { | 41 | getEPackageScope(document) |
51 | return context.scopeForMetamodelSpecification(reference,document) | 42 | case METAMODEL_ELEMENT__CLASSIFIER: |
52 | } else if(context instanceof AllPackageEntry){ | 43 | getEClassifierScope(context, document) |
53 | return context.scopeForAllPackageEntry(reference,document) | 44 | case METAMODEL_ELEMENT__FEATURE: |
54 | } else if(context instanceof PatternElement) { | 45 | getEStructuralFeatureScope(context, reference, document) |
55 | return context.scopeForPatternElement(reference,document) | 46 | case PATTERN_ENTRY__PACKAGE: |
56 | } else if(context instanceof PatternSpecification) { | 47 | getViatraPackageScope(context, reference, document) |
57 | return context.scopeForPatternSpecification(reference,document) | 48 | case PATTERN_ELEMENT__PATTERN: |
58 | } else if(context instanceof AllPatternEntry) { | 49 | getViatraPatternScope(context, document) |
59 | return context.scopeForAllPatternEntry(reference,document) | 50 | case RELIABILTIY_FUNCTION__PACKAGE: |
60 | } else if(context instanceof ClassReference) { | 51 | getCftPackageScope(context, reference, document) |
61 | return context.scopeForClassReference(reference,document) | 52 | case RELIABILTIY_FUNCTION__TRANSFORMATION: |
62 | }else { | 53 | getCftTransformationScope(context, document) |
63 | return super.getScope(context,reference) | 54 | default: |
55 | super.getScope(context, reference) | ||
64 | } | 56 | } |
65 | } | 57 | } |
66 | 58 | ||
67 | private def allEPackages(ConfigurationScript document) { | 59 | private def getAllEPackages(ConfigurationScript document) { |
68 | return document.imports.filter(EPackageImport).map[it.importedPackage].filterNull | 60 | document.imports.filter(EPackageImport).map[importedPackage].filterNull |
69 | } | 61 | } |
70 | private def allViatraPackages(ConfigurationScript document) { | 62 | |
71 | val res = document.imports.filter(ViatraImport).map[it.importedViatra].filterNull | 63 | private def getAllViatraPackages(ConfigurationScript document) { |
72 | //println('''All packages: «res.map[packageName].toList»''') | 64 | document.imports.filter(ViatraImport).map[importedViatra].filterNull |
73 | return res | ||
74 | } | 65 | } |
75 | private def allEClassifiers(ConfigurationScript document) { | 66 | |
67 | private def getAllEClassifiers(ConfigurationScript document) { | ||
76 | document.allEPackages.map[EClassifiers].flatten | 68 | document.allEPackages.map[EClassifiers].flatten |
77 | } | 69 | } |
78 | private def allPatterns(ConfigurationScript document) { | 70 | |
79 | val res = document.allViatraPackages.map[patterns].flatten | 71 | private def getAllPatterns(ConfigurationScript document) { |
80 | //println('''All patterns: «res.map[name].toList»''') | 72 | document.allViatraPackages.map[patterns].flatten |
81 | return res | ||
82 | } | 73 | } |
83 | 74 | ||
84 | protected def scopeForMetamodelElement(MetamodelElement context, EReference reference, ConfigurationScript document) { | 75 | private def getAllCftPackages(ConfigurationScript document) { |
85 | if(reference === language.metamodelEntry_Package) { | 76 | document.imports.filter(CftImport).map[importedCft].filterNull |
86 | return Scopes.scopeFor(document.allEPackages) | ||
87 | } else if(reference === language.metamodelElement_Classifier) { | ||
88 | if(context.package !== null) { | ||
89 | return Scopes.scopeFor(context.package.EClassifiers) | ||
90 | } else { | ||
91 | return Scopes.scopeFor(document.allEClassifiers) | ||
92 | } | ||
93 | } if (reference === language.metamodelElement_Feature) { | ||
94 | val referredClassifier = context.classifier | ||
95 | if(referredClassifier instanceof EClass) { | ||
96 | return Scopes.scopeFor(referredClassifier.EAllStructuralFeatures) | ||
97 | } else if(referredClassifier instanceof EEnum) { | ||
98 | return Scopes.scopeFor(referredClassifier.ELiterals) | ||
99 | } else { | ||
100 | super.getScope(context,reference) | ||
101 | } | ||
102 | } | ||
103 | } | 77 | } |
104 | 78 | ||
105 | protected def scopeForMetamodelSpecification(MetamodelSpecification context, EReference reference, ConfigurationScript document) { | 79 | private def getAllCftTransformations(ConfigurationScript document) { |
106 | if(reference === language.metamodelEntry_Package) { | 80 | document.allCftPackages.map[transformationDefinitions].flatten |
107 | return Scopes.scopeFor(document.allEPackages) | ||
108 | } else if(reference ===language.metamodelElement_Classifier) { | ||
109 | return Scopes.scopeFor(document.allEClassifiers) | ||
110 | } else { | ||
111 | return super.getScope(context,reference) | ||
112 | } | ||
113 | } | 81 | } |
114 | 82 | ||
115 | protected def scopeForAllPackageEntry(AllPackageEntry context, EReference reference, ConfigurationScript document) { | 83 | private def getEPackageScope(ConfigurationScript document) { |
116 | if(reference === language.metamodelEntry_Package) { | 84 | Scopes.scopeFor(document.allEPackages) |
117 | return Scopes.scopeFor(document.allEPackages) | ||
118 | } else if(reference === language.metamodelElement_Classifier) { | ||
119 | if(context.package === null) { | ||
120 | return Scopes.scopeFor(document.allEClassifiers) | ||
121 | } else { | ||
122 | return Scopes.scopeFor(context.package.EClassifiers) | ||
123 | } | ||
124 | } else { | ||
125 | return super.getScope(context,reference) | ||
126 | } | ||
127 | } | 85 | } |
128 | 86 | ||
129 | ////////// | 87 | private def getEClassifierScope(EObject context, ConfigurationScript document) { |
130 | 88 | val classifiers = switch (context) { | |
131 | def IScope scopeForClassReference(ClassReference classReference, EReference eReference, ConfigurationScript document) { | 89 | MetamodelEntry case context.package !== null: |
132 | if(eReference === language.metamodelEntry_Package) { | 90 | context.package.EClassifiers |
133 | return Scopes.scopeFor(document.allEPackages) | 91 | default: |
134 | } else if(eReference === language.metamodelElement_Classifier) { | 92 | document.allEClassifiers |
135 | Scopes.scopeFor(document.allEClassifiers) | ||
136 | } else { | ||
137 | return super.getScope(classReference,eReference) | ||
138 | } | 93 | } |
94 | Scopes.scopeFor(classifiers) | ||
139 | } | 95 | } |
140 | 96 | ||
141 | ////////// | 97 | private def getEStructuralFeatureScope(EObject context, EReference reference, ConfigurationScript document) { |
142 | 98 | val referredClassifier = if (context instanceof MetamodelElement) { | |
143 | protected def scopeForPatternElement(PatternElement context, EReference reference, ConfigurationScript document) { | 99 | context.classifier |
144 | if(reference === language.patternEntry_Package) { | ||
145 | return Scopes.scopeFor(document.allViatraPackages,nameConverter,super.getScope(context,reference)) | ||
146 | } else if(reference === language.patternElement_Pattern) { | ||
147 | if(context.package !== null) { | ||
148 | return Scopes.scopeFor(context.package.patterns) | ||
149 | } else { | 100 | } else { |
150 | return Scopes.scopeFor(document.allPatterns) | 101 | null |
151 | } | 102 | } |
152 | } else { | 103 | switch (referredClassifier) { |
153 | super.getScope(context,reference) | 104 | EClass: |
105 | Scopes.scopeFor(referredClassifier.EAllStructuralFeatures) | ||
106 | EEnum: | ||
107 | Scopes.scopeFor(referredClassifier.ELiterals) | ||
108 | default: | ||
109 | super.getScope(context, reference) | ||
154 | } | 110 | } |
155 | } | 111 | } |
156 | 112 | ||
157 | protected def scopeForPatternSpecification(PatternSpecification context, EReference reference, ConfigurationScript document) { | 113 | private def getViatraPackageScope(EObject context, EReference reference, ConfigurationScript document) { |
158 | if(reference === language.patternEntry_Package) { | 114 | val patternModelNameConverter = [ PatternModel patternModel | |
159 | return Scopes.scopeFor(document.allViatraPackages,nameConverter,super.getScope(context,reference)) | 115 | qualifiedNameConverter.toQualifiedName(patternModel.packageName) |
160 | } else if(reference ===language.patternElement_Pattern) { | 116 | ] |
161 | return Scopes.scopeFor(document.allPatterns) | 117 | Scopes.scopeFor(document.allViatraPackages, patternModelNameConverter, super.getScope(context, reference)) |
162 | } else { | 118 | } |
163 | return super.getScope(context,reference) | 119 | |
120 | private def getViatraPatternScope(EObject context, ConfigurationScript document) { | ||
121 | val patterns = switch (context) { | ||
122 | PatternEntry case context.package !== null: | ||
123 | context.package.patterns | ||
124 | default: | ||
125 | document.allPatterns | ||
164 | } | 126 | } |
127 | Scopes.scopeFor(patterns) | ||
165 | } | 128 | } |
166 | 129 | ||
167 | protected def scopeForAllPatternEntry(AllPatternEntry context, EReference reference, ConfigurationScript document) { | 130 | private def getCftPackageScope(EObject context, EReference reference, ConfigurationScript document) { |
168 | if(reference === language.patternEntry_Package) { | 131 | val cftModelNameConverter = [ CftModel cftModel | |
169 | val res = Scopes.scopeFor(document.allViatraPackages,nameConverter,super.getScope(context,reference)) | 132 | qualifiedNameConverter.toQualifiedName(cftModel.packageName) |
170 | return res | 133 | ] |
171 | } else if(reference === language.patternElement_Pattern) { | 134 | Scopes.scopeFor(document.allCftPackages, cftModelNameConverter, super.getScope(context, reference)) |
172 | if(context.package === null) { | 135 | } |
173 | return Scopes.scopeFor(document.allPatterns) | 136 | |
174 | } else { | 137 | private def getCftTransformationScope(EObject context, ConfigurationScript document) { |
175 | return Scopes.scopeFor(context.package.patterns) | 138 | val transformations = switch (context) { |
176 | } | 139 | ReliabiltiyFunction case context.package !== null: |
177 | } else { | 140 | context.package.transformationDefinitions |
178 | return super.getScope(context,reference) | 141 | default: |
142 | document.allCftTransformations | ||
179 | } | 143 | } |
144 | Scopes.scopeFor(transformations) | ||
180 | } | 145 | } |
181 | } | 146 | } |