Re: How to write a simple Code Rewrite for x -> self x?
Posted by
Tim M on
Mar 26, 2006; 12:48pm
URL: https://forum.world.st/How-to-write-a-simple-Code-Rewrite-for-x-self-x-tp3377980p3378026.html
Hi John,
Thanks for taking the time to show an example of using a TransformationRule
- I was doing a little internal presentation on refactoring and parse nodes
so it was really cool to reference your paper and show your response. People
commented that they were inspired by the topic - which is rewarding.
Thanks!
Tim
> Instead of using the code rewriter
> in
> the browser, you could use it directly:
> -------------
> | class rule |
> class := SmaCCParser.
> rule := SmalllintChecker
> runRule: (TransformationRule
> rewrite:
> (class instVarNames collect: [:each | Array with: each , ' := ``@a'
> with: 'self ' , each, ': ``@a']) ,
> (class instVarNames collect: [:each | Array with: each with: 'self
> '
> , each])
> methods: false
> name: 'Convert inst vars refs to messages')
> onEnvironment: (BrowserEnvironment new forClassHierarchyFrom: class).
> RewriteChangesBrowser showOn: rule changes
> -------------
> This will convert all instance variable references in SmaCCParser and
> its subclasses to go through accessors (of course, you'll need to
> define
> them first). Instead of looking at all variable references, this is
> only
> looking at variables defined in SmaCCParser.
> John Brant
>