author | Claus Gittinger <cg@exept.de> |
Sun, 11 May 2014 12:20:48 +0200 | |
changeset 14350 | bb47c314b586 |
parent 14096 | 3d2f347c2cbc |
child 14965 | 02bfa1f4aa9a |
permissions | -rw-r--r-- |
13829 | 1 |
" |
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
10485 | 12 |
"{ Package: 'stx:libtool' }" |
13 |
||
14 |
"{ NameSpace: Tools }" |
|
15 |
||
16 |
Object subclass:#LintHighlighter |
|
13829 | 17 |
instanceVariableNames:'rules annotations formattingMethod emphasisError |
18 |
emphasisInformation emphasisWarning' |
|
10485 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
21 |
category:'Interface-Lint' |
|
22 |
! |
|
23 |
||
13829 | 24 |
!LintHighlighter class methodsFor:'documentation'! |
25 |
||
26 |
copyright |
|
27 |
" |
|
28 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
! ! |
|
10485 | 39 |
|
40 |
!LintHighlighter methodsFor:'accessing'! |
|
41 |
||
13829 | 42 |
annotations |
43 |
^ annotations |
|
44 |
! |
|
45 |
||
10485 | 46 |
rules |
47 |
^ rules |
|
48 |
! |
|
49 |
||
11380 | 50 |
rules:aCollectionOfRules |
51 |
rules := aCollectionOfRules. |
|
52 |
||
53 |
"Modified (format): / 07-03-2012 / 17:24:02 / cg" |
|
10485 | 54 |
! ! |
55 |
||
56 |
!LintHighlighter methodsFor:'accessing-emphasis'! |
|
57 |
||
58 |
emphasisForError |
|
11394 | 59 |
|warnColor| |
10485 | 60 |
|
61 |
emphasisError isNil ifTrue:[ |
|
11394 | 62 |
warnColor := Color red. |
10485 | 63 |
emphasisError := Array |
13829 | 64 |
"/with: #backgroundColor -> warnColor lightened lightened |
10485 | 65 |
with: #underwave |
11394 | 66 |
with: #underlineColor -> warnColor |
10485 | 67 |
]. |
68 |
^emphasisError |
|
69 |
||
70 |
"Created: / 05-08-2011 / 09:31:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
11394 | 71 |
"Modified: / 08-03-2012 / 03:00:51 / cg" |
13829 | 72 |
"Modified: / 20-04-2012 / 18:29:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10485 | 73 |
! |
74 |
||
75 |
emphasisForInformation |
|
11394 | 76 |
|warnColor| |
10485 | 77 |
|
78 |
emphasisInformation isNil ifTrue:[ |
|
11394 | 79 |
warnColor := Color blue lighter. |
10485 | 80 |
emphasisInformation := Array |
13829 | 81 |
"/with: #backgroundColor -> warnColor lightened lightened |
10485 | 82 |
with: #underwave |
11394 | 83 |
with: #underlineColor -> warnColor |
10485 | 84 |
]. |
85 |
^emphasisInformation |
|
86 |
||
87 |
"Created: / 05-08-2011 / 09:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
11394 | 88 |
"Modified: / 08-03-2012 / 03:01:22 / cg" |
13829 | 89 |
"Modified: / 20-04-2012 / 18:29:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10485 | 90 |
! |
91 |
||
92 |
emphasisForSeverity: severity |
|
93 |
||
94 |
severity == #error ifTrue:[^self emphasisForError]. |
|
95 |
severity == #information ifTrue:[^self emphasisForInformation]. |
|
96 |
||
97 |
^self emphasisForWarning |
|
98 |
||
99 |
"Created: / 05-08-2011 / 09:31:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
100 |
! |
|
101 |
||
102 |
emphasisForWarning |
|
11394 | 103 |
|warnColor| |
10485 | 104 |
|
105 |
emphasisWarning isNil ifTrue:[ |
|
11394 | 106 |
warnColor := (Color redByte: 224 greenByte: 200 blueByte: 45). |
10485 | 107 |
emphasisWarning := Array |
13829 | 108 |
"/with: #backgroundColor -> warnColor lightened lightened |
10485 | 109 |
with: #underwave |
11394 | 110 |
with: #underlineColor -> warnColor |
10485 | 111 |
]. |
112 |
^emphasisWarning |
|
113 |
||
114 |
"Created: / 05-08-2011 / 09:31:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
11394 | 115 |
"Modified: / 08-03-2012 / 03:00:19 / cg" |
13829 | 116 |
"Modified: / 20-04-2012 / 18:29:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10485 | 117 |
! ! |
118 |
||
119 |
!LintHighlighter methodsFor:'formatting'! |
|
120 |
||
121 |
formatClassDefinition:source in:class |
|
122 |
||
123 |
formattingMethod := false. |
|
124 |
^ self format: source |
|
125 |
||
126 |
"Created: / 04-08-2011 / 23:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
127 |
! |
|
128 |
||
129 |
formatClassDefinition:source in:class elementsInto: elements |
|
130 |
||
131 |
formattingMethod := false. |
|
14096
3d2f347c2cbc
class: Tools::LintHighlighter
Claus Gittinger <cg@exept.de>
parents:
14068
diff
changeset
|
132 |
^ self format: source asText |
10485 | 133 |
|
134 |
"Created: / 04-08-2011 / 23:44:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
135 |
! |
|
136 |
||
137 |
formatExpression:source in:class |
|
138 |
||
139 |
formattingMethod := false. |
|
140 |
^ self format: source |
|
141 |
||
142 |
"Created: / 04-08-2011 / 23:45:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
143 |
! |
|
144 |
||
145 |
formatExpression:source in:class elementsInto: elements |
|
146 |
||
147 |
formattingMethod := false. |
|
148 |
^ self format: source |
|
149 |
||
150 |
"Created: / 04-08-2011 / 23:43:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
151 |
! |
|
152 |
||
153 |
formatMethod:mth source:source in:class using: preferences |
|
154 |
||
155 |
formattingMethod := true. |
|
156 |
^ self format: source |
|
157 |
||
158 |
"Created: / 04-08-2011 / 23:45:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
159 |
! |
|
160 |
||
161 |
formatMethod:mth source:source in:class using: preferences elementsInto: elements |
|
162 |
||
163 |
formattingMethod := true. |
|
164 |
^ self format: source |
|
165 |
||
166 |
"Created: / 04-08-2011 / 23:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
167 |
! ! |
|
168 |
||
169 |
!LintHighlighter methodsFor:'formatting-private'! |
|
170 |
||
171 |
format: text |
|
172 |
||
14096
3d2f347c2cbc
class: Tools::LintHighlighter
Claus Gittinger <cg@exept.de>
parents:
14068
diff
changeset
|
173 |
| tree t| |
13829 | 174 |
tree := RBParser parseMethod: text string onError:[:error :pos| ^ text ]. |
14096
3d2f347c2cbc
class: Tools::LintHighlighter
Claus Gittinger <cg@exept.de>
parents:
14068
diff
changeset
|
175 |
t := text asText. |
3d2f347c2cbc
class: Tools::LintHighlighter
Claus Gittinger <cg@exept.de>
parents:
14068
diff
changeset
|
176 |
self format: t tree: tree. |
3d2f347c2cbc
class: Tools::LintHighlighter
Claus Gittinger <cg@exept.de>
parents:
14068
diff
changeset
|
177 |
^t |
10485 | 178 |
|
179 |
"Created: / 04-08-2011 / 23:51:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
180 |
! |
|
181 |
||
182 |
format: text rule: rule |
|
183 |
||
184 |
| string emphasis | |
|
185 |
||
11380 | 186 |
string := text asString string. |
10485 | 187 |
emphasis := self emphasisForSeverity: rule severity. |
188 |
||
189 |
rule result isParseTreeEnvironment ifTrue:[ |
|
190 |
formattingMethod ifTrue:[ |
|
191 |
| interval | |
|
11226 | 192 |
[ |
193 |
interval := rule result selectionIntervalFor: string. |
|
11380 | 194 |
] on: Error do:[:ex | |
195 |
Transcript showCR:'error in LintHighlighter: ', ex description. |
|
196 |
self breakPoint:#jv. |
|
11226 | 197 |
interval := nil. |
198 |
]. |
|
10503 | 199 |
interval notNil ifTrue:[ |
11380 | 200 |
text asText |
201 |
emphasisFrom: interval first to: interval last |
|
202 |
add: emphasis. |
|
10503 | 203 |
] |
10485 | 204 |
]. |
205 |
] ifFalse:[ |
|
206 |
| searches | |
|
207 |
||
208 |
searches := rule result searchStrings asSet. |
|
209 |
||
210 |
searches do:[:search| |
|
211 |
| i | |
|
212 |
i := 1. |
|
213 |
[ |
|
214 |
i := string findString: search startingAt: i. |
|
215 |
i ~~ 0 |
|
216 |
] whileTrue:[ |
|
11380 | 217 |
text asText |
218 |
emphasisFrom: i to: (i + search size - 1) |
|
219 |
add: emphasis. |
|
10485 | 220 |
i := i + search size + 1. |
221 |
] |
|
222 |
||
223 |
||
224 |
] |
|
225 |
] |
|
226 |
||
227 |
"Created: / 04-08-2011 / 23:55:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
11380 | 228 |
"Modified: / 07-03-2012 / 18:18:25 / cg" |
13829 | 229 |
! |
230 |
||
231 |
format: text tree: tree |
|
232 |
||
233 |
annotations := SortedCollection new. |
|
234 |
rules ? #() do:[:rule| |
|
235 |
self format: text tree: tree rule: rule |
|
236 |
]. |
|
237 |
^text |
|
238 |
||
239 |
"Created: / 02-02-2012 / 23:32:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
240 |
! |
|
241 |
||
242 |
format: text tree: tree rule: rule |
|
243 |
||
244 |
| string | |
|
245 |
||
246 |
string := text string. |
|
247 |
rule result isParseTreeEnvironment ifTrue:[ |
|
248 |
formattingMethod ifTrue:[ |
|
14068
9b5814b4dd3c
class: Tools::LintHighlighter
Claus Gittinger <cg@exept.de>
parents:
13829
diff
changeset
|
249 |
rule resultSelectionIntervalsForSource: string tree: tree do: [:interval| |
13829 | 250 |
interval notEmptyOrNil ifTrue:[ |
251 |
(interval first == 1 and:[interval last == text size]) ifTrue:[ |
|
252 |
(OperatingSystem getLoginName = 'jv') ifTrue:[ |
|
253 |
Transcript showCR:'>> no meaningful selection interval for ' , rule printString. |
|
254 |
]. |
|
255 |
] ifFalse:[ |
|
256 |
self mark: text from: interval first to: interval last for: rule. |
|
257 |
] |
|
258 |
] |
|
259 |
]. |
|
260 |
]. |
|
261 |
] ifFalse: [ |
|
262 |
| searches | |
|
263 |
||
264 |
searches := rule result searchStrings asSet. |
|
265 |
||
266 |
searches do:[:search| |
|
267 |
| i | |
|
268 |
i := 1. |
|
269 |
[ |
|
270 |
i := string findString: search startingAt: i. |
|
271 |
i ~~ 0 |
|
272 |
] whileTrue:[ |
|
273 |
self mark: text from: i to: (i + search size - 1) for: rule. |
|
274 |
i := i + search size + 1. |
|
275 |
] |
|
276 |
||
277 |
||
278 |
] |
|
279 |
] |
|
280 |
||
281 |
"Created: / 03-02-2012 / 10:39:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
282 |
! ! |
|
283 |
||
284 |
!LintHighlighter methodsFor:'initialization'! |
|
285 |
||
286 |
reset |
|
287 |
annotations := OrderedCollection new. |
|
288 |
||
289 |
"Created: / 18-02-2012 / 22:54:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
290 |
"Modified: / 15-08-2013 / 12:40:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
291 |
! ! |
|
292 |
||
293 |
!LintHighlighter methodsFor:'markup'! |
|
294 |
||
295 |
mark: text from: start to: end for: rule |
|
296 |
| emphasis | |
|
297 |
||
298 |
emphasis := self emphasisForSeverity: rule severity. |
|
299 |
text emphasisFrom: start to: end add: emphasis. |
|
300 |
annotations add: |
|
301 |
(LintAnnotation from: start to: end rule: rule) |
|
302 |
||
303 |
"Created: / 30-01-2012 / 15:30:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10485 | 304 |
! ! |
305 |
||
306 |
!LintHighlighter class methodsFor:'documentation'! |
|
307 |
||
308 |
version |
|
14096
3d2f347c2cbc
class: Tools::LintHighlighter
Claus Gittinger <cg@exept.de>
parents:
14068
diff
changeset
|
309 |
^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.8 2014-03-02 22:51:00 cg Exp $' |
10485 | 310 |
! |
311 |
||
312 |
version_CVS |
|
14096
3d2f347c2cbc
class: Tools::LintHighlighter
Claus Gittinger <cg@exept.de>
parents:
14068
diff
changeset
|
313 |
^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.8 2014-03-02 22:51:00 cg Exp $' |
10485 | 314 |
! ! |
13829 | 315 |