mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: warn about lambda unfriendly constructor overloads too (IDEA-CR-8381)
This commit is contained in:
+1
@@ -2166,6 +2166,7 @@ optional.used.as.field.type.problem.descriptor=<code>#ref</code> used as type fo
|
||||
optional.used.as.parameter.type.problem.descriptor=<code>#ref</code> used as type for parameter ''{0}''
|
||||
lambda.unfriendly.method.overload.display.name=Lambda unfriendly method overload
|
||||
lambda.unfriendly.method.overload.problem.descriptor=Lambda unfriendly overload of method <code>#ref()</code>
|
||||
lambda.unfriendly.constructor.overload.problem.descriptor=Lambda unfriendly overload of constructor <code>#ref()</code>
|
||||
optional.contains.collection.display.name='Optional' contains array or collection
|
||||
optional.contains.collection.problem.descriptor='Optional' contains collection <code>#ref</code>
|
||||
optional.contains.array.problem.descriptor='Optional' contains array <code>#ref</code>
|
||||
|
||||
+5
-5
@@ -37,7 +37,10 @@ public class LambdaUnfriendlyMethodOverloadInspectionBase extends BaseInspection
|
||||
@NotNull
|
||||
@Override
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message("lambda.unfriendly.method.overload.problem.descriptor");
|
||||
final PsiMethod method = (PsiMethod)infos[0];
|
||||
return InspectionGadgetsBundle.message(method.isConstructor()
|
||||
? "lambda.unfriendly.constructor.overload.problem.descriptor"
|
||||
: "lambda.unfriendly.method.overload.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,9 +53,6 @@ public class LambdaUnfriendlyMethodOverloadInspectionBase extends BaseInspection
|
||||
@Override
|
||||
public void visitMethod(PsiMethod method) {
|
||||
super.visitMethod(method);
|
||||
if (method.isConstructor()) {
|
||||
return;
|
||||
}
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
final int parametersCount = parameterList.getParametersCount();
|
||||
if (parametersCount == 0) {
|
||||
@@ -91,7 +91,7 @@ public class LambdaUnfriendlyMethodOverloadInspectionBase extends BaseInspection
|
||||
}
|
||||
final PsiType functionalType = parameters[functionalIndex].getType();
|
||||
if (areSameShapeFunctionalTypes(functionalType, otherFunctionalType)) {
|
||||
registerMethodError(method);
|
||||
registerMethodError(method, method);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.siyeh.ig.naming;
|
||||
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -27,6 +28,10 @@ public class LambdaUnfriendlyMethodOverloadInspection extends LambdaUnfriendlyMe
|
||||
@Nullable
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
final PsiMethod method = (PsiMethod)infos[0];
|
||||
if (method.isConstructor()) {
|
||||
return null;
|
||||
}
|
||||
return new RenameFix();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports overloaded methods with similar functional interface type parameters for which
|
||||
Reports overloaded methods or constructors with similar functional interface type parameters for which
|
||||
any call sites will need a cast or parameter type specified on the lambda expression to resolve ambiguity.
|
||||
Such calls can look ugly and should be avoided if possible.
|
||||
It is preferable to give the overloaded methods a different name from each other, so that this problem does not occur.
|
||||
|
||||
+3
@@ -26,6 +26,9 @@ interface Stream<T> {
|
||||
<V> V <warning descr="Lambda unfriendly overload of method 'map()'">map</warning>(IntFunction<V> intMapper);
|
||||
}
|
||||
class X {
|
||||
<warning descr="Lambda unfriendly overload of constructor 'X()'">X</warning>(IntPredicate p) {}
|
||||
<warning descr="Lambda unfriendly overload of constructor 'X()'">X</warning>(Function<String, String> f) {}
|
||||
|
||||
void <warning descr="Lambda unfriendly overload of method 'a()'">a</warning>(IntPredicate p) {}
|
||||
void <warning descr="Lambda unfriendly overload of method 'a()'">a</warning> (Function<String, String> f) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user