Problem with searh and replace patterns
I've made the following search pattern
$param$ > $value1$ && $param$ < $value2$
and replace pattern
$param$.InRange($value1$, $value2$);
where param is of identifier type and value1, value2 are of expression type.
This pattern should work with the statements like
if(someInt > 1 && someInt < 10) and replace them with someInt.InRange(1, 10).
It works correctly in this case and with similar constructions. But the problem occurs when we have more than one condition in if-section.
I mean the following situation:
if(someInt > 1 && someInt < 10 && anotherInt > 1 && anotherInt < 10).
Search pattern works correctly for this statement. It recognizes two parts of the condition (someInt > 1 && someInt < 10 and this anotherInt > 1 && anotherInt < 10).
While ReSharper suggests that I replace the first part of condition with someInt.InRange(1, 10) and the second one with anotherInt.InRange(1, 10).
If I follow this suggestion and replace the first part via ReSharper everything is alright and the final condition looks this way:
if(someInt.InRange(1, 10) && anotherInt > 1 && anotherInt < 10).
But if I replace the second part I lose the first one. I mean final condition looks this way:
if(anotherInt.InRange(1, 10)).
While I expect it to look the following way:
if(someInt > 1 && someInt < 10 && anotherInt.InRange(1, 10)).
I can’t also fix the problem when I put parentheses around each expression: I lose the first part in this case too :(
Could you please tell me what is wrong with my patterns?
Please sign in to leave a comment.
This looks like a bug, rather than anything wrong with the pattern. I've raised an issue for you to track and vote for: http://youtrack.jetbrains.com/issue/RSRP-416198
Actually - quick idea, not expecting it to work - does the replace pattern end with a semi-colon? If so, remove that and see if it makes any difference.
thank you for your answer. i've just tried to remove semicolon but nothing has changed