Why does Structural Search find some of `(int) ($expr$ + 0.5f)`, but not all?

已回答

I'm trying to use Structural Search to replace a rounding anti-pattern with the correct pattern. I'm searching for:

(int) ($expr$ + 0.5f)

in order to replace it with:

Math.round($expr$)

Strangely, that search pattern finds most of the instances of the anti-pattern, but not all, and I can't see any difference. Here are two it doesn't find:

But just a few lines above, it had no problem with this expression:

return (int) (getHeight(x, y) + 0.5f);

or a few lines below with this expression:

if (((tallWaterLevel[xx + yy * TILE_SIZE]) > ((int) (tallHeightMap[xx + yy * TILE_SIZE] / 256f + 0.5f)))

nor with dozens of other similar instances in the codebase. I don't see the difference.

What's going on? Why doesn't it find the expressions in that screenshot? What's the difference, and how do I make it find them?

1

How did you define $expr$? Please share a sample project to reproduce and provide the exact settings for all the SSR aspects.

0

What do you mean by "define"? There are no filters on it as you can see. Nor did I change any SSR settings from the defaults.

I was hoping it would a simple matter of a lack of understanding on my part, but you seem to be implying that this is a bug. I'll see what I can do about creating a sample project to reproduce.

0

OK, I see that you don't have any filters. Please share the sample file where we can reproduce the issue: https://uploads.jetbrains.com.

0

So in that screenshot you see no reason why that search pattern would not match the two indicated expressions?

0

请先登录再写评论。