"Useless" word is replaced with "redundant" or other alternatives

This commit is contained in:
Tagir Valeev
2018-06-22 12:39:20 +07:00
parent 48b238f2e8
commit 20b6cba1d5
16 changed files with 47 additions and 44 deletions
@@ -39,9 +39,9 @@ public class ObviousNullCheckInspection extends AbstractBaseJavaLocalInspectionT
String explanation = getObviouslyNonNullExplanation(nullArg);
if (explanation == null) return;
if(nullCheckParameter.myNull) {
holder.registerProblem(nullArg, InspectionsBundle.message("inspection.useless.null.check.always.fail.message", explanation));
holder.registerProblem(nullArg, InspectionsBundle.message("inspection.redundant.null.check.always.fail.message", explanation));
} else {
holder.registerProblem(nullArg, InspectionsBundle.message("inspection.useless.null.check.message", explanation),
holder.registerProblem(nullArg, InspectionsBundle.message("inspection.redundant.null.check.message", explanation),
new RemoveNullCheckFix());
}
}
@@ -110,7 +110,7 @@ public class ObviousNullCheckInspection extends AbstractBaseJavaLocalInspectionT
@NotNull
@Override
public String getFamilyName() {
return InspectionsBundle.message("inspection.useless.null.check.fix.family.name");
return InspectionsBundle.message("inspection.redundant.null.check.fix.family.name");
}
@Override
@@ -155,8 +155,10 @@ public class RedundantStreamOptionalCallInspection extends AbstractBaseJavaLocal
if ("toSet".equals(furtherCallName) || "toCollection".equals(furtherCallName)) {
additionalFix = new CollectToOrderedSetFix();
}
register(call, InspectionsBundle.message("inspection.redundant.stream.optional.call.explanation.sorted", furtherCallName),
additionalFix);
String message = "sorted".equals(furtherCallName) ?
InspectionsBundle.message("inspection.redundant.stream.optional.call.explanation.sorted.twice") :
InspectionsBundle.message("inspection.redundant.stream.optional.call.explanation.sorted", furtherCallName);
register(call, message, additionalFix);
}
}
break;
@@ -3,7 +3,7 @@
Reports method references mapped to Comparator interface which don't fulfill its contract.
<p>
Some method references like <code>Integer::max</code> can be mapped to <code>Comparator</code> interface.
However using them as <code>Comparator</code> is useless and result might be unpredictable.
However using them as <code>Comparator</code> is meaningless and result might be unpredictable.
</p>
<!-- tooltip end -->
<p><small>New in 2016.3</small></p>
@@ -1,11 +1,11 @@
<html>
<body>
Reports useless Stream or Optional calls like <code>map(x -> x)</code> or <code>filter(x -> true)</code>,
useless <code>sorted</code> or <code>distinct</code>.
Reports redundant Stream or Optional calls like <code>map(x -> x)</code> or <code>filter(x -> true)</code>,
redundant <code>sorted</code> or <code>distinct</code>.
<p>Note that a mapping operation in code like <code>streamOfIntegers.map(Integer::valueOf)</code> works as <code>requireNonNull</code>
check:
if stream contains a <code>null</code>, it will throw <code>NullPointerException</code>, thus it's not absolutely useless. Uncheck the
"Report useless boxing in Stream.map" checkbox if you don't want such cases to be reported.</p>
if stream contains a <code>null</code>, it will throw <code>NullPointerException</code>, thus it's not absolutely redundant. Uncheck the
"Report redundant boxing in Stream.map" checkbox if you don't want such cases to be reported.</p>
<!-- tooltip end -->
<p>This inspection only reports if the project or module is configured to use a language level of 8 or higher.</p>
<p><small>New in 2017.1</small></p>
@@ -7,21 +7,21 @@ abstract class ObviousNullCheck {
abstract String getBar();
void test(String param) {
assertNotNull(<warning descr="Useless null-check: a value of primitive type is never null">5 + 6</warning>);
assertNotNull(<warning descr="Redundant null-check: a value of primitive type is never null">5 + 6</warning>);
assertNull("Null!", param);
assertNull(param, <warning descr="Null-check will always fail: literal is never null">"Null!"</warning>);
Objects.requireNonNull(null);
Objects.requireNonNull(<warning descr="Useless null-check: literal is never null">"xyz"</warning>, "xyz");
Objects.requireNonNull((<warning descr="Useless null-check: concatenation is never null">getFoo() + getBar()</warning>));
Objects.requireNonNull(<warning descr="Useless null-check: newly created object is never null">new ArrayList()</warning>, "new returned null");
Objects.requireNonNull(<warning descr="Useless null-check: this object is never null">this</warning>);
Objects.requireNonNull(<warning descr="Redundant null-check: literal is never null">"xyz"</warning>, "xyz");
Objects.requireNonNull((<warning descr="Redundant null-check: concatenation is never null">getFoo() + getBar()</warning>));
Objects.requireNonNull(<warning descr="Redundant null-check: newly created object is never null">new ArrayList()</warning>, "new returned null");
Objects.requireNonNull(<warning descr="Redundant null-check: this object is never null">this</warning>);
String s = Objects.requireNonNull(<warning descr="Useless null-check: literal is never null">" x "</warning>);
String s = Objects.requireNonNull(<warning descr="Redundant null-check: literal is never null">" x "</warning>);
String s1 = trim(" x ");
System.out.println(inferred(<warning descr="Useless null-check: literal is never null">"foo"</warning>));
System.out.println(inferred(<warning descr="Redundant null-check: literal is never null">"foo"</warning>));
}
@Contract(value="null -> fail", pure=true)
@@ -1,4 +1,4 @@
// "Remove useless null-check" "true"
// "Remove redundant null-check" "true"
import java.util.*;
public class Test {
@@ -1,4 +1,4 @@
// "Remove useless null-check" "true"
// "Remove redundant null-check" "true"
import java.util.*;
public class Test {
@@ -1,4 +1,4 @@
// "Remove useless null-check" "true"
// "Remove redundant null-check" "true"
import java.util.*;
public class Test {
@@ -1,4 +1,4 @@
// "Remove useless null-check" "true"
// "Remove redundant null-check" "true"
import java.util.*;
public class Test {
@@ -1,4 +1,4 @@
// "Remove useless null-check" "true"
// "Remove redundant null-check" "true"
import java.util.*;
public class Test {
@@ -1,4 +1,4 @@
// "Remove useless null-check" "true"
// "Remove redundant null-check" "true"
import java.util.*;
public class Test {
@@ -3,12 +3,12 @@ import java.util.stream.*;
public class RedundantStreamOptionalCall {
public void test() {
List<Integer> list = Stream.of(1, 2, 3).<warning descr="Redundant 'sorted' call: subsequent 'sorted' call makes sorting useless">sorted(Comparator.reverseOrder())</warning>
List<Integer> list = Stream.of(1, 2, 3).<warning descr="Redundant 'sorted' call: stream content is sorted again after that">sorted(Comparator.reverseOrder())</warning>
.filter(x -> x > 0).sorted().collect(Collectors.toList());
if(Stream.of(1, 2, 3).<warning descr="Redundant 'sorted' call: subsequent 'allMatch' call makes sorting useless">sorted()</warning>.filter(x -> x > 0).allMatch(x -> x < 10)) {
if(Stream.of(1, 2, 3).<warning descr="Redundant 'sorted' call: subsequent 'allMatch' call doesn't depend on the sort order">sorted()</warning>.filter(x -> x > 0).allMatch(x -> x < 10)) {
return;
}
if(Stream.of("foo", "bar", "baz").<warning descr="Redundant 'sorted' call: subsequent 'count' call makes sorting useless">sorted(String.CASE_INSENSITIVE_ORDER)</warning>.count() > 0) {
if(Stream.of("foo", "bar", "baz").<warning descr="Redundant 'sorted' call: subsequent 'count' call doesn't depend on the sort order">sorted(String.CASE_INSENSITIVE_ORDER)</warning>.count() > 0) {
return;
}
long first = Stream.of(1, 2, 3).distinct().sorted().skip(1).limit(2).<warning descr="Redundant 'distinct' call: there already was a 'distinct' call in the chain">distinct()</warning>
@@ -44,15 +44,15 @@ public class RedundantStreamOptionalCall {
Collection<String> collection = Arrays.asList("foo", "foo", "bar");
Set<String> set1 = collection.stream().<warning descr="Redundant 'distinct' call: elements will be distinct anyways when collected to the Set">distinct()</warning>.collect(Collectors.toSet());
Set<String> set2 = collection.stream().<warning descr="Redundant 'sorted' call: subsequent 'toSet' call makes sorting useless">sorted()</warning>.collect(Collectors.toSet());
Set<String> set3 = collection.stream().<warning descr="Redundant 'sorted' call: subsequent 'toSet' call makes sorting useless">sorted()</warning>.<warning descr="Redundant 'distinct' call: elements will be distinct anyways when collected to the Set">distinct()</warning>.collect(Collectors.toSet());
Set<String> set4 = collection.stream().<warning descr="Redundant 'distinct' call: elements will be distinct anyways when collected to the Set">distinct()</warning>.<warning descr="Redundant 'sorted' call: subsequent 'toSet' call makes sorting useless">sorted()</warning>.collect(Collectors.toSet());
Set<String> set2 = collection.stream().<warning descr="Redundant 'sorted' call: subsequent 'toSet' call doesn't depend on the sort order">sorted()</warning>.collect(Collectors.toSet());
Set<String> set3 = collection.stream().<warning descr="Redundant 'sorted' call: subsequent 'toSet' call doesn't depend on the sort order">sorted()</warning>.<warning descr="Redundant 'distinct' call: elements will be distinct anyways when collected to the Set">distinct()</warning>.collect(Collectors.toSet());
Set<String> set4 = collection.stream().<warning descr="Redundant 'distinct' call: elements will be distinct anyways when collected to the Set">distinct()</warning>.<warning descr="Redundant 'sorted' call: subsequent 'toSet' call doesn't depend on the sort order">sorted()</warning>.collect(Collectors.toSet());
List<String> list1 = collection.stream().distinct().collect(Collectors.toList());
List<String> list2 = collection.stream().sorted().collect(Collectors.toList());
Map<Integer, String> map1 = collection.stream().<warning descr="Redundant 'sorted' call: subsequent 'toMap' call makes sorting useless">sorted()</warning>.collect(Collectors.toMap(Integer::valueOf, x -> x));
Map<Integer, String> map1 = collection.stream().<warning descr="Redundant 'sorted' call: subsequent 'toMap' call doesn't depend on the sort order">sorted()</warning>.collect(Collectors.toMap(Integer::valueOf, x -> x));
Map<Integer, String> map2 = collection.stream().sorted().collect(Collectors.toMap(Integer::valueOf, x -> x, (a,b) ->a, LinkedHashMap::new));
Set<String> set5 = collection.stream().<warning descr="Redundant 'sorted' call: subsequent 'toCollection' call makes sorting useless">sorted()</warning>.collect(Collectors.toCollection(HashSet::new));
Set<String> set6 = collection.stream().<warning descr="Redundant 'sorted' call: subsequent 'toCollection' call makes sorting useless">sorted()</warning>.collect(Collectors.toCollection(() -> new HashSet<>()));
Set<String> set5 = collection.stream().<warning descr="Redundant 'sorted' call: subsequent 'toCollection' call doesn't depend on the sort order">sorted()</warning>.collect(Collectors.toCollection(HashSet::new));
Set<String> set6 = collection.stream().<warning descr="Redundant 'sorted' call: subsequent 'toCollection' call doesn't depend on the sort order">sorted()</warning>.collect(Collectors.toCollection(() -> new HashSet<>()));
Set<String> set6a = collection.stream().sorted().collect(Collectors.toCollection(() -> new LinkedHashSet<>()));
Set<String> set7 = collection.stream().<warning descr="Redundant 'distinct' call: elements will be distinct anyways when collected to the Set">distinct()</warning>.collect(Collectors.toCollection(HashSet::new));
Set<String> set8 = collection.stream().<warning descr="Redundant 'distinct' call: elements will be distinct anyways when collected to the Set">distinct()</warning>.collect(Collectors.toCollection(() -> new HashSet<>()));
@@ -64,12 +64,12 @@ public class RedundantStreamOptionalCall {
Stream.of("foo").flatMap(x -> Stream.of(x, x)).parallel();
Stream.of("foo").flatMap(x -> Stream.of(x, x)).<warning descr="Redundant 'parallel' call: stream created from single element will not be parallelized">parallel()</warning>.forEach(System.out::println);
Stream.of("foo", "bar", "baz").<warning descr="Redundant 'sorted' call: subsequent 'sorted' call makes sorting useless">sorted()</warning>.sorted(Comparator.<String>naturalOrder().reversed());
Stream.of("foo", "bar", "baz").<warning descr="Redundant 'sorted' call: stream content is sorted again after that">sorted()</warning>.sorted(Comparator.<String>naturalOrder().reversed());
Stream.of("foo", "bar", "baz").sorted().sorted(Comparator.comparing(x -> x.charAt(0) == 'b'));
Stream.of("foo", "bar", "baz").<warning descr="Redundant 'sorted' call: subsequent 'sorted' call makes sorting useless">sorted()</warning>.sorted(Comparator.comparing(x -> x.charAt(0) == 'b')).sorted(Comparator.reverseOrder());
Stream.of("foo", "bar", "baz").<warning descr="Redundant 'sorted' call: stream content is sorted again after that">sorted()</warning>.sorted(Comparator.comparing(x -> x.charAt(0) == 'b')).sorted(Comparator.reverseOrder());
Stream.of("foo", "bar", "baz").<warning descr="Redundant 'sorted' call: subsequent 'max' call makes sorting useless">sorted(String.CASE_INSENSITIVE_ORDER)</warning>.max(String.CASE_INSENSITIVE_ORDER.reversed());
Stream.of("foo", "bar", "baz").<warning descr="Redundant 'sorted' call: subsequent 'min' call makes sorting useless">sorted(String.CASE_INSENSITIVE_ORDER)</warning>.min(String.CASE_INSENSITIVE_ORDER);
Stream.of("foo", "bar", "baz").<warning descr="Redundant 'sorted' call: subsequent 'max' call doesn't depend on the sort order">sorted(String.CASE_INSENSITIVE_ORDER)</warning>.max(String.CASE_INSENSITIVE_ORDER.reversed());
Stream.of("foo", "bar", "baz").<warning descr="Redundant 'sorted' call: subsequent 'min' call doesn't depend on the sort order">sorted(String.CASE_INSENSITIVE_ORDER)</warning>.min(String.CASE_INSENSITIVE_ORDER);
Stream.of("foo", "bar", "baz").sorted(String.CASE_INSENSITIVE_ORDER).min(Comparator.naturalOrder());
}
}
@@ -828,7 +828,8 @@ inspection.require.non.null.option.min.size=Minimal delta length when inspection
inspection.redundant.stream.optional.call.message=Redundant ''{0}'' call
inspection.redundant.stream.optional.call.explanation.filter=predicate is always true
inspection.redundant.stream.optional.call.explanation.sorted=subsequent ''{0}'' call makes sorting useless
inspection.redundant.stream.optional.call.explanation.sorted=subsequent ''{0}'' call doesn''t depend on the sort order
inspection.redundant.stream.optional.call.explanation.sorted.twice=stream content is sorted again after that
inspection.redundant.stream.optional.call.explanation.distinct=there already was a 'distinct' call in the chain
inspection.redundant.stream.optional.call.explanation.distinct.set=elements will be distinct anyways when collected to the Set
inspection.redundant.stream.optional.call.explanation.unordered=there already was an 'unordered' call in the chain
@@ -838,7 +839,7 @@ inspection.redundant.stream.optional.call.explanation.parallel.single=stream cre
inspection.redundant.stream.optional.call.fix.family.name=Remove redundant chain call
inspection.redundant.stream.optional.call.fix.name=Remove ''{0}'' call
inspection.redundant.stream.optional.call.fix.collect.to.ordered.family.name=Collect to 'LinkedHashSet'
inspection.redundant.stream.optional.call.option.streamboxing=Report useless boxing in Stream.map
inspection.redundant.stream.optional.call.option.streamboxing=Report redundant boxing in Stream.map
inspection.map.foreach.message=Can be replaced with 'Map.forEach'
inspection.map.foreach.fix.name=Replace with Map.forEach
@@ -916,9 +917,9 @@ inspection.reflection.member.access.check.exists.exclude.chooser=Class to exclud
inspection.replace.with.trivial.lambda.fix.family.name=Replace with trivial lambda
inspection.replace.with.trivial.lambda.fix.name=Replace with lambda returning ''{0}''
inspection.useless.null.check.message=Useless null-check: {0} is never null
inspection.useless.null.check.always.fail.message=Null-check will always fail: {0} is never null
inspection.useless.null.check.fix.family.name=Remove useless null-check
inspection.redundant.null.check.message=Redundant null-check: {0} is never null
inspection.redundant.null.check.always.fail.message=Null-check will always fail: {0} is never null
inspection.redundant.null.check.fix.family.name=Remove redundant null-check
inspection.comparator.result.comparison.display.name=Suspicious usage of compare method
inspection.comparator.result.comparison.problem.display.name=Comparison of compare method result with specific constant
@@ -1,6 +1,6 @@
<html>
<body>
Reports boxing of already boxed values. This is a useless
Reports boxing of already boxed values. This is a redundant
operation since any boxed value will first be auto-unboxed before boxing the
value again. If done inside an inner loop such code may cause performance
problems.
@@ -1,7 +1,7 @@
<html>
<body>
Reports nested <b>synchronized</b> statements. Nested <b>synchronized</b> statements
are either useless (if the lock objects are identical) or prone to deadlock.
are either redundant (if the lock objects are identical) or prone to deadlock.
<!-- tooltip end -->
<p>
@@ -3,7 +3,7 @@
This inspection reports all instances of nested Groovy <b><font color="#000080">synchronized</font></b> statements. Nested <b><font
color="#000080">synchronized</font></b> statements
are either useless (if the lock objects are identical) or prone to deadlock.
are either redundant (if the lock objects are identical) or prone to deadlock.
<br>
<small>Powered by InspectorGroovy</small>
</body>