diff options
author | 2021-06-27 01:43:59 +0200 | |
---|---|---|
committer | 2021-06-27 02:01:19 +0200 | |
commit | b88c842ba625753ea185e6166cd967e694160798 (patch) | |
tree | 51931f892dff12d253f7697179e137bdfe705155 /org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java | |
parent | Opposite reference scope (diff) | |
download | refinery-b88c842ba625753ea185e6166cd967e694160798.tar.gz refinery-b88c842ba625753ea185e6166cd967e694160798.tar.zst refinery-b88c842ba625753ea185e6166cd967e694160798.zip |
Add enum support
Diffstat (limited to 'org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java')
-rw-r--r-- | org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/resource/ProblemLocationInFileProvider.java | 89 |
1 files changed, 3 insertions, 86 deletions
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 | } |