diff options
Diffstat (limited to 'Application/org.eclipse.viatra.solver.language.ui/src/org')
-rw-r--r-- | Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/SolverLanguageUiModule.xtend | 18 | ||||
-rw-r--r-- | Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/syntaxcoloring/SolverSemanticHighlightCalculator.xtend (renamed from Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticHighlightCalculator.xtend) | 45 | ||||
-rw-r--r-- | Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/syntaxcoloring/SolverSemanticTextAttributeProvider.xtend (renamed from Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticTextAttributeProvider.xtend) | 36 | ||||
-rw-r--r-- | Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/validation/SolverLanguageValidator.xtend | 25 |
4 files changed, 72 insertions, 52 deletions
diff --git a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/SolverLanguageUiModule.xtend b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/SolverLanguageUiModule.xtend index 1c165a0a..602646aa 100644 --- a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/SolverLanguageUiModule.xtend +++ b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/SolverLanguageUiModule.xtend | |||
@@ -4,21 +4,17 @@ | |||
4 | package org.eclipse.viatra.solver.language.ui | 4 | package org.eclipse.viatra.solver.language.ui |
5 | 5 | ||
6 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor | 6 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor |
7 | import org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator | ||
8 | import org.eclipse.xtext.ui.editor.syntaxcoloring.ITextAttributeProvider | ||
9 | import org.eclipse.viatra.solver.language.ui.highlight.SolverSemanticHighlightCalculator | ||
10 | import org.eclipse.viatra.solver.language.ui.highlight.SolverSemanticTextAttributeProvider | ||
11 | 7 | ||
12 | /** | 8 | /** |
13 | * Use this class to register components to be used within the Eclipse IDE. | 9 | * Use this class to register components to be used within the Eclipse IDE. |
14 | */ | 10 | */ |
15 | @FinalFieldsConstructor | 11 | @FinalFieldsConstructor |
16 | class SolverLanguageUiModule extends AbstractSolverLanguageUiModule { | 12 | class SolverLanguageUiModule extends AbstractSolverLanguageUiModule { |
17 | def Class<? extends ISemanticHighlightingCalculator> bindISemanticHighlightingCalculator() { | 13 | // def Class<? extends ISemanticHighlightingCalculator> bindISemanticHighlightingCalculator() { |
18 | SolverSemanticHighlightCalculator | 14 | // SolverSemanticHighlightCalculator |
19 | } | 15 | // } |
20 | 16 | // | |
21 | def Class<? extends ITextAttributeProvider> bindITextAttributeProvider() { | 17 | // def Class<? extends ITextAttributeProvider> bindITextAttributeProvider() { |
22 | SolverSemanticTextAttributeProvider | 18 | // SolverSemanticTextAttributeProvider |
23 | } | 19 | // } |
24 | } | 20 | } |
diff --git a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticHighlightCalculator.xtend b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/syntaxcoloring/SolverSemanticHighlightCalculator.xtend index cb10ebf4..5242a82e 100644 --- a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticHighlightCalculator.xtend +++ b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/syntaxcoloring/SolverSemanticHighlightCalculator.xtend | |||
@@ -1,8 +1,8 @@ | |||
1 | package org.eclipse.viatra.solver.language.ui.highlight | 1 | package org.eclipse.viatra.solver.language.ui.syntaxcoloring |
2 | 2 | ||
3 | import java.util.Random | 3 | import java.util.Random |
4 | import java.util.WeakHashMap | 4 | import java.util.WeakHashMap |
5 | import org.eclipse.viatra.solver.language.solverLanguage.ModelSymbol | 5 | import org.eclipse.viatra.solver.language.solverLanguage.Reference |
6 | import org.eclipse.xtext.ide.editor.syntaxcoloring.DefaultSemanticHighlightingCalculator | 6 | import org.eclipse.xtext.ide.editor.syntaxcoloring.DefaultSemanticHighlightingCalculator |
7 | import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor | 7 | import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor |
8 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils | 8 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils |
@@ -10,49 +10,50 @@ import org.eclipse.xtext.resource.XtextResource | |||
10 | import org.eclipse.xtext.util.CancelIndicator | 10 | import org.eclipse.xtext.util.CancelIndicator |
11 | 11 | ||
12 | class SolverSemanticHighlightCalculator extends DefaultSemanticHighlightingCalculator { | 12 | class SolverSemanticHighlightCalculator extends DefaultSemanticHighlightingCalculator { |
13 | public static val SmybolCode = "SymbolCode" | 13 | public static val SYMBOL_CODE = "SymbolCode::" |
14 | 14 | ||
15 | val symbolName2ID = new WeakHashMap<String,String> | 15 | val symbolName2ID = new WeakHashMap<String, String> |
16 | 16 | ||
17 | override provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) { | 17 | override provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor, |
18 | CancelIndicator cancelIndicator) { | ||
18 | if (resource === null || resource.getParseResult() === null) { | 19 | if (resource === null || resource.getParseResult() === null) { |
19 | return | 20 | return |
20 | } else { | 21 | } else { |
21 | val modelSymbols = resource.allContents.filter(ModelSymbol) | 22 | val modelSymbols = resource.allContents.filter(Reference) |
22 | while(modelSymbols.hasNext) { | 23 | while (modelSymbols.hasNext) { |
23 | val symbolElement = modelSymbols.next | 24 | val symbolElement = modelSymbols.next |
24 | val node = NodeModelUtils::getNode(symbolElement) | 25 | val node = NodeModelUtils.getNode(symbolElement) |
25 | acceptor.addPosition( | 26 | acceptor.addPosition( |
26 | node.getOffset(), | 27 | node.getOffset(), |
27 | node.getLength(), | 28 | node.getLength(), |
28 | getSymbolCode(symbolElement.name) | 29 | getSymbolCode(node.text) |
29 | ) | 30 | ) |
30 | } | 31 | } |
31 | } | 32 | } |
32 | } | 33 | } |
33 | 34 | ||
34 | def getSymbolCode(String name) { | 35 | def getSymbolCode(String name) { |
35 | if(symbolName2ID.containsKey(name)) { | 36 | if (symbolName2ID.containsKey(name)) { |
36 | return symbolName2ID.get(name) | 37 | return symbolName2ID.get(name) |
37 | } else { | 38 | } else { |
38 | val id = calculateSymbolCode(name) | 39 | val id = calculateSymbolCode(name) |
39 | symbolName2ID.put(name,id) | 40 | symbolName2ID.put(name, id) |
40 | return id | 41 | return id |
41 | } | 42 | } |
42 | } | 43 | } |
43 | 44 | ||
44 | def String calculateSymbolCode(String name) { | 45 | def String calculateSymbolCode(String name) { |
45 | val Random random = new Random(name.hashCode) | 46 | val Random random = new Random(name.hashCode) |
46 | val hue = huePick(random.nextFloat) | 47 | val hue = huePick(random.nextFloat) |
47 | val saturation = 0.2+random.nextFloat*0.3 | 48 | val saturation = 0.2 + random.nextFloat * 0.3 |
48 | val brightness = random.nextFloat*0.2+0.7f | 49 | val brightness = random.nextFloat * 0.2 + 0.7f |
49 | return '''«SmybolCode» «hue» «saturation» «brightness»''' | 50 | return '''«SYMBOL_CODE» «hue» «saturation» «brightness»''' |
50 | } | 51 | } |
52 | |||
51 | private def huePick(float random) { | 53 | private def huePick(float random) { |
52 | val pink = 300 | 54 | val pink = 300 |
53 | val tolerance = 10 | 55 | val tolerance = 10 |
54 | val degree = random*(360-2*tolerance) | 56 | val degree = random * (360 - 2 * tolerance) |
55 | if(degree<pink-tolerance) return degree | 57 | if(degree < pink - tolerance) return degree else return degree + 2 * tolerance |
56 | else return degree+2*tolerance | ||
57 | } | 58 | } |
58 | } \ No newline at end of file | 59 | } |
diff --git a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticTextAttributeProvider.xtend b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/syntaxcoloring/SolverSemanticTextAttributeProvider.xtend index 4eed59ce..ca74a9a2 100644 --- a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticTextAttributeProvider.xtend +++ b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/syntaxcoloring/SolverSemanticTextAttributeProvider.xtend | |||
@@ -1,4 +1,4 @@ | |||
1 | package org.eclipse.viatra.solver.language.ui.highlight | 1 | package org.eclipse.viatra.solver.language.ui.syntaxcoloring |
2 | 2 | ||
3 | import com.google.inject.Inject | 3 | import com.google.inject.Inject |
4 | import java.util.WeakHashMap | 4 | import java.util.WeakHashMap |
@@ -12,34 +12,34 @@ import org.eclipse.xtext.ui.editor.utils.EditorUtils | |||
12 | import org.eclipse.xtext.ui.editor.utils.TextStyle | 12 | import org.eclipse.xtext.ui.editor.utils.TextStyle |
13 | 13 | ||
14 | class SolverSemanticTextAttributeProvider extends TextAttributeProvider { | 14 | class SolverSemanticTextAttributeProvider extends TextAttributeProvider { |
15 | 15 | ||
16 | val defaultTextStyle = new TextStyle | 16 | val defaultTextStyle = new TextStyle |
17 | val colorID2TextAttribute = new WeakHashMap<String,TextAttribute> | 17 | val colorID2TextAttribute = new WeakHashMap<String, TextAttribute> |
18 | 18 | ||
19 | @Inject | 19 | @Inject |
20 | new(IHighlightingConfiguration highlightingConfig, IPreferenceStoreAccess preferenceStoreAccess, PreferenceStoreAccessor prefStoreAccessor) { | 20 | new(IHighlightingConfiguration highlightingConfig, IPreferenceStoreAccess preferenceStoreAccess, |
21 | PreferenceStoreAccessor prefStoreAccessor) { | ||
21 | super(highlightingConfig, preferenceStoreAccess, prefStoreAccessor) | 22 | super(highlightingConfig, preferenceStoreAccess, prefStoreAccessor) |
22 | } | 23 | } |
23 | 24 | ||
24 | |||
25 | override getAttribute(String id) { | 25 | override getAttribute(String id) { |
26 | if(isMetamodelElementColorID(id)) { | 26 | if (isMetamodelElementColorID(id)) { |
27 | if(colorID2TextAttribute.containsKey(id)) { | 27 | if (colorID2TextAttribute.containsKey(id)) { |
28 | return colorID2TextAttribute.get(id) | 28 | return colorID2TextAttribute.get(id) |
29 | } else { | 29 | } else { |
30 | val style = metamodelElementTextStyle(id) | 30 | val style = metamodelElementTextStyle(id) |
31 | colorID2TextAttribute.put(id,style) | 31 | colorID2TextAttribute.put(id, style) |
32 | return style | 32 | return style |
33 | } | 33 | } |
34 | } else { | 34 | } else { |
35 | super.getAttribute(id) | 35 | super.getAttribute(id) |
36 | } | 36 | } |
37 | } | 37 | } |
38 | 38 | ||
39 | private def isMetamodelElementColorID(String id) { | 39 | private def isMetamodelElementColorID(String id) { |
40 | id.startsWith(SolverSemanticHighlightCalculator::SmybolCode) | 40 | id.startsWith(SolverSemanticHighlightCalculator.SYMBOL_CODE) |
41 | } | 41 | } |
42 | 42 | ||
43 | private def TextAttribute metamodelElementTextStyle(String id) { | 43 | private def TextAttribute metamodelElementTextStyle(String id) { |
44 | val texts = id.split(' ') | 44 | val texts = id.split(' ') |
45 | val backgroundColor = new RGB( | 45 | val backgroundColor = new RGB( |
@@ -47,11 +47,9 @@ class SolverSemanticTextAttributeProvider extends TextAttributeProvider { | |||
47 | Float.parseFloat(texts.get(2)), | 47 | Float.parseFloat(texts.get(2)), |
48 | Float.parseFloat(texts.get(3)) | 48 | Float.parseFloat(texts.get(3)) |
49 | ) | 49 | ) |
50 | return new TextAttribute( | 50 | return new TextAttribute(EditorUtils.colorFromRGB(defaultTextStyle.color), |
51 | EditorUtils.colorFromRGB(defaultTextStyle.color), | 51 | EditorUtils.colorFromRGB(backgroundColor), defaultTextStyle.style, |
52 | EditorUtils.colorFromRGB(backgroundColor), | ||
53 | defaultTextStyle.style, | ||
54 | EditorUtils.fontFromFontData(defaultTextStyle.getFontData())); | 52 | EditorUtils.fontFromFontData(defaultTextStyle.getFontData())); |
55 | } | 53 | } |
56 | 54 | ||
57 | } \ No newline at end of file | 55 | } |
diff --git a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/validation/SolverLanguageValidator.xtend b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/validation/SolverLanguageValidator.xtend new file mode 100644 index 00000000..a7ff7252 --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/validation/SolverLanguageValidator.xtend | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.18.0.M3 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.validation | ||
5 | |||
6 | |||
7 | /** | ||
8 | * This class contains custom validation rules. | ||
9 | * | ||
10 | * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation | ||
11 | */ | ||
12 | class SolverLanguageValidator extends AbstractSolverLanguageValidator { | ||
13 | |||
14 | // public static val INVALID_NAME = 'invalidName' | ||
15 | // | ||
16 | // @Check | ||
17 | // def checkGreetingStartsWithCapital(Greeting greeting) { | ||
18 | // if (!Character.isUpperCase(greeting.name.charAt(0))) { | ||
19 | // warning('Name should start with a capital', | ||
20 | // SolverLanguagePackage.Literals.GREETING__NAME, | ||
21 | // INVALID_NAME) | ||
22 | // } | ||
23 | // } | ||
24 | |||
25 | } | ||