Structural Replace - Replacing constructor with factory method

Hi

I wanted to replace all occurrences of new Foo("test") with a call of the existing method Foo.create("test").

I tried

Find: new Foo($1$)
Replace: Foo.create($1$)

But this ended up as new Foo(Foo.create("test))

Can someone help me on this, i.e. explain to me what I'm doing wrong and how I can fix it.

Thanks!

--Etienne

2 comments
Comment actions Permalink

Just in case you're not aware of this, there is a "replace constructor
with factory method" refactoring already.

If you still want to do this using structural replace (maybe it's more
flexible in some way?), I'm afraid I can't help you -- I've never really
used it.

0
Comment actions Permalink

Yes, thanks, I'm aware of the built-in refactoring for this but would still like to understand how I can make this work using the Structural Search/Replace feature.

0

Please sign in to leave a comment.