author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 25 Jan 2013 17:57:06 +0000 | |
branch | refactoring-vmdata |
changeset 2002 | ef3da336a6c9 |
parent 1980 | 6fcdddce1241 |
child 2069 | 75d40b7b986f |
permissions | -rw-r--r-- |
1412 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
3 |
||
4 |
New code and modifications done at SWING Research Group [1]: |
|
5 |
||
6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
7 |
SWING Research Group, Czech Technical University in Prague |
|
8 |
||
9 |
This software is furnished under a license and may be used |
|
10 |
only in accordance with the terms of that license and with the |
|
11 |
inclusion of the above copyright notice. This software may not |
|
12 |
be provided or otherwise made available to, or used by, any |
|
13 |
other person. No title to or ownership of the software is |
|
14 |
hereby transferred. |
|
15 |
||
16 |
[1] Code written at SWING Research Group contains a signature |
|
17 |
of one of the above copright owners. For exact set of such code, |
|
18 |
see the differences between this version and version stx:libjava |
|
19 |
as of 1.9.2010 |
|
20 |
" |
|
21 |
"{ Package: 'stx:libjava/tools' }" |
|
22 |
||
23 |
Object subclass:#JavaSyntaxHighlighter |
|
24 |
instanceVariableNames:'preferences elements cachedStringEmphasis cachedStringColor |
|
25 |
sourceText' |
|
1426 | 26 |
classVariableNames:'FormattedSourceCache' |
1412 | 27 |
poolDictionaries:'' |
28 |
category:'Languages-Java-Tools' |
|
29 |
! |
|
30 |
||
31 |
JavaParseNodeBuilder subclass:#Builder |
|
32 |
instanceVariableNames:'highlighter' |
|
33 |
classVariableNames:'' |
|
34 |
poolDictionaries:'' |
|
35 |
privateIn:JavaSyntaxHighlighter |
|
36 |
! |
|
37 |
||
38 |
JavaParser subclass:#Parser |
|
39 |
instanceVariableNames:'stream' |
|
40 |
classVariableNames:'' |
|
41 |
poolDictionaries:'' |
|
42 |
privateIn:JavaSyntaxHighlighter |
|
43 |
! |
|
44 |
||
1424
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
45 |
JavaScanner subclass:#Scanner |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
46 |
instanceVariableNames:'highlighter' |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
47 |
classVariableNames:'' |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
48 |
poolDictionaries:'' |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
49 |
privateIn:JavaSyntaxHighlighter |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
50 |
! |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
51 |
|
1412 | 52 |
!JavaSyntaxHighlighter class methodsFor:'documentation'! |
53 |
||
54 |
copyright |
|
55 |
" |
|
56 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
57 |
||
58 |
New code and modifications done at SWING Research Group [1]: |
|
59 |
||
60 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
61 |
SWING Research Group, Czech Technical University in Prague |
|
62 |
||
63 |
This software is furnished under a license and may be used |
|
64 |
only in accordance with the terms of that license and with the |
|
65 |
inclusion of the above copyright notice. This software may not |
|
66 |
be provided or otherwise made available to, or used by, any |
|
67 |
other person. No title to or ownership of the software is |
|
68 |
hereby transferred. |
|
69 |
||
70 |
[1] Code written at SWING Research Group contains a signature |
|
71 |
of one of the above copright owners. For exact set of such code, |
|
72 |
see the differences between this version and version stx:libjava |
|
73 |
as of 1.9.2010 |
|
74 |
||
75 |
" |
|
76 |
! ! |
|
77 |
||
78 |
!JavaSyntaxHighlighter class methodsFor:'formatting'! |
|
79 |
||
80 |
formatClass: javaClass |
|
81 |
||
82 |
^self new formatClassDefinition: javaClass source in: javaClass |
|
83 |
||
84 |
"Created: / 15-12-2011 / 21:54:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
85 |
! |
|
86 |
||
87 |
formatClassDefinition:source in:class |
|
88 |
||
89 |
^self new formatClassDefinition:source in:class |
|
90 |
||
91 |
"Created: / 04-08-2011 / 23:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
92 |
! |
|
93 |
||
94 |
formatClassDefinition:source in:class elementsInto: elements |
|
95 |
||
96 |
^self new formatClassDefinition:source in:class elementsInto: elements |
|
97 |
||
98 |
"Created: / 04-08-2011 / 23:44:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
99 |
! |
|
100 |
||
101 |
formatExpression:source in:class |
|
102 |
||
103 |
^self new formatExpression:source in:class |
|
104 |
||
105 |
"Created: / 04-08-2011 / 23:45:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
106 |
! |
|
107 |
||
108 |
formatExpression:source in:class elementsInto: elements |
|
109 |
||
110 |
^self new formatExpression:source in:class elementsInto: elements |
|
111 |
||
112 |
"Created: / 04-08-2011 / 23:43:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
113 |
! |
|
114 |
||
115 |
formatMethod:mth source:source in:class |
|
116 |
||
117 |
^self formatMethod: mth source: source in: class using: UserPreferences current |
|
118 |
||
119 |
"Created: / 11-02-2012 / 18:18:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
120 |
! |
|
121 |
||
122 |
formatMethod:mth source:source in:class using: preferences |
|
123 |
||
124 |
^self new formatMethod:mth source:source in:class using: preferences |
|
125 |
||
126 |
"Created: / 04-08-2011 / 23:45:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
127 |
! |
|
128 |
||
129 |
formatMethod:mth source:source in:class using: preferences elementsInto: elements |
|
130 |
||
131 |
^self new formatMethod:mth source:source in:class using: preferences elementsInto: elements |
|
132 |
||
133 |
"Created: / 04-08-2011 / 23:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
134 |
! ! |
|
135 |
||
136 |
!JavaSyntaxHighlighter methodsFor:'formatting'! |
|
137 |
||
138 |
formatClassDefinition:source in:class |
|
139 |
||
1426 | 140 |
^ self format: source kind: #start in: class |
1412 | 141 |
|
142 |
"Created: / 04-08-2011 / 23:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
143 |
! |
|
144 |
||
145 |
formatClassDefinition:source in:class elementsInto: els |
|
146 |
||
147 |
elements := els. |
|
148 |
^self formatClassDefinition:source in:class |
|
149 |
||
150 |
"Created: / 04-08-2011 / 23:44:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
151 |
! |
|
152 |
||
153 |
formatExpression:source in:class |
|
154 |
||
1582 | 155 |
"/ self breakPoint:#jv. |
1460 | 156 |
^source. |
1426 | 157 |
^ self format: source kind: #'K_EXPRESSION' in: class |
1412 | 158 |
|
159 |
"Created: / 04-08-2011 / 23:45:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
160 |
! |
|
161 |
||
162 |
formatExpression:source in:class elementsInto: els |
|
163 |
||
164 |
elements := els. |
|
165 |
^self formatExpression:source in:class |
|
166 |
||
167 |
"Created: / 04-08-2011 / 23:43:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
168 |
! |
|
169 |
||
170 |
formatMethod:mth source:source in:class using: prefs |
|
171 |
||
172 |
preferences := prefs. |
|
1426 | 173 |
^ self format: source kind: #start in: class |
1412 | 174 |
|
175 |
"Created: / 04-08-2011 / 23:45:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
176 |
! |
|
177 |
||
178 |
formatMethod:mth source:source in:class using: prefs elementsInto: els |
|
179 |
||
180 |
preferences := prefs. |
|
181 |
elements := els. |
|
182 |
^self formatMethod:mth source:source in:class using: prefs |
|
183 |
||
184 |
"Created: / 04-08-2011 / 23:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
185 |
! ! |
|
186 |
||
187 |
!JavaSyntaxHighlighter methodsFor:'formatting - private'! |
|
188 |
||
1426 | 189 |
format: source kind: kind in: class |
190 |
||
191 |
| scanner parser builder cacheIt | |
|
1412 | 192 |
|
1426 | 193 |
"Optimization - if full class source is to be formatted, |
194 |
consult cache - when browsing the code or debugging, very |
|
195 |
often same same source is to be highlighted" |
|
196 |
cacheIt := kind == #start and: [class notNil]. |
|
197 |
cacheIt ifTrue:[ |
|
198 |
FormattedSourceCache isNil ifTrue:[ |
|
199 |
FormattedSourceCache := OrderedDictionary new |
|
200 |
] ifFalse:[ |
|
201 |
FormattedSourceCache |
|
202 |
at: class |
|
1479 | 203 |
ifPresent:[:sourceAndText| |
204 |
sourceAndText first = source ifTrue:[ |
|
205 |
^sourceAndText second |
|
206 |
]. |
|
207 |
||
1426 | 208 |
]. |
209 |
] |
|
210 |
]. |
|
211 |
||
1412 | 212 |
|
213 |
source isText ifTrue:[ |
|
214 |
sourceText := source copy |
|
215 |
] ifFalse:[ |
|
216 |
sourceText := source asText. |
|
217 |
]. |
|
218 |
||
219 |
preferences isNil ifTrue:[ |
|
220 |
preferences := UserPreferences current. |
|
221 |
]. |
|
222 |
||
1424
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
223 |
scanner := Scanner for: source. |
1412 | 224 |
builder := Builder new. |
225 |
builder highlighter: self. |
|
1424
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
226 |
scanner highlighter: self. |
1412 | 227 |
parser := Parser newStartingAt: kind. |
228 |
parser builder: builder. |
|
1424
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
229 |
parser stream: scanner. |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
230 |
parser parse: scanner. |
1412 | 231 |
|
1426 | 232 |
cacheIt ifTrue:[ |
233 |
[ FormattedSourceCache size > 25 ] whileTrue:[ |
|
234 |
FormattedSourceCache removeKey: FormattedSourceCache keys first. |
|
235 |
]. |
|
1479 | 236 |
FormattedSourceCache at: class put: { source . sourceText } |
1426 | 237 |
]. |
1412 | 238 |
^sourceText. |
239 |
||
1426 | 240 |
"Created: / 17-03-2012 / 14:02:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1412 | 241 |
! ! |
242 |
||
243 |
!JavaSyntaxHighlighter methodsFor:'syntax detection'! |
|
244 |
||
245 |
markArgumentIdentifierFrom:pos1 to:pos2 |
|
246 |
self |
|
247 |
markFrom:pos1 to:pos2 |
|
248 |
withEmphasis:(preferences argumentIdentifierEmphasis) color:(preferences argumentIdentifierColor) |
|
249 |
! |
|
250 |
||
1479 | 251 |
markBadIdentifierFrom:pos1 to:pos2 |
252 |
self |
|
253 |
markFrom:pos1 to:pos2 |
|
254 |
withEmphasis:(preferences badIdentifierEmphasis) |
|
255 |
color:(preferences badIdentifierColor) |
|
256 |
! |
|
257 |
||
1412 | 258 |
markClassVariableIdentifierFrom:pos1 to:pos2 |
259 |
self |
|
260 |
markFrom:pos1 to:pos2 |
|
261 |
withEmphasis:(preferences classVariableIdentifierEmphasis) color:(preferences classVariableIdentifierColor) |
|
262 |
||
263 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
|
264 |
! |
|
265 |
||
266 |
markCommentFrom:pos1 to:pos2 |
|
267 |
self |
|
268 |
markFrom:pos1 to:pos2 |
|
269 |
withEmphasis:(preferences commentEmphasis) color:(preferences commentColor) |
|
270 |
! |
|
271 |
||
272 |
markConstantFrom:pos1 to:pos2 |
|
273 |
self |
|
274 |
markFrom:pos1 to:pos2 |
|
275 |
withEmphasis:(preferences constantEmphasis) color:(preferences constantColor) |
|
276 |
! |
|
277 |
||
278 |
markFrom:pos1 to:pos2 withEmphasis:fontEmp color:clrIn |
|
279 |
|e p2 clr| |
|
280 |
||
281 |
clr := clrIn onDevice:Screen current. |
|
282 |
||
283 |
clr = Color black ifTrue:[ |
|
284 |
e := fontEmp |
|
285 |
] ifFalse:[ |
|
286 |
fontEmp isNil ifTrue:[ |
|
287 |
e := (#color->clr) |
|
288 |
] ifFalse:[ |
|
289 |
e := Text addEmphasis:fontEmp to:(#color->clr). |
|
290 |
] |
|
291 |
]. |
|
292 |
(p2 := pos2) isNil ifTrue:[ |
|
293 |
p2 := sourceText size |
|
294 |
] ifFalse:[ |
|
295 |
p2 := p2 min:sourceText size |
|
296 |
]. |
|
297 |
sourceText emphasizeFrom:pos1 to:p2 with:e |
|
298 |
||
299 |
"Created: / 31.3.1998 / 13:26:53 / cg" |
|
300 |
"Modified: / 1.4.1998 / 12:51:56 / cg" |
|
301 |
! |
|
302 |
||
303 |
markFunctionNameFrom:pos1 to:pos2 |
|
304 |
self |
|
305 |
markFrom:pos1 to:pos2 |
|
306 |
withEmphasis:(preferences methodSelectorEmphasis) color:(preferences methodSelectorColor) |
|
307 |
! |
|
308 |
||
309 |
markGlobalClassIdentifierFrom:pos1 to:pos2 |
|
310 |
self |
|
311 |
markFrom:pos1 to:pos2 |
|
312 |
withEmphasis:(preferences globalClassIdentifierEmphasis) color:(preferences globalClassIdentifierColor) |
|
313 |
||
314 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
|
315 |
"Created: / 4.3.1999 / 12:53:02 / cg" |
|
316 |
! |
|
317 |
||
318 |
markGlobalIdentifierFrom:pos1 to:pos2 |
|
319 |
self |
|
320 |
markFrom:pos1 to:pos2 |
|
321 |
withEmphasis:(preferences globalIdentifierEmphasis) color:(preferences globalIdentifierColor) |
|
322 |
||
323 |
"Modified: / 31.3.1998 / 18:02:14 / cg" |
|
324 |
! |
|
325 |
||
326 |
markIdentifierFrom:pos1 to:pos2 |
|
327 |
self |
|
328 |
markFrom:pos1 to:pos2 |
|
329 |
withEmphasis:(preferences identifierEmphasis) color:(preferences identifierColor) |
|
330 |
! |
|
331 |
||
332 |
markInstVarIdentifierFrom:pos1 to:pos2 |
|
333 |
self |
|
334 |
markFrom:pos1 to:pos2 |
|
335 |
withEmphasis:(preferences instVarIdentifierEmphasis) color:(preferences instVarIdentifierColor) |
|
336 |
||
337 |
"Created: / 16.4.1998 / 18:35:40 / cg" |
|
338 |
"Modified: / 16.4.1998 / 18:37:30 / cg" |
|
339 |
! |
|
340 |
||
341 |
markKeyword:kw from:pos1 to:pos2 |
|
342 |
|em clr| |
|
343 |
||
344 |
( #( 'if' 'else' |
|
345 |
'while' |
|
346 |
'for' |
|
347 |
'do' |
|
348 |
'return' |
|
349 |
) includes:kw) ifTrue:[ |
|
350 |
em := preferences controlFlowSelectorEmphasis. |
|
351 |
clr := preferences controlFlowSelectorColor. |
|
352 |
] ifFalse:[ |
|
353 |
em := preferences jsKeywordEmphasis. |
|
354 |
clr := preferences jsKeywordColor. |
|
355 |
]. |
|
356 |
self |
|
357 |
markFrom:pos1 to:pos2 |
|
358 |
withEmphasis:em color:clr |
|
359 |
||
360 |
"Modified: / 19-05-2010 / 15:07:59 / cg" |
|
1424
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
361 |
"Modified: / 17-03-2012 / 00:14:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1412 | 362 |
! |
363 |
||
364 |
markLocalIdentifierFrom:pos1 to:pos2 |
|
365 |
self |
|
366 |
markFrom:pos1 to:pos2 |
|
367 |
withEmphasis:(preferences localIdentifierEmphasis) color:(preferences localIdentifierColor) |
|
368 |
! |
|
369 |
||
1426 | 370 |
markSelector:selectorString from:pos1 to:pos2 |
371 |
| fg em | |
|
372 |
||
373 |
fg := preferences selectorColor. |
|
374 |
em := preferences selectorEmphasis. |
|
375 |
||
376 |
self |
|
377 |
markFrom:pos1 to:pos2 |
|
378 |
withEmphasis:em color:fg |
|
379 |
||
380 |
"Modified: / 04-10-2011 / 19:48:48 / cg" |
|
381 |
"Modified: / 17-03-2012 / 13:26:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
382 |
"Created: / 17-03-2012 / 19:12:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
383 |
! |
|
384 |
||
1412 | 385 |
markSelector:selectorString from:pos1 to:pos2 receiverNode:aReceiverNodeOrNil numArgs:numArgs |
386 |
|fg selectorSymbol check ok rec em currentEnvironment currentSuperclasses currentSubclasses classToCompileFor fullSelectorCheck| |
|
387 |
||
388 |
fg := preferences selectorColor. |
|
389 |
em := preferences selectorEmphasis. |
|
390 |
||
1426 | 391 |
"/ (currentEnvironment notNil |
392 |
"/ and:[ (((currentEnvironment _localVariables ? #()) contains:[:local | local name = selectorString]) |
|
393 |
"/ or:[((currentEnvironment _argVariables ? #()) contains:[:local | local name = selectorString])]) |
|
394 |
"/ ]) |
|
395 |
"/ ifTrue:[ |
|
396 |
"/ "/ a local call |
|
397 |
"/ ] ifFalse:[ |
|
398 |
"/ selectorSymbol := (self translatedSmalltalkSelectorFor:selectorString numArgs:numArgs) asSymbolIfInterned. |
|
399 |
"/ selectorSymbol isNil ifTrue:[ |
|
400 |
"/ fg := Color red. |
|
401 |
"/ ] ifFalse:[ |
|
402 |
"/ fullSelectorCheck == true ifTrue:[ |
|
403 |
"/ aReceiverNodeOrNil notNil ifTrue:[ |
|
404 |
"/ check := [:cls | (cls includesSelector:selectorSymbol) |
|
405 |
"/ or:[cls class includesSelector:selectorSymbol]]. |
|
406 |
"/ |
|
407 |
"/ ok := false. |
|
408 |
"/ |
|
409 |
"/ "/ limit search if possible |
|
410 |
"/ (classToCompileFor notNil |
|
411 |
"/ and:[aReceiverNodeOrNil isSelf or:[aReceiverNodeOrNil isSuper]]) ifTrue:[ |
|
412 |
"/ currentSuperclasses isNil ifTrue:[ |
|
413 |
"/ currentSuperclasses := classToCompileFor withAllSuperclasses. |
|
414 |
"/ ]. |
|
415 |
"/ ok := currentSuperclasses contains:check. |
|
416 |
"/ (ok not and:[aReceiverNodeOrNil isSelf]) ifTrue:[ |
|
417 |
"/ currentSubclasses isNil ifTrue:[ |
|
418 |
"/ currentSubclasses := classToCompileFor allSubclasses. |
|
419 |
"/ ]. |
|
420 |
"/ ok := currentSubclasses contains:check. |
|
421 |
"/ ]. |
|
422 |
"/ ] ifFalse:[ |
|
423 |
"/ aReceiverNodeOrNil isConstant ifTrue:[ |
|
424 |
"/ ok := aReceiverNodeOrNil evaluate class withAllSuperclasses contains:check. |
|
425 |
"/ ] ifFalse:[ |
|
426 |
"/ (aReceiverNodeOrNil isGlobal |
|
427 |
"/ and:[(rec := aReceiverNodeOrNil evaluate) isBehavior]) ifTrue:[ |
|
428 |
"/ ok := rec class withAllSuperclasses contains:check. |
|
429 |
"/ ] ifFalse:[ |
|
430 |
"/ ok := Smalltalk allClasses contains:check |
|
431 |
"/ ] |
|
432 |
"/ ] |
|
433 |
"/ ]. |
|
434 |
"/ |
|
435 |
"/ ok ifFalse:[ |
|
436 |
"/ em := preferences unimplementedSelectorEmphasis. |
|
437 |
"/ fg := preferences unimplementedSelectorColor. |
|
438 |
"/ ] |
|
439 |
"/ ] |
|
440 |
"/ ] |
|
441 |
"/ ]. |
|
442 |
"/ ]. |
|
1412 | 443 |
self |
444 |
markFrom:pos1 to:pos2 |
|
445 |
withEmphasis:em color:fg |
|
446 |
||
447 |
"Modified: / 04-10-2011 / 19:48:48 / cg" |
|
1426 | 448 |
"Modified: / 17-03-2012 / 13:26:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1412 | 449 |
! |
450 |
||
451 |
markSelfFrom:pos1 to:pos2 |
|
452 |
self |
|
453 |
markFrom:pos1 to:pos2 |
|
454 |
withEmphasis:(preferences selfEmphasis) color:(preferences selfColor) |
|
455 |
! |
|
456 |
||
457 |
markStringFrom:pos1 to:pos2 |
|
458 |
self |
|
459 |
markFrom:pos1 to:pos2 |
|
460 |
withEmphasis:(preferences stringEmphasis) color:(preferences stringColor) |
|
461 |
! |
|
462 |
||
463 |
markUnknownIdentifierFrom:pos1 to:pos2 |
|
464 |
self |
|
465 |
markFrom:pos1 to:pos2 |
|
466 |
withEmphasis:(preferences unknownIdentifierEmphasis) color:(preferences unknownIdentifierColor) |
|
467 |
! |
|
468 |
||
469 |
markVariable:v from:pos to:endPos |
|
470 |
"support for syntaxColoring" |
|
471 |
||
472 |
|type globalValue nameSym| |
|
473 |
||
474 |
type := v type. |
|
475 |
(type == #BlockArg |
|
476 |
or:[type == #MethodArg]) ifTrue:[ |
|
477 |
self markArgumentIdentifierFrom:pos to:endPos. |
|
478 |
^ self |
|
479 |
]. |
|
480 |
(type == #BlockVariable |
|
481 |
or:[type == #MethodVariable]) ifTrue:[ |
|
482 |
self markLocalIdentifierFrom:pos to:endPos. |
|
483 |
^ self |
|
484 |
]. |
|
485 |
(type == #GlobalVariable) ifTrue:[ |
|
486 |
nameSym := v name asSymbolIfInterned. |
|
487 |
(nameSym isNil |
|
488 |
or:[(Smalltalk includesKey:nameSym) not]) ifTrue:[ |
|
489 |
self markUnknownIdentifierFrom:pos to:endPos. |
|
490 |
^ self |
|
491 |
]. |
|
492 |
globalValue := Smalltalk at:nameSym ifAbsent:nil. |
|
493 |
globalValue isBehavior ifTrue:[ |
|
494 |
self markGlobalClassIdentifierFrom:pos to:endPos. |
|
495 |
] ifFalse:[ |
|
496 |
self markGlobalIdentifierFrom:pos to:endPos. |
|
497 |
]. |
|
498 |
^ self |
|
499 |
]. |
|
500 |
(type == #ClassVariable) ifTrue:[ |
|
501 |
self markClassVariableIdentifierFrom:pos to:endPos. |
|
502 |
^ self |
|
503 |
]. |
|
504 |
(type == #InstanceVariable) ifTrue:[ |
|
505 |
self markInstVarIdentifierFrom:pos to:endPos. |
|
506 |
^ self |
|
507 |
]. |
|
508 |
||
509 |
self markIdentifierFrom:pos to:endPos. |
|
510 |
||
511 |
"Created: / 16.4.1998 / 18:49:34 / cg" |
|
512 |
"Modified: / 4.3.1999 / 12:56:13 / cg" |
|
513 |
! ! |
|
514 |
||
515 |
!JavaSyntaxHighlighter::Builder methodsFor:'accessing'! |
|
516 |
||
517 |
highlighter |
|
518 |
^ highlighter |
|
519 |
! |
|
520 |
||
521 |
highlighter:something |
|
522 |
highlighter := something. |
|
523 |
! ! |
|
524 |
||
525 |
!JavaSyntaxHighlighter::Builder methodsFor:'building'! |
|
526 |
||
527 |
newComment: text |
|
528 |
||
529 |
highlighter markCommentFrom:start to: stop. |
|
530 |
^super newComment: text |
|
531 |
||
532 |
"Created: / 09-03-2012 / 17:11:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
533 |
! |
|
534 |
||
535 |
newJavaDoc: text |
|
536 |
||
537 |
highlighter markCommentFrom:start to: stop. |
|
538 |
^super newJavaDoc: text |
|
539 |
||
540 |
"Created: / 09-03-2012 / 17:11:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1426 | 541 |
! |
542 |
||
543 |
newStringLiteral: string |
|
544 |
||
545 |
highlighter markStringFrom:start to: stop. |
|
546 |
^super newStringLiteral: string |
|
547 |
||
548 |
"Created: / 17-03-2012 / 17:32:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1412 | 549 |
! ! |
550 |
||
551 |
!JavaSyntaxHighlighter::Parser methodsFor:'accessing'! |
|
552 |
||
1426 | 553 |
highlighter |
554 |
||
555 |
^builder highlighter |
|
556 |
||
557 |
"Created: / 17-03-2012 / 19:11:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
558 |
! |
|
559 |
||
1412 | 560 |
stream |
561 |
^ stream |
|
562 |
! |
|
563 |
||
564 |
stream:something |
|
565 |
stream := something. |
|
566 |
! ! |
|
567 |
||
1426 | 568 |
!JavaSyntaxHighlighter::Parser methodsFor:'grammar-classes-method'! |
569 |
||
570 |
constructorNameIdentifier |
|
571 |
||
572 |
^super constructorNameIdentifier ==> [:token| |
|
573 |
self highlighter |
|
574 |
markSelector: token value |
|
575 |
from: token startPosition to: token endPosition |
|
576 |
] |
|
1412 | 577 |
|
1426 | 578 |
"Created: / 17-03-2012 / 19:12:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
579 |
! |
|
580 |
||
1884
b5f94052b1c7
Bugfix in syntax highlighter (caused by JavaParserII refactoring)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1879
diff
changeset
|
581 |
identifier |
b5f94052b1c7
Bugfix in syntax highlighter (caused by JavaParserII refactoring)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1879
diff
changeset
|
582 |
|
1958
fe39b6009ee7
Bugfix in JavaSyntaxHighlighter: fixed class name after making JavaTokenParser a private class.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1884
diff
changeset
|
583 |
^(JavaParserI::TokenParser for: #Identifier) |
1884
b5f94052b1c7
Bugfix in syntax highlighter (caused by JavaParserII refactoring)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1879
diff
changeset
|
584 |
|
b5f94052b1c7
Bugfix in syntax highlighter (caused by JavaParserII refactoring)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1879
diff
changeset
|
585 |
"Created: / 16-12-2012 / 10:29:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1958
fe39b6009ee7
Bugfix in JavaSyntaxHighlighter: fixed class name after making JavaTokenParser a private class.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1884
diff
changeset
|
586 |
"Modified: / 17-01-2013 / 11:10:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1884
b5f94052b1c7
Bugfix in syntax highlighter (caused by JavaParserII refactoring)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1879
diff
changeset
|
587 |
! |
b5f94052b1c7
Bugfix in syntax highlighter (caused by JavaParserII refactoring)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1879
diff
changeset
|
588 |
|
1426 | 589 |
methodNameIdentifier |
590 |
||
591 |
^super methodNameIdentifier ==> [:token| |
|
592 |
self highlighter |
|
593 |
markSelector: token value |
|
594 |
from: token startPosition to: token endPosition |
|
595 |
] |
|
596 |
||
597 |
"Created: / 17-03-2012 / 19:13:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
598 |
! |
|
1412 | 599 |
|
1426 | 600 |
typeNameIdentifier |
601 |
||
602 |
^super typeNameIdentifier ==> [:token| |
|
603 |
self highlighter |
|
604 |
markSelector: token value |
|
605 |
from: token startPosition to: token endPosition |
|
606 |
] |
|
607 |
||
608 |
"Created: / 17-03-2012 / 19:44:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
609 |
! ! |
|
1412 | 610 |
|
1426 | 611 |
!JavaSyntaxHighlighter::Parser methodsFor:'grammar-literals-string'! |
612 |
||
613 |
stringLiteral |
|
1412 | 614 |
|
1426 | 615 |
^super stringLiteral ==> [:stringToken| |
616 |
builder |
|
617 |
start: stringToken startPosition |
|
618 |
stop: stringToken endPosition; |
|
619 |
newStringLiteral: stringToken value |
|
620 |
] |
|
621 |
||
622 |
"Created: / 17-03-2012 / 17:31:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1412 | 623 |
! ! |
624 |
||
625 |
!JavaSyntaxHighlighter::Parser methodsFor:'utility'! |
|
626 |
||
627 |
tokenFor: aString |
|
628 |
||
629 |
"/ | p | |
|
630 |
"/ |
|
631 |
"/ p := keywords at: aString ifAbsent:[nil]. |
|
632 |
"/ p notNil ifTrue:[ |
|
633 |
"/ ^ (self asToken: p) ==> [:token| |
|
634 |
"/ | start stop | |
|
635 |
"/ |
|
636 |
"/ stop := stream position. |
|
637 |
"/ start := stop - keyword size. |
|
638 |
"/ builder highlighter markKeyword: keyword from:start to:stop |
|
639 |
"/ ]. |
|
640 |
"/ ]. |
|
641 |
||
642 |
^super tokenFor: aString |
|
643 |
||
644 |
"Created: / 10-03-2012 / 11:52:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
645 |
! ! |
|
646 |
||
1424
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
647 |
!JavaSyntaxHighlighter::Scanner methodsFor:'accessing'! |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
648 |
|
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
649 |
highlighter |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
650 |
^ highlighter |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
651 |
! |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
652 |
|
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
653 |
highlighter:aJavaSyntaxHighlighter |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
654 |
highlighter := aJavaSyntaxHighlighter. |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
655 |
! ! |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
656 |
|
1479 | 657 |
!JavaSyntaxHighlighter::Scanner methodsFor:'error handling'! |
658 |
||
659 |
syntaxError:aMessage position:position to:endPos |
|
660 |
"a syntax error happened" |
|
661 |
||
662 |
endPos notNil ifTrue:[ |
|
663 |
highlighter markBadIdentifierFrom:position to: endPos. |
|
664 |
] |
|
665 |
||
666 |
"Created: / 13-04-2012 / 18:31:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
667 |
! ! |
|
668 |
||
1424
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
669 |
!JavaSyntaxHighlighter::Scanner methodsFor:'initialization'! |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
670 |
|
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
671 |
initialize |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
672 |
"initialize the scanner" |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
673 |
|
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
674 |
super initialize. |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
675 |
saveComments := true |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
676 |
|
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
677 |
"Created: / 17-03-2012 / 00:02:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
678 |
! ! |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
679 |
|
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
680 |
!JavaSyntaxHighlighter::Scanner methodsFor:'private'! |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
681 |
|
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
682 |
checkForKeyword:string |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
683 |
| isKW | |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
684 |
|
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
685 |
isKW := super checkForKeyword:string. |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
686 |
isKW ifTrue:[ |
1426 | 687 |
highlighter markKeyword:string from:tokenStartPosition + 1 to:tokenStartPosition + string size |
1424
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
688 |
]. |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
689 |
^isKW |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
690 |
|
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
691 |
"Created: / 17-03-2012 / 00:15:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
692 |
! ! |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
693 |
|
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
694 |
!JavaSyntaxHighlighter::Scanner methodsFor:'reading next token'! |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
695 |
|
1426 | 696 |
nextToken |
697 |
|t| |
|
698 |
||
699 |
[ |
|
700 |
t := super nextToken. |
|
701 |
tokenEndPosition := source position. |
|
702 |
t isNil |
|
703 |
] whileTrue. |
|
704 |
Verbose == true ifTrue:[ |
|
705 |
Transcript |
|
706 |
show:'JavaScanner nextToken => '; |
|
707 |
show: t storeString; |
|
708 |
show: ' | '; |
|
709 |
showCR: tokenValue. |
|
710 |
]. |
|
711 |
^ t |
|
712 |
||
713 |
"Created: / 14-05-1998 / 15:48:04 / cg" |
|
714 |
"Modified: / 16-05-1998 / 19:12:29 / cg" |
|
715 |
"Modified: / 17-03-2012 / 17:35:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
716 |
"Created: / 17-03-2012 / 19:15:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
717 |
! |
|
718 |
||
1424
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
719 |
skipComment |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
720 |
super skipComment. |
1426 | 721 |
highlighter markCommentFrom:((tokenStartPosition + 1) max: 1) to: source position. |
1424
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
722 |
^nil |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
723 |
|
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
724 |
"Created: / 17-03-2012 / 00:04:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
725 |
! |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
726 |
|
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
727 |
skipEOLComment |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
728 |
super skipEOLComment. |
1442 | 729 |
highlighter markCommentFrom:((tokenStartPosition - 1) max: 1) to: source position. |
1424
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
730 |
^nil |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
731 |
|
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
732 |
"Created: / 17-03-2012 / 00:05:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
733 |
! ! |
9d8337007106
Fixes in JavaSyntaxHighlighter to use new JavaParser
vranyj1
parents:
1412
diff
changeset
|
734 |
|
1412 | 735 |
!JavaSyntaxHighlighter class methodsFor:'documentation'! |
736 |
||
1879
7d232ff32dde
Refactoring of JavaParserII>>importDeclaration
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1818
diff
changeset
|
737 |
version_HG |
7d232ff32dde
Refactoring of JavaParserII>>importDeclaration
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1818
diff
changeset
|
738 |
|
7d232ff32dde
Refactoring of JavaParserII>>importDeclaration
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1818
diff
changeset
|
739 |
^ '$Changeset: <not expanded> $' |
7d232ff32dde
Refactoring of JavaParserII>>importDeclaration
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1818
diff
changeset
|
740 |
! |
7d232ff32dde
Refactoring of JavaParserII>>importDeclaration
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1818
diff
changeset
|
741 |
|
1412 | 742 |
version_SVN |
1980 | 743 |
^ 'Id' |
1412 | 744 |
! ! |