Yet another structural search question

Hi,
I'm trying to search for some code in a for loop, so I have
for($init$;$cond$;$post$) {
$expr1$; (0 to unlimited)
$var$ = $var$.add($arg$); // var is of type BigDecimal
$expr2$; (0 to unlimited)
}

This works fine for code like this
BigDecimal bd = BigDecimal.ZERO;
for(int i=0;i<10;i++) {
System.out.println(i);
bd = bd.add (new BigDecimal(i));
}

But it doesn't find code like this
BigDecimal bd = BigDecimal.ZERO;
for(int i=0;i<10;i++) {
System.out.println(i);
if (i<5)
bd = bd.add (new BigDecimal(i));
else
// something else
}
or even this
BigDecimal bd = BigDecimal.ZERO;
for(int i=0;i<10;i++) {
{
System.out.println(i);
bd = bd.add (new BigDecimal(i));
}
}

Am I structuring my search wrong or is this a limitation of the search?

Thanks for your help,
R
PS Perhaps there should be another forum for SSR requests ;)

1 comment

Hi,

$var$ = $var$.add($arg$); is matched as loop body statement (and thus
right now it is limitation of the SS).
We plan to add possibility to find something (not) within / contained in
another pattern match.

Robert Gibson wrote:

Hi,
I'm trying to search for some code in a for loop, so I have
for($init$;$cond$;$post$) {
$expr1$; (0 to unlimited)
$var$ = $var$.add($arg$); // var is of type BigDecimal
$expr2$; (0 to unlimited)
}

This works fine for code like this
BigDecimal bd = BigDecimal.ZERO;
for(int i=0;i<10;i++) {
System.out.println(i);
bd = bd.add (new BigDecimal(i));
}

But it doesn't find code like this
BigDecimal bd = BigDecimal.ZERO;
for(int i=0;i<10;i++) {
System.out.println(i);
if (i<5)
bd = bd.add (new BigDecimal(i));
else
// something else
}
or even this
BigDecimal bd = BigDecimal.ZERO;
for(int i=0;i<10;i++) {
{
System.out.println(i);
bd = bd.add (new BigDecimal(i));
}
}

Am I structuring my search wrong or is this a limitation of the search?

Thanks for your help,
R
PS Perhaps there should be another forum for SSR requests ;)



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

0

Please sign in to leave a comment.