Files
openide/java/java-impl/resources/inspectionDescriptions/DuplicateExpressions.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

28 lines
1.7 KiB
HTML

<html>
<body>
Reports multiple equivalent occurrences of the same expression within a method (or constructor, or class initializer)
if the result of the expression can be reused.
<p>
The expression is reported if it's free of side effects and its result is always the same (in terms of <code>Object.equals()</code>).
The examples of such expressions are <code>a + b</code>, <code>Math.max(a, b)</code>, <code>a.equals(b)</code>,
<code>s.substring(a,b)</code>. To make sure the result is always the same, it's verified that the variables used in the expression don't
change their values between the occurrences of the expression.</p>
<p>
Such expressions may contain methods of immutable classes like <code>String</code>, <code>BigDecimal</code>, and so on,
and of utility classes like <code>Objects</code>, <code>Math</code> (except <code>random()</code>).
The well-known methods, such as <code>Object.equals()</code>, <code>Object.hashCode()</code>, <code>Object.toString()</code>,
<code>Comparable.compareTo()</code>, and <code>Comparator.compare()</code> are OK as well because they normally don't have
any observable side effects.
</p>
<!-- tooltip end -->
<p>
Use the <b>Expression complexity threshold</b> option to specify the minimal expression complexity threshold. Specifying bigger
numbers will remove reports on short expressions.
</p>
<p>
<code>Path.of</code> and <code>Paths.get</code> calls are treated as equivalent calls if they have the same arguments. These calls
are always reported no matter how complex their arguments are. This behaviour can be tweaked using different complexity threshold.
</p>
<p><small>New in 2018.3</small></p>
</body>
</html>