diff options
Diffstat (limited to 'Application/org.eclipse.viatra.solver.language.ui/xtend-gen/org/eclipse/viatra/solver/language/ui/syntaxcoloring/SolverSemanticHighlightCalculator.java')
-rw-r--r-- | Application/org.eclipse.viatra.solver.language.ui/xtend-gen/org/eclipse/viatra/solver/language/ui/syntaxcoloring/SolverSemanticHighlightCalculator.java | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/Application/org.eclipse.viatra.solver.language.ui/xtend-gen/org/eclipse/viatra/solver/language/ui/syntaxcoloring/SolverSemanticHighlightCalculator.java b/Application/org.eclipse.viatra.solver.language.ui/xtend-gen/org/eclipse/viatra/solver/language/ui/syntaxcoloring/SolverSemanticHighlightCalculator.java new file mode 100644 index 00000000..2935dfd7 --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language.ui/xtend-gen/org/eclipse/viatra/solver/language/ui/syntaxcoloring/SolverSemanticHighlightCalculator.java | |||
@@ -0,0 +1,83 @@ | |||
1 | package org.eclipse.viatra.solver.language.ui.syntaxcoloring; | ||
2 | |||
3 | import com.google.common.collect.Iterators; | ||
4 | import java.util.Iterator; | ||
5 | import java.util.Random; | ||
6 | import java.util.WeakHashMap; | ||
7 | import org.eclipse.viatra.solver.language.solverLanguage.Reference; | ||
8 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
9 | import org.eclipse.xtext.ide.editor.syntaxcoloring.DefaultSemanticHighlightingCalculator; | ||
10 | import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor; | ||
11 | import org.eclipse.xtext.nodemodel.ICompositeNode; | ||
12 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils; | ||
13 | import org.eclipse.xtext.resource.XtextResource; | ||
14 | import org.eclipse.xtext.util.CancelIndicator; | ||
15 | |||
16 | @SuppressWarnings("all") | ||
17 | public class SolverSemanticHighlightCalculator extends DefaultSemanticHighlightingCalculator { | ||
18 | public static final String SYMBOL_CODE = "SymbolCode::"; | ||
19 | |||
20 | private final WeakHashMap<String, String> symbolName2ID = new WeakHashMap<String, String>(); | ||
21 | |||
22 | @Override | ||
23 | public void provideHighlightingFor(final XtextResource resource, final IHighlightedPositionAcceptor acceptor, final CancelIndicator cancelIndicator) { | ||
24 | if (((resource == null) || (resource.getParseResult() == null))) { | ||
25 | return; | ||
26 | } else { | ||
27 | final Iterator<Reference> modelSymbols = Iterators.<Reference>filter(resource.getAllContents(), Reference.class); | ||
28 | while (modelSymbols.hasNext()) { | ||
29 | { | ||
30 | final Reference symbolElement = modelSymbols.next(); | ||
31 | final ICompositeNode node = NodeModelUtils.getNode(symbolElement); | ||
32 | acceptor.addPosition( | ||
33 | node.getOffset(), | ||
34 | node.getLength(), | ||
35 | this.getSymbolCode(node.getText())); | ||
36 | } | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | |||
41 | public String getSymbolCode(final String name) { | ||
42 | boolean _containsKey = this.symbolName2ID.containsKey(name); | ||
43 | if (_containsKey) { | ||
44 | return this.symbolName2ID.get(name); | ||
45 | } else { | ||
46 | final String id = this.calculateSymbolCode(name); | ||
47 | this.symbolName2ID.put(name, id); | ||
48 | return id; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | public String calculateSymbolCode(final String name) { | ||
53 | int _hashCode = name.hashCode(); | ||
54 | final Random random = new Random(_hashCode); | ||
55 | final float hue = this.huePick(random.nextFloat()); | ||
56 | float _nextFloat = random.nextFloat(); | ||
57 | double _multiply = (_nextFloat * 0.3); | ||
58 | final double saturation = (0.2 + _multiply); | ||
59 | float _nextFloat_1 = random.nextFloat(); | ||
60 | double _multiply_1 = (_nextFloat_1 * 0.2); | ||
61 | final double brightness = (_multiply_1 + 0.7f); | ||
62 | StringConcatenation _builder = new StringConcatenation(); | ||
63 | _builder.append(SolverSemanticHighlightCalculator.SYMBOL_CODE); | ||
64 | _builder.append(" "); | ||
65 | _builder.append(hue); | ||
66 | _builder.append(" "); | ||
67 | _builder.append(saturation); | ||
68 | _builder.append(" "); | ||
69 | _builder.append(brightness); | ||
70 | return _builder.toString(); | ||
71 | } | ||
72 | |||
73 | private float huePick(final float random) { | ||
74 | final int pink = 300; | ||
75 | final int tolerance = 10; | ||
76 | final float degree = (random * (360 - (2 * tolerance))); | ||
77 | if ((degree < (pink - tolerance))) { | ||
78 | return degree; | ||
79 | } else { | ||
80 | return (degree + (2 * tolerance)); | ||
81 | } | ||
82 | } | ||
83 | } | ||