getSourceReplacingSelectorWith: newSelector
| oldKeywords newKeywords args newSelectorWithArgs source oldSelector s |
source := self sourceCode.
oldSelector := self parserClass new parseSelector: source.
oldSelector = newSelector ifTrue: [ ^ source ].
oldKeywords := oldSelector keywords.
newKeywords := (newSelector ifNil: [self defaultSelector]) keywords.
[oldKeywords size = newKeywords size] assert.
args := (self methodClass parserClass new
parseArgsAndTemps: source string notifying: nil) copyFrom: 1 to: self numArgs.
newSelectorWithArgs := String streamContents: [:stream |
newKeywords withIndexDo: [:keyword :index |
stream nextPutAll: keyword.
stream space.
args size >= index ifTrue: [
stream nextPutAll: (args at: index); space]]].
s := source string readStream.
oldKeywords do: [ :each | s match: each ].
args isEmpty ifFalse: [ s match: args last ].
^newSelectorWithArgs trimBoth, s upToEnd
So, why we cannot just�replace "self parserClass new parseSelector: source." with "self selector". Well, I think (talking with Guille) this ONLY because of Trait transformation/aliases that associates a selector with a method of a different selector.
If this is the case, it means that 99% of the cases,"oldSelector = newSelector ifTrue: [ ^ source ]. �" �is true. Because those aliases are only used in one trait in all the image ().�
So...if that is the case, can't we get the oldSelector from elsewhere �rather than needing to use the Compiler to get the selector from the source code ?
thanks
--
Mariano
http://marianopeck.wordpress.com