Skip to content

Commit 0dfba49

Browse files
committed
Refactored Highlighting and split up the global annotator into single chunks.
1 parent df66a18 commit 0dfba49

13 files changed

Lines changed: 427 additions & 410 deletions

src/de/halirutan/mathematica/codeinsight/highlighting/MathematicaColorSettingsPage.java

Lines changed: 0 additions & 134 deletions
This file was deleted.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 2017 Patrick Scheibe
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to deal
5+
* in the Software without restriction, including without limitation the rights
6+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
* copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
* THE SOFTWARE.
20+
*/
21+
22+
package de.halirutan.mathematica.codeinsight.highlighting
23+
24+
import com.intellij.openapi.editor.colors.TextAttributesKey
25+
import com.intellij.openapi.fileTypes.SyntaxHighlighter
26+
import com.intellij.openapi.options.colors.AttributesDescriptor
27+
import com.intellij.openapi.options.colors.ColorDescriptor
28+
import com.intellij.openapi.options.colors.ColorSettingsPage
29+
import com.intellij.openapi.util.io.StreamUtil
30+
import de.halirutan.mathematica.util.MathematicaIcons
31+
import gnu.trove.THashMap
32+
import java.io.IOException
33+
import javax.swing.Icon
34+
35+
/**
36+
* @author patrick (4/7/13)
37+
*/
38+
class MathematicaColorSettingsPage : ColorSettingsPage {
39+
40+
override fun getIcon(): Icon? {
41+
return MathematicaIcons.FILE_ICON
42+
}
43+
44+
override fun getHighlighter(): SyntaxHighlighter {
45+
return MathematicaSyntaxHighlighter()
46+
}
47+
48+
override fun getDemoText(): String {
49+
val resource = javaClass.classLoader.getResourceAsStream("/colors/demoText.txt")
50+
val demoText: String
51+
try {
52+
demoText = StreamUtil.readText(resource, "UTF-8")
53+
} catch (e: IOException) {
54+
throw RuntimeException("Mathematica Plugin could not load the syntax highlighter demo text.", e)
55+
}
56+
57+
return demoText
58+
}
59+
60+
override fun getAdditionalHighlightingTagToDescriptorMap(): Map<String, TextAttributesKey>? {
61+
val map = THashMap<String, TextAttributesKey>()
62+
map.put("i", MathematicaSyntaxHighlighterColors.IDENTIFIER)
63+
map.put("k", MathematicaSyntaxHighlighterColors.BUILTIN_FUNCTION)
64+
map.put("pat", MathematicaSyntaxHighlighterColors.PATTERN)
65+
map.put("usg", MathematicaSyntaxHighlighterColors.USAGE_MESSAGE)
66+
map.put("msg", MathematicaSyntaxHighlighterColors.MESSAGE)
67+
map.put("mod", MathematicaSyntaxHighlighterColors.MODULE_LOCALIZED)
68+
map.put("blk", MathematicaSyntaxHighlighterColors.BLOCK_LOCALIZED)
69+
map.put("fn", MathematicaSyntaxHighlighterColors.ANONYMOUS_FUNCTION)
70+
map.put("slot", MathematicaSyntaxHighlighterColors.SLOT)
71+
map.put("s", MathematicaSyntaxHighlighterColors.STRING)
72+
map.put("c", MathematicaSyntaxHighlighterColors.COMMENT)
73+
map.put("cs", MathematicaSyntaxHighlighterColors.COMMENT_SPECIAL)
74+
map.put("o", MathematicaSyntaxHighlighterColors.OPERATORS)
75+
map.put("b", MathematicaSyntaxHighlighterColors.BRACE)
76+
map.put("l", MathematicaSyntaxHighlighterColors.LITERAL)
77+
return map
78+
}
79+
80+
override fun getAttributeDescriptors(): Array<AttributesDescriptor> {
81+
return arrayOf(
82+
AttributesDescriptor("Identifier", MathematicaSyntaxHighlighterColors.IDENTIFIER),
83+
AttributesDescriptor("Built-In Function", MathematicaSyntaxHighlighterColors.BUILTIN_FUNCTION),
84+
AttributesDescriptor("Number", MathematicaSyntaxHighlighterColors.LITERAL),
85+
AttributesDescriptor("Operator Sign", MathematicaSyntaxHighlighterColors.OPERATORS),
86+
AttributesDescriptor("Parenthesis", MathematicaSyntaxHighlighterColors.BRACE),
87+
AttributesDescriptor("String", MathematicaSyntaxHighlighterColors.STRING),
88+
AttributesDescriptor("Comment", MathematicaSyntaxHighlighterColors.COMMENT),
89+
AttributesDescriptor("Comment Special", MathematicaSyntaxHighlighterColors.COMMENT_SPECIAL),
90+
AttributesDescriptor("Module Variables", MathematicaSyntaxHighlighterColors.MODULE_LOCALIZED),
91+
AttributesDescriptor("Block Variables", MathematicaSyntaxHighlighterColors.BLOCK_LOCALIZED),
92+
AttributesDescriptor("Patterns and Arguments", MathematicaSyntaxHighlighterColors.PATTERN),
93+
AttributesDescriptor("Anonymous functions", MathematicaSyntaxHighlighterColors.ANONYMOUS_FUNCTION),
94+
AttributesDescriptor("Slots", MathematicaSyntaxHighlighterColors.SLOT),
95+
AttributesDescriptor("Usage message", MathematicaSyntaxHighlighterColors.USAGE_MESSAGE),
96+
AttributesDescriptor("Other message", MathematicaSyntaxHighlighterColors.MESSAGE)
97+
)
98+
}
99+
100+
override fun getColorDescriptors(): Array<ColorDescriptor> {
101+
return ColorDescriptor.EMPTY_ARRAY
102+
}
103+
104+
override fun getDisplayName(): String {
105+
return "Mathematica"
106+
}
107+
108+
}

src/de/halirutan/mathematica/codeinsight/highlighting/MathematicaHighlightingAnnotator.kt

Lines changed: 0 additions & 134 deletions
This file was deleted.

0 commit comments

Comments
 (0)