From Configs to Baselines

I got tired of manually converting Configs into Baselines, so I wrote a
little script. You pass it the selector of a #baselineXyz: method, and it
converts it (i.e. changes the pragma, removes the blessing and repo, etc)
Hopefully you will find it useful. Cross posting to Metcello list...

ConfigurationOf>>#createBaselineFrom: selector

	| projectName baselineName baseline methodTree commonBlockBody repoSetter |
	
	"Create new class"
	projectName := self name allButFirst: self superclass name size.
	baselineName := 'BaselineOf', projectName.
	baseline := BaselineOf subclass: baselineName asSymbol
	instanceVariableNames: ''
	classVariableNames: ''
	category: baselineName.
	
	"Convert baseline##: method"
	methodTree := (self methodNamed: selector) parseTree.
	methodTree selector: #baseline:.
	methodTree pragmas at: 1 put: (RBPragmaNode selector: #baseline arguments:
#()).
	commonBlockBody := methodTree statements first arguments last body.
	repoSetter := commonBlockBody statements detect: [ :e | e selector =
#repository: ].
	commonBlockBody removeNode: repoSetter.
	
	"Compile baseline method"
	baseline compile: methodTree newSource classified: 'baseline'



-----
Cheers,
Sean
--
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: