[Pharo-project] Finding all places where a class is instantiated?
Hi: When refactoring code, I frequently try to find all places where a class is instantiated. Is there anything in the image which would work a bit more precise than a search for the class name in the finder? Thanks Stefan -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525
Depends on how you use your classes. If you have have a finite set of constructor methods you can use 'Refactor > Search code...' with something like this: RBParseTreeSearcher new matches: 'PluggableButtonMorph on: `@.arg1' do: [ :node :answer | node ]; matches: 'PluggableButtonMorph on: `@.arg1 getState: `@.arg2 action: `@.arg3' do: [ :node :answer | node ]; yourself Of course, if you put all your constructor methods into a distinct protocol, you could automate the creation of the searcher. Lukas On 15 January 2012 17:28, Stefan Marr <smalltalk@stefan-marr.de> wrote:
Hi:
When refactoring code, I frequently try to find all places where a class is instantiated. Is there anything in the image which would work a bit more precise than a search for the class name in the finder?
Thanks Stefan
-- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: Â +32 2 629 3525
-- Lukas Renggli www.lukas-renggli.ch
Hi Lukas: On 15 Jan 2012, at 17:46, Lukas Renggli wrote:
Depends on how you use your classes.
If you have have a finite set of constructor methods you can use 'Refactor > Search code...' with something like this:
RBParseTreeSearcher new matches: 'PluggableButtonMorph on: `@.arg1' do: [ :node :answer | node ]; matches: 'PluggableButtonMorph on: `@.arg1 getState: `@.arg2 action: `@.arg3' do: [ :node :answer | node ]; yourself Of course, if you put all your constructor methods into a distinct protocol, you could automate the creation of the searcher.
Hm, I should probably find out how to use that. But the code is old and not properly categorized, and all in all also not large enough to really worry. It is just one of those Sundays where these kind of little things are annoying ;) Thanks Stefan -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525
But I imagine that you can find these just looking at the users of the classes. The strength of RBPaserTreeSearcher is when you want to get a specific method invocation and rewrite it. Stefan why Shift+N is not enough for you? Stef
Depends on how you use your classes.
If you have have a finite set of constructor methods you can use 'Refactor > Search code...' with something like this:
RBParseTreeSearcher new matches: 'PluggableButtonMorph on: `@.arg1' do: [ :node :answer | node ]; matches: 'PluggableButtonMorph on: `@.arg1 getState: `@.arg2 action: `@.arg3' do: [ :node :answer | node ]; yourself
Of course, if you put all your constructor methods into a distinct protocol, you could automate the creation of the searcher.
Lukas
On 15 January 2012 17:28, Stefan Marr <smalltalk@stefan-marr.de> wrote:
Hi:
When refactoring code, I frequently try to find all places where a class is instantiated. Is there anything in the image which would work a bit more precise than a search for the class name in the finder?
Thanks Stefan
-- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525
-- Lukas Renggli www.lukas-renggli.ch
Hi: On 15 Jan 2012, at 19:06, Stéphane Ducasse wrote:
Stefan why Shift+N is not enough for you?
Shift+N? I assume you refer to cmd+n on a Mac, which gives me all senders. Well, senders of #new is not exactly helpful. Best regards Stefan -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525
On Sun, Jan 15, 2012 at 7:10 PM, Stefan Marr <smalltalk@stefan-marr.de>wrote:
Hi:
On 15 Jan 2012, at 19:06, Stéphane Ducasse wrote:
Stefan why Shift+N is not enough for you?
Shift+N? I assume you refer to cmd+n on a Mac, which gives me all senders.
No. cmd + shift + n gives you the list of references to a class.
Well, senders of #new is not exactly helpful.
Best regards Stefan
-- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525
-- Mariano http://marianopeck.wordpress.com
I've added a refactoring scope 'Refactoring Scope > Instantiations' that finds all the places where a method is sent to the selected class that eventually ends up in #basicNew or #basicNew:. If you don't use reflection this gives better and less false-positives than just the class references. Lukas On 15 January 2012 19:29, Mariano Martinez Peck <marianopeck@gmail.com> wrote:
On Sun, Jan 15, 2012 at 7:10 PM, Stefan Marr <smalltalk@stefan-marr.de> wrote:
Hi:
On 15 Jan 2012, at 19:06, Stéphane Ducasse wrote:
Stefan why Shift+N is not enough for you?
Shift+N? I assume you refer to cmd+n on a Mac, which gives me all senders.
No. cmd + shift + n gives you the list of references to a class.
Well, senders of #new is not exactly helpful.
Best regards Stefan
-- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: Â +32 2 629 3525
-- Mariano http://marianopeck.wordpress.com
-- Lukas Renggli www.lukas-renggli.ch
just keep in mind that some classes do not instantiating using #new -- Best regards, Igor Stasenko.
I've added a refactoring scope 'Refactoring Scope > Instantiations' that finds all the places where a method is sent to the selected class that eventually ends up in #basicNew or #basicNew:. If you don't use reflection this gives better and less false-positives than just the class references.
Ok this is what I wanted to know :)
On 15 Jan 2012, at 19:29, Mariano Martinez Peck wrote:
No. cmd + shift + n gives you the list of references to a class.
Thanks, that one is useful. Best regards Stefan -- Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525
participants (6)
-
Igor Stasenko -
Lawson English -
Lukas Renggli -
Mariano Martinez Peck -
Stefan Marr -
Stéphane Ducasse