redundant lambda code block: ensure conflicts between same param numbers are checked

This commit is contained in:
Anna Kozlova
2014-12-17 19:19:31 +01:00
parent 7343c62b7e
commit 24a7a43f7c
4 changed files with 55 additions and 4 deletions

View File

@@ -88,7 +88,10 @@ public class RedundantLambdaCodeBlockInspection extends BaseJavaBatchLocalInspec
final List<CandidateInfo> info = new ArrayList<CandidateInfo>(Arrays.asList(candidates));
final LanguageLevel level = PsiUtil.getLanguageLevel(parent);
final JavaMethodsConflictResolver conflictResolver = new JavaMethodsConflictResolver((PsiExpressionList)parent, level);
conflictResolver.checkSpecifics(info, MethodCandidateInfo.ApplicabilityLevel.FIXED_ARITY, level);
final PsiExpressionList argumentList = ((PsiCallExpression)gParent).getArgumentList();
if (argumentList == null) return;
JavaMethodsConflictResolver.checkParametersNumber(info, argumentList.getExpressions().length, false);
conflictResolver.checkSpecifics(info, MethodCandidateInfo.ApplicabilityLevel.VARARGS, level);
if (info.size() > 1) {
return;
}

View File

@@ -308,9 +308,9 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
return ((MethodCandidateInfo)info).getPertinentApplicabilityLevel() != MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE;
}
private static boolean checkParametersNumber(@NotNull List<CandidateInfo> conflicts,
final int argumentsCount,
boolean ignoreIfStaticsProblem) {
public static boolean checkParametersNumber(@NotNull List<CandidateInfo> conflicts,
final int argumentsCount,
boolean ignoreIfStaticsProblem) {
boolean atLeastOneMatch = false;
TIntArrayList unmatchedIndices = null;
for (int i = 0; i < conflicts.size(); i++) {

View File

@@ -0,0 +1,23 @@
// "Replace with expression lambda" "true"
import java.util.HashSet;
import java.util.Set;
class Test {
public static void main(String[] args) {
Set<String> strings = new HashSet<>();
new Test().query("", pResultSet -> strings.add("Col1"));
}
public Object query(String s, final ResultSetExtractor rse) {
return null;
}
public Object query(String s, final ResultSetExtractor rse, Object.. args) {
return null;
}
}
interface ResultSetExtractor {
Object extractData(ResultSet var1);
}
class ResultSet {}

View File

@@ -0,0 +1,25 @@
// "Replace with expression lambda" "true"
import java.util.HashSet;
import java.util.Set;
class Test {
public static void main(String[] args) {
Set<String> strings = new HashSet<>();
new Test().query("", pResultSet -> <caret>{
strings.add("Col1");
});
}
public Object query(String s, final ResultSetExtractor rse) {
return null;
}
public Object query(String s, final ResultSetExtractor rse, Object.. args) {
return null;
}
}
interface ResultSetExtractor {
Object extractData(ResultSet var1);
}
class ResultSet {}