|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2003 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a Java lexer with some additional methods. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.Qsci import QsciLexerJava, QsciScintilla |
|
13 |
|
14 from .Lexer import Lexer |
|
15 import Preferences |
|
16 |
|
17 |
|
18 class LexerJava(Lexer, QsciLexerJava): |
|
19 """ |
|
20 Subclass to implement some additional lexer dependant methods. |
|
21 """ |
|
22 def __init__(self, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param parent parent widget of this lexer |
|
27 """ |
|
28 QsciLexerJava.__init__(self, parent) |
|
29 Lexer.__init__(self) |
|
30 |
|
31 self.commentString = "//" |
|
32 self.streamCommentString = { |
|
33 'start': '/* ', |
|
34 'end': ' */' |
|
35 } |
|
36 self.boxCommentString = { |
|
37 'start': '/* ', |
|
38 'middle': ' * ', |
|
39 'end': ' */' |
|
40 } |
|
41 |
|
42 self.keywordSetDescriptions = [ |
|
43 self.tr("Primary keywords and identifiers"), |
|
44 self.tr("Secondary keywords and identifiers"), |
|
45 self.tr("Documentation comment keywords"), |
|
46 self.tr("Global classes and typedefs"), |
|
47 self.tr("Preprocessor definitions"), |
|
48 self.tr("Task marker and error marker keywords"), |
|
49 ] |
|
50 |
|
51 def initProperties(self): |
|
52 """ |
|
53 Public slot to initialize the properties. |
|
54 """ |
|
55 self.setFoldComments(Preferences.getEditor("CppFoldComment")) |
|
56 self.setFoldPreprocessor(Preferences.getEditor("CppFoldPreprocessor")) |
|
57 self.setFoldAtElse(Preferences.getEditor("CppFoldAtElse")) |
|
58 indentStyle = 0 |
|
59 if Preferences.getEditor("CppIndentOpeningBrace"): |
|
60 indentStyle |= QsciScintilla.AiOpening |
|
61 if Preferences.getEditor("CppIndentClosingBrace"): |
|
62 indentStyle |= QsciScintilla.AiClosing |
|
63 self.setAutoIndentStyle(indentStyle) |
|
64 self.setFoldCompact(Preferences.getEditor("AllFoldCompact")) |
|
65 |
|
66 def isCommentStyle(self, style): |
|
67 """ |
|
68 Public method to check, if a style is a comment style. |
|
69 |
|
70 @param style style to check (integer) |
|
71 @return flag indicating a comment style (boolean) |
|
72 """ |
|
73 return style in [QsciLexerJava.Comment, |
|
74 QsciLexerJava.CommentDoc, |
|
75 QsciLexerJava.CommentLine, |
|
76 QsciLexerJava.CommentLineDoc] |
|
77 |
|
78 def isStringStyle(self, style): |
|
79 """ |
|
80 Public method to check, if a style is a string style. |
|
81 |
|
82 @param style style to check (integer) |
|
83 @return flag indicating a string style (boolean) |
|
84 """ |
|
85 return style in [QsciLexerJava.DoubleQuotedString, |
|
86 QsciLexerJava.SingleQuotedString, |
|
87 QsciLexerJava.UnclosedString, |
|
88 QsciLexerJava.VerbatimString] |
|
89 |
|
90 def defaultKeywords(self, kwSet): |
|
91 """ |
|
92 Public method to get the default keywords. |
|
93 |
|
94 @param kwSet number of the keyword set (integer) |
|
95 @return string giving the keywords (string) or None |
|
96 """ |
|
97 return QsciLexerJava.keywords(self, kwSet) |
|
98 |
|
99 def maximumKeywordSet(self): |
|
100 """ |
|
101 Public method to get the maximum keyword set. |
|
102 |
|
103 @return maximum keyword set (integer) |
|
104 """ |
|
105 return 4 |