Send to Printer

st4u

ST 4U 266: Rewrite Tool Transformations

August 3, 2012 10:52:48.405

Today's Smalltalk 4 You looks at the rewrite tools in VA Smalltalk - they come in as part of the refactoring browser support. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

Rewrite.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll look at another one of the interesting tools that comes in with the Mastering ENVY Developer Tools - the rewrite tools (part of the refactoring engine). Specifically, we'll look at code transformation. Using the stock tools, it's easy enough to rename methods, but what if you want to selectively rewrite code within a subset of the applications and classes in the system? On the launcher, open the Rewrite Tool:

Rewrite Tool

To take a simple example, we have a small class in an application that has code like this:


shouldDoThing
	^shouldDoThing isNil
		ifTrue: [shouldDoThing := false]
		ifFalse: [shouldDoThing]

And we would like to change that pattern in this class to:



shouldDoThing
	^shouldDoThing 
		ifNil: [shouldDoThing := false]
		ifNotNil: [shouldDoThing]

Simple enough for one change, but what if there are a number of them in your application - and you don't want to make that change across the entire system?

rewrite

The matching rules above will do what we want - and you can follow that pattern for any such transformation. Next, we'll limit the scope of our change. Click the "Search In" button:

Limit Scope

As we did with Small Lint, select the applications and classes you want to apply the rule to. Then hit the "Ok" Button. You'll see something like the following:

Changes

Nothing has been done yet - the system is showing you the proposed changes. You can either select individual changes to apply, or select "Execute All":

Changes

If the application(s) affected are not open, you'll get prompted by ENVY (as per usual) to create a scratch edition. Once you approve that, you'll be able to open a browser and see the changes above

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , , ,

Enclosures:
[st4u266-iPhone.m4v ( Size: 6242633 )]

posted by James Robertson

 Share Tweet This