[java] Inspection description updated

GitOrigin-RevId: 264a3590ff70d79e5645d7a5ac7c804541bc4bb2
This commit is contained in:
Tagir Valeev
2021-03-15 08:48:05 +00:00
committed by intellij-monorepo-bot
parent a4b98111b1
commit fc089ebcb2
8 changed files with 140 additions and 27 deletions
@@ -1,7 +1,33 @@
<html>
<body>
Reports <code>switch</code> statements which can be replaced with an enhanced <code>switch</code> statement or expression.
Reports <code>switch</code> statements which can be automatically replaced with an enhanced <code>switch</code> statement or expression.
<p>Example:</p>
<pre>
double getPrice(String fruit) {
// Switch statement can be replaced with enhanced 'switch'
switch (fruit) {
case "Apple":
return 1.0;
case "Orange":
return 1.5;
case "Mango":
return 2.0;
default:
throw new IllegalArgumentException();
}
}
</pre>
<p>After the quick-fix is applied, the code will look like this:</p>
<pre>
double getPrice(String fruit) {
return switch (fruit) {
case "Apple" -> 1.0;
case "Orange" -> 1.5;
case "Mango" -> 2.0;
default -> throw new IllegalArgumentException();
};
}
</pre>
<!-- tooltip end -->
<p>This inspection only applies to language level 14 or higher</p>
<p><small>New in 2019.1</small></p>
@@ -1,12 +1,19 @@
<html>
<body>
Reports the Java code constructs that may fail to compile in future Java versions. The following problems are reported:
Reports the Java code constructs that may fail to compile in future Java versions.
The following problems are reported:
<ul>
<li>Use of 'assert', 'enum' or '_' as an identifier</li>
<li>Use of restricted keyword 'var' as a type name</li>
<li>Use of restricted identifier 'var', 'yield', or 'record' as a type name</li>
<li>Unqualified calls to method named 'yield'</li>
<li>Modifiers on 'requires java.base' statement inside module-info.java</li>
</ul>
<p>Example:</p>
<pre>
// Since Java 14, this class will stop compiling, as 'yield' becomes a restricted identifier.
public class yield {}
</pre>
<p>Fixing these issues timely may simplify migration to future Java versions.</p>
<!-- tooltip end -->
</body>
</html>
@@ -1,12 +1,46 @@
<html>
<body>
Finds Stream API chains, <b>Iterable.forEach</b> and <b>Map.forEach</b> calls and provides quick fix to convert them into classical loops.
Reports Stream API chains, <code>Iterable.forEach</code> and <code>Map.forEach</code> calls that can be automatically converted into classical loops.
<p>Example:</p>
<pre>
String joinNonEmpty(List&lt;String&gt; list) {
return list.stream() // Stream can be converted to loop
.filter(s -> !s.isEmpty())
.map(String::trim)
.collect(Collectors.joining(", "));
}
</pre>
<p>After the fix is applied, the result will be like this:</p>
<pre>
String joinNonEmpty(List&lt;String&gt; list) {
StringJoiner joiner = new StringJoiner(", ");
for (String s : list) {
if (!s.isEmpty()) {
String trim = s.trim();
joiner.add(trim);
}
}
return joiner.toString();
}
</pre>
<p>
Note that sometimes this inspection might cause slight semantic changes.
Special care should be taken when it comes to short-circuiting, as it's not specified how many elements will be actually read when
the stream short-circuits.
</p>
<!-- tooltip end -->
<p>Use checkbox below to suggest conversions for streams with unrecognized source. In this case, iterator will be created from the stream.
For example, when checkbox is checked, the conversion will be suggested here:</p>
<pre>
List&lt;ProcessHandle&gt; handles = ProcessHandle.allProcesses().collect(Collectors.toList());</pre>
<p>In this case, the result will be like this:</p>
<pre>
List&lt;ProcessHandle&gt; handles = new ArrayList<>();
for (Iterator&lt;ProcessHandle&gt; it = ProcessHandle.allProcesses().iterator(); it.hasNext(); ) {
ProcessHandle allProcess = it.next();
handles.add(allProcess);
}
</pre>
<p><small>New in 2017.1</small></p>
</body>
</html>
@@ -1,10 +1,15 @@
<html>
<body>
Reports conditional expressions of the form
<b>true?<i>result1</i>:<i>result2</i></b> or <b>false?<i>result1</i>:<i>result2</i></b>.
Reports conditional expressions where the condition is either <code>true</code> or <code>false</code> constant.
These expressions sometimes occur as the result of automatic refactorings, and may obviously be simplified.
<p>Example:</p>
<pre>
return true ? "Yes" : "No";
</pre>
<p>After quick-fix is applied, the result will be</p>
<pre>
return "Yes";
</pre>
<!-- tooltip end -->
<p>
</body>
</html>
@@ -1,9 +1,16 @@
<html>
<body>
Reports double negation.
<p>
For example:
<pre><code><b>if</b> (!!functionCall())</code></pre>
Reports double negation that can be simplified.
<p>Examples:</p>
<pre>
if (!!functionCall()) {} // double negation
if (!(a != b)) {} // double negation
</pre>
<p>After quick-fix is applied, the result will be</p>
<pre>
if (functionCall()) {}
if (a == b) {}
</pre>
<!-- tooltip end -->
<p>
@@ -1,9 +1,9 @@
<html>
<body>
Reports empty <b>try</b> blocks.
Reports empty <code>try</code> blocks, including try-with-resources statements.
<!-- tooltip end -->
<p>
At present, this inspection is disabled in JSP files.
This inspection does not report in JSP files.
<p>
</body>
@@ -1,18 +1,31 @@
<html>
<body>
Reports <b>for</b> loops which iterate
over collections or arrays, and can be replaced with an enhanced <b>for</b> loop (i.e. the foreach iteration syntax).
Reports <code>for</code> loops that iterate over collections or arrays,
and can be automatically replaced with an enhanced <code>for</code> loop (i.e. the foreach iteration syntax).
<!-- 'foreach' still used in this description so that the inspection continues to be found using this keyword -->
<p>Example:</p>
<pre>
for (Iterator&lt;String&gt; iterator = list.iterator(); iterator.hasNext(); ) {
String item = iterator.next();
System.out.println(item);
}
</pre>
<p>After the quick-fix is applied the result looks like:</p>
<pre>
for (String item : list) {
System.out.println(item);
}
</pre>
<!-- tooltip end -->
<p>
Use the first checkbox below to find loops involving <b>list.get(index)</b> calls.
These loops generally can be replaced with an enhanced <b>for</b> loop, unless they modify underlying list in the process, e.g. by calling <b>list.remove(index)</b>.
If latter is the case, the enhanced <b>for</b> loop may throw <b>ConcurrentModificationException</b>.
Use the first checkbox below to find loops involving <code>list.get(index)</code> calls.
These loops generally can be replaced with an enhanced <code>for</code> loop,
unless they modify underlying list in the process, e.g. by calling <code>list.remove(index)</code>.
If latter is the case, the enhanced <code>for</code> loop may throw <code>ConcurrentModificationException</code>.
Also, in some cases, <code>list.get(index)</code> loops may work a little bit faster.
<p>
Use the second checkbox below to ignore collections which do not have type parameters. This prevents the creation of
enhanced <b>for</b> loop variables of type <b>java.lang.Object</b> and the insertion of casts where the loop variable is used.
Use the second checkbox below to ignore collections which do not have type parameters. This prevents the creation of
enhanced <code>for</code> loop variables of type <code>java.lang.Object</code> and the insertion of casts where the loop variable is used.
<p>This inspection only reports if the language level of the project or module is 5 or higher</p>
<p>
</body>
</html>
@@ -1,9 +1,30 @@
<html>
<body>
Reports any calls to <b>Throwable.initCause()</b> where the exception constructor also takes a <b>Throwable</b> cause argument.
In this case the <b>initCause()</b> call can be removed and its argument added to the call to the exception's constructor.
Reports any calls to <code>Throwable.initCause()</code> where the exception constructor also takes a <code>Throwable</code> cause argument.
In this case, the <code>initCause()</code> call can be removed and its argument added to the call to the exception's constructor.
<p>Example:</p>
<pre>
try {
process();
}
catch (RuntimeException ex) {
RuntimeException wrapper = new RuntimeException("Error while processing");
wrapper.initCause(ex); // Unnecessary call to 'Throwable.initCause()'
throw wrapper;
}
</pre>
<p>A quick-fix is provided to pass the cause to constructor:</p>
<pre>
try {
process();
}
catch (RuntimeException ex) {
RuntimeException wrapper = new RuntimeException("Error while processing", ex);
throw wrapper;
}
</pre>
<!-- tooltip end -->
<p>
<small>New in 16</small>
<small>New in 2016.1</small>
</body>
</html>