Buggy structural replace?

I am trying to remove a parameter from all methods in my project. I have created a search pattern, which works when I use structural search. It looks like this:

class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$, $SessionUtil$ $sessionutil$){
$content$;
}
$classremain$;
}

Variables $content$ and $classremain$ are marked as (0..*) $SessionUtil$ has text=SessionUtil

The replace pattern looks like this:

class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$){
$content$;
}
$classremain$;
}

When I press 'Find' I get two hits (compared to 131 hits using structural search) and the buttons (do replace all, replace selected, etc) remains grayed out and inactive. If I change the cardinality of the $classremain$ to 1-1, I don't get the replacement I'm looking for, but the buttons do becomes active...

What am I doing wrong? Have I stumbled upon a bug?

5 comments
Comment actions Permalink

When replacement is about to be performed then occurence is whole
context matched (class in your example), when search is done then
occurence is some variable (e.g. MethodName)

Jesper Thuun-Petersen wrote:

I am trying to remove a parameter from all methods in my project. I have created a search pattern, which works when I use structural search. It looks like this:

class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$, $SessionUtil$ $sessionutil$){
$content$;
}
$classremain$;
}

Variables $content$ and $classremain$ are marked as (0..*) $SessionUtil$ has text=SessionUtil

The replace pattern looks like this:

class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$){
$content$;
}
$classremain$;
}

When I press 'Find' I get two hits (compared to 131 hits using structural search) and the buttons (do replace all, replace selected, etc) remains grayed out and inactive. If I change the cardinality of the $classremain$ to 1-1, I don't get the replacement I'm looking for, but the buttons do becomes active...

What am I doing wrong? Have I stumbled upon a bug?



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

0
Comment actions Permalink

I'm sorry, but I didn't quite get your point. Could you please elaborate on that, like, what am I supposed to be doing?

0
Comment actions Permalink

Hi,

I mean that one can get different number of occurences during search and
replace (if search pattern has some variable selected as 'target of the
search').

Please provide more info on IDEA version used and some steps on
reproduction of the problem (I was unable to reproduce just using
similar replace)

Jesper Thuun-Petersen wrote:

I'm sorry, but I didn't quite get your point. Could you please elaborate on that, like, what am I supposed to be doing?



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

0
Comment actions Permalink

Here's a testclass for which I have reproduced the problem:

+public class TestStructuralReplace {

public void testA(int a, String s){
}

public int testB(boolean b, String s, float q){
return 0;
}

public boolean testC(String s){
return false;
}

public void testD(String s, int c, boolean d){
}
}
+

I would like to remove all parameters of type String from all methods. Therefore I have a search/replace-pattern like this:

+class $Class$ {
$remainingclass$;
$ReturnType$ $MethodName$($ParameterType$ $Parameter$, $removeParmType$ $removeParm$){
$content$;
}
}

class $Class$ {
$remainingclass$;
$ReturnType$ $MethodName$($ParameterType$ $Parameter$){
$content$;
}+
}
class is 1-1, remainingclass 0-, returntype, methodname is 1-. Parametervars is 0-, and the removeparm is 1-, and removeparmtype has pattern like String.

Behavior: all buttons are rendered inactive, but I get a single hit, although I would have assumed at least two.

0
Comment actions Permalink

Hi,

When Replace searches for match it find occurences of complete search
pattern (and thus you get one hit).
You seems got exception during finding match/building replacement (I got
this exeption too) and the exception disabled the buttons.

Jesper Thuun-Petersen wrote:

Here's a testclass for which I have reproduced the problem:

+public class TestStructuralReplace {

public void testA(int a, String s){
}

public int testB(boolean b, String s, float q){
return 0;
}

public boolean testC(String s){
return false;
}

public void testD(String s, int c, boolean d){
}
}
+

I would like to remove all parameters of type String from all methods. Therefore I have a search/replace-pattern like this:

+class $Class$ {
$remainingclass$;
$ReturnType$ $MethodName$($ParameterType$ $Parameter$, $removeParmType$ $removeParm$){
$content$;
}
}

class $Class$ {
$remainingclass$;
$ReturnType$ $MethodName$($ParameterType$ $Parameter$){
$content$;
}+
}
class is 1-1, remainingclass 0-, returntype, methodname is 1-. Parametervars is 0-, and the removeparm is 1-, and removeparmtype has pattern like String.

Behavior: all buttons are rendered inactive, but I get a single hit, although I would have assumed at least two.



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

0

Please sign in to leave a comment.