aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/language/src/main/java/tools/refinery/language/scoping/ProblemScopeProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/language/src/main/java/tools/refinery/language/scoping/ProblemScopeProvider.java')
-rw-r--r--subprojects/language/src/main/java/tools/refinery/language/scoping/ProblemScopeProvider.java35
1 files changed, 15 insertions, 20 deletions
diff --git a/subprojects/language/src/main/java/tools/refinery/language/scoping/ProblemScopeProvider.java b/subprojects/language/src/main/java/tools/refinery/language/scoping/ProblemScopeProvider.java
index a4437ba6..d94c9a13 100644
--- a/subprojects/language/src/main/java/tools/refinery/language/scoping/ProblemScopeProvider.java
+++ b/subprojects/language/src/main/java/tools/refinery/language/scoping/ProblemScopeProvider.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 */
@@ -9,17 +9,15 @@
9 */ 9 */
10package tools.refinery.language.scoping; 10package tools.refinery.language.scoping;
11 11
12import com.google.inject.Inject;
13import org.eclipse.emf.ecore.EObject; 12import org.eclipse.emf.ecore.EObject;
14import org.eclipse.emf.ecore.EReference; 13import org.eclipse.emf.ecore.EReference;
15import org.eclipse.xtext.EcoreUtil2; 14import org.eclipse.xtext.EcoreUtil2;
16import org.eclipse.xtext.scoping.IScope; 15import org.eclipse.xtext.scoping.IScope;
17import org.eclipse.xtext.scoping.Scopes; 16import org.eclipse.xtext.scoping.Scopes;
18import tools.refinery.language.model.problem.*; 17import tools.refinery.language.model.problem.*;
19import tools.refinery.language.utils.ProblemDesugarer;
20 18
21import java.util.ArrayList; 19import java.util.Collection;
22import java.util.List; 20import java.util.LinkedHashSet;
23 21
24/** 22/**
25 * This class contains custom scoping description. 23 * This class contains custom scoping description.
@@ -29,9 +27,6 @@ import java.util.List;
29 * on how and when to use it. 27 * on how and when to use it.
30 */ 28 */
31public class ProblemScopeProvider extends AbstractProblemScopeProvider { 29public class ProblemScopeProvider extends AbstractProblemScopeProvider {
32 @Inject
33 private ProblemDesugarer desugarer;
34
35 @Override 30 @Override
36 public IScope getScope(EObject context, EReference reference) { 31 public IScope getScope(EObject context, EReference reference) {
37 var scope = super.getScope(context, reference); 32 var scope = super.getScope(context, reference);
@@ -58,7 +53,7 @@ public class ProblemScopeProvider extends AbstractProblemScopeProvider {
58 } 53 }
59 54
60 protected IScope getVariableScope(EObject context, IScope delegateScope) { 55 protected IScope getVariableScope(EObject context, IScope delegateScope) {
61 List<Variable> variables = new ArrayList<>(); 56 Collection<Variable> variables = new LinkedHashSet<>();
62 addSingletonVariableToScope(context, variables); 57 addSingletonVariableToScope(context, variables);
63 EObject currentContext = context; 58 EObject currentContext = context;
64 while (currentContext != null && !(currentContext instanceof ParametricDefinition)) { 59 while (currentContext != null && !(currentContext instanceof ParametricDefinition)) {
@@ -73,7 +68,7 @@ public class ProblemScopeProvider extends AbstractProblemScopeProvider {
73 return Scopes.scopeFor(variables, parentScope); 68 return Scopes.scopeFor(variables, parentScope);
74 } 69 }
75 70
76 protected void addSingletonVariableToScope(EObject context, List<Variable> variables) { 71 protected void addSingletonVariableToScope(EObject context, Collection<Variable> variables) {
77 if (context instanceof VariableOrNodeExpr expr) { 72 if (context instanceof VariableOrNodeExpr expr) {
78 Variable singletonVariable = expr.getSingletonVariable(); 73 Variable singletonVariable = expr.getSingletonVariable();
79 if (singletonVariable != null) { 74 if (singletonVariable != null) {
@@ -82,18 +77,21 @@ public class ProblemScopeProvider extends AbstractProblemScopeProvider {
82 } 77 }
83 } 78 }
84 79
85 protected void addExistentiallyQualifiedVariableToScope(EObject currentContext, List<Variable> variables) { 80 protected void addExistentiallyQualifiedVariableToScope(EObject currentContext, Collection<Variable> variables) {
86 if (currentContext instanceof ExistentialQuantifier quantifier) { 81 switch (currentContext) {
87 variables.addAll(quantifier.getImplicitVariables()); 82 case ExistentialQuantifier quantifier -> variables.addAll(quantifier.getImplicitVariables());
88 } else if (currentContext instanceof Match match) { 83 case Match match -> variables.addAll(match.getCondition().getImplicitVariables());
89 variables.addAll(match.getCondition().getImplicitVariables()); 84 case Consequent consequent -> {
90 } else if (currentContext instanceof Consequent consequent) {
91 for (var literal : consequent.getActions()) { 85 for (var literal : consequent.getActions()) {
92 if (literal instanceof NewAction newAction && newAction.getVariable() != null) { 86 if (literal instanceof NewAction newAction && newAction.getVariable() != null) {
93 variables.add(newAction.getVariable()); 87 variables.add(newAction.getVariable());
94 } 88 }
95 } 89 }
96 } 90 }
91 default -> {
92 // Nothing to add.
93 }
94 }
97 } 95 }
98 96
99 protected IScope getOppositeScope(EObject context) { 97 protected IScope getOppositeScope(EObject context) {
@@ -105,10 +103,7 @@ public class ProblemScopeProvider extends AbstractProblemScopeProvider {
105 if (!(relation instanceof ClassDeclaration classDeclaration)) { 103 if (!(relation instanceof ClassDeclaration classDeclaration)) {
106 return IScope.NULLSCOPE; 104 return IScope.NULLSCOPE;
107 } 105 }
108 var referenceDeclarations = classDeclaration.getFeatureDeclarations() 106 var referenceDeclarations = classDeclaration.getFeatureDeclarations();
109 .stream()
110 .filter(ReferenceDeclaration.class::isInstance)
111 .toList();
112 return Scopes.scopeFor(referenceDeclarations); 107 return Scopes.scopeFor(referenceDeclarations);
113 } 108 }
114} 109}