diff options
Diffstat (limited to 'org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java/org/eclipse/viatra/solver/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java')
1 files changed, 41 insertions, 24 deletions
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java/org/eclipse/viatra/solver/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java/org/eclipse/viatra/solver/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java index f6a29457..2f69e946 100644 --- a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java/org/eclipse/viatra/solver/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java/org/eclipse/viatra/solver/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java | |||
@@ -7,6 +7,7 @@ import org.eclipse.emf.ecore.EAttribute; | |||
7 | import org.eclipse.emf.ecore.EObject; | 7 | import org.eclipse.emf.ecore.EObject; |
8 | import org.eclipse.emf.ecore.EReference; | 8 | import org.eclipse.emf.ecore.EReference; |
9 | import org.eclipse.emf.ecore.resource.Resource; | 9 | import org.eclipse.emf.ecore.resource.Resource; |
10 | import org.eclipse.viatra.solver.language.ProblemUtil; | ||
10 | import org.eclipse.viatra.solver.language.model.problem.ClassDeclaration; | 11 | import org.eclipse.viatra.solver.language.model.problem.ClassDeclaration; |
11 | import org.eclipse.viatra.solver.language.model.problem.Node; | 12 | import org.eclipse.viatra.solver.language.model.problem.Node; |
12 | import org.eclipse.viatra.solver.language.model.problem.Parameter; | 13 | import org.eclipse.viatra.solver.language.model.problem.Parameter; |
@@ -22,6 +23,7 @@ import org.eclipse.xtext.service.OperationCanceledManager; | |||
22 | import org.eclipse.xtext.util.CancelIndicator; | 23 | import org.eclipse.xtext.util.CancelIndicator; |
23 | import org.eclipse.xtext.util.SimpleAttributeResolver; | 24 | import org.eclipse.xtext.util.SimpleAttributeResolver; |
24 | 25 | ||
26 | import com.google.common.collect.ImmutableList; | ||
25 | import com.google.inject.Inject; | 27 | import com.google.inject.Inject; |
26 | 28 | ||
27 | public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighlightingCalculator { | 29 | public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighlightingCalculator { |
@@ -33,8 +35,11 @@ public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighli | |||
33 | private static final String PREDICATE_CLASS = "problem-predicate"; | 35 | private static final String PREDICATE_CLASS = "problem-predicate"; |
34 | private static final String ERROR_CLASS = "problem-error"; | 36 | private static final String ERROR_CLASS = "problem-error"; |
35 | private static final String NODE_CLASS = "problem-node"; | 37 | private static final String NODE_CLASS = "problem-node"; |
38 | private static final String ENUM_NODE_CLASS = "problem-enum-node"; | ||
39 | private static final String NEW_NODE_CLASS = "problem-new-node"; | ||
36 | private static final String PARAMETER_CLASS = "problem-parameter"; | 40 | private static final String PARAMETER_CLASS = "problem-parameter"; |
37 | private static final String VARIABLE_CLASS = "problem-variable"; | 41 | private static final String VARIABLE_CLASS = "problem-variable"; |
42 | private static final String SINGLETON_VARIABLE_CLASS = "problem-singleton-variable"; | ||
38 | 43 | ||
39 | @Inject | 44 | @Inject |
40 | private OperationCanceledManager operationCanceledManager; | 45 | private OperationCanceledManager operationCanceledManager; |
@@ -49,8 +54,8 @@ public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighli | |||
49 | 54 | ||
50 | protected void highlightName(EObject object, IHighlightedPositionAcceptor acceptor, | 55 | protected void highlightName(EObject object, IHighlightedPositionAcceptor acceptor, |
51 | CancelIndicator cancelIndicator) { | 56 | CancelIndicator cancelIndicator) { |
52 | String highlightClass = getHighlightClass(object); | 57 | String[] highlightClass = getHighlightClass(object); |
53 | if (highlightClass != null) { | 58 | if (highlightClass.length > 0) { |
54 | EAttribute nameAttribute = SimpleAttributeResolver.NAME_RESOLVER.getAttribute(object); | 59 | EAttribute nameAttribute = SimpleAttributeResolver.NAME_RESOLVER.getAttribute(object); |
55 | if (nameAttribute != null) { | 60 | if (nameAttribute != null) { |
56 | highlightFeature(acceptor, object, nameAttribute, highlightClass); | 61 | highlightFeature(acceptor, object, nameAttribute, highlightClass); |
@@ -65,72 +70,84 @@ public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighli | |||
65 | continue; | 70 | continue; |
66 | } | 71 | } |
67 | operationCanceledManager.checkCanceled(cancelIndicator); | 72 | operationCanceledManager.checkCanceled(cancelIndicator); |
68 | Object value = object.eGet(reference); | 73 | if (reference.isMany()) { |
69 | if (value instanceof EList) { | ||
70 | @SuppressWarnings("unchecked") | 74 | @SuppressWarnings("unchecked") |
71 | EList<? extends EObject> values = (EList<? extends EObject>) value; | 75 | EList<? extends EObject> values = (EList<? extends EObject>) object.eGet(reference); |
72 | List<INode> nodes = NodeModelUtils.findNodesForFeature(object, reference); | 76 | List<INode> nodes = NodeModelUtils.findNodesForFeature(object, reference); |
73 | int size = Math.min(values.size(), nodes.size()); | 77 | int size = Math.min(values.size(), nodes.size()); |
74 | for (int i = 0; i < size; i++) { | 78 | for (int i = 0; i < size; i++) { |
75 | EObject valueInList = values.get(i); | 79 | EObject valueInList = values.get(i); |
76 | INode node = nodes.get(i); | 80 | INode node = nodes.get(i); |
77 | String highlightClass = getHighlightClass(valueInList); | 81 | String[] highlightClass = getHighlightClass(valueInList); |
78 | if (highlightClass != null) { | 82 | if (highlightClass.length > 0) { |
79 | highlightNode(acceptor, node, highlightClass); | 83 | highlightNode(acceptor, node, highlightClass); |
80 | } | 84 | } |
81 | } | 85 | } |
82 | } else if (value instanceof EObject) { | 86 | } else { |
83 | EObject valueObj = (EObject) value; | 87 | EObject valueObj = (EObject) object.eGet(reference); |
84 | String highlightClass = getHighlightClass(valueObj); | 88 | String[] highlightClass = getHighlightClass(valueObj); |
85 | if (highlightClass != null) { | 89 | if (highlightClass.length > 0) { |
86 | highlightFeature(acceptor, object, reference, highlightClass); | 90 | highlightFeature(acceptor, object, reference, highlightClass); |
87 | } | 91 | } |
88 | } | 92 | } |
89 | } | 93 | } |
90 | } | 94 | } |
91 | 95 | ||
92 | protected String getHighlightClass(EObject eObject) { | 96 | protected String[] getHighlightClass(EObject eObject) { |
93 | if (isBuiltIn(eObject)) { | 97 | if (isBuiltIn(eObject)) { |
94 | return BUILTIN_CLASS; | 98 | return new String[] { BUILTIN_CLASS }; |
95 | } | 99 | } |
100 | ImmutableList.Builder<String> classesBuilder = ImmutableList.builder(); | ||
96 | if (eObject instanceof ClassDeclaration) { | 101 | if (eObject instanceof ClassDeclaration) { |
102 | classesBuilder.add(CLASS_CLASS); | ||
97 | ClassDeclaration classDeclaration = (ClassDeclaration) eObject; | 103 | ClassDeclaration classDeclaration = (ClassDeclaration) eObject; |
98 | if (classDeclaration.isAbstract()) { | 104 | if (classDeclaration.isAbstract()) { |
99 | return ABSTRACT_CLASS; | 105 | classesBuilder.add(ABSTRACT_CLASS); |
100 | } | 106 | } |
101 | return CLASS_CLASS; | ||
102 | } | 107 | } |
103 | if (eObject instanceof ReferenceDeclaration) { | 108 | if (eObject instanceof ReferenceDeclaration) { |
109 | classesBuilder.add(REFERENCE_CLASS); | ||
104 | ReferenceDeclaration referenceDeclaration = (ReferenceDeclaration) eObject; | 110 | ReferenceDeclaration referenceDeclaration = (ReferenceDeclaration) eObject; |
105 | if (referenceDeclaration.isContainment()) { | 111 | if (referenceDeclaration.isContainment()) { |
106 | return CONTAINMENT_CLASS; | 112 | classesBuilder.add(CONTAINMENT_CLASS); |
107 | } | 113 | } |
108 | return REFERENCE_CLASS; | ||
109 | } | 114 | } |
110 | if (eObject instanceof PredicateDefinition) { | 115 | if (eObject instanceof PredicateDefinition) { |
116 | classesBuilder.add(PREDICATE_CLASS); | ||
111 | PredicateDefinition predicateDefinition = (PredicateDefinition) eObject; | 117 | PredicateDefinition predicateDefinition = (PredicateDefinition) eObject; |
112 | if (predicateDefinition.isError()) { | 118 | if (predicateDefinition.isError()) { |
113 | return ERROR_CLASS; | 119 | classesBuilder.add(ERROR_CLASS); |
114 | } | 120 | } |
115 | return PREDICATE_CLASS; | ||
116 | } | 121 | } |
117 | if (eObject instanceof Node) { | 122 | if (eObject instanceof Node) { |
118 | return NODE_CLASS; | 123 | classesBuilder.add(NODE_CLASS); |
124 | Node node = (Node) eObject; | ||
125 | if (ProblemUtil.isEnumNode(node)) { | ||
126 | classesBuilder.add(ENUM_NODE_CLASS); | ||
127 | } | ||
128 | if (ProblemUtil.isNewNode(node)) { | ||
129 | classesBuilder.add(NEW_NODE_CLASS); | ||
130 | } | ||
119 | } | 131 | } |
120 | if (eObject instanceof Parameter) { | 132 | if (eObject instanceof Parameter) { |
121 | return PARAMETER_CLASS; | 133 | classesBuilder.add(PARAMETER_CLASS); |
122 | } | 134 | } |
123 | if (eObject instanceof Variable) { | 135 | if (eObject instanceof Variable) { |
124 | return VARIABLE_CLASS; | 136 | classesBuilder.add(VARIABLE_CLASS); |
137 | Variable variable = (Variable) eObject; | ||
138 | if (ProblemUtil.isSingletonVariable(variable)) { | ||
139 | classesBuilder.add(SINGLETON_VARIABLE_CLASS); | ||
140 | } | ||
125 | } | 141 | } |
126 | return null; | 142 | List<String> classes = classesBuilder.build(); |
143 | return classes.toArray(new String[0]); | ||
127 | } | 144 | } |
128 | 145 | ||
129 | protected boolean isBuiltIn(EObject eObject) { | 146 | protected boolean isBuiltIn(EObject eObject) { |
130 | if (eObject != null) { | 147 | if (eObject != null) { |
131 | Resource eResource = eObject.eResource(); | 148 | Resource eResource = eObject.eResource(); |
132 | if (eResource != null) { | 149 | if (eResource != null) { |
133 | return ProblemGlobalScopeProvider.LIBRARY_URI.equals(eResource.getURI()); | 150 | return ProblemGlobalScopeProvider.BULTIN_LIBRARY_URI.equals(eResource.getURI()); |
134 | } | 151 | } |
135 | } | 152 | } |
136 | return false; | 153 | return false; |