diff options
author | 2020-04-28 20:43:04 +0200 | |
---|---|---|
committer | 2020-04-28 20:43:04 +0200 | |
commit | 8a7b9b436b31e6d2f5a0521a077c960ebdeb4cbe (patch) | |
tree | d525bef75519f364d637e0779f8e63d4199dee31 /Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language | |
parent | check expressions are mapped to WF constraints (diff) | |
download | VIATRA-Generator-8a7b9b436b31e6d2f5a0521a077c960ebdeb4cbe.tar.gz VIATRA-Generator-8a7b9b436b31e6d2f5a0521a077c960ebdeb4cbe.tar.zst VIATRA-Generator-8a7b9b436b31e6d2f5a0521a077c960ebdeb4cbe.zip |
initial commit
Diffstat (limited to 'Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language')
8 files changed, 245 insertions, 0 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 new file mode 100644 index 00000000..1c165a0a --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/SolverLanguageUiModule.xtend | |||
@@ -0,0 +1,24 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.18.0.M3 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.ui | ||
5 | |||
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 | |||
12 | /** | ||
13 | * Use this class to register components to be used within the Eclipse IDE. | ||
14 | */ | ||
15 | @FinalFieldsConstructor | ||
16 | class SolverLanguageUiModule extends AbstractSolverLanguageUiModule { | ||
17 | def Class<? extends ISemanticHighlightingCalculator> bindISemanticHighlightingCalculator() { | ||
18 | SolverSemanticHighlightCalculator | ||
19 | } | ||
20 | |||
21 | def Class<? extends ITextAttributeProvider> bindITextAttributeProvider() { | ||
22 | SolverSemanticTextAttributeProvider | ||
23 | } | ||
24 | } | ||
diff --git a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/contentassist/SolverLanguageProposalProvider.xtend b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/contentassist/SolverLanguageProposalProvider.xtend new file mode 100644 index 00000000..9b6ab0fc --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/contentassist/SolverLanguageProposalProvider.xtend | |||
@@ -0,0 +1,12 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.18.0.M3 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.ui.contentassist | ||
5 | |||
6 | |||
7 | /** | ||
8 | * See https://www.eclipse.org/Xtext/documentation/304_ide_concepts.html#content-assist | ||
9 | * on how to customize the content assistant. | ||
10 | */ | ||
11 | class SolverLanguageProposalProvider extends AbstractSolverLanguageProposalProvider { | ||
12 | } | ||
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/highlight/SolverSemanticHighlightCalculator.xtend new file mode 100644 index 00000000..c9ceb36a --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticHighlightCalculator.xtend | |||
@@ -0,0 +1,58 @@ | |||
1 | package org.eclipse.viatra.solver.language.ui.highlight | ||
2 | |||
3 | import java.util.Random | ||
4 | import java.util.WeakHashMap | ||
5 | import org.eclipse.viatra.solver.language.solverLanguage.ModelSymbol | ||
6 | import org.eclipse.xtext.ide.editor.syntaxcoloring.DefaultSemanticHighlightingCalculator | ||
7 | import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor | ||
8 | import org.eclipse.xtext.nodemodel.util.NodeModelUtils | ||
9 | import org.eclipse.xtext.resource.XtextResource | ||
10 | import org.eclipse.xtext.util.CancelIndicator | ||
11 | |||
12 | class SolverSemanticHighlightCalculator extends DefaultSemanticHighlightingCalculator { | ||
13 | public static val SmybolCode = "SymbolCode" | ||
14 | |||
15 | val symbolName2ID = new WeakHashMap<String,String> | ||
16 | |||
17 | override provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) { | ||
18 | if (resource === null || resource.getParseResult() === null) { | ||
19 | return | ||
20 | } else { | ||
21 | val modelSymbols = resource.allContents.filter(ModelSymbol) | ||
22 | while(modelSymbols.hasNext) { | ||
23 | val symbolElement = modelSymbols.next | ||
24 | val node = NodeModelUtils::getNode(symbolElement) | ||
25 | acceptor.addPosition( | ||
26 | node.getOffset(), | ||
27 | node.getLength(), | ||
28 | getSymbolCode(symbolElement.name) | ||
29 | ) | ||
30 | } | ||
31 | } | ||
32 | } | ||
33 | |||
34 | def getSymbolCode(String name) { | ||
35 | if(symbolName2ID.containsKey(name)) { | ||
36 | return symbolName2ID.get(name) | ||
37 | } else { | ||
38 | val id = calculateSymbolCode(name) | ||
39 | symbolName2ID.put(name,id) | ||
40 | return id | ||
41 | } | ||
42 | } | ||
43 | |||
44 | def String calculateSymbolCode(String name) { | ||
45 | val Random random = new Random(name.hashCode) | ||
46 | val hue = huePick(random.nextFloat) | ||
47 | val saturation = 0.1+random.nextFloat*0.2 | ||
48 | val brightness = random.nextFloat/4+0.7f | ||
49 | return '''«SmybolCode» «hue» «saturation» «brightness»''' | ||
50 | } | ||
51 | private def huePick(float random) { | ||
52 | val pink = 300 | ||
53 | val tolerance = 10 | ||
54 | val degree = random*(360-2*tolerance) | ||
55 | if(degree<pink-tolerance) return degree | ||
56 | else return degree+2*tolerance | ||
57 | } | ||
58 | } \ No newline at end of file | ||
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/highlight/SolverSemanticTextAttributeProvider.xtend new file mode 100644 index 00000000..4eed59ce --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/highlight/SolverSemanticTextAttributeProvider.xtend | |||
@@ -0,0 +1,57 @@ | |||
1 | package org.eclipse.viatra.solver.language.ui.highlight | ||
2 | |||
3 | import com.google.inject.Inject | ||
4 | import java.util.WeakHashMap | ||
5 | import org.eclipse.jface.text.TextAttribute | ||
6 | import org.eclipse.swt.graphics.RGB | ||
7 | import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess | ||
8 | import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration | ||
9 | import org.eclipse.xtext.ui.editor.syntaxcoloring.PreferenceStoreAccessor | ||
10 | import org.eclipse.xtext.ui.editor.syntaxcoloring.TextAttributeProvider | ||
11 | import org.eclipse.xtext.ui.editor.utils.EditorUtils | ||
12 | import org.eclipse.xtext.ui.editor.utils.TextStyle | ||
13 | |||
14 | class SolverSemanticTextAttributeProvider extends TextAttributeProvider { | ||
15 | |||
16 | val defaultTextStyle = new TextStyle | ||
17 | val colorID2TextAttribute = new WeakHashMap<String,TextAttribute> | ||
18 | |||
19 | @Inject | ||
20 | new(IHighlightingConfiguration highlightingConfig, IPreferenceStoreAccess preferenceStoreAccess, PreferenceStoreAccessor prefStoreAccessor) { | ||
21 | super(highlightingConfig, preferenceStoreAccess, prefStoreAccessor) | ||
22 | } | ||
23 | |||
24 | |||
25 | override getAttribute(String id) { | ||
26 | if(isMetamodelElementColorID(id)) { | ||
27 | if(colorID2TextAttribute.containsKey(id)) { | ||
28 | return colorID2TextAttribute.get(id) | ||
29 | } else { | ||
30 | val style = metamodelElementTextStyle(id) | ||
31 | colorID2TextAttribute.put(id,style) | ||
32 | return style | ||
33 | } | ||
34 | } else { | ||
35 | super.getAttribute(id) | ||
36 | } | ||
37 | } | ||
38 | |||
39 | private def isMetamodelElementColorID(String id) { | ||
40 | id.startsWith(SolverSemanticHighlightCalculator::SmybolCode) | ||
41 | } | ||
42 | |||
43 | private def TextAttribute metamodelElementTextStyle(String id) { | ||
44 | val texts = id.split(' ') | ||
45 | val backgroundColor = new RGB( | ||
46 | Float.parseFloat(texts.get(1)), | ||
47 | Float.parseFloat(texts.get(2)), | ||
48 | Float.parseFloat(texts.get(3)) | ||
49 | ) | ||
50 | return new TextAttribute( | ||
51 | EditorUtils.colorFromRGB(defaultTextStyle.color), | ||
52 | EditorUtils.colorFromRGB(backgroundColor), | ||
53 | defaultTextStyle.style, | ||
54 | EditorUtils.fontFromFontData(defaultTextStyle.getFontData())); | ||
55 | } | ||
56 | |||
57 | } \ No newline at end of file | ||
diff --git a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/labeling/SolverLanguageDescriptionLabelProvider.xtend b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/labeling/SolverLanguageDescriptionLabelProvider.xtend new file mode 100644 index 00000000..32f81edc --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/labeling/SolverLanguageDescriptionLabelProvider.xtend | |||
@@ -0,0 +1,24 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.18.0.M3 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.ui.labeling | ||
5 | |||
6 | import org.eclipse.xtext.ui.label.DefaultDescriptionLabelProvider | ||
7 | |||
8 | /** | ||
9 | * Provides labels for IEObjectDescriptions and IResourceDescriptions. | ||
10 | * | ||
11 | * See https://www.eclipse.org/Xtext/documentation/304_ide_concepts.html#label-provider | ||
12 | */ | ||
13 | class SolverLanguageDescriptionLabelProvider extends DefaultDescriptionLabelProvider { | ||
14 | |||
15 | // Labels and icons can be computed like this: | ||
16 | |||
17 | // override text(IEObjectDescription ele) { | ||
18 | // ele.name.toString | ||
19 | // } | ||
20 | // | ||
21 | // override image(IEObjectDescription ele) { | ||
22 | // ele.EClass.name + '.gif' | ||
23 | // } | ||
24 | } | ||
diff --git a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/labeling/SolverLanguageLabelProvider.xtend b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/labeling/SolverLanguageLabelProvider.xtend new file mode 100644 index 00000000..c2d8ac75 --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/labeling/SolverLanguageLabelProvider.xtend | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.18.0.M3 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.ui.labeling | ||
5 | |||
6 | import com.google.inject.Inject | ||
7 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider | ||
8 | import org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider | ||
9 | |||
10 | /** | ||
11 | * Provides labels for EObjects. | ||
12 | * | ||
13 | * See https://www.eclipse.org/Xtext/documentation/304_ide_concepts.html#label-provider | ||
14 | */ | ||
15 | class SolverLanguageLabelProvider extends DefaultEObjectLabelProvider { | ||
16 | |||
17 | @Inject | ||
18 | new(AdapterFactoryLabelProvider delegate) { | ||
19 | super(delegate); | ||
20 | } | ||
21 | |||
22 | // Labels and icons can be computed like this: | ||
23 | |||
24 | // def text(Greeting ele) { | ||
25 | // 'A greeting to ' + ele.name | ||
26 | // } | ||
27 | // | ||
28 | // def image(Greeting ele) { | ||
29 | // 'Greeting.gif' | ||
30 | // } | ||
31 | } | ||
diff --git a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/outline/SolverLanguageOutlineTreeProvider.xtend b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/outline/SolverLanguageOutlineTreeProvider.xtend new file mode 100644 index 00000000..abd2855c --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/outline/SolverLanguageOutlineTreeProvider.xtend | |||
@@ -0,0 +1,15 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.18.0.M3 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.ui.outline | ||
5 | |||
6 | import org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider | ||
7 | |||
8 | /** | ||
9 | * Customization of the default outline structure. | ||
10 | * | ||
11 | * See https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#outline | ||
12 | */ | ||
13 | class SolverLanguageOutlineTreeProvider extends DefaultOutlineTreeProvider { | ||
14 | |||
15 | } | ||
diff --git a/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/quickfix/SolverLanguageQuickfixProvider.xtend b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/quickfix/SolverLanguageQuickfixProvider.xtend new file mode 100644 index 00000000..42f81255 --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language.ui/src/org/eclipse/viatra/solver/language/ui/quickfix/SolverLanguageQuickfixProvider.xtend | |||
@@ -0,0 +1,24 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.18.0.M3 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.ui.quickfix | ||
5 | |||
6 | import org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider | ||
7 | |||
8 | /** | ||
9 | * Custom quickfixes. | ||
10 | * | ||
11 | * See https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#quick-fixes | ||
12 | */ | ||
13 | class SolverLanguageQuickfixProvider extends DefaultQuickfixProvider { | ||
14 | |||
15 | // @Fix(SolverLanguageValidator.INVALID_NAME) | ||
16 | // def capitalizeName(Issue issue, IssueResolutionAcceptor acceptor) { | ||
17 | // acceptor.accept(issue, 'Capitalize name', 'Capitalize the name.', 'upcase.png') [ | ||
18 | // context | | ||
19 | // val xtextDocument = context.xtextDocument | ||
20 | // val firstLetter = xtextDocument.get(issue.offset, 1) | ||
21 | // xtextDocument.replace(issue.offset, 1, firstLetter.toUpperCase) | ||
22 | // ] | ||
23 | // } | ||
24 | } | ||