diff options
author | 2021-06-30 02:34:51 +0200 | |
---|---|---|
committer | 2021-06-30 02:39:54 +0200 | |
commit | 5c515bbe92e32c9cea7fd968ec9436a49af9ebf9 (patch) | |
tree | a4a3602e6fa729ecccbccdc316a1f186fcfdc8b5 /language/src/main/java/org/eclipse/viatra | |
parent | Node scoping fixes (diff) | |
download | refinery-5c515bbe92e32c9cea7fd968ec9436a49af9ebf9.tar.gz refinery-5c515bbe92e32c9cea7fd968ec9436a49af9ebf9.tar.zst refinery-5c515bbe92e32c9cea7fd968ec9436a49af9ebf9.zip |
Fix enum literal scopes
Diffstat (limited to 'language/src/main/java/org/eclipse/viatra')
-rw-r--r-- | language/src/main/java/org/eclipse/viatra/solver/language/resource/NodeNameCollector.java | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/language/src/main/java/org/eclipse/viatra/solver/language/resource/NodeNameCollector.java b/language/src/main/java/org/eclipse/viatra/solver/language/resource/NodeNameCollector.java index 4dee5434..79d7ffbb 100644 --- a/language/src/main/java/org/eclipse/viatra/solver/language/resource/NodeNameCollector.java +++ b/language/src/main/java/org/eclipse/viatra/solver/language/resource/NodeNameCollector.java | |||
@@ -12,10 +12,8 @@ import org.eclipse.viatra.solver.language.model.problem.Assertion; | |||
12 | import org.eclipse.viatra.solver.language.model.problem.AssertionArgument; | 12 | import org.eclipse.viatra.solver.language.model.problem.AssertionArgument; |
13 | import org.eclipse.viatra.solver.language.model.problem.Atom; | 13 | import org.eclipse.viatra.solver.language.model.problem.Atom; |
14 | import org.eclipse.viatra.solver.language.model.problem.Conjunction; | 14 | import org.eclipse.viatra.solver.language.model.problem.Conjunction; |
15 | import org.eclipse.viatra.solver.language.model.problem.EnumDeclaration; | ||
16 | import org.eclipse.viatra.solver.language.model.problem.Literal; | 15 | import org.eclipse.viatra.solver.language.model.problem.Literal; |
17 | import org.eclipse.viatra.solver.language.model.problem.NegativeLiteral; | 16 | import org.eclipse.viatra.solver.language.model.problem.NegativeLiteral; |
18 | import org.eclipse.viatra.solver.language.model.problem.Node; | ||
19 | import org.eclipse.viatra.solver.language.model.problem.NodeAssertionArgument; | 17 | import org.eclipse.viatra.solver.language.model.problem.NodeAssertionArgument; |
20 | import org.eclipse.viatra.solver.language.model.problem.NodeValueAssertion; | 18 | import org.eclipse.viatra.solver.language.model.problem.NodeValueAssertion; |
21 | import org.eclipse.viatra.solver.language.model.problem.PredicateDefinition; | 19 | import org.eclipse.viatra.solver.language.model.problem.PredicateDefinition; |
@@ -47,7 +45,6 @@ public class NodeNameCollector { | |||
47 | private IScopeProvider scopeProvider; | 45 | private IScopeProvider scopeProvider; |
48 | 46 | ||
49 | private final Set<String> nodeNames = new HashSet<>(); | 47 | private final Set<String> nodeNames = new HashSet<>(); |
50 | private final Set<String> existingNodeNames = new HashSet<>(); | ||
51 | 48 | ||
52 | private IScope nodeScope; | 49 | private IScope nodeScope; |
53 | 50 | ||
@@ -56,27 +53,12 @@ public class NodeNameCollector { | |||
56 | } | 53 | } |
57 | 54 | ||
58 | public void collectNodeNames(Problem problem) { | 55 | public void collectNodeNames(Problem problem) { |
59 | nodeScope = scopeProvider.getScope(problem, ProblemPackage.Literals.ASSERTION__ARGUMENTS); | 56 | nodeScope = scopeProvider.getScope(problem, ProblemPackage.Literals.NODE_ASSERTION_ARGUMENT__NODE); |
60 | collectEnumLiteralNames(problem); | ||
61 | for (Statement statement : problem.getStatements()) { | 57 | for (Statement statement : problem.getStatements()) { |
62 | collectStatementNodeNames(statement); | 58 | collectStatementNodeNames(statement); |
63 | } | 59 | } |
64 | } | 60 | } |
65 | 61 | ||
66 | protected void collectEnumLiteralNames(Problem problem) { | ||
67 | for (Statement statement : problem.getStatements()) { | ||
68 | if (statement instanceof EnumDeclaration) { | ||
69 | EnumDeclaration enumDeclaration = (EnumDeclaration) statement; | ||
70 | for (Node literal : enumDeclaration.getLiterals()) { | ||
71 | String name = literal.getName(); | ||
72 | if (ProblemDerivedStateComputer.validId(name)) { | ||
73 | existingNodeNames.add(name); | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | |||
80 | protected void collectStatementNodeNames(Statement statement) { | 62 | protected void collectStatementNodeNames(Statement statement) { |
81 | if (statement instanceof Assertion) { | 63 | if (statement instanceof Assertion) { |
82 | collectAssertionNodeNames((Assertion) statement); | 64 | collectAssertionNodeNames((Assertion) statement); |
@@ -90,14 +72,14 @@ public class NodeNameCollector { | |||
90 | protected void collectAssertionNodeNames(Assertion assertion) { | 72 | protected void collectAssertionNodeNames(Assertion assertion) { |
91 | for (AssertionArgument argument : assertion.getArguments()) { | 73 | for (AssertionArgument argument : assertion.getArguments()) { |
92 | if (argument instanceof NodeAssertionArgument) { | 74 | if (argument instanceof NodeAssertionArgument) { |
93 | addNodeNames(argument, ProblemPackage.Literals.NODE_ASSERTION_ARGUMENT__NODE, | 75 | collectNodeNames(argument, ProblemPackage.Literals.NODE_ASSERTION_ARGUMENT__NODE, |
94 | ProblemDerivedStateComputer::validNodeName); | 76 | ProblemDerivedStateComputer::validNodeName); |
95 | } | 77 | } |
96 | } | 78 | } |
97 | } | 79 | } |
98 | 80 | ||
99 | protected void collectNodeValueAssertionNodeNames(NodeValueAssertion nodeValueAssertion) { | 81 | protected void collectNodeValueAssertionNodeNames(NodeValueAssertion nodeValueAssertion) { |
100 | addNodeNames(nodeValueAssertion, ProblemPackage.Literals.NODE_VALUE_ASSERTION__NODE, | 82 | collectNodeNames(nodeValueAssertion, ProblemPackage.Literals.NODE_VALUE_ASSERTION__NODE, |
101 | ProblemDerivedStateComputer::validNodeName); | 83 | ProblemDerivedStateComputer::validNodeName); |
102 | } | 84 | } |
103 | 85 | ||
@@ -116,7 +98,7 @@ public class NodeNameCollector { | |||
116 | } | 98 | } |
117 | for (Argument argument : atom.getArguments()) { | 99 | for (Argument argument : atom.getArguments()) { |
118 | if (argument instanceof VariableOrNodeArgument) { | 100 | if (argument instanceof VariableOrNodeArgument) { |
119 | addNodeNames(argument, ProblemPackage.Literals.VARIABLE_OR_NODE_ARGUMENT__VARIABLE_OR_NODE, | 101 | collectNodeNames(argument, ProblemPackage.Literals.VARIABLE_OR_NODE_ARGUMENT__VARIABLE_OR_NODE, |
120 | ProblemDerivedStateComputer::validQuotedId); | 102 | ProblemDerivedStateComputer::validQuotedId); |
121 | } | 103 | } |
122 | } | 104 | } |
@@ -124,7 +106,7 @@ public class NodeNameCollector { | |||
124 | } | 106 | } |
125 | } | 107 | } |
126 | 108 | ||
127 | private void addNodeNames(EObject eObject, EStructuralFeature feature, Predicate<String> condition) { | 109 | private void collectNodeNames(EObject eObject, EStructuralFeature feature, Predicate<String> condition) { |
128 | List<INode> nodes = NodeModelUtils.findNodesForFeature(eObject, feature); | 110 | List<INode> nodes = NodeModelUtils.findNodesForFeature(eObject, feature); |
129 | for (INode node : nodes) { | 111 | for (INode node : nodes) { |
130 | String nodeName = linkingHelper.getCrossRefNodeAsString(node, true); | 112 | String nodeName = linkingHelper.getCrossRefNodeAsString(node, true); |
@@ -132,7 +114,7 @@ public class NodeNameCollector { | |||
132 | continue; | 114 | continue; |
133 | } | 115 | } |
134 | QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(nodeName); | 116 | QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(nodeName); |
135 | if (!existingNodeNames.contains(nodeName) && nodeScope.getSingleElement(qualifiedName) == null) { | 117 | if (nodeScope.getSingleElement(qualifiedName) == null) { |
136 | nodeNames.add(nodeName); | 118 | nodeNames.add(nodeName); |
137 | } | 119 | } |
138 | } | 120 | } |