Structural Search: Searching for a code snippet

I have snippets of code in various parts of my project that look like this:

Node parent = currentNode.getParent();
if (parent == null || !parent.isComposite()) {
// do stuff
}

I would like to find and replace these snippets with this:

if (currentNode.isOuter()) {
// do stuff
}

However, the following search template is not finding the snippet:

Node $parent$ = $node$.getParent();
if ($parent$ == null || !$parent$.isComposite()) {
$stuff$
}

Where $parent$ has the default settings, $node$ has a type hierarchy
expression of "Node" and $stuff$ has min 0, max 100000.

Why is the template not working?

Ciao,
Gordon

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

4 comments

Hi,
Please, give exact sample code for which the problem appears.

Gordon Tyler wrote:

I have snippets of code in various parts of my project that look like this:

Node parent = currentNode.getParent();
if (parent == null || !parent.isComposite()) {
// do stuff
}

I would like to find and replace these snippets with this:

if (currentNode.isOuter()) {
// do stuff
}

However, the following search template is not finding the snippet:

Node $parent$ = $node$.getParent();
if ($parent$ == null || !$parent$.isComposite()) {
$stuff$
}

Where $parent$ has the default settings, $node$ has a type hierarchy
expression of "Node" and $stuff$ has min 0, max 100000.

Why is the template not working?

Ciao,
Gordon



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

0

Hi, try following (; after $stuff to dentote statements)

Node $parent$ = $node$.getParent();
if ($parent$ == null || !$parent$.isComposite()) {
$stuff$;
}

0

Maxim Mossienko wrote:

Hi, try following (; after $stuff to dentote statements)

Node $parent$ = $node$.getParent();
if ($parent$ == null || !$parent$.isComposite()) {
$stuff$;
}


Nope, doesn't work.

My exact search template is:

SemanticRequestNode $parent$ = $node$.getParent();
if ($parent$ == null || !$parent$.isComposite()) {
$stuff$;
}

And one of the occurrences that I want to find looks like this:

SemanticRequestNode parent = srNode.getParent();
if (parent == null || !parent.isComposite()) {
// for outer nodes we need to adjust for the location indicator
textWidth += LayoutConstants.LOCATION_INDICATOR_WIDTH;
}

Thanks,
Gordon

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

0

Hi,

Ok, does it work without comment?

Gordon Tyler wrote:

Maxim Mossienko wrote:

>> Hi, try following (; after $stuff to dentote statements)
>>
>> Node $parent$ = $node$.getParent();
>> if ($parent$ == null || !$parent$.isComposite()) {
>> $stuff$;
>> }


Nope, doesn't work.

My exact search template is:

SemanticRequestNode $parent$ = $node$.getParent();
if ($parent$ == null || !$parent$.isComposite()) {
$stuff$;
}

And one of the occurrences that I want to find looks like this:

SemanticRequestNode parent = srNode.getParent();
if (parent == null || !parent.isComposite()) {
// for outer nodes we need to adjust for the location indicator
textWidth += LayoutConstants.LOCATION_INDICATOR_WIDTH;
}

Thanks,
Gordon



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

0

Please sign in to leave a comment.