aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/Alloy-Solver2/hu.bme.mit.inf.dslreasoner.alloy.language/src/hu/bme/mit/inf/dslreasoner/scoping/AlloyLanguageScopeProvider.xtend
diff options
context:
space:
mode:
Diffstat (limited to 'Solvers/Alloy-Solver2/hu.bme.mit.inf.dslreasoner.alloy.language/src/hu/bme/mit/inf/dslreasoner/scoping/AlloyLanguageScopeProvider.xtend')
-rw-r--r--Solvers/Alloy-Solver2/hu.bme.mit.inf.dslreasoner.alloy.language/src/hu/bme/mit/inf/dslreasoner/scoping/AlloyLanguageScopeProvider.xtend81
1 files changed, 0 insertions, 81 deletions
diff --git a/Solvers/Alloy-Solver2/hu.bme.mit.inf.dslreasoner.alloy.language/src/hu/bme/mit/inf/dslreasoner/scoping/AlloyLanguageScopeProvider.xtend b/Solvers/Alloy-Solver2/hu.bme.mit.inf.dslreasoner.alloy.language/src/hu/bme/mit/inf/dslreasoner/scoping/AlloyLanguageScopeProvider.xtend
deleted file mode 100644
index b2333f51..00000000
--- a/Solvers/Alloy-Solver2/hu.bme.mit.inf.dslreasoner.alloy.language/src/hu/bme/mit/inf/dslreasoner/scoping/AlloyLanguageScopeProvider.xtend
+++ /dev/null
@@ -1,81 +0,0 @@
1/*
2 * generated by Xtext
3 */
4package hu.bme.mit.inf.dslreasoner.scoping
5
6import hu.bme.mit.inf.dslreasoner.alloyLanguage.ALSDefinition
7import hu.bme.mit.inf.dslreasoner.alloyLanguage.ALSDocument
8import hu.bme.mit.inf.dslreasoner.alloyLanguage.ALSEnumDeclaration
9import hu.bme.mit.inf.dslreasoner.alloyLanguage.ALSFunctionCall
10import hu.bme.mit.inf.dslreasoner.alloyLanguage.ALSQuantifiedEx
11import hu.bme.mit.inf.dslreasoner.alloyLanguage.ALSReference
12import hu.bme.mit.inf.dslreasoner.alloyLanguage.ALSRelationDeclaration
13import hu.bme.mit.inf.dslreasoner.alloyLanguage.ALSRelationDefinition
14import hu.bme.mit.inf.dslreasoner.alloyLanguage.ALSSignatureBody
15import hu.bme.mit.inf.dslreasoner.alloyLanguage.ALSSum
16import java.util.ArrayList
17import java.util.Collections
18import java.util.HashSet
19import java.util.LinkedList
20import java.util.List
21import java.util.Set
22import org.eclipse.emf.ecore.EObject
23import org.eclipse.emf.ecore.EReference
24import org.eclipse.xtext.scoping.IScope
25import org.eclipse.xtext.scoping.Scopes
26import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider
27
28/**
29 * This class contains custom scoping description.
30 *
31 * see : http://www.eclipse.org/Xtext/documentation.html#scoping
32 * on how and when to use it
33 *
34 */
35class AlloyLanguageScopeProvider extends AbstractDeclarativeScopeProvider {
36
37 def public IScope scope_ALSReference_referred(ALSReference alsReferecnce, EReference ref) {
38 val Set<ALSRelationDeclaration> declarations = new HashSet
39
40 val parent = alsReferecnce.getAllParents(ALSDocument).head as ALSDocument
41 val signatures = parent.signatureBodies.map[ALSSignatureBody x|x.declarations].flatten
42 declarations+=parent.enumDeclarations
43 declarations+=signatures
44 declarations+=parent.enumDeclarations.map[ALSEnumDeclaration x | x.literal].flatten
45 declarations+=parent.signatureBodies.map[ALSSignatureBody x|x.fields].flatten
46
47 declarations+=alsReferecnce.getAllParents(ALSQuantifiedEx).map[ALSQuantifiedEx x | x.variables].flatten
48 declarations+=alsReferecnce.getAllParents(ALSSum).map[ALSSum x | x.variables].flatten
49 declarations+=alsReferecnce.getAllParents(ALSRelationDefinition).map[ALSRelationDefinition x | x.variables].flatten
50
51// println("---")
52// println(declarations.map[it.name].join(", "))
53
54 return Scopes.scopeFor(declarations)
55 }
56 //{ALSFunctionCall} (/*functionName=ALSID |*/ referredDefinition=[ALSDefinition])
57 def public IScope scope_ALSFunctionCall_referredDefinition(ALSFunctionCall call, EReference ref) {
58 val parent = call.<ALSDocument>getAllParents(ALSDocument).head as ALSDocument
59 val list = new LinkedList<ALSDefinition>
60 list += parent.relationDefinitions
61 list += parent.functionDefinitions
62 //list.forEach[println(it.name + " " + it.eContainer)]
63 return Scopes.scopeFor(list)
64 }
65
66 def <X extends EObject> List<X> getAllParents(EObject object, Class<X> type) {
67 if(object.eContainer == null) {
68 return Collections.EMPTY_LIST
69 } else {
70 val container = object.eContainer;
71 val previousParents = container.getAllParents(type)
72 if(type.isInstance(container)){
73 val res = new ArrayList(previousParents)
74 res+= container as X
75 return res
76 }
77 else return previousParents
78
79 }
80 }
81}