Some cool RewriteTool tricks
Ned Konz
ned at squeakland.org
Sat Feb 26 20:57:53 UTC 2005
Assuming that you've loaded:
* Monticello
* the SqueakMap version of Refactory (Refactory-md.3.8.12)
* my latest RB improvements
(http://bike-nomad.com/squeak/Refactory-nk.3830.mcd)
you can try out some interesting tricks with the FinderTool and the new
RewriteTool:
For instance:
* to find sends to globals that they don't understand (I have a Lint rule for
this, but...) (this could also be done in the search pattern, as in the
second example):
search for:
`{:node :context | node isVariable and: [ Smalltalk includesKey: node name
asSymbol ] } `@message: `@args
and use this condition:
| what | what := Smalltalk at: aNode receiver name asSymbol.
what notNil
and: [ what ~~ Preferences
and: [ (what respondsTo: aNode selector) not ]]
* to find references to all globals that aren't classes, search for:
`{:node :context | | what | node isVariable and: [ (what := Smalltalk at: node
name ifAbsent: []) notNil and: [ what isBehavior not ] ] }
* to replace all menu constructors that use #labels:lines:selections: to use
#addTranslatedList: instead (changing three parameters into one):
search for:
`@Expression labels: `#labels lines: `#lines selections: `#selections
replace with:
`@Expression addTranslatedList: `{:a | | labels lines selections list |
labels := (a valueForPatternVariableNode: '`#labels') value findTokens:
Character cr.
lines := (a valueForPatternVariableNode: '`#lines') value.
selections := (a valueForPatternVariableNode: '`#selections') value.
list := labels with: selections collect: [ :l :s | { l. s. } ].
list := Array streamContents: [ :strm | list withIndexDo: [ :l :i | strm
nextPut: l.
(lines includes: i) ifTrue: [ strm nextPut: '-' ]]].
RBParser parseExpression: list storeString }
Enjoy,
--
Ned Konz
http://bike-nomad.com/squeak/
More information about the Squeak-dev
mailing list
|