diff options
author | 2020-06-25 19:55:10 +0200 | |
---|---|---|
committer | 2020-06-25 19:55:10 +0200 | |
commit | c3a6d4b9cf3657070d180aa65ddbf0459e880329 (patch) | |
tree | 780c4fc61578dcb309af53fb0c164c7627e51676 /Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/scoping/ApplicationConfigurationScopeProvider.xtend | |
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 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/scoping/ApplicationConfigurationScopeProvider.xtend')
-rw-r--r-- | Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/scoping/ApplicationConfigurationScopeProvider.xtend | 209 |
1 files changed, 75 insertions, 134 deletions
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..e5db9893 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,17 +3,12 @@ | |||
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 | ||
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 | 7 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript |
12 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.EPackageImport | 8 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.EPackageImport |
13 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelElement | 9 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelElement |
14 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelSpecification | 10 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.MetamodelEntry |
15 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternElement | 11 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternEntry |
16 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternSpecification | ||
17 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ViatraImport | 12 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ViatraImport |
18 | import org.eclipse.emf.ecore.EClass | 13 | import org.eclipse.emf.ecore.EClass |
19 | import org.eclipse.emf.ecore.EEnum | 14 | import org.eclipse.emf.ecore.EEnum |
@@ -21,10 +16,11 @@ import org.eclipse.emf.ecore.EObject | |||
21 | import org.eclipse.emf.ecore.EReference | 16 | import org.eclipse.emf.ecore.EReference |
22 | import org.eclipse.viatra.query.patternlanguage.emf.vql.PatternModel | 17 | import org.eclipse.viatra.query.patternlanguage.emf.vql.PatternModel |
23 | import org.eclipse.xtext.EcoreUtil2 | 18 | import org.eclipse.xtext.EcoreUtil2 |
24 | import org.eclipse.xtext.naming.QualifiedName | 19 | import org.eclipse.xtext.naming.IQualifiedNameConverter |
25 | import org.eclipse.xtext.scoping.IScope | ||
26 | import org.eclipse.xtext.scoping.Scopes | 20 | import org.eclipse.xtext.scoping.Scopes |
27 | 21 | ||
22 | import static hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ApplicationConfigurationPackage.Literals.* | ||
23 | |||
28 | /** | 24 | /** |
29 | * This class contains custom scoping description. | 25 | * This class contains custom scoping description. |
30 | * | 26 | * |
@@ -32,150 +28,95 @@ import org.eclipse.xtext.scoping.Scopes | |||
32 | * on how and when to use it. | 28 | * on how and when to use it. |
33 | */ | 29 | */ |
34 | class ApplicationConfigurationScopeProvider extends AbstractApplicationConfigurationScopeProvider { | 30 | class ApplicationConfigurationScopeProvider extends AbstractApplicationConfigurationScopeProvider { |
35 | 31 | ||
36 | private val language = ApplicationConfigurationPackage.eINSTANCE | 32 | @Inject IQualifiedNameConverter qualifiedNameConverter |
37 | protected val nameConverter = new Function<PatternModel,QualifiedName>() { | 33 | |
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) { | 34 | override getScope(EObject context, EReference reference) { |
47 | val document = EcoreUtil2.getContainerOfType(context,ConfigurationScript) | 35 | val document = EcoreUtil2.getContainerOfType(context, ConfigurationScript) |
48 | if(context instanceof MetamodelElement) { | 36 | switch (reference) { |
49 | return context.scopeForMetamodelElement(reference,document) | 37 | case METAMODEL_ENTRY__PACKAGE: |
50 | } else if(context instanceof MetamodelSpecification) { | 38 | getEPackageScope(document) |
51 | return context.scopeForMetamodelSpecification(reference,document) | 39 | case METAMODEL_ELEMENT__CLASSIFIER: |
52 | } else if(context instanceof AllPackageEntry){ | 40 | getEClassifierScope(context, document) |
53 | return context.scopeForAllPackageEntry(reference,document) | 41 | case METAMODEL_ELEMENT__FEATURE: |
54 | } else if(context instanceof PatternElement) { | 42 | getEStructuralFeatureScope(context, reference, document) |
55 | return context.scopeForPatternElement(reference,document) | 43 | case PATTERN_ENTRY__PACKAGE: |
56 | } else if(context instanceof PatternSpecification) { | 44 | getViatraPackageScope(context, reference, document) |
57 | return context.scopeForPatternSpecification(reference,document) | 45 | case PATTERN_ELEMENT__PATTERN: |
58 | } else if(context instanceof AllPatternEntry) { | 46 | getViatraPatternScope(context, document) |
59 | return context.scopeForAllPatternEntry(reference,document) | 47 | default: |
60 | } else if(context instanceof ClassReference) { | 48 | super.getScope(context, reference) |
61 | return context.scopeForClassReference(reference,document) | ||
62 | }else { | ||
63 | return super.getScope(context,reference) | ||
64 | } | 49 | } |
65 | } | 50 | } |
66 | 51 | ||
67 | private def allEPackages(ConfigurationScript document) { | 52 | private def getAllEPackages(ConfigurationScript document) { |
68 | return document.imports.filter(EPackageImport).map[it.importedPackage].filterNull | 53 | document.imports.filter(EPackageImport).map[importedPackage].filterNull |
69 | } | 54 | } |
70 | private def allViatraPackages(ConfigurationScript document) { | 55 | |
71 | val res = document.imports.filter(ViatraImport).map[it.importedViatra].filterNull | 56 | private def getAllViatraPackages(ConfigurationScript document) { |
72 | //println('''All packages: «res.map[packageName].toList»''') | 57 | document.imports.filter(ViatraImport).map[importedViatra].filterNull |
73 | return res | ||
74 | } | 58 | } |
75 | private def allEClassifiers(ConfigurationScript document) { | 59 | |
60 | private def getAllEClassifiers(ConfigurationScript document) { | ||
76 | document.allEPackages.map[EClassifiers].flatten | 61 | document.allEPackages.map[EClassifiers].flatten |
77 | } | 62 | } |
78 | private def allPatterns(ConfigurationScript document) { | 63 | |
79 | val res = document.allViatraPackages.map[patterns].flatten | 64 | private def getAllPatterns(ConfigurationScript document) { |
80 | //println('''All patterns: «res.map[name].toList»''') | 65 | document.allViatraPackages.map[patterns].flatten |
81 | return res | ||
82 | } | 66 | } |
83 | 67 | ||
84 | protected def scopeForMetamodelElement(MetamodelElement context, EReference reference, ConfigurationScript document) { | 68 | private def getEPackageScope(ConfigurationScript document) { |
85 | if(reference === language.metamodelEntry_Package) { | 69 | Scopes.scopeFor(document.allEPackages) |
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 | } | 70 | } |
104 | 71 | ||
105 | protected def scopeForMetamodelSpecification(MetamodelSpecification context, EReference reference, ConfigurationScript document) { | 72 | private def getEClassifierScope(EObject context, ConfigurationScript document) { |
106 | if(reference === language.metamodelEntry_Package) { | 73 | val classifiers = switch (context) { |
107 | return Scopes.scopeFor(document.allEPackages) | 74 | MetamodelEntry case context.package !== null: |
108 | } else if(reference ===language.metamodelElement_Classifier) { | 75 | context.package.EClassifiers |
109 | return Scopes.scopeFor(document.allEClassifiers) | 76 | default: |
110 | } else { | 77 | document.allEClassifiers |
111 | return super.getScope(context,reference) | ||
112 | } | 78 | } |
79 | Scopes.scopeFor(classifiers) | ||
113 | } | 80 | } |
114 | 81 | ||
115 | protected def scopeForAllPackageEntry(AllPackageEntry context, EReference reference, ConfigurationScript document) { | 82 | private def getEStructuralFeatureScope(EObject context, EReference reference, ConfigurationScript document) { |
116 | if(reference === language.metamodelEntry_Package) { | 83 | val referredClassifier = if (context instanceof MetamodelElement) { |
117 | return Scopes.scopeFor(document.allEPackages) | 84 | context.classifier |
118 | } else if(reference === language.metamodelElement_Classifier) { | ||
119 | if(context.package === null) { | ||
120 | return Scopes.scopeFor(document.allEClassifiers) | ||
121 | } else { | 85 | } else { |
122 | return Scopes.scopeFor(context.package.EClassifiers) | 86 | null |
123 | } | 87 | } |
124 | } else { | 88 | switch (referredClassifier) { |
125 | return super.getScope(context,reference) | 89 | EClass: |
126 | } | 90 | Scopes.scopeFor(referredClassifier.EAllStructuralFeatures) |
127 | } | 91 | EEnum: |
128 | 92 | Scopes.scopeFor(referredClassifier.ELiterals) | |
129 | ////////// | 93 | default: |
130 | 94 | super.getScope(context, reference) | |
131 | def IScope scopeForClassReference(ClassReference classReference, EReference eReference, ConfigurationScript document) { | ||
132 | if(eReference === language.metamodelEntry_Package) { | ||
133 | return Scopes.scopeFor(document.allEPackages) | ||
134 | } else if(eReference === language.metamodelElement_Classifier) { | ||
135 | Scopes.scopeFor(document.allEClassifiers) | ||
136 | } else { | ||
137 | return super.getScope(classReference,eReference) | ||
138 | } | 95 | } |
139 | } | 96 | } |
140 | 97 | ||
141 | ////////// | 98 | private def getViatraPackageScope(EObject context, EReference reference, ConfigurationScript document) { |
142 | 99 | val patternModelNameConverter = [ PatternModel patternModel | | |
143 | protected def scopeForPatternElement(PatternElement context, EReference reference, ConfigurationScript document) { | 100 | toQualifiedNameOrNull(patternModel.packageName) |
144 | if(reference === language.patternEntry_Package) { | 101 | ] |
145 | return Scopes.scopeFor(document.allViatraPackages,nameConverter,super.getScope(context,reference)) | 102 | Scopes.scopeFor(document.allViatraPackages, patternModelNameConverter, 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 { | ||
150 | return Scopes.scopeFor(document.allPatterns) | ||
151 | } | ||
152 | } else { | ||
153 | super.getScope(context,reference) | ||
154 | } | ||
155 | } | 103 | } |
156 | 104 | ||
157 | protected def scopeForPatternSpecification(PatternSpecification context, EReference reference, ConfigurationScript document) { | 105 | private def getViatraPatternScope(EObject context, ConfigurationScript document) { |
158 | if(reference === language.patternEntry_Package) { | 106 | val patterns = switch (context) { |
159 | return Scopes.scopeFor(document.allViatraPackages,nameConverter,super.getScope(context,reference)) | 107 | PatternEntry case context.package !== null: |
160 | } else if(reference ===language.patternElement_Pattern) { | 108 | context.package.patterns |
161 | return Scopes.scopeFor(document.allPatterns) | 109 | default: |
162 | } else { | 110 | document.allPatterns |
163 | return super.getScope(context,reference) | ||
164 | } | 111 | } |
112 | Scopes.scopeFor(patterns) | ||
165 | } | 113 | } |
166 | 114 | ||
167 | protected def scopeForAllPatternEntry(AllPatternEntry context, EReference reference, ConfigurationScript document) { | 115 | private def toQualifiedNameOrNull(String packageName) { |
168 | if(reference === language.patternEntry_Package) { | 116 | if (packageName === null) { |
169 | val res = Scopes.scopeFor(document.allViatraPackages,nameConverter,super.getScope(context,reference)) | 117 | null |
170 | return res | ||
171 | } else if(reference === language.patternElement_Pattern) { | ||
172 | if(context.package === null) { | ||
173 | return Scopes.scopeFor(document.allPatterns) | ||
174 | } else { | ||
175 | return Scopes.scopeFor(context.package.patterns) | ||
176 | } | ||
177 | } else { | 118 | } else { |
178 | return super.getScope(context,reference) | 119 | qualifiedNameConverter.toQualifiedName(packageName) |
179 | } | 120 | } |
180 | } | 121 | } |
181 | } | 122 | } |