blob: 254284a82eee3c109392763d2eda69c353b6d185 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*
* generated by Xtext 2.25.0
*/
package org.eclipse.viatra.solver.language.scoping;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.viatra.solver.language.model.problem.ClassDeclaration;
import org.eclipse.viatra.solver.language.model.problem.ExistentialQuantifier;
import org.eclipse.viatra.solver.language.model.problem.PredicateDefinition;
import org.eclipse.viatra.solver.language.model.problem.Problem;
import org.eclipse.viatra.solver.language.model.problem.ProblemPackage;
import org.eclipse.viatra.solver.language.model.problem.ReferenceDeclaration;
import org.eclipse.viatra.solver.language.model.problem.Statement;
import org.eclipse.viatra.solver.language.model.problem.Variable;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.Scopes;
import com.google.common.collect.ImmutableList;
/**
* This class contains custom scoping description.
*
* See
* https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping
* on how and when to use it.
*/
public class ProblemScopeProvider extends AbstractProblemScopeProvider {
@Override
public IScope getScope(EObject context, EReference reference) {
IScope scope = super.getScope(context, reference);
if (reference == ProblemPackage.Literals.ATOM__ARGUMENTS) {
return getVariableScope(context, scope);
} else if (EcoreUtil2.isAssignableFrom(reference.getEReferenceType(),
ProblemPackage.Literals.REFERENCE_DECLARATION)) {
Problem problem = EcoreUtil2.getContainerOfType(context, Problem.class);
if (problem == null) {
return scope;
}
ImmutableList.Builder<ReferenceDeclaration> builder = ImmutableList.builder();
for (Statement statement : problem.getStatements()) {
if (statement instanceof ClassDeclaration) {
ClassDeclaration classDeclaration = (ClassDeclaration) statement;
builder.addAll(classDeclaration.getReferenceDeclarations());
}
}
return Scopes.scopeFor(builder.build(), scope);
}
return scope;
}
protected IScope getVariableScope(EObject context, IScope delegateScope) {
List<Variable> variables = new ArrayList<>();
EObject currentContext = context;
while (currentContext != null && !(currentContext instanceof PredicateDefinition)) {
if (currentContext instanceof ExistentialQuantifier) {
ExistentialQuantifier quantifier = (ExistentialQuantifier) currentContext;
variables.addAll(quantifier.getImplicitVariables());
}
currentContext = currentContext.eContainer();
}
if (currentContext instanceof PredicateDefinition) {
PredicateDefinition definition = (PredicateDefinition) currentContext;
variables.addAll(definition.getParameters());
}
return Scopes.scopeFor(variables);
}
}
|