Structural Replace: Indicate subset of search template to replace

Hi,

I've used Structural Search and Replace a few times and have read in
this forum about some of the difficulties other people have had. It
recently occurred to me that since the search template often requires
extra "context" to be able to find what you're looking for, it might be
useful if one could indicate what subset of the search template should
be replaced by the replacement template. For example:

Search template:
class $class$ {
$<$FooBar $field$;$>$
}

Replacement template:
FooBar $field$ = FooBar.create();

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://java.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

1 comment
Comment actions Permalink

Hi,

Replacement context always equals to context the match of the search
pattern. This is adequate for the replacement of expression or statement.
However, for class related replacements (btw, they are in the process of
maturing) this requirement means adding some variable which matches
insignificant class content to search pattern and explicit mentioning it
in the replacement pattern. In another words:

Search template:
class $class$ {
$FieldType$ $Field$;
$OtherClassContent$; // this matches all class content (fields,
methods, etc) that is not important for replacement
}

Replacement content:
class $class$ {
$FieldType$ $Field$ = $FieldType$.create();
$OtherClassContent$; // Insignificant class content is inserted
}


Gordon Tyler wrote:

Hi,

I've used Structural Search and Replace a few times and have read in
this forum about some of the difficulties other people have had. It
recently occurred to me that since the search template often requires
extra "context" to be able to find what you're looking for, it might be
useful if one could indicate what subset of the search template should
be replaced by the replacement template. For example:

Search template:
class $class$ {
$<$FooBar $field$;$>$
}

Replacement template:
FooBar $field$ = FooBar.create();

Ciao,
Gordon



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0

Please sign in to leave a comment.