diff options
author | 2024-02-02 16:28:19 +0100 | |
---|---|---|
committer | 2024-02-02 17:36:24 +0100 | |
commit | 2dfcb286216419976368ad926f8ac7f018aa2bf9 (patch) | |
tree | b9d235ebf2049e42e58126e743c782333d64681a /subprojects/language-ide/src | |
parent | refactor: serialize solutions as modules (diff) | |
download | refinery-2dfcb286216419976368ad926f8ac7f018aa2bf9.tar.gz refinery-2dfcb286216419976368ad926f8ac7f018aa2bf9.tar.zst refinery-2dfcb286216419976368ad926f8ac7f018aa2bf9.zip |
refactor(language): name disambiguation
* Use fully qualified names starting with :: (as in C++) to unambiguously refer
to an element.
* Name shadowing within modules.
Diffstat (limited to 'subprojects/language-ide/src')
2 files changed, 14 insertions, 10 deletions
diff --git a/subprojects/language-ide/src/main/java/tools/refinery/language/ide/contentassist/ProblemCrossrefProposalProvider.java b/subprojects/language-ide/src/main/java/tools/refinery/language/ide/contentassist/ProblemCrossrefProposalProvider.java index 166b4400..fa04a012 100644 --- a/subprojects/language-ide/src/main/java/tools/refinery/language/ide/contentassist/ProblemCrossrefProposalProvider.java +++ b/subprojects/language-ide/src/main/java/tools/refinery/language/ide/contentassist/ProblemCrossrefProposalProvider.java | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2021-2024 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
@@ -15,13 +15,14 @@ import org.eclipse.xtext.EcoreUtil2; | |||
15 | import org.eclipse.xtext.GrammarUtil; | 15 | import org.eclipse.xtext.GrammarUtil; |
16 | import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext; | 16 | import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext; |
17 | import org.eclipse.xtext.ide.editor.contentassist.IdeCrossrefProposalProvider; | 17 | import org.eclipse.xtext.ide.editor.contentassist.IdeCrossrefProposalProvider; |
18 | import org.eclipse.xtext.naming.QualifiedName; | ||
19 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils; | 18 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils; |
20 | import org.eclipse.xtext.resource.IEObjectDescription; | 19 | import org.eclipse.xtext.resource.IEObjectDescription; |
21 | import org.eclipse.xtext.scoping.IScope; | 20 | import org.eclipse.xtext.scoping.IScope; |
22 | import org.eclipse.xtext.xtext.CurrentTypeFinder; | 21 | import org.eclipse.xtext.xtext.CurrentTypeFinder; |
23 | import org.jetbrains.annotations.Nullable; | 22 | import org.jetbrains.annotations.Nullable; |
24 | import tools.refinery.language.model.problem.*; | 23 | import tools.refinery.language.model.problem.*; |
24 | import tools.refinery.language.naming.NamingUtil; | ||
25 | import tools.refinery.language.naming.ProblemQualifiedNameConverter; | ||
25 | import tools.refinery.language.resource.ProblemResourceDescriptionStrategy; | 26 | import tools.refinery.language.resource.ProblemResourceDescriptionStrategy; |
26 | import tools.refinery.language.utils.BuiltinSymbols; | 27 | import tools.refinery.language.utils.BuiltinSymbols; |
27 | import tools.refinery.language.utils.ProblemDesugarer; | 28 | import tools.refinery.language.utils.ProblemDesugarer; |
@@ -46,14 +47,12 @@ public class ProblemCrossrefProposalProvider extends IdeCrossrefProposalProvider | |||
46 | @Override | 47 | @Override |
47 | protected Iterable<IEObjectDescription> queryScope(IScope scope, CrossReference crossReference, | 48 | protected Iterable<IEObjectDescription> queryScope(IScope scope, CrossReference crossReference, |
48 | ContentAssistContext context) { | 49 | ContentAssistContext context) { |
49 | var eObjectDescriptionsByName = new HashMap<QualifiedName, List<IEObjectDescription>>(); | 50 | var eObjectDescriptionsByName = new HashMap<ProblemResourceDescriptionStrategy.ShadowingKey, |
51 | List<IEObjectDescription>>(); | ||
50 | for (var candidate : super.queryScope(scope, crossReference, context)) { | 52 | for (var candidate : super.queryScope(scope, crossReference, context)) { |
51 | if (isExistingObject(candidate, crossReference, context)) { | 53 | if (isExistingObject(candidate, crossReference, context)) { |
52 | // {@code getQualifiedName()} will refer to the full name for objects that are loaded from the global | 54 | var shadowingKey = ProblemResourceDescriptionStrategy.getShadowingKey(candidate); |
53 | // scope, but {@code getName()} returns the qualified name that we set in | 55 | var candidateList = eObjectDescriptionsByName.computeIfAbsent(shadowingKey, |
54 | // {@code ProblemResourceDescriptionStrategy}. | ||
55 | var qualifiedName = candidate.getName(); | ||
56 | var candidateList = eObjectDescriptionsByName.computeIfAbsent(qualifiedName, | ||
57 | ignored -> new ArrayList<>()); | 56 | ignored -> new ArrayList<>()); |
58 | candidateList.add(candidate); | 57 | candidateList.add(candidate); |
59 | } | 58 | } |
@@ -61,7 +60,7 @@ public class ProblemCrossrefProposalProvider extends IdeCrossrefProposalProvider | |||
61 | var eObjectDescriptions = new ArrayList<IEObjectDescription>(); | 60 | var eObjectDescriptions = new ArrayList<IEObjectDescription>(); |
62 | for (var candidates : eObjectDescriptionsByName.values()) { | 61 | for (var candidates : eObjectDescriptionsByName.values()) { |
63 | if (candidates.size() == 1) { | 62 | if (candidates.size() == 1) { |
64 | var candidate = candidates.get(0); | 63 | var candidate = candidates.getFirst(); |
65 | if (shouldBeVisible(candidate, crossReference, context)) { | 64 | if (shouldBeVisible(candidate, crossReference, context)) { |
66 | eObjectDescriptions.add(candidate); | 65 | eObjectDescriptions.add(candidate); |
67 | } | 66 | } |
@@ -96,6 +95,11 @@ public class ProblemCrossrefProposalProvider extends IdeCrossrefProposalProvider | |||
96 | 95 | ||
97 | protected boolean shouldBeVisible(IEObjectDescription candidate, CrossReference crossReference, | 96 | protected boolean shouldBeVisible(IEObjectDescription candidate, CrossReference crossReference, |
98 | ContentAssistContext context) { | 97 | ContentAssistContext context) { |
98 | if (NamingUtil.isFullyQualified(candidate.getName()) && | ||
99 | !context.getPrefix().startsWith(ProblemQualifiedNameConverter.DELIMITER)) { | ||
100 | // Do not propose names with a root prefix unless explicitly asked for. | ||
101 | return false; | ||
102 | } | ||
99 | var errorPredicate = candidate.getUserData(ProblemResourceDescriptionStrategy.ERROR_PREDICATE); | 103 | var errorPredicate = candidate.getUserData(ProblemResourceDescriptionStrategy.ERROR_PREDICATE); |
100 | if (ProblemResourceDescriptionStrategy.ERROR_PREDICATE_TRUE.equals(errorPredicate)) { | 104 | if (ProblemResourceDescriptionStrategy.ERROR_PREDICATE_TRUE.equals(errorPredicate)) { |
101 | return false; | 105 | return false; |
diff --git a/subprojects/language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java b/subprojects/language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java index 94a61c4f..891c73c7 100644 --- a/subprojects/language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java +++ b/subprojects/language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java | |||
@@ -99,7 +99,7 @@ public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighli | |||
99 | 99 | ||
100 | protected String[] getHighlightClass(EObject eObject, EReference reference) { | 100 | protected String[] getHighlightClass(EObject eObject, EReference reference) { |
101 | boolean isError = ProblemUtil.isError(eObject); | 101 | boolean isError = ProblemUtil.isError(eObject); |
102 | if (ProblemUtil.isBuiltIn(eObject)) { | 102 | if (ProblemUtil.isBuiltIn(eObject) && !(eObject instanceof Problem)) { |
103 | var className = isError ? ERROR_CLASS : BUILTIN_CLASS; | 103 | var className = isError ? ERROR_CLASS : BUILTIN_CLASS; |
104 | return new String[]{className}; | 104 | return new String[]{className}; |
105 | } | 105 | } |