author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 02 Dec 2014 13:26:01 +0100 | |
changeset 14965 | 02bfa1f4aa9a |
parent 14096 | 3d2f347c2cbc |
child 15031 | fd2c24c7f230 |
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. |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
124 |
^ self format: source in: class |
10485 | 125 |
|
126 |
"Created: / 04-08-2011 / 23:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
127 |
"Modified: / 02-12-2014 / 11:29:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10485 | 128 |
! |
129 |
||
130 |
formatClassDefinition:source in:class elementsInto: elements |
|
131 |
||
132 |
formattingMethod := false. |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
133 |
^ self format: source asText in: class |
10485 | 134 |
|
135 |
"Created: / 04-08-2011 / 23:44:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
136 |
"Modified: / 02-12-2014 / 11:29:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10485 | 137 |
! |
138 |
||
139 |
formatExpression:source in:class |
|
140 |
||
141 |
formattingMethod := false. |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
142 |
^ self format: source in: class |
10485 | 143 |
|
144 |
"Created: / 04-08-2011 / 23:45:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
145 |
"Modified: / 02-12-2014 / 11:29:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10485 | 146 |
! |
147 |
||
148 |
formatExpression:source in:class elementsInto: elements |
|
149 |
||
150 |
formattingMethod := false. |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
151 |
^ self format: source in: class |
10485 | 152 |
|
153 |
"Created: / 04-08-2011 / 23:43:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
154 |
"Modified: / 02-12-2014 / 11:29:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10485 | 155 |
! |
156 |
||
157 |
formatMethod:mth source:source in:class using: preferences |
|
158 |
||
159 |
formattingMethod := true. |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
160 |
^ self format: source in: class |
10485 | 161 |
|
162 |
"Created: / 04-08-2011 / 23:45:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
163 |
"Modified: / 02-12-2014 / 11:29:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10485 | 164 |
! |
165 |
||
166 |
formatMethod:mth source:source in:class using: preferences elementsInto: elements |
|
167 |
||
168 |
formattingMethod := true. |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
169 |
^ self format: source in: class |
10485 | 170 |
|
171 |
"Created: / 04-08-2011 / 23:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
172 |
"Modified: / 02-12-2014 / 11:30:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10485 | 173 |
! ! |
174 |
||
175 |
!LintHighlighter methodsFor:'formatting-private'! |
|
176 |
||
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
177 |
format: text in: class |
10485 | 178 |
|
14096
3d2f347c2cbc
class: Tools::LintHighlighter
Claus Gittinger <cg@exept.de>
parents:
14068
diff
changeset
|
179 |
| tree t| |
13829 | 180 |
tree := RBParser parseMethod: text string onError:[:error :pos| ^ text ]. |
14096
3d2f347c2cbc
class: Tools::LintHighlighter
Claus Gittinger <cg@exept.de>
parents:
14068
diff
changeset
|
181 |
t := text asText. |
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
182 |
self format: t tree: tree in: class. |
14096
3d2f347c2cbc
class: Tools::LintHighlighter
Claus Gittinger <cg@exept.de>
parents:
14068
diff
changeset
|
183 |
^t |
10485 | 184 |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
185 |
"Created: / 02-12-2014 / 11:27:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10485 | 186 |
! |
187 |
||
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
188 |
format: text tree: tree in: class |
13829 | 189 |
|
190 |
annotations := SortedCollection new. |
|
191 |
rules ? #() do:[:rule| |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
192 |
self format: text tree: tree in: class rule: rule |
13829 | 193 |
]. |
194 |
^text |
|
195 |
||
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
196 |
"Created: / 02-12-2014 / 11:28:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
13829 | 197 |
! |
198 |
||
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
199 |
format: text tree: tree in: class rule: rule |
13829 | 200 |
|
201 |
| string | |
|
202 |
||
203 |
string := text string. |
|
204 |
rule result isParseTreeEnvironment ifTrue:[ |
|
205 |
formattingMethod ifTrue:[ |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
206 |
rule resultSelectionIntervalsForSource: string tree: tree in: class do: [:interval| |
13829 | 207 |
interval notEmptyOrNil ifTrue:[ |
208 |
(interval first == 1 and:[interval last == text size]) ifTrue:[ |
|
209 |
(OperatingSystem getLoginName = 'jv') ifTrue:[ |
|
210 |
Transcript showCR:'>> no meaningful selection interval for ' , rule printString. |
|
211 |
]. |
|
212 |
] ifFalse:[ |
|
213 |
self mark: text from: interval first to: interval last for: rule. |
|
214 |
] |
|
215 |
] |
|
216 |
]. |
|
217 |
]. |
|
218 |
] ifFalse: [ |
|
219 |
| searches | |
|
220 |
||
221 |
searches := rule result searchStrings asSet. |
|
222 |
||
223 |
searches do:[:search| |
|
224 |
| i | |
|
225 |
i := 1. |
|
226 |
[ |
|
227 |
i := string findString: search startingAt: i. |
|
228 |
i ~~ 0 |
|
229 |
] whileTrue:[ |
|
230 |
self mark: text from: i to: (i + search size - 1) for: rule. |
|
231 |
i := i + search size + 1. |
|
232 |
] |
|
233 |
||
234 |
||
235 |
] |
|
236 |
] |
|
237 |
||
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
238 |
"Created: / 02-12-2014 / 11:28:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
13829 | 239 |
! ! |
240 |
||
241 |
!LintHighlighter methodsFor:'initialization'! |
|
242 |
||
243 |
reset |
|
244 |
annotations := OrderedCollection new. |
|
245 |
||
246 |
"Created: / 18-02-2012 / 22:54:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
247 |
"Modified: / 15-08-2013 / 12:40:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
248 |
! ! |
|
249 |
||
250 |
!LintHighlighter methodsFor:'markup'! |
|
251 |
||
252 |
mark: text from: start to: end for: rule |
|
253 |
| emphasis | |
|
254 |
||
255 |
emphasis := self emphasisForSeverity: rule severity. |
|
256 |
text emphasisFrom: start to: end add: emphasis. |
|
257 |
annotations add: |
|
258 |
(LintAnnotation from: start to: end rule: rule) |
|
259 |
||
260 |
"Created: / 30-01-2012 / 15:30:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10485 | 261 |
! ! |
262 |
||
263 |
!LintHighlighter class methodsFor:'documentation'! |
|
264 |
||
265 |
version |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
266 |
^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.9 2014-12-02 12:26:01 vrany Exp $' |
10485 | 267 |
! |
268 |
||
269 |
version_CVS |
|
14965
02bfa1f4aa9a
When highlighing rules, pass a class to selectionIntervals so the highlighter/searcher
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14096
diff
changeset
|
270 |
^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.9 2014-12-02 12:26:01 vrany Exp $' |
10485 | 271 |
! ! |
13829 | 272 |