diff options
author | 2021-11-04 17:41:52 +0100 | |
---|---|---|
committer | 2021-11-04 17:41:52 +0100 | |
commit | 432ff3aaee8d45025f309436db541d0ec1b76485 (patch) | |
tree | 0d49c583f71f9972c6f5050540ac50e78992eaf2 /language/src | |
parent | fix(web): fix autocomplete prefix behavior (diff) | |
download | refinery-432ff3aaee8d45025f309436db541d0ec1b76485.tar.gz refinery-432ff3aaee8d45025f309436db541d0ec1b76485.tar.zst refinery-432ff3aaee8d45025f309436db541d0ec1b76485.zip |
fix(language): hide current implicit proposal
Content assist proposals should not display the object that is only
added to the model because the current context assist input refers to
it (e.g., an implicit node or variable that is only referenced in the
currently edited context).
Diffstat (limited to 'language/src')
-rw-r--r-- | language/src/main/java/tools/refinery/language/resource/ReferenceCounter.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/language/src/main/java/tools/refinery/language/resource/ReferenceCounter.java b/language/src/main/java/tools/refinery/language/resource/ReferenceCounter.java new file mode 100644 index 00000000..56186bc9 --- /dev/null +++ b/language/src/main/java/tools/refinery/language/resource/ReferenceCounter.java | |||
@@ -0,0 +1,43 @@ | |||
1 | package tools.refinery.language.resource; | ||
2 | |||
3 | import java.util.HashMap; | ||
4 | import java.util.Map; | ||
5 | |||
6 | import org.eclipse.emf.ecore.EObject; | ||
7 | import org.eclipse.xtext.util.IResourceScopeCache; | ||
8 | |||
9 | import com.google.inject.Inject; | ||
10 | import com.google.inject.Singleton; | ||
11 | |||
12 | import tools.refinery.language.model.problem.Problem; | ||
13 | |||
14 | @Singleton | ||
15 | public class ReferenceCounter { | ||
16 | @Inject | ||
17 | private IResourceScopeCache cache; | ||
18 | |||
19 | public Map<EObject, Integer> getReferenceCounts(Problem problem) { | ||
20 | var resource = problem.eResource(); | ||
21 | if (resource == null) { | ||
22 | return doGetReferenceCounts(problem); | ||
23 | } | ||
24 | return cache.get(problem, resource, () -> doGetReferenceCounts(problem)); | ||
25 | } | ||
26 | |||
27 | protected Map<EObject, Integer> doGetReferenceCounts(Problem problem) { | ||
28 | var map = new HashMap<EObject, Integer>(); | ||
29 | countCrossReferences(problem, map); | ||
30 | var iterator = problem.eAllContents(); | ||
31 | while (iterator.hasNext()) { | ||
32 | var eObject = iterator.next(); | ||
33 | countCrossReferences(eObject, map); | ||
34 | } | ||
35 | return map; | ||
36 | } | ||
37 | |||
38 | protected void countCrossReferences(EObject eObject, Map<EObject, Integer> map) { | ||
39 | for (var referencedObject : eObject.eCrossReferences()) { | ||
40 | map.compute(referencedObject, (key, currentValue) -> currentValue == null ? 1 : currentValue + 1); | ||
41 | } | ||
42 | } | ||
43 | } | ||