Files
Mathiasandintellij-monorepo-bot 7dd10b82b1 IDEA-380160 java: Add an inspection for Math.clamp()
For what it should have been, the final code feels a bit over-engineered.

GitOrigin-RevId: 893e1fb82670568ef3fbf5106b132e4891b276cf
2026-02-13 13:37:41 +00:00

24 lines
777 B
HTML

<html>
<body>
Reports combinations of <code>Math.max()</code> and <code>Math.min()</code> that are equivalent to <code>Math.clamp()</code>.
<p>
Example:
</p>
<pre><code>
int min = 5, max = 10;
/*before*/ input = Math.max(Math.min(max, input), min);
/*after*/ input = Math.clamp(input, min, max);
</code></pre>
<!-- tooltip end -->
<p>
By default, the inspection only shows when it can statically prove that <code>min</code> is lesser or equal than <code>max</code>.
This is done to avoid any <code>IllegalArgumentException</code> due to semantics changes.
If you want the inspection to show up nonetheless, you can enable the <b>Warn even if the lower bound could be higher than the upper
bound</b> option.
</p>
<p><small>New in 2026.1</small></p>
</body>
</html>