diff options
Diffstat (limited to 'subprojects')
-rw-r--r-- | subprojects/language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/TypeHashProvider.java | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/subprojects/language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/TypeHashProvider.java b/subprojects/language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/TypeHashProvider.java index f75ecdb2..dd9f1053 100644 --- a/subprojects/language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/TypeHashProvider.java +++ b/subprojects/language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/TypeHashProvider.java | |||
@@ -11,10 +11,13 @@ import com.google.inject.Singleton; | |||
11 | import org.eclipse.xtext.EcoreUtil2; | 11 | import org.eclipse.xtext.EcoreUtil2; |
12 | import org.eclipse.xtext.naming.IQualifiedNameConverter; | 12 | import org.eclipse.xtext.naming.IQualifiedNameConverter; |
13 | import org.eclipse.xtext.naming.IQualifiedNameProvider; | 13 | import org.eclipse.xtext.naming.IQualifiedNameProvider; |
14 | import org.eclipse.xtext.resource.IResourceDescription; | ||
14 | import org.eclipse.xtext.scoping.IScopeProvider; | 15 | import org.eclipse.xtext.scoping.IScopeProvider; |
16 | import org.eclipse.xtext.scoping.impl.GlobalResourceDescriptionProvider; | ||
15 | import org.eclipse.xtext.util.IResourceScopeCache; | 17 | import org.eclipse.xtext.util.IResourceScopeCache; |
16 | import tools.refinery.language.model.problem.*; | 18 | import tools.refinery.language.model.problem.*; |
17 | import tools.refinery.language.resource.ProblemResourceDescriptionStrategy; | 19 | import tools.refinery.language.resource.ProblemResourceDescriptionStrategy; |
20 | import tools.refinery.language.scoping.imports.ImportCollector; | ||
18 | import tools.refinery.language.utils.ProblemUtil; | 21 | import tools.refinery.language.utils.ProblemUtil; |
19 | 22 | ||
20 | import java.util.*; | 23 | import java.util.*; |
@@ -36,6 +39,12 @@ public class TypeHashProvider { | |||
36 | @Inject | 39 | @Inject |
37 | private IQualifiedNameConverter qualifiedNameConverter; | 40 | private IQualifiedNameConverter qualifiedNameConverter; |
38 | 41 | ||
42 | @Inject | ||
43 | private ImportCollector importCollector; | ||
44 | |||
45 | @Inject | ||
46 | private GlobalResourceDescriptionProvider globalResourceDescriptionProvider; | ||
47 | |||
39 | public String getTypeHash(Relation relation) { | 48 | public String getTypeHash(Relation relation) { |
40 | if (!(relation instanceof ClassDeclaration || relation instanceof EnumDeclaration) || | 49 | if (!(relation instanceof ClassDeclaration || relation instanceof EnumDeclaration) || |
41 | ProblemUtil.isBuiltIn(relation)) { | 50 | ProblemUtil.isBuiltIn(relation)) { |
@@ -55,13 +64,15 @@ public class TypeHashProvider { | |||
55 | } | 64 | } |
56 | 65 | ||
57 | private Map<String, String> computeHashes(Problem problem) { | 66 | private Map<String, String> computeHashes(Problem problem) { |
67 | var resourceDescriptions = getResourceDescriptions(problem); | ||
58 | var qualifiedNameStrings = new TreeSet<String>(); | 68 | var qualifiedNameStrings = new TreeSet<String>(); |
59 | var scope = scopeProvider.getScope(problem, ProblemPackage.Literals.ASSERTION__RELATION); | 69 | for (var resourceDescription : resourceDescriptions) { |
60 | for (var description : scope.getAllElements()) { | 70 | for (var description : resourceDescription.getExportedObjectsByType(ProblemPackage.Literals.RELATION)) { |
61 | if (ProblemResourceDescriptionStrategy.COLOR_RELATION_TRUE.equals( | 71 | if (ProblemResourceDescriptionStrategy.COLOR_RELATION_TRUE.equals( |
62 | description.getUserData(ProblemResourceDescriptionStrategy.COLOR_RELATION))) { | 72 | description.getUserData(ProblemResourceDescriptionStrategy.COLOR_RELATION))) { |
63 | var qualifiedNameString = qualifiedNameConverter.toString(description.getQualifiedName()); | 73 | var qualifiedNameString = qualifiedNameConverter.toString(description.getQualifiedName()); |
64 | qualifiedNameStrings.add(qualifiedNameString); | 74 | qualifiedNameStrings.add(qualifiedNameString); |
75 | } | ||
65 | } | 76 | } |
66 | } | 77 | } |
67 | var stringList = new ArrayList<>(qualifiedNameStrings); | 78 | var stringList = new ArrayList<>(qualifiedNameStrings); |
@@ -90,4 +101,30 @@ public class TypeHashProvider { | |||
90 | } | 101 | } |
91 | return mapBuilder.build(); | 102 | return mapBuilder.build(); |
92 | } | 103 | } |
104 | |||
105 | private List<IResourceDescription> getResourceDescriptions(Problem problem) { | ||
106 | var resource = problem.eResource(); | ||
107 | if (resource == null) { | ||
108 | return List.of(); | ||
109 | } | ||
110 | var resourceDescriptions = new ArrayList<IResourceDescription>(); | ||
111 | var resourceDescription = globalResourceDescriptionProvider.getResourceDescription(resource); | ||
112 | if (resourceDescription != null) { | ||
113 | resourceDescriptions.add(resourceDescription); | ||
114 | } | ||
115 | var resourceSet = resource.getResourceSet(); | ||
116 | if (resourceSet != null) { | ||
117 | for (var importedUri : importCollector.getAllImports(resource).toUriSet()) { | ||
118 | var importedResource = resourceSet.getResource(importedUri, false); | ||
119 | if (importedResource != null) { | ||
120 | var importedResourceDescription = globalResourceDescriptionProvider.getResourceDescription( | ||
121 | importedResource); | ||
122 | if (importedResourceDescription != null) { | ||
123 | resourceDescriptions.add(importedResourceDescription); | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | return resourceDescriptions; | ||
129 | } | ||
93 | } | 130 | } |