diff options
Diffstat (limited to 'org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java')
3 files changed, 177 insertions, 0 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/ProblemIdeModule.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java/org/eclipse/viatra/solver/language/ide/ProblemIdeModule.java new file mode 100644 index 00000000..c6e41049 --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java/org/eclipse/viatra/solver/language/ide/ProblemIdeModule.java | |||
@@ -0,0 +1,17 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.ide; | ||
5 | |||
6 | import org.eclipse.viatra.solver.language.ide.syntaxcoloring.ProblemSemanticHighlightingCalculator; | ||
7 | import org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator; | ||
8 | |||
9 | /** | ||
10 | * Use this class to register ide components. | ||
11 | */ | ||
12 | public class ProblemIdeModule extends AbstractProblemIdeModule { | ||
13 | |||
14 | public Class<? extends ISemanticHighlightingCalculator> bindISemanticHighlightingCalculator() { | ||
15 | return ProblemSemanticHighlightingCalculator.class; | ||
16 | } | ||
17 | } | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java/org/eclipse/viatra/solver/language/ide/ProblemIdeSetup.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java/org/eclipse/viatra/solver/language/ide/ProblemIdeSetup.java new file mode 100644 index 00000000..ca1fec30 --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java/org/eclipse/viatra/solver/language/ide/ProblemIdeSetup.java | |||
@@ -0,0 +1,22 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.ide; | ||
5 | |||
6 | import com.google.inject.Guice; | ||
7 | import com.google.inject.Injector; | ||
8 | import org.eclipse.viatra.solver.language.ProblemRuntimeModule; | ||
9 | import org.eclipse.viatra.solver.language.ProblemStandaloneSetup; | ||
10 | import org.eclipse.xtext.util.Modules2; | ||
11 | |||
12 | /** | ||
13 | * Initialization support for running Xtext languages as language servers. | ||
14 | */ | ||
15 | public class ProblemIdeSetup extends ProblemStandaloneSetup { | ||
16 | |||
17 | @Override | ||
18 | public Injector createInjector() { | ||
19 | return Guice.createInjector(Modules2.mixin(new ProblemRuntimeModule(), new ProblemIdeModule())); | ||
20 | } | ||
21 | |||
22 | } | ||
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 new file mode 100644 index 00000000..f6a29457 --- /dev/null +++ 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 | |||
@@ -0,0 +1,138 @@ | |||
1 | package org.eclipse.viatra.solver.language.ide.syntaxcoloring; | ||
2 | |||
3 | import java.util.List; | ||
4 | |||
5 | import org.eclipse.emf.common.util.EList; | ||
6 | import org.eclipse.emf.ecore.EAttribute; | ||
7 | import org.eclipse.emf.ecore.EObject; | ||
8 | import org.eclipse.emf.ecore.EReference; | ||
9 | import org.eclipse.emf.ecore.resource.Resource; | ||
10 | 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.Parameter; | ||
13 | import org.eclipse.viatra.solver.language.model.problem.PredicateDefinition; | ||
14 | import org.eclipse.viatra.solver.language.model.problem.ReferenceDeclaration; | ||
15 | import org.eclipse.viatra.solver.language.model.problem.Variable; | ||
16 | import org.eclipse.viatra.solver.language.scoping.ProblemGlobalScopeProvider; | ||
17 | import org.eclipse.xtext.ide.editor.syntaxcoloring.DefaultSemanticHighlightingCalculator; | ||
18 | import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor; | ||
19 | import org.eclipse.xtext.nodemodel.INode; | ||
20 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils; | ||
21 | import org.eclipse.xtext.service.OperationCanceledManager; | ||
22 | import org.eclipse.xtext.util.CancelIndicator; | ||
23 | import org.eclipse.xtext.util.SimpleAttributeResolver; | ||
24 | |||
25 | import com.google.inject.Inject; | ||
26 | |||
27 | public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighlightingCalculator { | ||
28 | private static final String BUILTIN_CLASS = "cm-keyword"; | ||
29 | private static final String CLASS_CLASS = "problem-class"; | ||
30 | private static final String ABSTRACT_CLASS = "problem-abstract"; | ||
31 | private static final String REFERENCE_CLASS = "problem-reference"; | ||
32 | private static final String CONTAINMENT_CLASS = "problem-containment"; | ||
33 | private static final String PREDICATE_CLASS = "problem-predicate"; | ||
34 | private static final String ERROR_CLASS = "problem-error"; | ||
35 | private static final String NODE_CLASS = "problem-node"; | ||
36 | private static final String PARAMETER_CLASS = "problem-parameter"; | ||
37 | private static final String VARIABLE_CLASS = "problem-variable"; | ||
38 | |||
39 | @Inject | ||
40 | private OperationCanceledManager operationCanceledManager; | ||
41 | |||
42 | @Override | ||
43 | protected boolean highlightElement(EObject object, IHighlightedPositionAcceptor acceptor, | ||
44 | CancelIndicator cancelIndicator) { | ||
45 | highlightName(object, acceptor, cancelIndicator); | ||
46 | highlightCrossReferences(object, acceptor, cancelIndicator); | ||
47 | return false; | ||
48 | } | ||
49 | |||
50 | protected void highlightName(EObject object, IHighlightedPositionAcceptor acceptor, | ||
51 | CancelIndicator cancelIndicator) { | ||
52 | String highlightClass = getHighlightClass(object); | ||
53 | if (highlightClass != null) { | ||
54 | EAttribute nameAttribute = SimpleAttributeResolver.NAME_RESOLVER.getAttribute(object); | ||
55 | if (nameAttribute != null) { | ||
56 | highlightFeature(acceptor, object, nameAttribute, highlightClass); | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | |||
61 | protected void highlightCrossReferences(EObject object, IHighlightedPositionAcceptor acceptor, | ||
62 | CancelIndicator cancelIndicator) { | ||
63 | for (EReference reference : object.eClass().getEAllReferences()) { | ||
64 | if (reference.isContainment()) { | ||
65 | continue; | ||
66 | } | ||
67 | operationCanceledManager.checkCanceled(cancelIndicator); | ||
68 | Object value = object.eGet(reference); | ||
69 | if (value instanceof EList) { | ||
70 | @SuppressWarnings("unchecked") | ||
71 | EList<? extends EObject> values = (EList<? extends EObject>) value; | ||
72 | List<INode> nodes = NodeModelUtils.findNodesForFeature(object, reference); | ||
73 | int size = Math.min(values.size(), nodes.size()); | ||
74 | for (int i = 0; i < size; i++) { | ||
75 | EObject valueInList = values.get(i); | ||
76 | INode node = nodes.get(i); | ||
77 | String highlightClass = getHighlightClass(valueInList); | ||
78 | if (highlightClass != null) { | ||
79 | highlightNode(acceptor, node, highlightClass); | ||
80 | } | ||
81 | } | ||
82 | } else if (value instanceof EObject) { | ||
83 | EObject valueObj = (EObject) value; | ||
84 | String highlightClass = getHighlightClass(valueObj); | ||
85 | if (highlightClass != null) { | ||
86 | highlightFeature(acceptor, object, reference, highlightClass); | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | |||
92 | protected String getHighlightClass(EObject eObject) { | ||
93 | if (isBuiltIn(eObject)) { | ||
94 | return BUILTIN_CLASS; | ||
95 | } | ||
96 | if (eObject instanceof ClassDeclaration) { | ||
97 | ClassDeclaration classDeclaration = (ClassDeclaration) eObject; | ||
98 | if (classDeclaration.isAbstract()) { | ||
99 | return ABSTRACT_CLASS; | ||
100 | } | ||
101 | return CLASS_CLASS; | ||
102 | } | ||
103 | if (eObject instanceof ReferenceDeclaration) { | ||
104 | ReferenceDeclaration referenceDeclaration = (ReferenceDeclaration) eObject; | ||
105 | if (referenceDeclaration.isContainment()) { | ||
106 | return CONTAINMENT_CLASS; | ||
107 | } | ||
108 | return REFERENCE_CLASS; | ||
109 | } | ||
110 | if (eObject instanceof PredicateDefinition) { | ||
111 | PredicateDefinition predicateDefinition = (PredicateDefinition) eObject; | ||
112 | if (predicateDefinition.isError()) { | ||
113 | return ERROR_CLASS; | ||
114 | } | ||
115 | return PREDICATE_CLASS; | ||
116 | } | ||
117 | if (eObject instanceof Node) { | ||
118 | return NODE_CLASS; | ||
119 | } | ||
120 | if (eObject instanceof Parameter) { | ||
121 | return PARAMETER_CLASS; | ||
122 | } | ||
123 | if (eObject instanceof Variable) { | ||
124 | return VARIABLE_CLASS; | ||
125 | } | ||
126 | return null; | ||
127 | } | ||
128 | |||
129 | protected boolean isBuiltIn(EObject eObject) { | ||
130 | if (eObject != null) { | ||
131 | Resource eResource = eObject.eResource(); | ||
132 | if (eResource != null) { | ||
133 | return ProblemGlobalScopeProvider.LIBRARY_URI.equals(eResource.getURI()); | ||
134 | } | ||
135 | } | ||
136 | return false; | ||
137 | } | ||
138 | } | ||