author | Claus Gittinger <cg@exept.de> |
Tue, 06 Nov 2012 18:49:11 +0100 | |
changeset 12037 | ca4d1532f6c1 |
parent 9486 | fb1fc792752e |
child 12608 | eda08ac36e6d |
permissions | -rw-r--r-- |
6179 | 1 |
" |
2 |
COPYRIGHT (c) 2004 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 |
" |
|
5592 | 12 |
"{ Package: 'stx:libtool' }" |
5591 | 13 |
|
14 |
"{ NameSpace: Tools }" |
|
15 |
||
16 |
Object subclass:#ClassChecker |
|
17 |
instanceVariableNames:'checkedClass badClasses badClassInfo badMethods badMethodInfo |
|
18 |
obsoleteWarners allObsoleteMethods checksPerformed' |
|
19 |
classVariableNames:'' |
|
20 |
poolDictionaries:'' |
|
21 |
category:'Interface-Browsers-New' |
|
22 |
! |
|
23 |
||
24 |
!ClassChecker class methodsFor:'documentation'! |
|
25 |
||
6179 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 2004 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 |
! |
|
39 |
||
5591 | 40 |
documentation |
41 |
" |
|
42 |
embeddable application displaying the class-categories. |
|
43 |
Provides an outputGenerator, which enumerates the classes in |
|
44 |
the selected categories. |
|
45 |
||
8071 | 46 |
Attention: do not change the method categories 'checks-' into something else. |
47 |
The 'checks-' prefix is used to detect checks and these are listed in the browsers |
|
48 |
lint dialog. |
|
49 |
||
5591 | 50 |
[author:] |
8071 | 51 |
Claus Gittinger (cg@exept.de) |
5591 | 52 |
" |
53 |
! ! |
|
54 |
||
55 |
!ClassChecker class methodsFor:'queries'! |
|
56 |
||
57 |
individualChecks |
|
58 |
"return a list of supported checks" |
|
59 |
||
60 |
|checks| |
|
61 |
||
62 |
checks := OrderedCollection new. |
|
63 |
self methodDictionary keysAndValuesDo:[:sel :mthd | |
|
64 |
(mthd category startsWith:'checks') ifTrue:[checks add:sel] |
|
65 |
]. |
|
66 |
checks sort. |
|
67 |
^ checks |
|
68 |
||
69 |
" |
|
70 |
self individualChecks |
|
71 |
" |
|
72 |
||
73 |
"Created: / 18.8.2000 / 22:30:46 / cg" |
|
74 |
"Modified: / 18.8.2000 / 22:31:02 / cg" |
|
75 |
! ! |
|
76 |
||
77 |
!ClassChecker methodsFor:'accessing'! |
|
78 |
||
79 |
badClassInfo |
|
80 |
^ badClassInfo |
|
81 |
! |
|
82 |
||
83 |
badMethodInfo |
|
84 |
^ badMethodInfo |
|
85 |
! |
|
86 |
||
87 |
checkedClass |
|
88 |
"return the value of the instance variable 'checkedClass' (automatically generated)" |
|
89 |
||
90 |
^ checkedClass |
|
91 |
! |
|
92 |
||
93 |
checkedClass:something |
|
94 |
"set the value of the instance variable 'checkedClass' (automatically generated)" |
|
95 |
||
96 |
checkedClass := something. |
|
97 |
checksPerformed := nil. |
|
98 |
! ! |
|
99 |
||
100 |
!ClassChecker methodsFor:'checking'! |
|
101 |
||
102 |
allChecks |
|
103 |
self errorChecks. |
|
104 |
self warningChecks. |
|
105 |
self styleChecks. |
|
106 |
! |
|
107 |
||
108 |
doCheck:whichCheck |
|
109 |
checksPerformed isNil ifTrue:[ |
|
110 |
checksPerformed := Set new. |
|
111 |
]. |
|
112 |
(checksPerformed includes:whichCheck) ifFalse:[ |
|
113 |
checksPerformed add:whichCheck. |
|
114 |
self perform:whichCheck |
|
115 |
] |
|
116 |
! |
|
117 |
||
118 |
errorChecks |
|
119 |
self doCheck:#subclassResponsibilityNotDefined. |
|
120 |
self doCheck:#sentNotImplemented. |
|
121 |
self doCheck:#definesEqualButNotHash. |
|
122 |
self doCheck:#instanceVariablesNeverWritten. |
|
123 |
! |
|
124 |
||
125 |
styleChecks |
|
126 |
self doCheck:#checkProtocols. |
|
8071 | 127 |
self doCheck:#sendsObsoleteMethodWarningButNotTaggedAsObsoleteOrViceVersa. |
9485
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
128 |
self doCheck:#unusedInstanceVariables. |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
129 |
self doCheck:#unusedClassVariables. |
8071 | 130 |
|
6548 | 131 |
"/ self doCheck:#guardingClause. |
9485
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
132 |
|
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
133 |
"Modified: / 18-05-2010 / 14:38:15 / cg" |
5591 | 134 |
! |
135 |
||
136 |
warningChecks |
|
137 |
self doCheck:#messageNeverSentAndNotUsedAsSymbol. |
|
138 |
self doCheck:#sendsObsoleteMessages. |
|
139 |
self doCheck:#instanceVariablesNeverUsed. |
|
140 |
self doCheck:#instanceVariablesNeverWritten. |
|
141 |
self doCheck:#classVariablesNeverUsed. |
|
142 |
self doCheck:#classVariablesNeverWritten. |
|
143 |
self doCheck:#classInstanceVariablesNeverUsed. |
|
144 |
self doCheck:#classInstanceVariablesNeverWritten. |
|
8483 | 145 |
self doCheck:#invalidKeyInImageResourceMethod |
5591 | 146 |
! ! |
147 |
||
148 |
!ClassChecker methodsFor:'checks-individual'! |
|
149 |
||
150 |
checkProtocols |
|
151 |
checkedClass instAndClassSelectorsAndMethodsDo:[:mSelector :method | |
|
152 |
self checkProtocolOf:method |
|
153 |
] |
|
154 |
! |
|
155 |
||
156 |
checkVariableNameConventions |
|
157 |
|badInstVars badClassVars| |
|
158 |
||
6645 | 159 |
badInstVars := checkedClass instanceVariableNames select:[:varName | varName isUppercaseFirst]. |
5591 | 160 |
badClassVars := checkedClass classVarNames select:[:varName | varName first isLowercase]. |
161 |
||
162 |
badInstVars notEmpty ifTrue:[ |
|
6645 | 163 |
badInstVars := (badInstVars collect:[:v | '''' , v , '''']) asStringWith:$, . |
164 |
self |
|
165 |
rememberBadClass:checkedClass |
|
166 |
info:('instVars ' , badInstVars , ' should be lowercase (#checkNameConventions)'). |
|
5591 | 167 |
]. |
168 |
badClassVars notEmpty ifTrue:[ |
|
6645 | 169 |
badClassVars := (badClassVars collect:[:v | '''' , v , '''']) asStringWith:$, . |
170 |
self |
|
171 |
rememberBadClass:checkedClass |
|
172 |
info:('classVars ' , badClassVars , ' should be uppercase (#checkNameConventions)'). |
|
5591 | 173 |
]. |
174 |
! |
|
175 |
||
176 |
classInstanceVariablesNeverUsed |
|
177 |
self instanceVariablesNeverUsedIn:checkedClass theMetaclass. |
|
178 |
! |
|
179 |
||
180 |
classInstanceVariablesNeverWritten |
|
181 |
self instanceVariablesNeverWrittenIn:checkedClass theMetaclass. |
|
182 |
! |
|
183 |
||
184 |
classVariablesNeverUsed |
|
185 |
|cls notUsedHere notUsedAnyWhere anySubclass| |
|
186 |
||
187 |
cls := checkedClass theNonMetaclass. |
|
188 |
notUsedHere := cls classVarNames asSet. |
|
189 |
notUsedHere isEmpty ifTrue:[^ self]. |
|
190 |
||
191 |
self removeUsedClassVariablesIn:cls from:notUsedHere. |
|
192 |
self removeUsedClassVariablesIn:cls class from:notUsedHere. |
|
193 |
||
194 |
notUsedHere notEmpty ifTrue:[ |
|
195 |
notUsedAnyWhere := notUsedHere copy. |
|
196 |
anySubclass := false. |
|
197 |
cls allSubclassesDo:[:eachSubclass | |
|
198 |
anySubclass := true. |
|
199 |
notUsedAnyWhere notEmpty ifTrue:[ |
|
200 |
self removeUsedClassVariablesIn:eachSubclass from:notUsedAnyWhere. |
|
201 |
self removeUsedClassVariablesIn:eachSubclass class from:notUsedAnyWhere. |
|
202 |
] |
|
203 |
]. |
|
204 |
||
205 |
notUsedHere do:[:eachVariable | |
|
206 |
|className| |
|
207 |
||
208 |
className := checkedClass name allBold. |
|
209 |
self |
|
210 |
rememberBadClass:cls |
|
211 |
info:('classVar ' , eachVariable allBold , ' is unused in ' , className , ' (#classVariablesNeverUsed)'). |
|
212 |
(notUsedAnyWhere includes:eachVariable) ifTrue:[ |
|
213 |
self |
|
214 |
rememberBadClass:cls |
|
215 |
info:('classVar ' , eachVariable allBold , ' is not even used in subclasses of ' , className , ' (#classVariablesNeverUsed)') |
|
216 |
] |
|
217 |
]. |
|
218 |
] |
|
219 |
! |
|
220 |
||
221 |
classVariablesNeverWritten |
|
222 |
|cls notWrittenHere notWrittenAnyWhere anySubclass| |
|
223 |
||
224 |
cls := checkedClass theNonMetaclass. |
|
225 |
notWrittenHere := cls classVarNames asSet. |
|
226 |
notWrittenHere isEmpty ifTrue:[^ self]. |
|
227 |
||
228 |
self removeWrittenClassVariablesIn:cls from:notWrittenHere. |
|
229 |
self removeWrittenClassVariablesIn:cls class from:notWrittenHere. |
|
230 |
||
231 |
notWrittenHere notEmpty ifTrue:[ |
|
232 |
notWrittenAnyWhere := notWrittenHere copy. |
|
233 |
anySubclass := false. |
|
234 |
cls allSubclassesDo:[:eachSubclass | |
|
235 |
anySubclass := true. |
|
236 |
notWrittenAnyWhere notEmpty ifTrue:[ |
|
237 |
self removeWrittenClassVariablesIn:eachSubclass from:notWrittenAnyWhere. |
|
238 |
self removeWrittenClassVariablesIn:eachSubclass class from:notWrittenAnyWhere. |
|
239 |
] |
|
240 |
]. |
|
241 |
||
242 |
notWrittenHere do:[:eachVariable | |
|
243 |
|className| |
|
244 |
||
245 |
className := cls name allBold. |
|
246 |
self |
|
247 |
rememberBadClass:cls |
|
248 |
info:('classVar ' , eachVariable allBold , ' is not set in ' , className , ' (#classVariablesNeverWritten)'). |
|
249 |
(notWrittenAnyWhere includes:eachVariable) ifTrue:[ |
|
250 |
self |
|
251 |
rememberBadClass:cls |
|
252 |
info:('classVar ' , eachVariable allBold , ' is not even set in subclasses of ' , className , ' (#classVariablesNeverWritten)') |
|
253 |
] |
|
254 |
]. |
|
255 |
] |
|
256 |
! |
|
257 |
||
258 |
definesEqualButNotHash |
|
259 |
(checkedClass includesSelector:#=) ifTrue:[ |
|
260 |
(checkedClass includesSelector:#hash) ifFalse:[ |
|
261 |
self |
|
262 |
rememberBadClass:checkedClass |
|
263 |
info:(checkedClass name allBold, ' redefines #=, but not #hash (#definesEqualButNotHash)'). |
|
264 |
] |
|
265 |
] |
|
266 |
! |
|
267 |
||
6548 | 268 |
guardingClause |
269 |
|detector| |
|
270 |
||
271 |
detector := ParseTreeLintRule guardingClause. |
|
272 |
detector runOnEnvironment: (Array with:checkedClass). |
|
8360 | 273 |
self breakPoint:#cg. |
6548 | 274 |
! |
275 |
||
5591 | 276 |
instanceVariablesNeverUsed |
277 |
self instanceVariablesNeverUsedIn:checkedClass theNonMetaclass. |
|
278 |
! |
|
279 |
||
280 |
instanceVariablesNeverWritten |
|
281 |
self instanceVariablesNeverWrittenIn:checkedClass theNonMetaclass. |
|
282 |
! |
|
283 |
||
8483 | 284 |
invalidKeyInImageResourceMethod |
285 |
Icon flushCachedIcons. |
|
286 |
checkedClass instAndClassSelectorsAndMethodsDo:[:sel :mthd | |
|
287 |
|img key name| |
|
288 |
||
9253
684c9ecf8d17
changed: #invalidKeyInImageResourceMethod
Claus Gittinger <cg@exept.de>
parents:
8484
diff
changeset
|
289 |
(mthd hasImageResource) ifTrue:[ |
8483 | 290 |
img := mthd valueWithReceiver:nil arguments:#(). |
291 |
key := (Icon classVarAt:#KnownIcons) keyAtIdentityValue:img. |
|
292 |
key notNil ifTrue:[ |
|
293 |
mthd mclass notNil ifTrue:[ |
|
294 |
name := (mthd mclass name , ' ', mthd selector). |
|
295 |
name ~= key ifTrue:[ |
|
296 |
self |
|
297 |
rememberBadMethod:mthd |
|
298 |
key:#invalidKeyInImageResourceMethod |
|
299 |
info:('key in constantNamed: does not match the method name') |
|
300 |
] |
|
301 |
] |
|
302 |
] |
|
303 |
] |
|
304 |
]. |
|
305 |
! |
|
306 |
||
5591 | 307 |
messageNeverSent |
308 |
"/ old code: (slow) |
|
309 |
"/ checkedClass instAndClassSelectorsAndMethodsDo:[:mSelector :method | |
|
310 |
"/ (self anySendsOf:mSelector) ifFalse:[ |
|
311 |
"/ self |
|
312 |
"/ rememberBadMethod:method |
|
313 |
"/ info:('#' , mSelector , ' is nowhere sent (#messageNeverSent)') |
|
314 |
"/ ]. |
|
315 |
"/ ]. |
|
316 |
||
317 |
|selectorsOfInterest| |
|
318 |
||
319 |
selectorsOfInterest := IdentitySet new. |
|
320 |
checkedClass instAndClassSelectorsAndMethodsDo:[:mSelector :method | selectorsOfInterest add:mSelector]. |
|
321 |
(self messagesNeverSentIn:selectorsOfInterest) do:[:eachNeverSent | |
|
322 |
self |
|
323 |
rememberBadMethod:(checkedClass compiledMethodAt:eachNeverSent) |
|
324 |
key:#messageNeverSent |
|
325 |
info:('#' , eachNeverSent allBold, ' is nowhere sent (#messageNeverSent)') |
|
326 |
]. |
|
327 |
||
328 |
"Modified: / 18.8.2000 / 22:54:45 / cg" |
|
329 |
! |
|
330 |
||
331 |
messageNeverSentAndNotUsedAsSymbol |
|
332 |
|selectorsOfInterest| |
|
333 |
||
334 |
selectorsOfInterest := IdentitySet new. |
|
335 |
checkedClass instAndClassSelectorsAndMethodsDo:[:mSelector :method | selectorsOfInterest add:mSelector]. |
|
336 |
(self messagesNeverSentAndNotUsedAsSymbolIn:selectorsOfInterest) do:[:eachNeverSent | |
|
337 |
self |
|
338 |
rememberBadMethod:(checkedClass compiledMethodAt:eachNeverSent) |
|
339 |
key:#messageNeverSentAndNotUsedAsSymbol |
|
340 |
info:('#' , eachNeverSent allBold, ' is nowhere sent and selector-symbol not used in any method (#messageNeverSentAndNotUsedAsSymbol)') |
|
341 |
]. |
|
342 |
||
343 |
"Modified: / 18.8.2000 / 23:10:56 / cg" |
|
344 |
! |
|
345 |
||
9486
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
346 |
parseMethod:method in:aClass withParserDo:aBlock onErrorDo:errorBlock |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
347 |
|source parser| |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
348 |
|
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
349 |
source := method source. |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
350 |
parser := Parser |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
351 |
parseMethod:source |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
352 |
in:aClass |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
353 |
ignoreErrors:true |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
354 |
ignoreWarnings:true. |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
355 |
|
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
356 |
(parser notNil and:[parser ~~ #Error]) ifTrue:[ |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
357 |
aBlock value:parser |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
358 |
] ifFalse:[ |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
359 |
errorBlock value |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
360 |
]. |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
361 |
|
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
362 |
"Created: / 18-05-2010 / 15:17:19 / cg" |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
363 |
! |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
364 |
|
5591 | 365 |
sendsObsoleteMessages |
366 |
obsoleteWarners isNil ifTrue:[ |
|
6513 | 367 |
obsoleteWarners := Object selectors select:[:each | each startsWith:'obsoleteMethodWarning']. |
5591 | 368 |
]. |
369 |
allObsoleteMethods isNil ifTrue:[ |
|
6513 | 370 |
allObsoleteMethods := IdentitySet new. |
371 |
Method allSubInstancesDo:[:eachMethod | |lits selector| |
|
372 |
((lits := eachMethod literals) notNil |
|
373 |
and:[lits includesAny:obsoleteWarners]) ifTrue:[ |
|
374 |
(eachMethod messagesSent includesAny:obsoleteWarners) ifTrue:[ |
|
375 |
selector := eachMethod selector. |
|
376 |
selector notNil ifTrue:[ |
|
377 |
allObsoleteMethods add:selector. |
|
378 |
] |
|
379 |
]. |
|
380 |
]. |
|
381 |
]. |
|
5591 | 382 |
|
6513 | 383 |
"/ manually patchup; there are some which should not be considered as bad ... |
384 |
allObsoleteMethods removeAllFoundIn:#( #',' #'at:' #'at:put:' #'raise'). |
|
385 |
allObsoleteMethods removeAllFoundIn:#( #'asText'). |
|
386 |
allObsoleteMethods removeAllFoundIn:obsoleteWarners. |
|
5591 | 387 |
]. |
388 |
||
389 |
checkedClass instAndClassSelectorsAndMethodsDo:[:sel :mthd | |
|
6513 | 390 |
|lits sentMessages whichOnes pT searcher nodes| |
5591 | 391 |
|
6513 | 392 |
((lits := mthd literals) notNil |
393 |
and:[lits includesAny:allObsoleteMethods]) ifTrue:[ |
|
394 |
sentMessages := mthd messagesSent. |
|
395 |
(sentMessages includesAny:allObsoleteMethods) ifTrue:[ |
|
396 |
whichOnes := sentMessages select:[:each | allObsoleteMethods includes:each]. |
|
5591 | 397 |
|
6513 | 398 |
(RBParser notNil |
399 |
and:[RBParser isLoaded]) ifTrue:[ |
|
400 |
"/ lets look at this a bit more detailed; |
|
401 |
"/ parse it and see if we can filter out any messages |
|
402 |
"/ (i.e. look if we can figure out the receiver type) |
|
5591 | 403 |
|
404 |
"/ pT := RBParser |
|
405 |
"/ parseMethod: (mthd source) |
|
406 |
"/ onError: [:aString :pos | nil]. |
|
407 |
"/ pT notNil ifTrue:[ |
|
408 |
"/ searcher := ParseTreeSearcher |
|
409 |
"/ allMessageSendsMatchingAny:whichOnes ignoreCase:false. |
|
410 |
"/ nodes := searcher executeTree:pT initialAnswer:(OrderedCollection new). |
|
411 |
"/ nodes := nodes |
|
412 |
"/ select: |
|
413 |
"/ [:aSendNode | |
|
414 |
"/ self halt. |
|
415 |
"/ ]. |
|
416 |
"/ whichOnes := nodes collect:[:aSendNode | aSendNode selector]. |
|
417 |
"/ ]. |
|
6513 | 418 |
]. |
5591 | 419 |
|
6513 | 420 |
whichOnes asOrderedCollection sort do:[:eachObsoleteMessage | |
421 |
self |
|
422 |
rememberBadMethod:mthd |
|
423 |
key:#sendsObsoleteMessages |
|
424 |
info:('possibly sends an obsolete message: ' , eachObsoleteMessage , ' (#sendsObsoleteMessages)') |
|
425 |
]. |
|
426 |
]. |
|
427 |
] |
|
5591 | 428 |
] |
429 |
! |
|
430 |
||
8071 | 431 |
sendsObsoleteMethodWarningButNotTaggedAsObsoleteOrViceVersa |
432 |
|obsoleteWarners| |
|
433 |
||
434 |
obsoleteWarners := #( #'obsoleteMethodWarning' #'obsoleteMethodWarning:' ). |
|
435 |
||
436 |
checkedClass instAndClassSelectorsAndMethodsDo:[:sel :mthd | |
|
437 |
|lits sentMessages whichOnes pT searcher nodes| |
|
438 |
||
439 |
((lits := mthd literals) notNil |
|
440 |
and:[lits includesAny:obsoleteWarners]) ifTrue:[ |
|
441 |
mthd isObsolete ifFalse:[ |
|
442 |
self |
|
443 |
rememberBadMethod:mthd |
|
444 |
key:#sendsObsoleteMethodWarningButNotTaggedAsObsoleteOrViceVersa |
|
445 |
info:('sends obsoleteMethodWarning but not tagged as obsolete') |
|
446 |
]. |
|
447 |
] ifFalse:[ |
|
448 |
mthd isObsolete ifTrue:[ |
|
449 |
self |
|
450 |
rememberBadMethod:mthd |
|
451 |
key:#sendsObsoleteMethodWarningButNotTaggedAsObsoleteOrViceVersa |
|
452 |
info:('tagged as obsolete but does not send an obsoleteMethodWarning') |
|
453 |
]. |
|
454 |
]. |
|
455 |
] |
|
456 |
! |
|
457 |
||
5591 | 458 |
sentNotImplemented |
459 |
|alreadyChecked alreadyCheckedSelf alreadyCheckedSuper| |
|
460 |
||
461 |
alreadyChecked := IdentitySet new. |
|
462 |
alreadyCheckedSelf := IdentitySet new. |
|
463 |
alreadyCheckedSuper := IdentitySet new. |
|
464 |
||
465 |
checkedClass methodDictionary keysAndValuesDo:[:mSelector :method | |
|
466 |
|sentSelectors selfSelectors superSelectors selectorsNoWhereImplemented| |
|
467 |
||
468 |
selectorsNoWhereImplemented := IdentitySet new. |
|
469 |
sentSelectors := method messagesSent. |
|
470 |
sentSelectors do:[:eachSelector | |
|
471 |
(alreadyChecked includes:eachSelector) ifFalse:[ |
|
472 |
(self anyImplementationOf:eachSelector) ifTrue:[ |
|
473 |
alreadyChecked add:eachSelector |
|
474 |
] ifFalse:[ |
|
475 |
selectorsNoWhereImplemented add:eachSelector. |
|
476 |
self |
|
477 |
rememberBadMethod:method |
|
478 |
key:#sentNotImplemented |
|
479 |
info:('#' , eachSelector allBold, ' is nowhere implemented (#sentNotImplemented)') |
|
480 |
] |
|
481 |
] |
|
482 |
]. |
|
483 |
||
484 |
selfSelectors := method messagesSentToSelf. |
|
485 |
selfSelectors do:[:eachSelector | |
|
486 |
(selectorsNoWhereImplemented includes:eachSelector) ifFalse:[ |
|
487 |
(alreadyCheckedSelf includes:eachSelector) ifFalse:[ |
|
488 |
(self anyImplementationOf:eachSelector inOrAbove:checkedClass) ifTrue:[ |
|
489 |
alreadyCheckedSelf add:eachSelector |
|
490 |
] ifFalse:[ |
|
491 |
self |
|
492 |
rememberBadMethod:method |
|
493 |
key:#sentNotImplemented |
|
494 |
info:('#' , eachSelector allBold, ' is not implemented in the class (#sentNotImplemented)') |
|
495 |
] |
|
496 |
] |
|
497 |
] |
|
498 |
]. |
|
499 |
||
500 |
superSelectors := method messagesSentToSuper. |
|
501 |
superSelectors do:[:eachSelector | |
|
502 |
(selectorsNoWhereImplemented includes:eachSelector) ifFalse:[ |
|
503 |
(alreadyCheckedSuper includes:eachSelector) ifFalse:[ |
|
504 |
(self anyImplementationOf:eachSelector inOrAbove:(checkedClass superclass)) ifTrue:[ |
|
505 |
alreadyCheckedSuper add:eachSelector |
|
506 |
] ifFalse:[ |
|
507 |
self |
|
508 |
rememberBadMethod:method |
|
509 |
key:#sentNotImplemented |
|
510 |
info:('#' , eachSelector allBold, ' is not implemented in any superclass (#sentNotImplemented)') |
|
511 |
] |
|
512 |
] |
|
513 |
] |
|
514 |
]. |
|
515 |
]. |
|
516 |
! |
|
517 |
||
518 |
subclassResponsibilityNotDefined |
|
519 |
|classesInBetween| |
|
520 |
||
521 |
checkedClass allSuperclasses do:[:eachSuperClass | |
|
522 |
eachSuperClass methodDictionary keysAndValuesDo:[:mSelector :method | |
|
523 |
(method referencesLiteral:#subclassResponsibility) ifTrue:[ |
|
524 |
"/ parse it to see if it really does ... |
|
525 |
(method sends:#subclassResponsibility) ifTrue:[ |
|
526 |
"/ ok, got one; |
|
527 |
"/ now, see if it is defined below this superClass |
|
528 |
classesInBetween := checkedClass withAllSuperclasses copy. |
|
529 |
classesInBetween removeAll:(eachSuperClass withAllSuperclasses). |
|
530 |
(self anyImplementationOf:mSelector in:classesInBetween) ifFalse:[ |
|
531 |
(self methodShouldBeIgnoredInSubclassResponsibilityNotDefined:method) |
|
532 |
ifFalse:[ |
|
533 |
self |
|
534 |
rememberBadMethod:method |
|
535 |
key:#subclassResponsibilityNotDefined |
|
536 |
info:(checkedClass name allBold , ' should redefine the #' , mSelector allBold , ' method (#subclassResponsibilityNotDefined)'). |
|
537 |
]. |
|
538 |
]. |
|
539 |
] |
|
540 |
] |
|
541 |
] |
|
542 |
]. |
|
9485
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
543 |
! |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
544 |
|
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
545 |
unusedClassVariables |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
546 |
|remainingVars| |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
547 |
|
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
548 |
remainingVars := checkedClass theNonMetaclass classVarNames asSet. |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
549 |
|
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
550 |
checkedClass theNonMetaclass withAllSubclassesDo:[:eachClassToCheck | |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
551 |
eachClassToCheck instAndClassMethodsDo:[:method | |
9486
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
552 |
self |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
553 |
parseMethod:method in:method mclass |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
554 |
withParserDo:[:parser | |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
555 |
remainingVars removeAllFoundIn:(parser usedClassVars) |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
556 |
] |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
557 |
onErrorDo:[] |
9485
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
558 |
]. |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
559 |
]. |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
560 |
|
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
561 |
remainingVars asSortedCollection do:[:eachVar | |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
562 |
self rememberBadClass:checkedClass info:'Unused class variable: ',eachVar |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
563 |
]. |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
564 |
|
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
565 |
"Created: / 18-05-2010 / 14:37:42 / cg" |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
566 |
! |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
567 |
|
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
568 |
unusedInstanceVariables |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
569 |
|remainingVars| |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
570 |
|
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
571 |
remainingVars := checkedClass theNonMetaclass instVarNames asSet. |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
572 |
|
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
573 |
checkedClass theNonMetaclass withAllSubclassesDo:[:eachClassToCheck | |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
574 |
eachClassToCheck methodDictionary keysAndValuesDo:[:mSelector :method | |
9486
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
575 |
self |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
576 |
parseMethod:method in:eachClassToCheck |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
577 |
withParserDo:[:parser | |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
578 |
remainingVars removeAllFoundIn:(parser usedInstVars) |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
579 |
] |
fb1fc792752e
added: #parseMethod:in:withParserDo:onErrorDo:
Claus Gittinger <cg@exept.de>
parents:
9485
diff
changeset
|
580 |
onErrorDo:[] |
9485
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
581 |
]. |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
582 |
]. |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
583 |
|
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
584 |
remainingVars asSortedCollection do:[:eachVar | |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
585 |
self rememberBadClass:checkedClass info:'Unused instance variable: ',eachVar |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
586 |
]. |
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
587 |
|
9c45ce543fd9
added: unusedClassVariables, unusedInstanceVariables
Claus Gittinger <cg@exept.de>
parents:
9253
diff
changeset
|
588 |
"Created: / 18-05-2010 / 14:32:09 / cg" |
5591 | 589 |
! ! |
590 |
||
591 |
!ClassChecker methodsFor:'helpers'! |
|
592 |
||
593 |
anyImplementationOf:aSelector |
|
594 |
Smalltalk allClassesDo:[:eachClass | |
|
595 |
(eachClass theNonMetaclass includesSelector:aSelector) ifTrue:[^ true]. |
|
596 |
(eachClass theMetaclass includesSelector:aSelector) ifTrue:[^ true]. |
|
597 |
]. |
|
598 |
^ false |
|
599 |
! |
|
600 |
||
601 |
anyImplementationOf:aSelector in:aCollectionOfClasses |
|
6645 | 602 |
^ aCollectionOfClasses |
603 |
contains:[:aClass | (aClass includesSelector:aSelector) ]. |
|
5591 | 604 |
! |
605 |
||
606 |
anyImplementationOf:aSelector inOrAbove:aClass |
|
607 |
aClass withAllSuperclassesDo:[:eachClass | |
|
608 |
(eachClass includesSelector:aSelector) ifTrue:[^ true]. |
|
609 |
]. |
|
610 |
^ false |
|
611 |
! |
|
612 |
||
613 |
anySendsOf:aSelector |
|
6666 | 614 |
Smalltalk allMethodsDo:[:mthd | |
615 |
(mthd sends:aSelector) ifTrue:[^ true]. |
|
5591 | 616 |
]. |
617 |
^ false |
|
618 |
! |
|
619 |
||
620 |
checkProtocolOf:aMethod |
|
621 |
|mClass mSelector protocol superClass implClass superProtocol| |
|
622 |
||
623 |
mClass := aMethod mclass. |
|
624 |
mSelector := aMethod selector. |
|
12037 | 625 |
mClass isNil ifTrue:[^ true]. |
626 |
mSelector isNil ifTrue:[^ true]. |
|
5591 | 627 |
|
628 |
protocol := aMethod category. |
|
629 |
protocol isNil ifTrue: [^true]. |
|
630 |
||
631 |
superClass := mClass superclass. |
|
632 |
superClass isNil ifTrue: [^true]. |
|
633 |
||
634 |
implClass := superClass whichClassIncludesSelector:mSelector. |
|
635 |
implClass isNil ifTrue: [^true]. |
|
636 |
||
637 |
superProtocol := (implClass compiledMethodAt:mSelector) category. |
|
638 |
superProtocol = protocol ifTrue: [^true]. |
|
639 |
superProtocol isNil ifTrue: [^true]. |
|
640 |
||
641 |
self |
|
12037 | 642 |
rememberBadMethod:aMethod |
643 |
key:#checkProtocols |
|
644 |
info:('#' , mSelector allBold , ' is classified under "' , protocol allBold , '" in ' |
|
645 |
, mClass name , ' and under "' , superProtocol allBold , '" in ' , implClass name |
|
646 |
, ' (#checkProtocols)') |
|
5591 | 647 |
|
648 |
"Modified: / 18.8.2000 / 23:13:53 / cg" |
|
649 |
! |
|
650 |
||
651 |
checkUnusedVariables:aMethod rememberReadInstVarsIn:readInstVars writtenInstVarsIn:writtenInstVars readClassVarsIn:readClassVars writtenClassVarsIn:writtenClassVars |
|
652 |
|p mClass sourceString| |
|
653 |
||
654 |
sourceString := aMethod source. |
|
655 |
||
656 |
mClass := aMethod mclass. |
|
657 |
||
658 |
p := Parser parseMethodSilent:sourceString in:mClass. |
|
659 |
readInstVars addAll:(p readInstVars). |
|
660 |
writtenInstVars addAll:(p modifiedInstVars). |
|
661 |
readClassVars addAll:(p readClassVars). |
|
662 |
writtenClassVars addAll:(p modifiedClassVars). |
|
663 |
! |
|
664 |
||
665 |
instanceVariablesNeverUsedIn:aClass |
|
666 |
|notUsedHere notUsedAnyWhere anySubclass| |
|
667 |
||
668 |
notUsedHere := aClass instVarNames asSet. |
|
669 |
notUsedHere isEmpty ifTrue:[^ self]. |
|
670 |
||
671 |
self removeUsedInstanceVariablesIn:aClass from:notUsedHere. |
|
672 |
||
673 |
notUsedHere notEmpty ifTrue:[ |
|
674 |
notUsedAnyWhere := notUsedHere copy. |
|
675 |
anySubclass := false. |
|
676 |
aClass allSubclassesDo:[:eachSubclass | |
|
677 |
anySubclass := true. |
|
678 |
notUsedAnyWhere notEmpty ifTrue:[ |
|
679 |
self removeUsedInstanceVariablesIn:eachSubclass from:notUsedAnyWhere. |
|
680 |
] |
|
681 |
]. |
|
682 |
||
683 |
notUsedHere do:[:eachVariable | |
|
684 |
|className| |
|
685 |
||
686 |
className := aClass name allBold. |
|
687 |
self |
|
688 |
rememberBadClass:aClass |
|
689 |
info:('instVar ' , eachVariable allBold , ' is unused in ' , className , ' (#instanceVariablesNeverUsed)'). |
|
690 |
||
691 |
anySubclass ifTrue:[ |
|
692 |
(notUsedAnyWhere includes:eachVariable) ifTrue:[ |
|
693 |
self |
|
694 |
rememberBadClass:aClass |
|
695 |
info:('instVar ' , eachVariable allBold , ' is not even used in subclasses of ' , className , ' (#instanceVariablesNeverUsed)') |
|
696 |
] |
|
697 |
] |
|
698 |
]. |
|
699 |
] |
|
700 |
! |
|
701 |
||
702 |
instanceVariablesNeverWrittenIn:aClass |
|
703 |
|notWrittenHere notWrittenAnyWhere anySubclass| |
|
704 |
||
705 |
notWrittenHere := aClass instVarNames asSet. |
|
706 |
notWrittenHere isEmpty ifTrue:[^ self]. |
|
707 |
||
708 |
self removeWrittenInstanceVariablesIn:aClass from:notWrittenHere. |
|
709 |
||
710 |
notWrittenHere notEmpty ifTrue:[ |
|
711 |
notWrittenAnyWhere := notWrittenHere copy. |
|
712 |
anySubclass := false. |
|
713 |
aClass allSubclassesDo:[:eachSubclass | |
|
714 |
anySubclass := true. |
|
715 |
notWrittenAnyWhere notEmpty ifTrue:[ |
|
716 |
self removeWrittenInstanceVariablesIn:eachSubclass from:notWrittenAnyWhere. |
|
717 |
] |
|
718 |
]. |
|
719 |
||
720 |
notWrittenHere do:[:eachVariable | |
|
721 |
|className| |
|
722 |
||
723 |
className := aClass name allBold. |
|
724 |
self |
|
725 |
rememberBadClass:aClass |
|
726 |
info:('instVar ' , eachVariable allBold , ' is nowhere set in ' , className , ' (#instanceVariablesNeverWritten)'). |
|
727 |
anySubclass ifTrue:[ |
|
728 |
(notWrittenAnyWhere includes:eachVariable) ifTrue:[ |
|
729 |
self |
|
730 |
rememberBadClass:aClass |
|
731 |
info:('instVar ' , eachVariable allBold , ' is not even set in subclasses of ' , className , ' (#instanceVariablesNeverWritten)') |
|
732 |
] |
|
733 |
] |
|
734 |
]. |
|
735 |
] |
|
736 |
! |
|
737 |
||
738 |
messagesNeverSentAndNotUsedAsSymbolIn:selectorsOfInterest |
|
739 |
|remaining toRemove checkBlock| |
|
740 |
||
741 |
remaining := selectorsOfInterest copy asIdentitySet. |
|
742 |
toRemove := IdentitySet new. |
|
743 |
||
744 |
checkBlock := [:eachClass | |
|
745 |
eachClass instAndClassSelectorsAndMethodsDo:[:mSel :mthd | |lits| |
|
746 |
lits := mthd literals. |
|
747 |
lits notNil ifTrue:[ |
|
748 |
lits traverse:[:eachLiteral | |
|
749 |
eachLiteral isSymbol ifTrue:[ |
|
750 |
remaining remove:eachLiteral ifAbsent:nil. |
|
751 |
] |
|
752 |
]. |
|
753 |
remaining isEmpty ifTrue:[^ remaining]. |
|
754 |
] |
|
755 |
]. |
|
756 |
]. |
|
757 |
||
758 |
"/ start searching in the checkedClass - chances are high, we find some here |
|
759 |
checkBlock value:checkedClass. |
|
760 |
checkedClass superclass notNil ifTrue:[checkBlock value:checkedClass superclass]. |
|
761 |
Smalltalk allClassesDo:checkBlock. |
|
762 |
||
763 |
^ remaining |
|
764 |
||
765 |
"Modified: / 18.8.2000 / 23:05:53 / cg" |
|
766 |
"Created: / 18.8.2000 / 23:06:55 / cg" |
|
767 |
! |
|
768 |
||
769 |
messagesNeverSentIn:selectorsOfInterest |
|
770 |
|remaining| |
|
771 |
||
772 |
remaining := selectorsOfInterest copy. |
|
6666 | 773 |
Smalltalk allMethodsDo:[:mthd | |
774 |
|lits| |
|
775 |
||
776 |
lits := mthd literals. |
|
777 |
lits notNil ifTrue:[ |
|
778 |
(lits includesAny:remaining) ifTrue:[ |
|
779 |
remaining removeAllFoundIn:(mthd messagesSent). |
|
780 |
remaining isEmpty ifTrue:[^ remaining]. |
|
781 |
] |
|
782 |
] |
|
5591 | 783 |
]. |
784 |
^ remaining |
|
785 |
||
786 |
"Created: / 18.8.2000 / 22:53:38 / cg" |
|
787 |
"Modified: / 18.8.2000 / 22:56:59 / cg" |
|
788 |
! |
|
789 |
||
790 |
methodShouldBeIgnoredInSubclassResponsibilityNotDefined:aMethod |
|
791 |
"a kludge for now - would like to have a pragma, resource or other |
|
792 |
way to mark such a method" |
|
793 |
||
794 |
aMethod == (Object compiledMethodAt:#implementedBySubclass) ifTrue:[^ true]. |
|
795 |
aMethod == (Object compiledMethodAt:#readBinaryContentsFromData:manager:) ifTrue:[^ true]. |
|
6511 | 796 |
aMethod == (Object compiledMethodAt:#finalize) ifTrue:[^ true]. |
5591 | 797 |
^ false. |
798 |
! |
|
799 |
||
800 |
rememberBadClass:class info:whatIsWrong |
|
801 |
|entry| |
|
802 |
||
803 |
badClasses isNil ifTrue:[ |
|
804 |
badClasses := IdentitySet new. |
|
805 |
]. |
|
806 |
badClasses add:class. |
|
807 |
||
808 |
badClassInfo isNil ifTrue:[ |
|
809 |
badClassInfo := IdentityDictionary new. |
|
810 |
]. |
|
811 |
entry := badClassInfo at:class ifAbsentPut:[ OrderedCollection new ]. |
|
812 |
entry add:whatIsWrong. |
|
813 |
! |
|
814 |
||
815 |
rememberBadMethod:method key:key info:whatIsWrong |
|
816 |
|entry| |
|
817 |
||
818 |
badMethods isNil ifTrue:[ |
|
819 |
badMethods := Set new. |
|
820 |
]. |
|
821 |
(badMethods includes:(method -> key)) ifTrue:[^ self]. |
|
822 |
||
823 |
badMethods add:(method -> key). |
|
824 |
||
825 |
badMethodInfo isNil ifTrue:[ |
|
826 |
badMethodInfo := IdentityDictionary new. |
|
827 |
]. |
|
828 |
entry := badMethodInfo at:method ifAbsentPut:[ OrderedCollection new ]. |
|
829 |
entry add:whatIsWrong. |
|
830 |
! |
|
831 |
||
832 |
rememberBadMethods:methods key:key info:whatIsWrong |
|
833 |
methods do:[:eachMethod | |
|
834 |
self rememberBadMethod:eachMethod key:key info:whatIsWrong |
|
835 |
]. |
|
836 |
! |
|
837 |
||
838 |
removeUsedClassVariablesIn:aClass from:aCollectionOfVariablenames |
|
839 |
aClass selectorsAndMethodsDo:[:mSelector :method | |
|
840 |
|src usedVars parser| |
|
841 |
||
842 |
src := method source. |
|
843 |
src notNil ifTrue:[ |
|
844 |
parser := Parser |
|
845 |
parseMethod:src |
|
846 |
in:aClass |
|
847 |
ignoreErrors:true |
|
848 |
ignoreWarnings:true. |
|
849 |
||
850 |
(parser notNil and:[parser ~~ #Error]) ifTrue:[ |
|
851 |
aCollectionOfVariablenames removeAllFoundIn:(parser usedClassVars). |
|
852 |
aCollectionOfVariablenames isEmpty ifTrue:[^ self]. |
|
853 |
] |
|
854 |
]. |
|
855 |
]. |
|
856 |
! |
|
857 |
||
858 |
removeUsedInstanceVariablesIn:aClass from:aCollectionOfVariablenames |
|
859 |
aClass selectorsAndMethodsDo:[:mSelector :method | |
|
860 |
|src usedVars parser| |
|
861 |
||
862 |
src := method source. |
|
863 |
src notNil ifTrue:[ |
|
864 |
parser := Parser |
|
865 |
parseMethod:src |
|
866 |
in:aClass |
|
867 |
ignoreErrors:true |
|
868 |
ignoreWarnings:true. |
|
869 |
||
870 |
(parser notNil and:[parser ~~ #Error]) ifTrue:[ |
|
871 |
aCollectionOfVariablenames removeAllFoundIn:(parser usedInstVars). |
|
872 |
aCollectionOfVariablenames isEmpty ifTrue:[^ self]. |
|
873 |
] |
|
874 |
]. |
|
875 |
]. |
|
876 |
! |
|
877 |
||
878 |
removeWrittenClassVariablesIn:aClass from:aCollectionOfVariablenames |
|
879 |
aClass selectorsAndMethodsDo:[:mSelector :method | |
|
880 |
|src usedVars parser| |
|
881 |
||
882 |
src := method source. |
|
883 |
src notNil ifTrue:[ |
|
884 |
parser := Parser |
|
885 |
parseMethod:src |
|
886 |
in:aClass |
|
887 |
ignoreErrors:true |
|
888 |
ignoreWarnings:true. |
|
889 |
||
890 |
(parser notNil and:[parser ~~ #Error]) ifTrue:[ |
|
891 |
aCollectionOfVariablenames removeAllFoundIn:(parser modifiedClassVars). |
|
892 |
aCollectionOfVariablenames isEmpty ifTrue:[^ self]. |
|
893 |
] |
|
894 |
]. |
|
895 |
]. |
|
896 |
! |
|
897 |
||
898 |
removeWrittenInstanceVariablesIn:aClass from:aCollectionOfVariablenames |
|
899 |
aClass selectorsAndMethodsDo:[:mSelector :method | |
|
900 |
|src usedVars parser| |
|
901 |
||
902 |
src := method source. |
|
903 |
src notNil ifTrue:[ |
|
904 |
parser := Parser |
|
905 |
parseMethod:src |
|
906 |
in:aClass |
|
907 |
ignoreErrors:true |
|
908 |
ignoreWarnings:true. |
|
909 |
||
910 |
(parser notNil and:[parser ~~ #Error]) ifTrue:[ |
|
911 |
aCollectionOfVariablenames removeAllFoundIn:(parser modifiedInstVars). |
|
912 |
aCollectionOfVariablenames isEmpty ifTrue:[^ self]. |
|
913 |
] |
|
914 |
]. |
|
915 |
]. |
|
916 |
! ! |
|
917 |
||
918 |
!ClassChecker class methodsFor:'documentation'! |
|
919 |
||
920 |
version |
|
12037 | 921 |
^ '$Header: /cvs/stx/stx/libtool/Tools_ClassChecker.st,v 1.17 2012-11-06 17:49:11 cg Exp $' |
9253
684c9ecf8d17
changed: #invalidKeyInImageResourceMethod
Claus Gittinger <cg@exept.de>
parents:
8484
diff
changeset
|
922 |
! |
684c9ecf8d17
changed: #invalidKeyInImageResourceMethod
Claus Gittinger <cg@exept.de>
parents:
8484
diff
changeset
|
923 |
|
684c9ecf8d17
changed: #invalidKeyInImageResourceMethod
Claus Gittinger <cg@exept.de>
parents:
8484
diff
changeset
|
924 |
version_CVS |
12037 | 925 |
^ '$Header: /cvs/stx/stx/libtool/Tools_ClassChecker.st,v 1.17 2012-11-06 17:49:11 cg Exp $' |
5591 | 926 |
! ! |