10485
|
1 |
"{ Package: 'stx:libtool' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Tools }"
|
|
4 |
|
|
5 |
Object subclass:#LintHighlighter
|
|
6 |
instanceVariableNames:'rules formattingMethod emphasisError emphasisInformation
|
|
7 |
emphasisWarning'
|
|
8 |
classVariableNames:''
|
|
9 |
poolDictionaries:''
|
|
10 |
category:'Interface-Lint'
|
|
11 |
!
|
|
12 |
|
|
13 |
|
|
14 |
!LintHighlighter methodsFor:'accessing'!
|
|
15 |
|
|
16 |
rules
|
|
17 |
^ rules
|
|
18 |
!
|
|
19 |
|
11380
|
20 |
rules:aCollectionOfRules
|
|
21 |
rules := aCollectionOfRules.
|
|
22 |
|
|
23 |
"Modified (format): / 07-03-2012 / 17:24:02 / cg"
|
10485
|
24 |
! !
|
|
25 |
|
|
26 |
!LintHighlighter methodsFor:'accessing-emphasis'!
|
|
27 |
|
|
28 |
emphasisForError
|
11394
|
29 |
|warnColor|
|
10485
|
30 |
|
|
31 |
emphasisError isNil ifTrue:[
|
11394
|
32 |
warnColor := Color red.
|
10485
|
33 |
emphasisError := Array
|
11394
|
34 |
with: #backgroundColor -> warnColor lightened lightened
|
10485
|
35 |
with: #underwave
|
11394
|
36 |
with: #underlineColor -> warnColor
|
10485
|
37 |
].
|
|
38 |
^emphasisError
|
|
39 |
|
|
40 |
"Created: / 05-08-2011 / 09:31:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
11394
|
41 |
"Modified: / 08-03-2012 / 03:00:51 / cg"
|
10485
|
42 |
!
|
|
43 |
|
|
44 |
emphasisForInformation
|
11394
|
45 |
|warnColor|
|
10485
|
46 |
|
|
47 |
emphasisInformation isNil ifTrue:[
|
11394
|
48 |
warnColor := Color blue lighter.
|
10485
|
49 |
emphasisInformation := Array
|
11394
|
50 |
with: #backgroundColor -> warnColor lightened lightened
|
10485
|
51 |
with: #underwave
|
11394
|
52 |
with: #underlineColor -> warnColor
|
10485
|
53 |
].
|
|
54 |
^emphasisInformation
|
|
55 |
|
|
56 |
"Created: / 05-08-2011 / 09:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
11394
|
57 |
"Modified: / 08-03-2012 / 03:01:22 / cg"
|
10485
|
58 |
!
|
|
59 |
|
|
60 |
emphasisForSeverity: severity
|
|
61 |
|
|
62 |
severity == #error ifTrue:[^self emphasisForError].
|
|
63 |
severity == #information ifTrue:[^self emphasisForInformation].
|
|
64 |
|
|
65 |
^self emphasisForWarning
|
|
66 |
|
|
67 |
"Created: / 05-08-2011 / 09:31:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
68 |
!
|
|
69 |
|
|
70 |
emphasisForWarning
|
11394
|
71 |
|warnColor|
|
10485
|
72 |
|
|
73 |
emphasisWarning isNil ifTrue:[
|
11394
|
74 |
warnColor := (Color redByte: 224 greenByte: 200 blueByte: 45).
|
10485
|
75 |
emphasisWarning := Array
|
11394
|
76 |
with: #backgroundColor -> warnColor lightened lightened
|
10485
|
77 |
with: #underwave
|
11394
|
78 |
with: #underlineColor -> warnColor
|
10485
|
79 |
].
|
|
80 |
^emphasisWarning
|
|
81 |
|
|
82 |
"Created: / 05-08-2011 / 09:31:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
11394
|
83 |
"Modified: / 08-03-2012 / 03:00:19 / cg"
|
10485
|
84 |
! !
|
|
85 |
|
|
86 |
!LintHighlighter methodsFor:'formatting'!
|
|
87 |
|
|
88 |
formatClassDefinition:source in:class
|
|
89 |
|
|
90 |
formattingMethod := false.
|
|
91 |
^ self format: source
|
|
92 |
|
|
93 |
"Created: / 04-08-2011 / 23:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
94 |
!
|
|
95 |
|
|
96 |
formatClassDefinition:source in:class elementsInto: elements
|
|
97 |
|
|
98 |
formattingMethod := false.
|
|
99 |
^ self format: source
|
|
100 |
|
|
101 |
"Created: / 04-08-2011 / 23:44:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
102 |
!
|
|
103 |
|
|
104 |
formatExpression:source in:class
|
|
105 |
|
|
106 |
formattingMethod := false.
|
|
107 |
^ self format: source
|
|
108 |
|
|
109 |
"Created: / 04-08-2011 / 23:45:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
110 |
!
|
|
111 |
|
|
112 |
formatExpression:source in:class elementsInto: elements
|
|
113 |
|
|
114 |
formattingMethod := false.
|
|
115 |
^ self format: source
|
|
116 |
|
|
117 |
"Created: / 04-08-2011 / 23:43:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
118 |
!
|
|
119 |
|
|
120 |
formatMethod:mth source:source in:class using: preferences
|
|
121 |
|
|
122 |
formattingMethod := true.
|
|
123 |
^ self format: source
|
|
124 |
|
|
125 |
"Created: / 04-08-2011 / 23:45:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
126 |
!
|
|
127 |
|
|
128 |
formatMethod:mth source:source in:class using: preferences elementsInto: elements
|
|
129 |
|
|
130 |
formattingMethod := true.
|
|
131 |
^ self format: source
|
|
132 |
|
|
133 |
"Created: / 04-08-2011 / 23:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
134 |
! !
|
|
135 |
|
|
136 |
!LintHighlighter methodsFor:'formatting-private'!
|
|
137 |
|
|
138 |
format: text
|
|
139 |
|
|
140 |
rules ? #() do:[:rule|
|
|
141 |
self format: text rule: rule
|
|
142 |
].
|
|
143 |
^text
|
|
144 |
|
|
145 |
"Created: / 04-08-2011 / 23:51:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
146 |
!
|
|
147 |
|
|
148 |
format: text rule: rule
|
|
149 |
|
|
150 |
| string emphasis |
|
|
151 |
|
11380
|
152 |
string := text asString string.
|
10485
|
153 |
emphasis := self emphasisForSeverity: rule severity.
|
|
154 |
|
|
155 |
rule result isParseTreeEnvironment ifTrue:[
|
|
156 |
formattingMethod ifTrue:[
|
|
157 |
| interval |
|
11226
|
158 |
[
|
|
159 |
interval := rule result selectionIntervalFor: string.
|
11380
|
160 |
] on: Error do:[:ex |
|
|
161 |
Transcript showCR:'error in LintHighlighter: ', ex description.
|
|
162 |
self breakPoint:#jv.
|
11226
|
163 |
interval := nil.
|
|
164 |
].
|
10503
|
165 |
interval notNil ifTrue:[
|
11380
|
166 |
text asText
|
|
167 |
emphasisFrom: interval first to: interval last
|
|
168 |
add: emphasis.
|
10503
|
169 |
]
|
10485
|
170 |
].
|
|
171 |
] ifFalse:[
|
|
172 |
| searches |
|
|
173 |
|
|
174 |
searches := rule result searchStrings asSet.
|
|
175 |
|
|
176 |
searches do:[:search|
|
|
177 |
| i |
|
|
178 |
i := 1.
|
|
179 |
[
|
|
180 |
i := string findString: search startingAt: i.
|
|
181 |
i ~~ 0
|
|
182 |
] whileTrue:[
|
11380
|
183 |
text asText
|
|
184 |
emphasisFrom: i to: (i + search size - 1)
|
|
185 |
add: emphasis.
|
10485
|
186 |
i := i + search size + 1.
|
|
187 |
]
|
|
188 |
|
|
189 |
|
|
190 |
]
|
|
191 |
]
|
|
192 |
|
|
193 |
"Created: / 04-08-2011 / 23:55:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
11380
|
194 |
"Modified: / 07-03-2012 / 18:18:25 / cg"
|
10485
|
195 |
! !
|
|
196 |
|
|
197 |
!LintHighlighter class methodsFor:'documentation'!
|
|
198 |
|
|
199 |
version
|
11394
|
200 |
^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.5 2012-03-08 03:16:18 cg Exp $'
|
10485
|
201 |
!
|
|
202 |
|
|
203 |
version_CVS
|
11394
|
204 |
^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.5 2012-03-08 03:16:18 cg Exp $'
|
10485
|
205 |
! !
|