author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sun, 05 Feb 2012 01:49:41 +0000 | |
branch | jv |
changeset 12144 | 18c25ec50d96 |
parent 12141 | f95099b6b5f7 |
child 12170 | 6c9c4b7981ee |
permissions | -rw-r--r-- |
12128
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
1 |
" |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
3 |
All Rights Reserved |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
4 |
|
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
5 |
This software is furnished under a license and may be used |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
6 |
only in accordance with the terms of that license and with the |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
7 |
inclusion of the above copyright notice. This software may not |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
8 |
be provided or otherwise made available to, or used by, any |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
9 |
other person. No title to or ownership of the software is |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
10 |
hereby transferred. |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
11 |
" |
10485 | 12 |
"{ Package: 'stx:libtool' }" |
13 |
||
14 |
"{ NameSpace: Tools }" |
|
15 |
||
16 |
Object subclass:#LintHighlighter |
|
12128
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
17 |
instanceVariableNames:'rules annotations formattingMethod emphasisError |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
18 |
emphasisInformation emphasisWarning' |
10485 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
21 |
category:'Interface-Lint' |
|
22 |
! |
|
23 |
||
12128
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
24 |
!LintHighlighter class methodsFor:'documentation'! |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
25 |
|
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
26 |
copyright |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
27 |
" |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
28 |
COPYRIGHT (c) 2006 by eXept Software AG |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
29 |
All Rights Reserved |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
30 |
|
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
31 |
This software is furnished under a license and may be used |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
32 |
only in accordance with the terms of that license and with the |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
33 |
inclusion of the above copyright notice. This software may not |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
34 |
be provided or otherwise made available to, or used by, any |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
35 |
other person. No title to or ownership of the software is |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
36 |
hereby transferred. |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
37 |
" |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
38 |
! ! |
10485 | 39 |
|
40 |
!LintHighlighter methodsFor:'accessing'! |
|
41 |
||
12128
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
42 |
annotations |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
43 |
^ annotations |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
44 |
! |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
45 |
|
10485 | 46 |
rules |
47 |
^ rules |
|
48 |
! |
|
49 |
||
50 |
rules:something |
|
51 |
rules := something. |
|
52 |
! ! |
|
53 |
||
54 |
!LintHighlighter methodsFor:'accessing-emphasis'! |
|
55 |
||
56 |
emphasisForError |
|
57 |
||
58 |
emphasisError isNil ifTrue:[ |
|
59 |
emphasisError := Array |
|
60 |
with: #underwave |
|
61 |
with: #underlineColor -> Color red |
|
62 |
]. |
|
63 |
^emphasisError |
|
64 |
||
65 |
"Created: / 05-08-2011 / 09:31:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
66 |
! |
|
67 |
||
68 |
emphasisForInformation |
|
69 |
||
70 |
emphasisInformation isNil ifTrue:[ |
|
71 |
emphasisInformation := Array |
|
72 |
with: #underwave |
|
73 |
with: #underlineColor -> Color blue lighter |
|
74 |
]. |
|
75 |
^emphasisInformation |
|
76 |
||
77 |
"Created: / 05-08-2011 / 09:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
78 |
! |
|
79 |
||
80 |
emphasisForSeverity: severity |
|
81 |
||
82 |
severity == #error ifTrue:[^self emphasisForError]. |
|
83 |
severity == #information ifTrue:[^self emphasisForInformation]. |
|
84 |
||
85 |
^self emphasisForWarning |
|
86 |
||
87 |
"Created: / 05-08-2011 / 09:31:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
88 |
! |
|
89 |
||
90 |
emphasisForWarning |
|
91 |
||
92 |
emphasisWarning isNil ifTrue:[ |
|
93 |
emphasisWarning := Array |
|
94 |
with: #underwave |
|
12125 | 95 |
with: #underlineColor -> (Color redByte: 224 greenByte: 200 blueByte: 45) |
10485 | 96 |
]. |
97 |
^emphasisWarning |
|
98 |
||
99 |
"Created: / 05-08-2011 / 09:31:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
100 |
! ! |
|
101 |
||
102 |
!LintHighlighter methodsFor:'formatting'! |
|
103 |
||
104 |
formatClassDefinition:source in:class |
|
105 |
||
106 |
formattingMethod := false. |
|
107 |
^ self format: source |
|
108 |
||
109 |
"Created: / 04-08-2011 / 23:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
110 |
! |
|
111 |
||
112 |
formatClassDefinition:source in:class elementsInto: elements |
|
113 |
||
114 |
formattingMethod := false. |
|
115 |
^ self format: source |
|
116 |
||
117 |
"Created: / 04-08-2011 / 23:44:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
118 |
! |
|
119 |
||
120 |
formatExpression:source in:class |
|
121 |
||
122 |
formattingMethod := false. |
|
123 |
^ self format: source |
|
124 |
||
125 |
"Created: / 04-08-2011 / 23:45:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
126 |
! |
|
127 |
||
128 |
formatExpression:source in:class elementsInto: elements |
|
129 |
||
130 |
formattingMethod := false. |
|
131 |
^ self format: source |
|
132 |
||
133 |
"Created: / 04-08-2011 / 23:43:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
134 |
! |
|
135 |
||
136 |
formatMethod:mth source:source in:class using: preferences |
|
137 |
||
138 |
formattingMethod := true. |
|
139 |
^ self format: source |
|
140 |
||
141 |
"Created: / 04-08-2011 / 23:45:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
142 |
! |
|
143 |
||
144 |
formatMethod:mth source:source in:class using: preferences elementsInto: elements |
|
145 |
||
146 |
formattingMethod := true. |
|
147 |
^ self format: source |
|
148 |
||
149 |
"Created: / 04-08-2011 / 23:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
150 |
! ! |
|
151 |
||
152 |
!LintHighlighter methodsFor:'formatting-private'! |
|
153 |
||
154 |
format: text |
|
155 |
||
12141 | 156 |
| tree | |
157 |
tree := RBParser parseMethod: text string onError:[:error :pos| ^ text ]. |
|
158 |
self format: text tree: tree. |
|
10485 | 159 |
^text |
160 |
||
161 |
"Created: / 04-08-2011 / 23:51:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
162 |
! |
|
163 |
||
12141 | 164 |
format: text tree: tree |
165 |
||
166 |
annotations := SortedCollection new. |
|
167 |
rules ? #() do:[:rule| |
|
168 |
self format: text tree: tree rule: rule |
|
169 |
]. |
|
170 |
^text |
|
171 |
||
172 |
"Created: / 02-02-2012 / 23:32:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
173 |
! |
|
174 |
||
175 |
format: text tree: tree rule: rule |
|
10485 | 176 |
|
12128
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
177 |
| string | |
10485 | 178 |
|
12141 | 179 |
string := text string. |
10485 | 180 |
rule result isParseTreeEnvironment ifTrue:[ |
181 |
formattingMethod ifTrue:[ |
|
12141 | 182 |
rule result selectionIntervalsForSource: string tree: tree do: [:interval| |
183 |
interval notNil ifTrue:[ |
|
184 |
self mark: text from: interval first to: interval last for: rule. |
|
185 |
] |
|
12125 | 186 |
]. |
10485 | 187 |
]. |
12141 | 188 |
] ifFalse: [ |
10485 | 189 |
| searches | |
190 |
||
191 |
searches := rule result searchStrings asSet. |
|
192 |
||
193 |
searches do:[:search| |
|
194 |
| i | |
|
195 |
i := 1. |
|
196 |
[ |
|
197 |
i := string findString: search startingAt: i. |
|
198 |
i ~~ 0 |
|
199 |
] whileTrue:[ |
|
12128
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
200 |
self mark: text from: i to: (i + search size - 1) for: rule. |
10485 | 201 |
i := i + search size + 1. |
202 |
] |
|
203 |
||
204 |
||
205 |
] |
|
206 |
] |
|
207 |
||
12141 | 208 |
"Created: / 03-02-2012 / 10:39:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10485 | 209 |
! ! |
210 |
||
12128
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
211 |
!LintHighlighter methodsFor:'markup'! |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
212 |
|
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
213 |
mark: text from: start to: end for: rule |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
214 |
| emphasis | |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
215 |
|
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
216 |
emphasis := self emphasisForSeverity: rule severity. |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
217 |
text emphasisFrom: start to: end add: emphasis. |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
218 |
annotations add: |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
219 |
(LintAnnotation from: start to: end rule: rule) |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
220 |
|
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
221 |
"Created: / 30-01-2012 / 15:30:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
222 |
! ! |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
223 |
|
10485 | 224 |
!LintHighlighter class methodsFor:'documentation'! |
225 |
||
226 |
version |
|
12141 | 227 |
^ '$Id: Tools__LintHighlighter.st 7868 2012-02-03 10:54:40Z vranyj1 $' |
10485 | 228 |
! |
229 |
||
230 |
version_CVS |
|
12125 | 231 |
^ '§Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.3 2012/01/27 21:18:06 vrany Exp §' |
12128
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
232 |
! |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
233 |
|
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
234 |
version_SVN |
12141 | 235 |
^ '$Id: Tools__LintHighlighter.st 7868 2012-02-03 10:54:40Z vranyj1 $' |
12125 | 236 |
! ! |