1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "stylescijava.h"
6#include "textedittabwidget/style/stylejsonfile.h"
7#include "textedittabwidget/style/stylecolor.h"
8#include "textedittabwidget/textedit.h"
9#include "SciLexer.h"
10
11StyleSciJava::StyleSciJava(TextEdit *parent)
12 : StyleSci (parent)
13{
14
15}
16
17QMap<int, QString> StyleSciJava::keyWords() const
18{
19 return StyleSci::keyWords();
20}
21
22void StyleSciJava::setStyle()
23{
24 StyleSci::setStyle();
25
26 auto jsonFile = edit()->getStyleFile();
27 if (jsonFile->setTheme(StyleJsonFile::Theme::get()->Dark)) {
28 QJsonObject tempObj;
29 int tempFore;
30 tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Comment).toObject();
31 tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16));
32 edit()->styleSetFore(SCE_JAVA_COMMENT, tempFore); // #整行
33 edit()->styleSetFore(SCE_JAVA_COMMENTLINE, tempFore); // //注释
34 edit()->styleSetFore(SCE_JAVA_COMMENTDOC, tempFore);
35 edit()->styleSetFore(SCE_JAVA_COMMENTLINEDOC, tempFore); // ///注释
36 edit()->styleSetFore(SCE_JAVA_COMMENTDOCKEYWORD, tempFore - 0x3333);
37 edit()->styleSetFore(SCE_JAVA_COMMENTDOCKEYWORDERROR, tempFore - 0x3333); // /// @
38 edit()->styleSetFore(SCE_JAVA_PREPROCESSORCOMMENT, tempFore);
39 edit()->styleSetFore(SCE_JAVA_PREPROCESSORCOMMENTDOC, tempFore);
40
41 tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Number).toObject();
42 tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16));
43 edit()->styleSetFore(SCE_JAVA_NUMBER, tempFore);
44
45 tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Keyword).toObject();
46 tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16));
47 edit()->styleSetFore(SCE_JAVA_WORD, tempFore);
48 edit()->styleSetFore(SCE_JAVA_WORD2, tempFore);
49
50 tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->String).toObject();
51 tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16));
52 edit()->styleSetFore(SCE_JAVA_STRING, tempFore); // 字符串
53 edit()->styleSetFore(SCE_JAVA_CHARACTER, tempFore); // 字符串
54 edit()->styleSetFore(SCE_JAVA_UUID, tempFore);
55 edit()->styleSetFore(SCE_JAVA_STRINGEOL, tempFore);
56 edit()->styleSetFore(SCE_JAVA_REGEX, tempFore);
57 edit()->styleSetFore(SCE_JAVA_STRINGRAW, tempFore);
58 edit()->styleSetFore(SCE_JAVA_VERBATIM, tempFore);
59 edit()->styleSetFore(SCE_JAVA_HASHQUOTEDSTRING, tempFore);
60
61 tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Preprocessor).toObject();
62 tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16));
63 edit()->styleSetFore(SCE_JAVA_PREPROCESSOR, tempFore); // #
64
65 tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Operators).toObject();
66 tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16));
67 edit()->styleSetFore(SCE_JAVA_OPERATOR, tempFore); // 符号
68
69 tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Text).toObject();
70 tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16));
71 edit()->styleSetFore(SCE_JAVA_IDENTIFIER, tempFore);
72 edit()->styleSetFore(SCE_JAVA_USERLITERAL, tempFore);
73 edit()->styleSetFore(SCE_JAVA_TASKMARKER, tempFore);
74 edit()->styleSetFore(SCE_JAVA_ESCAPESEQUENCE, tempFore);
75
76 tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Global).toObject();
77 tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16));
78 edit()->styleSetFore(SCE_JAVA_GLOBALCLASS, tempFore);
79 } else {
80 edit()->styleSetFore(SCE_JAVA_COMMENT, StyleColor::color(StyleColor::Table::get()->DeepSkyBlue)); // #整行
81 edit()->styleSetFore(SCE_JAVA_COMMENTLINE, StyleColor::color(StyleColor::Table::get()->DarkTurquoise)); // //注释
82 edit()->styleSetFore(SCE_JAVA_COMMENTDOC, StyleColor::color(StyleColor::Table::get()->DarkTurquoise));
83 edit()->styleSetFore(SCE_JAVA_NUMBER, StyleColor::color(StyleColor::Table::get()->Magenta));
84 edit()->styleSetFore(SCE_JAVA_WORD, StyleColor::color(StyleColor::Table::get()->Gold));
85 edit()->styleSetFore(SCE_JAVA_STRING, StyleColor::color(StyleColor::Table::get()->Magenta)); // 字符串
86 edit()->styleSetFore(SCE_JAVA_CHARACTER, StyleColor::color(StyleColor::Table::get()->Magenta));
87 edit()->styleSetFore(SCE_JAVA_UUID, StyleColor::color(StyleColor::Table::get()->Magenta));
88 edit()->styleSetFore(SCE_JAVA_PREPROCESSOR, StyleColor::color(StyleColor::Table::get()->MediumBlue)); // #
89 edit()->styleSetFore(SCE_JAVA_OPERATOR, edit()->styleFore(SCE_JAVA_DEFAULT)); // 符号
90 edit()->styleSetFore(SCE_JAVA_IDENTIFIER, edit()->styleFore(SCE_JAVA_DEFAULT));
91 edit()->styleSetFore(SCE_JAVA_STRINGEOL, StyleColor::color(StyleColor::Table::get()->Magenta));
92 edit()->styleSetFore(SCE_JAVA_VERBATIM, StyleColor::color(StyleColor::Table::get()->Magenta));
93 edit()->styleSetFore(SCE_JAVA_REGEX, StyleColor::color(StyleColor::Table::get()->Magenta));
94 edit()->styleSetFore(SCE_JAVA_COMMENTLINEDOC, StyleColor::color(StyleColor::Table::get()->DarkTurquoise)); // ///注释
95 edit()->styleSetFore(SCE_JAVA_WORD2, StyleColor::color(StyleColor::Table::get()->Gold)); // 1 一般关键字
96 edit()->styleSetFore(SCE_JAVA_COMMENTDOCKEYWORD, StyleColor::color(StyleColor::Table::get()->DeepSkyBlue));
97 edit()->styleSetFore(SCE_JAVA_COMMENTDOCKEYWORDERROR, StyleColor::color(StyleColor::Table::get()->DeepSkyBlue)); // /// @
98 edit()->styleSetFore(SCE_JAVA_GLOBALCLASS, StyleColor::color(StyleColor::Table::get()->Gold));
99 edit()->styleSetFore(SCE_JAVA_STRINGRAW, StyleColor::color(StyleColor::Table::get()->Gainsboro));
100 edit()->styleSetFore(SCE_JAVA_HASHQUOTEDSTRING, StyleColor::color(StyleColor::Table::get()->Gainsboro));
101 edit()->styleSetFore(SCE_JAVA_PREPROCESSORCOMMENT, StyleColor::color(StyleColor::Table::get()->Gainsboro));
102 edit()->styleSetFore(SCE_JAVA_PREPROCESSORCOMMENTDOC, StyleColor::color(StyleColor::Table::get()->Gainsboro));
103 edit()->styleSetFore(SCE_JAVA_USERLITERAL, StyleColor::color(StyleColor::Table::get()->Gainsboro));
104 edit()->styleSetFore(SCE_JAVA_TASKMARKER, StyleColor::color(StyleColor::Table::get()->Gainsboro));
105 edit()->styleSetFore(SCE_JAVA_ESCAPESEQUENCE, StyleColor::color(StyleColor::Table::get()->Gainsboro));
106 }
107 return;
108}
109
110void StyleSciJava::setLexer()
111{
112 StyleSci::setLexer();
113}
114
115int StyleSciJava::sectionEnd() const
116{
117 return SCE_JAVA_ESCAPESEQUENCE;
118}
119