PharoView this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide)

MetaLink: Check that method is called private

Question


I would like to automatically insert a line of code in all the methods of a class. This line of code checks to see if the sender of the method is also “self”. In other words I am automatically checking to see if the method is public or private. I know how to do the checking (using thisContext), but I don’t know how to automatically insert one line of code at the top of thirty methods.

Answer

from Marcus on 9.3.2017 on Slack
theClass := TabsExample.

link := MetaLink new
	metaObject: [ :context :object |  context sender receiver == object ifTrue: [ context crLog ] ];
	selector: #value:value:;
	arguments: #(context object);
	control: #before.
	
theClass methods  do: [ :each |	
	each ast link: link.
]

"and get rid of it"
link uninstall.

-----------

Link to this Page