diff options
Diffstat (limited to 'org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language')
6 files changed, 136 insertions, 125 deletions
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/Problem.xtext b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/Problem.xtext index 2d4eb1b9..5f8b35f3 100644 --- a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/Problem.xtext +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/Problem.xtext | |||
@@ -4,34 +4,42 @@ import "http://www.eclipse.org/emf/2002/Ecore" as ecore | |||
4 | import "http://www.eclipse.org/viatra/solver/language/model/Problem" | 4 | import "http://www.eclipse.org/viatra/solver/language/model/Problem" |
5 | 5 | ||
6 | Problem: | 6 | Problem: |
7 | ("problem" name=ID ".")? | 7 | ("problem" name=Identifier ".")? |
8 | statements+=Statement*; | 8 | statements+=Statement*; |
9 | 9 | ||
10 | Statement: | 10 | Statement: |
11 | ClassDeclaration | PredicateDefinition | Assertion | ScopeDeclaration; | 11 | ClassDeclaration | EnumDeclaration | PredicateDefinition | Assertion | ScopeDeclaration; |
12 | 12 | ||
13 | ClassDeclaration: | 13 | ClassDeclaration: |
14 | abstract?="abstract"? "class" | 14 | abstract?="abstract"? "class" |
15 | name=ID | 15 | name=Identifier |
16 | ("extends" superTypes+=[ClassDeclaration|QualifiedName] ("," superTypes+=[ClassDeclaration|QualifiedName])*)? | 16 | ("extends" superTypes+=[Relation|QualifiedName] ("," superTypes+=[Relation|QualifiedName])*)? |
17 | ("{" (referenceDeclarations+=ReferenceDeclaration ";"?)* "}" | "."); | 17 | ("{" (referenceDeclarations+=ReferenceDeclaration ";"?)* "}" | "."); |
18 | 18 | ||
19 | EnumDeclaration: | ||
20 | "enum" | ||
21 | name=Identifier | ||
22 | ("{" (literals+=EnumLiteral ("," literals+=EnumLiteral)* ("," | ";")?)? "}" | "."); | ||
23 | |||
24 | EnumLiteral returns Node: | ||
25 | name=QuotedOrUnquotedId; | ||
26 | |||
19 | ReferenceDeclaration: | 27 | ReferenceDeclaration: |
20 | (containment?="contains" | "refers") | 28 | (containment?="contains" | "refers")? |
21 | referenceType=[ClassDeclaration|QualifiedName] | 29 | referenceType=[Relation|QualifiedName] |
22 | ("[" multiplicity=Multiplicity "]")? | 30 | ("[" multiplicity=Multiplicity "]")? |
23 | name=ID | 31 | name=Identifier |
24 | ("opposite" opposite=[ReferenceDeclaration|QualifiedName])?; | 32 | ("opposite" opposite=[ReferenceDeclaration|QualifiedName])?; |
25 | 33 | ||
26 | PredicateDefinition: | 34 | PredicateDefinition: |
27 | (error?="error" "pred"? | "pred") | 35 | (error?="error" "pred"? | "pred") |
28 | name=ID | 36 | name=Identifier |
29 | "(" (parameters+=Parameter ("," parameters+=Parameter)*)? ")" | 37 | "(" (parameters+=Parameter ("," parameters+=Parameter)*)? ")" |
30 | (":-" bodies+=Conjunction (";" bodies+=Conjunction)*)? | 38 | (":-" bodies+=Conjunction (";" bodies+=Conjunction)*)? |
31 | "."; | 39 | "."; |
32 | 40 | ||
33 | Parameter: | 41 | Parameter: |
34 | parameterType=[ClassDeclaration] name=ID; | 42 | parameterType=[Relation|QualifiedName]? name=Identifier; |
35 | 43 | ||
36 | Conjunction: | 44 | Conjunction: |
37 | literals+=Literal ("," literals+=Literal)*; | 45 | literals+=Literal ("," literals+=Literal)*; |
@@ -48,7 +56,7 @@ Atom: | |||
48 | "(" (arguments+=Argument ("," arguments+=Argument)*)? ")"; | 56 | "(" (arguments+=Argument ("," arguments+=Argument)*)? ")"; |
49 | 57 | ||
50 | Argument: | 58 | Argument: |
51 | variable=[Variable]; | 59 | variableOrNode=[VariableOrNode|QualifiedName]; |
52 | 60 | ||
53 | Assertion: | 61 | Assertion: |
54 | (relation=[Relation|QualifiedName] | 62 | (relation=[Relation|QualifiedName] |
@@ -91,10 +99,18 @@ ExactMultiplicity: | |||
91 | UpperBound returns ecore::EInt: | 99 | UpperBound returns ecore::EInt: |
92 | INT | "*"; | 100 | INT | "*"; |
93 | 101 | ||
102 | QuotedOrUnquotedId: | ||
103 | QUOTED_ID | Identifier; | ||
104 | |||
94 | QualifiedName: | 105 | QualifiedName: |
95 | QUOTED_ID | ID (":" ID)* (":" QUOTED_ID)?; | 106 | QUOTED_ID | Identifier (":" Identifier)* (":" QUOTED_ID)?; |
107 | |||
108 | Identifier: | ||
109 | ID | "true" | "false"; | ||
96 | 110 | ||
97 | @Override | 111 | @Override |
98 | terminal STRING: '"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"'; | 112 | terminal STRING: |
113 | '"' ('\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\' | '"'))* '"'; | ||
99 | 114 | ||
100 | terminal QUOTED_ID: "'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'"; | 115 | terminal QUOTED_ID: |
116 | "'" ('\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\' | "'"))* "'"; | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/ProblemUtil.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/ProblemUtil.java index 3e7d515f..09f062f5 100644 --- a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/ProblemUtil.java +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/ProblemUtil.java | |||
@@ -14,6 +14,7 @@ import org.eclipse.viatra.solver.language.model.problem.Node; | |||
14 | import org.eclipse.viatra.solver.language.model.problem.Problem; | 14 | import org.eclipse.viatra.solver.language.model.problem.Problem; |
15 | import org.eclipse.viatra.solver.language.model.problem.ProblemPackage; | 15 | import org.eclipse.viatra.solver.language.model.problem.ProblemPackage; |
16 | import org.eclipse.viatra.solver.language.model.problem.ReferenceDeclaration; | 16 | import org.eclipse.viatra.solver.language.model.problem.ReferenceDeclaration; |
17 | import org.eclipse.viatra.solver.language.model.problem.Relation; | ||
17 | import org.eclipse.viatra.solver.language.model.problem.Variable; | 18 | import org.eclipse.viatra.solver.language.model.problem.Variable; |
18 | import org.eclipse.viatra.solver.language.scoping.ProblemGlobalScopeProvider; | 19 | import org.eclipse.viatra.solver.language.scoping.ProblemGlobalScopeProvider; |
19 | 20 | ||
@@ -40,9 +41,15 @@ public final class ProblemUtil { | |||
40 | return variable.eContainingFeature() == ProblemPackage.Literals.ARGUMENT__SINGLETON_VARIABLE; | 41 | return variable.eContainingFeature() == ProblemPackage.Literals.ARGUMENT__SINGLETON_VARIABLE; |
41 | } | 42 | } |
42 | 43 | ||
44 | public static boolean isEnumLiteral(Node node) { | ||
45 | return node.eContainingFeature() == ProblemPackage.Literals.ENUM_DECLARATION__LITERALS; | ||
46 | } | ||
47 | |||
43 | public static boolean isEnumNode(Node node) { | 48 | public static boolean isEnumNode(Node node) { |
44 | String name = node.getName(); | 49 | String name = node.getName(); |
45 | return name != null && name.startsWith(ENUM_NODE_NAME_QUOTE) && name.endsWith(ENUM_NODE_NAME_QUOTE); | 50 | boolean isNameQuoted = name != null && name.startsWith(ENUM_NODE_NAME_QUOTE) |
51 | && name.endsWith(ENUM_NODE_NAME_QUOTE); | ||
52 | return isNameQuoted || isEnumLiteral(node); | ||
46 | } | 53 | } |
47 | 54 | ||
48 | public static boolean isNewNode(Node node) { | 55 | public static boolean isNewNode(Node node) { |
@@ -71,7 +78,11 @@ public final class ProblemUtil { | |||
71 | ClassDeclaration current = queue.removeFirst(); | 78 | ClassDeclaration current = queue.removeFirst(); |
72 | if (!found.contains(current)) { | 79 | if (!found.contains(current)) { |
73 | found.add(current); | 80 | found.add(current); |
74 | queue.addAll(current.getSuperTypes()); | 81 | for (Relation superType : current.getSuperTypes()) { |
82 | if (superType instanceof ClassDeclaration) { | ||
83 | queue.addLast((ClassDeclaration) superType); | ||
84 | } | ||
85 | } | ||
75 | } | 86 | } |
76 | } | 87 | } |
77 | return found; | 88 | return found; |
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemDerivedStateComputer.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemDerivedStateComputer.java index c161de22..b885ce0e 100644 --- a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemDerivedStateComputer.java +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemDerivedStateComputer.java | |||
@@ -3,9 +3,11 @@ package org.eclipse.viatra.solver.language.resource; | |||
3 | import java.util.HashSet; | 3 | import java.util.HashSet; |
4 | import java.util.List; | 4 | import java.util.List; |
5 | import java.util.Set; | 5 | import java.util.Set; |
6 | import java.util.function.Predicate; | ||
6 | import java.util.regex.Pattern; | 7 | import java.util.regex.Pattern; |
7 | 8 | ||
8 | import org.eclipse.emf.ecore.EObject; | 9 | import org.eclipse.emf.ecore.EObject; |
10 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
9 | import org.eclipse.viatra.solver.language.ProblemUtil; | 11 | import org.eclipse.viatra.solver.language.ProblemUtil; |
10 | import org.eclipse.viatra.solver.language.model.problem.Argument; | 12 | import org.eclipse.viatra.solver.language.model.problem.Argument; |
11 | import org.eclipse.viatra.solver.language.model.problem.Assertion; | 13 | import org.eclipse.viatra.solver.language.model.problem.Assertion; |
@@ -30,18 +32,21 @@ import org.eclipse.xtext.nodemodel.INode; | |||
30 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils; | 32 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils; |
31 | import org.eclipse.xtext.resource.DerivedStateAwareResource; | 33 | import org.eclipse.xtext.resource.DerivedStateAwareResource; |
32 | import org.eclipse.xtext.resource.IDerivedStateComputer; | 34 | import org.eclipse.xtext.resource.IDerivedStateComputer; |
33 | import org.eclipse.xtext.scoping.IGlobalScopeProvider; | ||
34 | import org.eclipse.xtext.scoping.IScope; | 35 | import org.eclipse.xtext.scoping.IScope; |
36 | import org.eclipse.xtext.scoping.IScopeProvider; | ||
37 | import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider; | ||
35 | 38 | ||
36 | import com.google.common.base.Predicates; | ||
37 | import com.google.inject.Inject; | 39 | import com.google.inject.Inject; |
38 | import com.google.inject.Singleton; | 40 | import com.google.inject.Singleton; |
41 | import com.google.inject.name.Named; | ||
39 | 42 | ||
40 | @Singleton | 43 | @Singleton |
41 | public class ProblemDerivedStateComputer implements IDerivedStateComputer { | 44 | public class ProblemDerivedStateComputer implements IDerivedStateComputer { |
42 | public static final String NEW_NODE = "new"; | 45 | public static final String NEW_NODE = "new"; |
43 | 46 | ||
44 | private static final Pattern ID_REGEX = Pattern.compile("[_a-zA-Z][_0-9a-zA-Z]*|'(\\\\.|[^\\'])*'"); | 47 | private static final Pattern ID_REGEX = Pattern.compile("[_a-zA-Z][_0-9a-zA-Z]*"); |
48 | |||
49 | private static final Pattern QUOTED_ID_REGEX = Pattern.compile("'(\\\\.|[^\\'])*'"); | ||
45 | 50 | ||
46 | @Inject | 51 | @Inject |
47 | private LinkingHelper linkingHelper; | 52 | private LinkingHelper linkingHelper; |
@@ -50,7 +55,8 @@ public class ProblemDerivedStateComputer implements IDerivedStateComputer { | |||
50 | private IQualifiedNameConverter qualifiedNameConverter; | 55 | private IQualifiedNameConverter qualifiedNameConverter; |
51 | 56 | ||
52 | @Inject | 57 | @Inject |
53 | private IGlobalScopeProvider scopeProvider; | 58 | @Named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE) |
59 | private IScopeProvider scopeProvider; | ||
54 | 60 | ||
55 | @Override | 61 | @Override |
56 | public void installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) { | 62 | public void installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) { |
@@ -65,11 +71,11 @@ public class ProblemDerivedStateComputer implements IDerivedStateComputer { | |||
65 | installNewNodes(problem); | 71 | installNewNodes(problem); |
66 | if (!preLinkingPhase) { | 72 | if (!preLinkingPhase) { |
67 | installDerivedNodes(problem); | 73 | installDerivedNodes(problem); |
68 | } | 74 | for (Statement statement : problem.getStatements()) { |
69 | for (Statement statement : problem.getStatements()) { | 75 | if (statement instanceof PredicateDefinition) { |
70 | if (statement instanceof PredicateDefinition) { | 76 | PredicateDefinition definition = (PredicateDefinition) statement; |
71 | PredicateDefinition definition = (PredicateDefinition) statement; | 77 | installDerivedPredicateDefinitionState(definition); |
72 | installDerivedPredicateDefinitionState(definition); | 78 | } |
73 | } | 79 | } |
74 | } | 80 | } |
75 | } | 81 | } |
@@ -87,20 +93,30 @@ public class ProblemDerivedStateComputer implements IDerivedStateComputer { | |||
87 | } | 93 | } |
88 | 94 | ||
89 | protected void installDerivedNodes(Problem problem) { | 95 | protected void installDerivedNodes(Problem problem) { |
90 | IScope nodeScope = scopeProvider.getScope(problem.eResource(), ProblemPackage.Literals.ASSERTION__ARGUMENTS, | 96 | IScope nodeScope = scopeProvider.getScope(problem, ProblemPackage.Literals.ASSERTION__ARGUMENTS); |
91 | Predicates.alwaysTrue()); | ||
92 | Set<String> nodeNames = new HashSet<>(); | 97 | Set<String> nodeNames = new HashSet<>(); |
93 | for (Statement statement : problem.getStatements()) { | 98 | for (Statement statement : problem.getStatements()) { |
94 | if (statement instanceof Assertion) { | 99 | if (statement instanceof Assertion) { |
95 | Assertion assertion = (Assertion) statement; | 100 | addNodeNames(nodeNames, nodeScope, statement, ProblemPackage.Literals.ASSERTION__ARGUMENTS, |
96 | List<INode> nodes = NodeModelUtils.findNodesForFeature(assertion, | 101 | ProblemDerivedStateComputer::validNodeName); |
97 | ProblemPackage.Literals.ASSERTION__ARGUMENTS); | 102 | } else if (statement instanceof PredicateDefinition) { |
98 | for (INode node : nodes) { | 103 | PredicateDefinition predicateDefinition = (PredicateDefinition) statement; |
99 | String nodeName = linkingHelper.getCrossRefNodeAsString(node, true); | 104 | for (Conjunction body : predicateDefinition.getBodies()) { |
100 | if (validId(nodeName)) { | 105 | for (Literal literal : body.getLiterals()) { |
101 | QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(nodeName); | 106 | Atom atom = null; |
102 | if (!nodeNames.contains(nodeName) && nodeScope.getSingleElement(qualifiedName) == null) { | 107 | if (literal instanceof Atom) { |
103 | nodeNames.add(nodeName); | 108 | atom = (Atom) literal; |
109 | } else if (literal instanceof NegativeLiteral) { | ||
110 | NegativeLiteral negativeLiteral = (NegativeLiteral) literal; | ||
111 | atom = negativeLiteral.getAtom(); | ||
112 | } | ||
113 | if (atom == null) { | ||
114 | continue; | ||
115 | } | ||
116 | for (Argument argument : atom.getArguments()) { | ||
117 | addNodeNames(nodeNames, nodeScope, argument, | ||
118 | ProblemPackage.Literals.ARGUMENT__VARIABLE_OR_NODE, | ||
119 | ProblemDerivedStateComputer::validQuotedId); | ||
104 | } | 120 | } |
105 | } | 121 | } |
106 | } | 122 | } |
@@ -113,6 +129,21 @@ public class ProblemDerivedStateComputer implements IDerivedStateComputer { | |||
113 | } | 129 | } |
114 | } | 130 | } |
115 | 131 | ||
132 | private void addNodeNames(Set<String> nodeNames, IScope nodeScope, EObject eObject, EStructuralFeature feature, | ||
133 | Predicate<String> condition) { | ||
134 | List<INode> nodes = NodeModelUtils.findNodesForFeature(eObject, feature); | ||
135 | for (INode node : nodes) { | ||
136 | String nodeName = linkingHelper.getCrossRefNodeAsString(node, true); | ||
137 | if (!condition.test(nodeName)) { | ||
138 | continue; | ||
139 | } | ||
140 | QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(nodeName); | ||
141 | if (!nodeNames.contains(nodeName) && nodeScope.getSingleElement(qualifiedName) == null) { | ||
142 | nodeNames.add(nodeName); | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | |||
116 | protected Node createNode(String name) { | 147 | protected Node createNode(String name) { |
117 | Node node = ProblemFactory.eINSTANCE.createNode(); | 148 | Node node = ProblemFactory.eINSTANCE.createNode(); |
118 | node.setName(name); | 149 | node.setName(name); |
@@ -158,6 +189,7 @@ public class ProblemDerivedStateComputer implements IDerivedStateComputer { | |||
158 | 189 | ||
159 | protected void createSigletonVariablesAndCollectVariables(Atom atom, Set<String> knownVariables, | 190 | protected void createSigletonVariablesAndCollectVariables(Atom atom, Set<String> knownVariables, |
160 | Set<String> newVariables) { | 191 | Set<String> newVariables) { |
192 | IScope scope = scopeProvider.getScope(atom, ProblemPackage.Literals.ARGUMENT__VARIABLE_OR_NODE); | ||
161 | List<INode> nodes = NodeModelUtils.findNodesForFeature(atom, ProblemPackage.Literals.ATOM__ARGUMENTS); | 193 | List<INode> nodes = NodeModelUtils.findNodesForFeature(atom, ProblemPackage.Literals.ATOM__ARGUMENTS); |
162 | int nodesSize = nodes.size(); | 194 | int nodesSize = nodes.size(); |
163 | List<Argument> arguments = atom.getArguments(); | 195 | List<Argument> arguments = atom.getArguments(); |
@@ -165,6 +197,13 @@ public class ProblemDerivedStateComputer implements IDerivedStateComputer { | |||
165 | for (int i = 0; i < nodesSize; i++) { | 197 | for (int i = 0; i < nodesSize; i++) { |
166 | INode node = nodes.get(i); | 198 | INode node = nodes.get(i); |
167 | String variableName = linkingHelper.getCrossRefNodeAsString(node, true); | 199 | String variableName = linkingHelper.getCrossRefNodeAsString(node, true); |
200 | if (!validId(variableName)) { | ||
201 | continue; | ||
202 | } | ||
203 | QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(variableName); | ||
204 | if (scope.getSingleElement(qualifiedName) != null) { | ||
205 | continue; | ||
206 | } | ||
168 | if (ProblemUtil.isSingletonVariableName(variableName)) { | 207 | if (ProblemUtil.isSingletonVariableName(variableName)) { |
169 | if (i < argumentsSize) { | 208 | if (i < argumentsSize) { |
170 | createSingletonVariable(arguments.get(i), variableName); | 209 | createSingletonVariable(arguments.get(i), variableName); |
@@ -223,9 +262,13 @@ public class ProblemDerivedStateComputer implements IDerivedStateComputer { | |||
223 | for (Conjunction body : definition.getBodies()) { | 262 | for (Conjunction body : definition.getBodies()) { |
224 | body.getImplicitVariables().clear(); | 263 | body.getImplicitVariables().clear(); |
225 | for (Literal literal : body.getLiterals()) { | 264 | for (Literal literal : body.getLiterals()) { |
265 | if (literal instanceof Atom) { | ||
266 | discardDerivedAtomState((Atom) literal); | ||
267 | } | ||
226 | if (literal instanceof NegativeLiteral) { | 268 | if (literal instanceof NegativeLiteral) { |
227 | NegativeLiteral negativeLiteral = (NegativeLiteral) literal; | 269 | NegativeLiteral negativeLiteral = (NegativeLiteral) literal; |
228 | negativeLiteral.getImplicitVariables().clear(); | 270 | negativeLiteral.getImplicitVariables().clear(); |
271 | discardDerivedAtomState(negativeLiteral.getAtom()); | ||
229 | } | 272 | } |
230 | } | 273 | } |
231 | } | 274 | } |
@@ -233,7 +276,24 @@ public class ProblemDerivedStateComputer implements IDerivedStateComputer { | |||
233 | } | 276 | } |
234 | } | 277 | } |
235 | 278 | ||
279 | protected void discardDerivedAtomState(Atom atom) { | ||
280 | if (atom == null) { | ||
281 | return; | ||
282 | } | ||
283 | for (Argument argument : atom.getArguments()) { | ||
284 | argument.setSingletonVariable(null); | ||
285 | } | ||
286 | } | ||
287 | |||
236 | protected static boolean validId(String name) { | 288 | protected static boolean validId(String name) { |
237 | return name != null && ID_REGEX.matcher(name).matches(); | 289 | return name != null && ID_REGEX.matcher(name).matches(); |
238 | } | 290 | } |
291 | |||
292 | protected static boolean validQuotedId(String name) { | ||
293 | return name != null && QUOTED_ID_REGEX.matcher(name).matches(); | ||
294 | } | ||
295 | |||
296 | protected static boolean validNodeName(String name) { | ||
297 | return validId(name) || validQuotedId(name); | ||
298 | } | ||
239 | } | 299 | } |
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java index d3976ec5..94dbdfee 100644 --- a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java | |||
@@ -1,21 +1,9 @@ | |||
1 | package org.eclipse.viatra.solver.language.resource; | 1 | package org.eclipse.viatra.solver.language.resource; |
2 | 2 | ||
3 | import java.util.Iterator; | ||
4 | |||
5 | import org.eclipse.emf.ecore.EObject; | 3 | import org.eclipse.emf.ecore.EObject; |
6 | import org.eclipse.viatra.solver.language.ProblemUtil; | 4 | import org.eclipse.viatra.solver.language.ProblemUtil; |
7 | import org.eclipse.viatra.solver.language.model.problem.Argument; | ||
8 | import org.eclipse.viatra.solver.language.model.problem.Assertion; | ||
9 | import org.eclipse.viatra.solver.language.model.problem.Atom; | ||
10 | import org.eclipse.viatra.solver.language.model.problem.Conjunction; | ||
11 | import org.eclipse.viatra.solver.language.model.problem.ImplicitVariable; | 5 | import org.eclipse.viatra.solver.language.model.problem.ImplicitVariable; |
12 | import org.eclipse.viatra.solver.language.model.problem.Literal; | ||
13 | import org.eclipse.viatra.solver.language.model.problem.NegativeLiteral; | ||
14 | import org.eclipse.viatra.solver.language.model.problem.Node; | 6 | import org.eclipse.viatra.solver.language.model.problem.Node; |
15 | import org.eclipse.viatra.solver.language.model.problem.Problem; | ||
16 | import org.eclipse.viatra.solver.language.model.problem.ProblemPackage; | ||
17 | import org.eclipse.viatra.solver.language.model.problem.Statement; | ||
18 | import org.eclipse.xtext.EcoreUtil2; | ||
19 | import org.eclipse.xtext.resource.DefaultLocationInFileProvider; | 7 | import org.eclipse.xtext.resource.DefaultLocationInFileProvider; |
20 | import org.eclipse.xtext.util.ITextRegion; | 8 | import org.eclipse.xtext.util.ITextRegion; |
21 | 9 | ||
@@ -26,90 +14,19 @@ public class ProblemLocationInFileProvider extends DefaultLocationInFileProvider | |||
26 | return getNodeTextRegion((Node) obj, query); | 14 | return getNodeTextRegion((Node) obj, query); |
27 | } | 15 | } |
28 | if (obj instanceof ImplicitVariable) { | 16 | if (obj instanceof ImplicitVariable) { |
29 | return getVariableTextRegion((ImplicitVariable) obj, query); | 17 | return ITextRegion.EMPTY_REGION; |
30 | } | 18 | } |
31 | return super.doGetTextRegion(obj, query); | 19 | return super.doGetTextRegion(obj, query); |
32 | } | 20 | } |
33 | 21 | ||
34 | protected ITextRegion getNodeTextRegion(Node node, RegionDescription query) { | 22 | protected ITextRegion getNodeTextRegion(Node node, RegionDescription query) { |
35 | ITextRegion newNodeRegion = getNewNodeTextRegion(node, query); | 23 | if (ProblemUtil.isEnumLiteral(node)) { |
36 | if (newNodeRegion != null) { | 24 | return super.doGetTextRegion(node, query); |
37 | return newNodeRegion; | ||
38 | } | 25 | } |
39 | return getNodeFirstReferenceTextRegion(node, query); | ||
40 | } | ||
41 | |||
42 | protected ITextRegion getNewNodeTextRegion(Node node, RegionDescription query) { | ||
43 | if (ProblemUtil.isNewNode(node)) { | 26 | if (ProblemUtil.isNewNode(node)) { |
44 | EObject container = node.eContainer(); | 27 | EObject container = node.eContainer(); |
45 | return doGetTextRegion(container, query); | 28 | return doGetTextRegion(container, query); |
46 | } | 29 | } |
47 | return null; | ||
48 | } | ||
49 | |||
50 | protected ITextRegion getNodeFirstReferenceTextRegion(Node node, RegionDescription query) { | ||
51 | Problem problem = EcoreUtil2.getContainerOfType(node, Problem.class); | ||
52 | if (problem == null) { | ||
53 | return ITextRegion.EMPTY_REGION; | ||
54 | } | ||
55 | for (Statement statement : problem.getStatements()) { | ||
56 | if (statement instanceof Assertion) { | ||
57 | Assertion assertion = (Assertion) statement; | ||
58 | int index = assertion.getArguments().indexOf(node); | ||
59 | if (index >= 0) { | ||
60 | return doGetLocationOfFeature(assertion, ProblemPackage.Literals.ASSERTION__ARGUMENTS, index, | ||
61 | query); | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | return ITextRegion.EMPTY_REGION; | ||
66 | } | ||
67 | |||
68 | protected ITextRegion getVariableTextRegion(ImplicitVariable variable, RegionDescription query) { | ||
69 | EObject container = variable.eContainer(); | ||
70 | if (container instanceof Argument) { | ||
71 | return getArgumentTextRegion((Argument) container, query); | ||
72 | } | ||
73 | if (container instanceof Conjunction) { | ||
74 | return getFirstReferenceToVariableInConjunction(variable, (Conjunction) container, query); | ||
75 | } | ||
76 | if (container instanceof NegativeLiteral) { | ||
77 | return getFirstReferenceToVariableInNegativeLiteral(variable, (NegativeLiteral) container, query); | ||
78 | } | ||
79 | return ITextRegion.EMPTY_REGION; | ||
80 | } | ||
81 | |||
82 | protected ITextRegion getFirstReferenceToVariableInConjunction(ImplicitVariable variable, Conjunction conjunction, | ||
83 | RegionDescription query) { | ||
84 | Iterator<Literal> iterator = conjunction.getLiterals().iterator(); | ||
85 | ITextRegion found = ITextRegion.EMPTY_REGION; | ||
86 | while (found == ITextRegion.EMPTY_REGION && iterator.hasNext()) { | ||
87 | Literal literal = iterator.next(); | ||
88 | if (literal instanceof Atom) { | ||
89 | found = getFirstReferenceToVariableInAtom(variable, (Atom) literal, query); | ||
90 | } else if (literal instanceof NegativeLiteral) { | ||
91 | found = getFirstReferenceToVariableInNegativeLiteral(variable, (NegativeLiteral) literal, query); | ||
92 | } | ||
93 | } | ||
94 | return found; | ||
95 | } | ||
96 | |||
97 | protected ITextRegion getFirstReferenceToVariableInNegativeLiteral(ImplicitVariable variable, | ||
98 | NegativeLiteral literal, RegionDescription query) { | ||
99 | return getFirstReferenceToVariableInAtom(variable, literal.getAtom(), query); | ||
100 | } | ||
101 | |||
102 | protected ITextRegion getFirstReferenceToVariableInAtom(ImplicitVariable variable, Atom atom, | ||
103 | RegionDescription query) { | ||
104 | for (Argument argument : atom.getArguments()) { | ||
105 | if (argument.getVariable().equals(variable)) { | ||
106 | return getArgumentTextRegion(argument, query); | ||
107 | } | ||
108 | } | ||
109 | return ITextRegion.EMPTY_REGION; | 30 | return ITextRegion.EMPTY_REGION; |
110 | } | 31 | } |
111 | |||
112 | protected ITextRegion getArgumentTextRegion(Argument argument, RegionDescription query) { | ||
113 | return doGetLocationOfFeature(argument, ProblemPackage.Literals.ARGUMENT__VARIABLE, 0, query); | ||
114 | } | ||
115 | } | 32 | } |
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemResourceDescriptionStrategy.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemResourceDescriptionStrategy.java index 95a9fe6b..edb25a1c 100644 --- a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemResourceDescriptionStrategy.java +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemResourceDescriptionStrategy.java | |||
@@ -1,7 +1,9 @@ | |||
1 | package org.eclipse.viatra.solver.language.resource; | 1 | package org.eclipse.viatra.solver.language.resource; |
2 | 2 | ||
3 | import org.eclipse.emf.ecore.EObject; | 3 | import org.eclipse.emf.ecore.EObject; |
4 | import org.eclipse.viatra.solver.language.ProblemUtil; | ||
4 | import org.eclipse.viatra.solver.language.model.problem.NamedElement; | 5 | import org.eclipse.viatra.solver.language.model.problem.NamedElement; |
6 | import org.eclipse.viatra.solver.language.model.problem.Node; | ||
5 | import org.eclipse.viatra.solver.language.model.problem.Problem; | 7 | import org.eclipse.viatra.solver.language.model.problem.Problem; |
6 | import org.eclipse.viatra.solver.language.model.problem.Variable; | 8 | import org.eclipse.viatra.solver.language.model.problem.Variable; |
7 | import org.eclipse.xtext.EcoreUtil2; | 9 | import org.eclipse.xtext.EcoreUtil2; |
@@ -73,6 +75,9 @@ public class ProblemResourceDescriptionStrategy extends DefaultResourceDescripti | |||
73 | } | 75 | } |
74 | 76 | ||
75 | protected boolean shouldExportSimpleName(EObject eObject) { | 77 | protected boolean shouldExportSimpleName(EObject eObject) { |
78 | if (eObject instanceof Node) { | ||
79 | return !ProblemUtil.isNewNode((Node) eObject); | ||
80 | } | ||
76 | return true; | 81 | return true; |
77 | } | 82 | } |
78 | 83 | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemScopeProvider.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemScopeProvider.java index c639f24c..fc4034ae 100644 --- a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemScopeProvider.java +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/scoping/ProblemScopeProvider.java | |||
@@ -16,6 +16,7 @@ import org.eclipse.viatra.solver.language.model.problem.ExistentialQuantifier; | |||
16 | import org.eclipse.viatra.solver.language.model.problem.PredicateDefinition; | 16 | import org.eclipse.viatra.solver.language.model.problem.PredicateDefinition; |
17 | import org.eclipse.viatra.solver.language.model.problem.ProblemPackage; | 17 | import org.eclipse.viatra.solver.language.model.problem.ProblemPackage; |
18 | import org.eclipse.viatra.solver.language.model.problem.ReferenceDeclaration; | 18 | import org.eclipse.viatra.solver.language.model.problem.ReferenceDeclaration; |
19 | import org.eclipse.viatra.solver.language.model.problem.Relation; | ||
19 | import org.eclipse.viatra.solver.language.model.problem.Variable; | 20 | import org.eclipse.viatra.solver.language.model.problem.Variable; |
20 | import org.eclipse.xtext.EcoreUtil2; | 21 | import org.eclipse.xtext.EcoreUtil2; |
21 | import org.eclipse.xtext.scoping.IScope; | 22 | import org.eclipse.xtext.scoping.IScope; |
@@ -33,7 +34,7 @@ public class ProblemScopeProvider extends AbstractProblemScopeProvider { | |||
33 | @Override | 34 | @Override |
34 | public IScope getScope(EObject context, EReference reference) { | 35 | public IScope getScope(EObject context, EReference reference) { |
35 | IScope scope = super.getScope(context, reference); | 36 | IScope scope = super.getScope(context, reference); |
36 | if (reference == ProblemPackage.Literals.ARGUMENT__VARIABLE) { | 37 | if (reference == ProblemPackage.Literals.ARGUMENT__VARIABLE_OR_NODE) { |
37 | return getVariableScope(context, scope); | 38 | return getVariableScope(context, scope); |
38 | } else if (reference == ProblemPackage.Literals.REFERENCE_DECLARATION__OPPOSITE) { | 39 | } else if (reference == ProblemPackage.Literals.REFERENCE_DECLARATION__OPPOSITE) { |
39 | return getOppositeScope(context, scope); | 40 | return getOppositeScope(context, scope); |
@@ -62,7 +63,7 @@ public class ProblemScopeProvider extends AbstractProblemScopeProvider { | |||
62 | PredicateDefinition definition = (PredicateDefinition) currentContext; | 63 | PredicateDefinition definition = (PredicateDefinition) currentContext; |
63 | variables.addAll(definition.getParameters()); | 64 | variables.addAll(definition.getParameters()); |
64 | } | 65 | } |
65 | return Scopes.scopeFor(variables); | 66 | return Scopes.scopeFor(variables, delegateScope); |
66 | } | 67 | } |
67 | 68 | ||
68 | protected IScope getOppositeScope(EObject context, IScope delegateScope) { | 69 | protected IScope getOppositeScope(EObject context, IScope delegateScope) { |
@@ -70,10 +71,11 @@ public class ProblemScopeProvider extends AbstractProblemScopeProvider { | |||
70 | if (referenceDeclaration == null) { | 71 | if (referenceDeclaration == null) { |
71 | return delegateScope; | 72 | return delegateScope; |
72 | } | 73 | } |
73 | ClassDeclaration classDeclaration = referenceDeclaration.getReferenceType(); | 74 | Relation relation = referenceDeclaration.getReferenceType(); |
74 | if (classDeclaration == null) { | 75 | if (!(relation instanceof ClassDeclaration)) { |
75 | return delegateScope; | 76 | return delegateScope; |
76 | } | 77 | } |
78 | ClassDeclaration classDeclaration = (ClassDeclaration) relation; | ||
77 | Collection<ReferenceDeclaration> referenceDeclarations = ProblemUtil | 79 | Collection<ReferenceDeclaration> referenceDeclarations = ProblemUtil |
78 | .getAllReferenceDeclarations(classDeclaration); | 80 | .getAllReferenceDeclarations(classDeclaration); |
79 | return Scopes.scopeFor(referenceDeclarations, delegateScope); | 81 | return Scopes.scopeFor(referenceDeclarations, delegateScope); |