diff options
author | 2021-10-30 20:14:50 +0200 | |
---|---|---|
committer | 2021-10-31 19:26:14 +0100 | |
commit | cbf442d8fd9f72c567ebf9f036a219a9ff100487 (patch) | |
tree | a128345d9a9863bef7f3670da585bcb62d13cb34 /language-ide/src/main/java/tools | |
parent | feat(web): show error count on generate button (diff) | |
download | refinery-cbf442d8fd9f72c567ebf9f036a219a9ff100487.tar.gz refinery-cbf442d8fd9f72c567ebf9f036a219a9ff100487.tar.zst refinery-cbf442d8fd9f72c567ebf9f036a219a9ff100487.zip |
feat(web): semantic highlighting
Diffstat (limited to 'language-ide/src/main/java/tools')
-rw-r--r-- | language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java | 51 |
1 files changed, 14 insertions, 37 deletions
diff --git a/language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java b/language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java index 76a67f96..d9abf12d 100644 --- a/language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java +++ b/language-ide/src/main/java/tools/refinery/language/ide/syntaxcoloring/ProblemSemanticHighlightingCalculator.java | |||
@@ -17,30 +17,20 @@ import com.google.inject.Inject; | |||
17 | 17 | ||
18 | import tools.refinery.language.model.ProblemUtil; | 18 | import tools.refinery.language.model.ProblemUtil; |
19 | import tools.refinery.language.model.problem.ClassDeclaration; | 19 | import tools.refinery.language.model.problem.ClassDeclaration; |
20 | import tools.refinery.language.model.problem.EnumDeclaration; | ||
21 | import tools.refinery.language.model.problem.NamedElement; | 20 | import tools.refinery.language.model.problem.NamedElement; |
22 | import tools.refinery.language.model.problem.Node; | 21 | import tools.refinery.language.model.problem.Node; |
23 | import tools.refinery.language.model.problem.Parameter; | ||
24 | import tools.refinery.language.model.problem.PredicateDefinition; | 22 | import tools.refinery.language.model.problem.PredicateDefinition; |
25 | import tools.refinery.language.model.problem.ProblemPackage; | 23 | import tools.refinery.language.model.problem.ProblemPackage; |
26 | import tools.refinery.language.model.problem.ReferenceDeclaration; | 24 | import tools.refinery.language.model.problem.ReferenceDeclaration; |
27 | import tools.refinery.language.model.problem.Variable; | ||
28 | 25 | ||
29 | public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighlightingCalculator { | 26 | public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighlightingCalculator { |
30 | private static final String BUILTIN_CLASS = "cm-keyword"; | 27 | private static final String BUILTIN_CLASS = "builtin"; |
31 | private static final String CLASS_CLASS = "problem-class"; | 28 | private static final String ABSTRACT_CLASS = "abstract"; |
32 | private static final String ABSTRACT_CLASS = "problem-abstract"; | 29 | private static final String CONTAINMENT_CLASS = "containment"; |
33 | private static final String ENUM_CLASS = "problem-enum"; | 30 | private static final String ERROR_CLASS = "error"; |
34 | private static final String REFERENCE_CLASS = "problem-reference"; | 31 | private static final String NODE_CLASS = "node"; |
35 | private static final String CONTAINMENT_CLASS = "problem-containment"; | 32 | private static final String UNIQUE_NODE_CLASS = "unique"; |
36 | private static final String PREDICATE_CLASS = "problem-predicate"; | 33 | private static final String NEW_NODE_CLASS = "new"; |
37 | private static final String ERROR_CLASS = "problem-error"; | ||
38 | private static final String NODE_CLASS = "problem-node"; | ||
39 | private static final String UNIQUE_NODE_CLASS = "problem-unique-node"; | ||
40 | private static final String NEW_NODE_CLASS = "problem-new-node"; | ||
41 | private static final String PARAMETER_CLASS = "problem-parameter"; | ||
42 | private static final String VARIABLE_CLASS = "problem-variable"; | ||
43 | private static final String SINGLETON_VARIABLE_CLASS = "problem-singleton-variable"; | ||
44 | 34 | ||
45 | @Inject | 35 | @Inject |
46 | private OperationCanceledManager operationCanceledManager; | 36 | private OperationCanceledManager operationCanceledManager; |
@@ -57,7 +47,7 @@ public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighli | |||
57 | if (!(object instanceof NamedElement)) { | 47 | if (!(object instanceof NamedElement)) { |
58 | return; | 48 | return; |
59 | } | 49 | } |
60 | String[] highlightClass = getHighlightClass(object); | 50 | String[] highlightClass = getHighlightClass(object, null); |
61 | if (highlightClass.length > 0) { | 51 | if (highlightClass.length > 0) { |
62 | highlightFeature(acceptor, object, ProblemPackage.Literals.NAMED_ELEMENT__NAME, highlightClass); | 52 | highlightFeature(acceptor, object, ProblemPackage.Literals.NAMED_ELEMENT__NAME, highlightClass); |
63 | } | 53 | } |
@@ -80,7 +70,7 @@ public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighli | |||
80 | 70 | ||
81 | protected void highlightSingleValue(EObject object, EReference reference, IHighlightedPositionAcceptor acceptor) { | 71 | protected void highlightSingleValue(EObject object, EReference reference, IHighlightedPositionAcceptor acceptor) { |
82 | EObject valueObj = (EObject) object.eGet(reference); | 72 | EObject valueObj = (EObject) object.eGet(reference); |
83 | String[] highlightClass = getHighlightClass(valueObj); | 73 | String[] highlightClass = getHighlightClass(valueObj, reference); |
84 | if (highlightClass.length > 0) { | 74 | if (highlightClass.length > 0) { |
85 | highlightFeature(acceptor, object, reference, highlightClass); | 75 | highlightFeature(acceptor, object, reference, highlightClass); |
86 | } | 76 | } |
@@ -94,41 +84,37 @@ public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighli | |||
94 | for (var i = 0; i < size; i++) { | 84 | for (var i = 0; i < size; i++) { |
95 | EObject valueInList = values.get(i); | 85 | EObject valueInList = values.get(i); |
96 | INode node = nodes.get(i); | 86 | INode node = nodes.get(i); |
97 | String[] highlightClass = getHighlightClass(valueInList); | 87 | String[] highlightClass = getHighlightClass(valueInList, reference); |
98 | if (highlightClass.length > 0) { | 88 | if (highlightClass.length > 0) { |
99 | highlightNode(acceptor, node, highlightClass); | 89 | highlightNode(acceptor, node, highlightClass); |
100 | } | 90 | } |
101 | } | 91 | } |
102 | } | 92 | } |
103 | 93 | ||
104 | protected String[] getHighlightClass(EObject eObject) { | 94 | protected String[] getHighlightClass(EObject eObject, EReference reference) { |
105 | if (ProblemUtil.isBuiltIn(eObject)) { | 95 | if (ProblemUtil.isBuiltIn(eObject)) { |
106 | return new String[] { BUILTIN_CLASS }; | 96 | return new String[] { BUILTIN_CLASS }; |
107 | } | 97 | } |
108 | ImmutableList.Builder<String> classesBuilder = ImmutableList.builder(); | 98 | ImmutableList.Builder<String> classesBuilder = ImmutableList.builder(); |
109 | if (eObject instanceof ClassDeclaration classDeclaration) { | 99 | if (eObject instanceof ClassDeclaration classDeclaration) { |
110 | classesBuilder.add(CLASS_CLASS); | ||
111 | if (classDeclaration.isAbstract()) { | 100 | if (classDeclaration.isAbstract()) { |
112 | classesBuilder.add(ABSTRACT_CLASS); | 101 | classesBuilder.add(ABSTRACT_CLASS); |
113 | } | 102 | } |
114 | } | 103 | } |
115 | if (eObject instanceof EnumDeclaration) { | ||
116 | classesBuilder.add(ENUM_CLASS); | ||
117 | } | ||
118 | if (eObject instanceof ReferenceDeclaration referenceDeclaration) { | 104 | if (eObject instanceof ReferenceDeclaration referenceDeclaration) { |
119 | classesBuilder.add(REFERENCE_CLASS); | ||
120 | if (referenceDeclaration.isContainment()) { | 105 | if (referenceDeclaration.isContainment()) { |
121 | classesBuilder.add(CONTAINMENT_CLASS); | 106 | classesBuilder.add(CONTAINMENT_CLASS); |
122 | } | 107 | } |
123 | } | 108 | } |
124 | if (eObject instanceof PredicateDefinition predicateDefinition) { | 109 | if (eObject instanceof PredicateDefinition predicateDefinition) { |
125 | classesBuilder.add(PREDICATE_CLASS); | ||
126 | if (predicateDefinition.isError()) { | 110 | if (predicateDefinition.isError()) { |
127 | classesBuilder.add(ERROR_CLASS); | 111 | classesBuilder.add(ERROR_CLASS); |
128 | } | 112 | } |
129 | } | 113 | } |
130 | if (eObject instanceof Node node) { | 114 | if (eObject instanceof Node node) { |
131 | classesBuilder.add(NODE_CLASS); | 115 | if (reference == ProblemPackage.Literals.VARIABLE_OR_NODE_ARGUMENT__VARIABLE_OR_NODE) { |
116 | classesBuilder.add(NODE_CLASS); | ||
117 | } | ||
132 | if (ProblemUtil.isUniqueNode(node)) { | 118 | if (ProblemUtil.isUniqueNode(node)) { |
133 | classesBuilder.add(UNIQUE_NODE_CLASS); | 119 | classesBuilder.add(UNIQUE_NODE_CLASS); |
134 | } | 120 | } |
@@ -136,15 +122,6 @@ public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighli | |||
136 | classesBuilder.add(NEW_NODE_CLASS); | 122 | classesBuilder.add(NEW_NODE_CLASS); |
137 | } | 123 | } |
138 | } | 124 | } |
139 | if (eObject instanceof Parameter) { | ||
140 | classesBuilder.add(PARAMETER_CLASS); | ||
141 | } | ||
142 | if (eObject instanceof Variable variable) { | ||
143 | classesBuilder.add(VARIABLE_CLASS); | ||
144 | if (ProblemUtil.isSingletonVariable(variable)) { | ||
145 | classesBuilder.add(SINGLETON_VARIABLE_CLASS); | ||
146 | } | ||
147 | } | ||
148 | List<String> classes = classesBuilder.build(); | 125 | List<String> classes = classesBuilder.build(); |
149 | return classes.toArray(new String[0]); | 126 | return classes.toArray(new String[0]); |
150 | } | 127 | } |