diff options
author | 2021-06-27 14:22:40 +0200 | |
---|---|---|
committer | 2021-06-27 14:22:40 +0200 | |
commit | 07719e927f9d398765e661c84fd8778cefb39083 (patch) | |
tree | 9652080f7e580f09a0763a3e258348dea6e02684 /org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java | |
parent | Add enum support (diff) | |
download | refinery-07719e927f9d398765e661c84fd8778cefb39083.tar.gz refinery-07719e927f9d398765e661c84fd8778cefb39083.tar.zst refinery-07719e927f9d398765e661c84fd8778cefb39083.zip |
Simplify project layout
Diffstat (limited to 'org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java')
3 files changed, 0 insertions, 199 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 deleted file mode 100644 index c6e41049..00000000 --- a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java/org/eclipse/viatra/solver/language/ide/ProblemIdeModule.java +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
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 deleted file mode 100644 index ca1fec30..00000000 --- a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.ide/src/main/java/org/eclipse/viatra/solver/language/ide/ProblemIdeSetup.java +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
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 deleted file mode 100644 index eee5070b..00000000 --- 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 +++ /dev/null | |||
@@ -1,160 +0,0 @@ | |||
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.ProblemUtil; | ||
11 | import org.eclipse.viatra.solver.language.model.problem.ClassDeclaration; | ||
12 | import org.eclipse.viatra.solver.language.model.problem.EnumDeclaration; | ||
13 | import org.eclipse.viatra.solver.language.model.problem.Node; | ||
14 | import org.eclipse.viatra.solver.language.model.problem.Parameter; | ||
15 | import org.eclipse.viatra.solver.language.model.problem.PredicateDefinition; | ||
16 | import org.eclipse.viatra.solver.language.model.problem.ReferenceDeclaration; | ||
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; | ||
20 | import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor; | ||
21 | import org.eclipse.xtext.nodemodel.INode; | ||
22 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils; | ||
23 | import org.eclipse.xtext.service.OperationCanceledManager; | ||
24 | import org.eclipse.xtext.util.CancelIndicator; | ||
25 | import org.eclipse.xtext.util.SimpleAttributeResolver; | ||
26 | |||
27 | import com.google.common.collect.ImmutableList; | ||
28 | import com.google.inject.Inject; | ||
29 | |||
30 | public class ProblemSemanticHighlightingCalculator extends DefaultSemanticHighlightingCalculator { | ||
31 | private static final String BUILTIN_CLASS = "cm-keyword"; | ||
32 | private static final String CLASS_CLASS = "problem-class"; | ||
33 | private static final String ABSTRACT_CLASS = "problem-abstract"; | ||
34 | private static final String ENUM_CLASS = "problem-enum"; | ||
35 | private static final String REFERENCE_CLASS = "problem-reference"; | ||
36 | private static final String CONTAINMENT_CLASS = "problem-containment"; | ||
37 | private static final String PREDICATE_CLASS = "problem-predicate"; | ||
38 | private static final String ERROR_CLASS = "problem-error"; | ||
39 | private static final String NODE_CLASS = "problem-node"; | ||
40 | private static final String ENUM_NODE_CLASS = "problem-enum-node"; | ||
41 | private static final String NEW_NODE_CLASS = "problem-new-node"; | ||
42 | private static final String PARAMETER_CLASS = "problem-parameter"; | ||
43 | private static final String VARIABLE_CLASS = "problem-variable"; | ||
44 | private static final String SINGLETON_VARIABLE_CLASS = "problem-singleton-variable"; | ||
45 | |||
46 | @Inject | ||
47 | private OperationCanceledManager operationCanceledManager; | ||
48 | |||
49 | @Override | ||
50 | protected boolean highlightElement(EObject object, IHighlightedPositionAcceptor acceptor, | ||
51 | CancelIndicator cancelIndicator) { | ||
52 | highlightName(object, acceptor, cancelIndicator); | ||
53 | highlightCrossReferences(object, acceptor, cancelIndicator); | ||
54 | return false; | ||
55 | } | ||
56 | |||
57 | protected void highlightName(EObject object, IHighlightedPositionAcceptor acceptor, | ||
58 | CancelIndicator cancelIndicator) { | ||
59 | String[] highlightClass = getHighlightClass(object); | ||
60 | if (highlightClass.length > 0) { | ||
61 | EAttribute nameAttribute = SimpleAttributeResolver.NAME_RESOLVER.getAttribute(object); | ||
62 | if (nameAttribute != null) { | ||
63 | highlightFeature(acceptor, object, nameAttribute, highlightClass); | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | |||
68 | protected void highlightCrossReferences(EObject object, IHighlightedPositionAcceptor acceptor, | ||
69 | CancelIndicator cancelIndicator) { | ||
70 | for (EReference reference : object.eClass().getEAllReferences()) { | ||
71 | if (reference.isContainment()) { | ||
72 | continue; | ||
73 | } | ||
74 | operationCanceledManager.checkCanceled(cancelIndicator); | ||
75 | if (reference.isMany()) { | ||
76 | @SuppressWarnings("unchecked") | ||
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 { | ||
89 | EObject valueObj = (EObject) object.eGet(reference); | ||
90 | String[] highlightClass = getHighlightClass(valueObj); | ||
91 | if (highlightClass.length > 0) { | ||
92 | highlightFeature(acceptor, object, reference, highlightClass); | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | protected String[] getHighlightClass(EObject eObject) { | ||
99 | if (isBuiltIn(eObject)) { | ||
100 | return new String[] { BUILTIN_CLASS }; | ||
101 | } | ||
102 | ImmutableList.Builder<String> classesBuilder = ImmutableList.builder(); | ||
103 | if (eObject instanceof ClassDeclaration) { | ||
104 | classesBuilder.add(CLASS_CLASS); | ||
105 | ClassDeclaration classDeclaration = (ClassDeclaration) eObject; | ||
106 | if (classDeclaration.isAbstract()) { | ||
107 | classesBuilder.add(ABSTRACT_CLASS); | ||
108 | } | ||
109 | } | ||
110 | if (eObject instanceof EnumDeclaration) { | ||
111 | classesBuilder.add(ENUM_CLASS); | ||
112 | } | ||
113 | if (eObject instanceof ReferenceDeclaration) { | ||
114 | classesBuilder.add(REFERENCE_CLASS); | ||
115 | ReferenceDeclaration referenceDeclaration = (ReferenceDeclaration) eObject; | ||
116 | if (referenceDeclaration.isContainment()) { | ||
117 | classesBuilder.add(CONTAINMENT_CLASS); | ||
118 | } | ||
119 | } | ||
120 | if (eObject instanceof PredicateDefinition) { | ||
121 | classesBuilder.add(PREDICATE_CLASS); | ||
122 | PredicateDefinition predicateDefinition = (PredicateDefinition) eObject; | ||
123 | if (predicateDefinition.isError()) { | ||
124 | classesBuilder.add(ERROR_CLASS); | ||
125 | } | ||
126 | } | ||
127 | if (eObject instanceof Node) { | ||
128 | classesBuilder.add(NODE_CLASS); | ||
129 | Node node = (Node) eObject; | ||
130 | if (ProblemUtil.isEnumNode(node)) { | ||
131 | classesBuilder.add(ENUM_NODE_CLASS); | ||
132 | } | ||
133 | if (ProblemUtil.isNewNode(node)) { | ||
134 | classesBuilder.add(NEW_NODE_CLASS); | ||
135 | } | ||
136 | } | ||
137 | if (eObject instanceof Parameter) { | ||
138 | classesBuilder.add(PARAMETER_CLASS); | ||
139 | } | ||
140 | if (eObject instanceof Variable) { | ||
141 | classesBuilder.add(VARIABLE_CLASS); | ||
142 | Variable variable = (Variable) eObject; | ||
143 | if (ProblemUtil.isSingletonVariable(variable)) { | ||
144 | classesBuilder.add(SINGLETON_VARIABLE_CLASS); | ||
145 | } | ||
146 | } | ||
147 | List<String> classes = classesBuilder.build(); | ||
148 | return classes.toArray(new String[0]); | ||
149 | } | ||
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 | } | ||