diff options
Diffstat (limited to 'language-ide/src/main/java/org/eclipse/viatra/solver/language')
-rw-r--r-- | language-ide/src/main/java/org/eclipse/viatra/solver/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java | 85 |
1 files changed, 40 insertions, 45 deletions
diff --git a/language-ide/src/main/java/org/eclipse/viatra/solver/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java b/language-ide/src/main/java/org/eclipse/viatra/solver/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java index eee5070b..b1a69e9d 100644 --- a/language-ide/src/main/java/org/eclipse/viatra/solver/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java +++ b/language-ide/src/main/java/org/eclipse/viatra/solver/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java | |||
@@ -3,26 +3,24 @@ package org.eclipse.viatra.solver.language.ide.syntaxcoloring; | |||
3 | import java.util.List; | 3 | import java.util.List; |
4 | 4 | ||
5 | import org.eclipse.emf.common.util.EList; | 5 | import org.eclipse.emf.common.util.EList; |
6 | import org.eclipse.emf.ecore.EAttribute; | ||
7 | import org.eclipse.emf.ecore.EObject; | 6 | import org.eclipse.emf.ecore.EObject; |
8 | import org.eclipse.emf.ecore.EReference; | 7 | import org.eclipse.emf.ecore.EReference; |
9 | import org.eclipse.emf.ecore.resource.Resource; | ||
10 | import org.eclipse.viatra.solver.language.ProblemUtil; | 8 | import org.eclipse.viatra.solver.language.ProblemUtil; |
11 | import org.eclipse.viatra.solver.language.model.problem.ClassDeclaration; | 9 | import org.eclipse.viatra.solver.language.model.problem.ClassDeclaration; |
12 | import org.eclipse.viatra.solver.language.model.problem.EnumDeclaration; | 10 | import org.eclipse.viatra.solver.language.model.problem.EnumDeclaration; |
11 | import org.eclipse.viatra.solver.language.model.problem.NamedElement; | ||
13 | import org.eclipse.viatra.solver.language.model.problem.Node; | 12 | import org.eclipse.viatra.solver.language.model.problem.Node; |
14 | import org.eclipse.viatra.solver.language.model.problem.Parameter; | 13 | import org.eclipse.viatra.solver.language.model.problem.Parameter; |
15 | import org.eclipse.viatra.solver.language.model.problem.PredicateDefinition; | 14 | import org.eclipse.viatra.solver.language.model.problem.PredicateDefinition; |
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.Variable; | 17 | import org.eclipse.viatra.solver.language.model.problem.Variable; |
18 | import org.eclipse.viatra.solver.language.scoping.ProblemGlobalScopeProvider; | ||
19 | import org.eclipse.xtext.ide.editor.syntaxcoloring.DefaultSemanticHighlightingCalculator; | 18 | import org.eclipse.xtext.ide.editor.syntaxcoloring.DefaultSemanticHighlightingCalculator; |
20 | import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor; | 19 | import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor; |
21 | import org.eclipse.xtext.nodemodel.INode; | 20 | import org.eclipse.xtext.nodemodel.INode; |
22 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils; | 21 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils; |
23 | import org.eclipse.xtext.service.OperationCanceledManager; | 22 | import org.eclipse.xtext.service.OperationCanceledManager; |
24 | import org.eclipse.xtext.util.CancelIndicator; | 23 | import org.eclipse.xtext.util.CancelIndicator; |
25 | import org.eclipse.xtext.util.SimpleAttributeResolver; | ||
26 | 24 | ||
27 | import com.google.common.collect.ImmutableList; | 25 | import com.google.common.collect.ImmutableList; |
28 | import com.google.inject.Inject; | 26 | import com.google.inject.Inject; |
@@ -49,19 +47,18 @@ public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighli | |||
49 | @Override | 47 | @Override |
50 | protected boolean highlightElement(EObject object, IHighlightedPositionAcceptor acceptor, | 48 | protected boolean highlightElement(EObject object, IHighlightedPositionAcceptor acceptor, |
51 | CancelIndicator cancelIndicator) { | 49 | CancelIndicator cancelIndicator) { |
52 | highlightName(object, acceptor, cancelIndicator); | 50 | highlightName(object, acceptor); |
53 | highlightCrossReferences(object, acceptor, cancelIndicator); | 51 | highlightCrossReferences(object, acceptor, cancelIndicator); |
54 | return false; | 52 | return false; |
55 | } | 53 | } |
56 | 54 | ||
57 | protected void highlightName(EObject object, IHighlightedPositionAcceptor acceptor, | 55 | protected void highlightName(EObject object, IHighlightedPositionAcceptor acceptor) { |
58 | CancelIndicator cancelIndicator) { | 56 | if (!(object instanceof NamedElement)) { |
57 | return; | ||
58 | } | ||
59 | String[] highlightClass = getHighlightClass(object); | 59 | String[] highlightClass = getHighlightClass(object); |
60 | if (highlightClass.length > 0) { | 60 | if (highlightClass.length > 0) { |
61 | EAttribute nameAttribute = SimpleAttributeResolver.NAME_RESOLVER.getAttribute(object); | 61 | highlightFeature(acceptor, object, ProblemPackage.Literals.NAMED_ELEMENT__NAME, highlightClass); |
62 | if (nameAttribute != null) { | ||
63 | highlightFeature(acceptor, object, nameAttribute, highlightClass); | ||
64 | } | ||
65 | } | 62 | } |
66 | } | 63 | } |
67 | 64 | ||
@@ -73,36 +70,44 @@ public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighli | |||
73 | } | 70 | } |
74 | operationCanceledManager.checkCanceled(cancelIndicator); | 71 | operationCanceledManager.checkCanceled(cancelIndicator); |
75 | if (reference.isMany()) { | 72 | if (reference.isMany()) { |
76 | @SuppressWarnings("unchecked") | 73 | highlightManyValues(object, reference, acceptor); |
77 | EList<? extends EObject> values = (EList<? extends EObject>) object.eGet(reference); | ||
78 | List<INode> nodes = NodeModelUtils.findNodesForFeature(object, reference); | ||
79 | int size = Math.min(values.size(), nodes.size()); | ||
80 | for (int i = 0; i < size; i++) { | ||
81 | EObject valueInList = values.get(i); | ||
82 | INode node = nodes.get(i); | ||
83 | String[] highlightClass = getHighlightClass(valueInList); | ||
84 | if (highlightClass.length > 0) { | ||
85 | highlightNode(acceptor, node, highlightClass); | ||
86 | } | ||
87 | } | ||
88 | } else { | 74 | } else { |
89 | EObject valueObj = (EObject) object.eGet(reference); | 75 | highlightSingleValue(object, reference, acceptor); |
90 | String[] highlightClass = getHighlightClass(valueObj); | 76 | } |
91 | if (highlightClass.length > 0) { | 77 | } |
92 | highlightFeature(acceptor, object, reference, highlightClass); | 78 | } |
93 | } | 79 | |
80 | protected void highlightSingleValue(EObject object, EReference reference, IHighlightedPositionAcceptor acceptor) { | ||
81 | EObject valueObj = (EObject) object.eGet(reference); | ||
82 | String[] highlightClass = getHighlightClass(valueObj); | ||
83 | if (highlightClass.length > 0) { | ||
84 | highlightFeature(acceptor, object, reference, highlightClass); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | protected void highlightManyValues(EObject object, EReference reference, IHighlightedPositionAcceptor acceptor) { | ||
89 | @SuppressWarnings("unchecked") | ||
90 | EList<? extends EObject> values = (EList<? extends EObject>) object.eGet(reference); | ||
91 | List<INode> nodes = NodeModelUtils.findNodesForFeature(object, reference); | ||
92 | int size = Math.min(values.size(), nodes.size()); | ||
93 | for (var i = 0; i < size; i++) { | ||
94 | EObject valueInList = values.get(i); | ||
95 | INode node = nodes.get(i); | ||
96 | String[] highlightClass = getHighlightClass(valueInList); | ||
97 | if (highlightClass.length > 0) { | ||
98 | highlightNode(acceptor, node, highlightClass); | ||
94 | } | 99 | } |
95 | } | 100 | } |
96 | } | 101 | } |
97 | 102 | ||
98 | protected String[] getHighlightClass(EObject eObject) { | 103 | protected String[] getHighlightClass(EObject eObject) { |
99 | if (isBuiltIn(eObject)) { | 104 | if (ProblemUtil.isBuiltIn(eObject)) { |
100 | return new String[] { BUILTIN_CLASS }; | 105 | return new String[] { BUILTIN_CLASS }; |
101 | } | 106 | } |
102 | ImmutableList.Builder<String> classesBuilder = ImmutableList.builder(); | 107 | ImmutableList.Builder<String> classesBuilder = ImmutableList.builder(); |
103 | if (eObject instanceof ClassDeclaration) { | 108 | if (eObject instanceof ClassDeclaration) { |
104 | classesBuilder.add(CLASS_CLASS); | 109 | classesBuilder.add(CLASS_CLASS); |
105 | ClassDeclaration classDeclaration = (ClassDeclaration) eObject; | 110 | var classDeclaration = (ClassDeclaration) eObject; |
106 | if (classDeclaration.isAbstract()) { | 111 | if (classDeclaration.isAbstract()) { |
107 | classesBuilder.add(ABSTRACT_CLASS); | 112 | classesBuilder.add(ABSTRACT_CLASS); |
108 | } | 113 | } |
@@ -112,21 +117,21 @@ public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighli | |||
112 | } | 117 | } |
113 | if (eObject instanceof ReferenceDeclaration) { | 118 | if (eObject instanceof ReferenceDeclaration) { |
114 | classesBuilder.add(REFERENCE_CLASS); | 119 | classesBuilder.add(REFERENCE_CLASS); |
115 | ReferenceDeclaration referenceDeclaration = (ReferenceDeclaration) eObject; | 120 | var referenceDeclaration = (ReferenceDeclaration) eObject; |
116 | if (referenceDeclaration.isContainment()) { | 121 | if (referenceDeclaration.isContainment()) { |
117 | classesBuilder.add(CONTAINMENT_CLASS); | 122 | classesBuilder.add(CONTAINMENT_CLASS); |
118 | } | 123 | } |
119 | } | 124 | } |
120 | if (eObject instanceof PredicateDefinition) { | 125 | if (eObject instanceof PredicateDefinition) { |
121 | classesBuilder.add(PREDICATE_CLASS); | 126 | classesBuilder.add(PREDICATE_CLASS); |
122 | PredicateDefinition predicateDefinition = (PredicateDefinition) eObject; | 127 | var predicateDefinition = (PredicateDefinition) eObject; |
123 | if (predicateDefinition.isError()) { | 128 | if (predicateDefinition.isError()) { |
124 | classesBuilder.add(ERROR_CLASS); | 129 | classesBuilder.add(ERROR_CLASS); |
125 | } | 130 | } |
126 | } | 131 | } |
127 | if (eObject instanceof Node) { | 132 | if (eObject instanceof Node) { |
128 | classesBuilder.add(NODE_CLASS); | 133 | classesBuilder.add(NODE_CLASS); |
129 | Node node = (Node) eObject; | 134 | var node = (Node) eObject; |
130 | if (ProblemUtil.isEnumNode(node)) { | 135 | if (ProblemUtil.isEnumNode(node)) { |
131 | classesBuilder.add(ENUM_NODE_CLASS); | 136 | classesBuilder.add(ENUM_NODE_CLASS); |
132 | } | 137 | } |
@@ -139,7 +144,7 @@ public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighli | |||
139 | } | 144 | } |
140 | if (eObject instanceof Variable) { | 145 | if (eObject instanceof Variable) { |
141 | classesBuilder.add(VARIABLE_CLASS); | 146 | classesBuilder.add(VARIABLE_CLASS); |
142 | Variable variable = (Variable) eObject; | 147 | var variable = (Variable) eObject; |
143 | if (ProblemUtil.isSingletonVariable(variable)) { | 148 | if (ProblemUtil.isSingletonVariable(variable)) { |
144 | classesBuilder.add(SINGLETON_VARIABLE_CLASS); | 149 | classesBuilder.add(SINGLETON_VARIABLE_CLASS); |
145 | } | 150 | } |
@@ -147,14 +152,4 @@ public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighli | |||
147 | List<String> classes = classesBuilder.build(); | 152 | List<String> classes = classesBuilder.build(); |
148 | return classes.toArray(new String[0]); | 153 | return classes.toArray(new String[0]); |
149 | } | 154 | } |
150 | |||
151 | protected boolean isBuiltIn(EObject eObject) { | ||
152 | if (eObject != null) { | ||
153 | Resource eResource = eObject.eResource(); | ||
154 | if (eResource != null) { | ||
155 | return ProblemGlobalScopeProvider.BULTIN_LIBRARY_URI.equals(eResource.getURI()); | ||
156 | } | ||
157 | } | ||
158 | return false; | ||
159 | } | ||
160 | } | 155 | } |