mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
overload resolution: reject java 8 varargs methods when they are checked by fixed arity and number of parameters doesn't match
This commit is contained in:
@@ -102,7 +102,7 @@ public class RedundantLambdaCodeBlockInspection extends BaseJavaBatchLocalInspec
|
||||
final PsiElement gParent = parent.getParent();
|
||||
if (gParent instanceof PsiCallExpression) {
|
||||
final CandidateInfo[] candidates = PsiResolveHelper.SERVICE.getInstance(gParent.getProject())
|
||||
.getReferencedMethodCandidates((PsiCallExpression)gParent, false);
|
||||
.getReferencedMethodCandidates((PsiCallExpression)gParent, false, true);
|
||||
if (candidates.length > 1) {
|
||||
final List<CandidateInfo> info = new ArrayList<CandidateInfo>(Arrays.asList(candidates));
|
||||
final LanguageLevel level = PsiUtil.getLanguageLevel(parent);
|
||||
@@ -111,7 +111,7 @@ public class RedundantLambdaCodeBlockInspection extends BaseJavaBatchLocalInspec
|
||||
if (argumentList == null) {
|
||||
return null;
|
||||
}
|
||||
JavaMethodsConflictResolver.checkParametersNumber(info, argumentList.getExpressions().length, false);
|
||||
conflictResolver.checkParametersNumber(info, argumentList.getExpressions().length, false);
|
||||
conflictResolver.checkSpecifics(info, MethodCandidateInfo.ApplicabilityLevel.VARARGS, level);
|
||||
if (info.size() > 1) {
|
||||
return null;
|
||||
|
||||
@@ -351,9 +351,9 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
return ((MethodCandidateInfo)info).getPertinentApplicabilityLevel() != MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE;
|
||||
}
|
||||
|
||||
public static boolean checkParametersNumber(@NotNull List<CandidateInfo> conflicts,
|
||||
final int argumentsCount,
|
||||
boolean ignoreIfStaticsProblem) {
|
||||
public 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++) {
|
||||
@@ -362,7 +362,8 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
if (ignoreIfStaticsProblem && !info.isStaticsScopeCorrect()) return true;
|
||||
if (!(info instanceof MethodCandidateInfo)) continue;
|
||||
PsiMethod method = ((MethodCandidateInfo)info).getElement();
|
||||
if (method.isVarArgs() || method.getParameterList().getParametersCount() == argumentsCount) {
|
||||
if ((myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) ? ((MethodCandidateInfo)info).isVarargs() : method.isVarArgs()) ||
|
||||
method.getParameterList().getParametersCount() == argumentsCount) {
|
||||
// remove all unmatched before
|
||||
if (unmatchedIndices != null) {
|
||||
for (int u=unmatchedIndices.size()-1; u>=0; u--) {
|
||||
|
||||
@@ -20,7 +20,7 @@ class TestIDEA128101 {
|
||||
|
||||
public static void test() {
|
||||
construct(String.class, createPath(integerAttribute), createPath(stringAttribute));
|
||||
construct1<error descr="Cannot resolve method 'construct1(java.lang.Class<java.lang.String>, TestIDEA128101.Path<java.lang.Integer>, TestIDEA128101.Path<java.lang.String>)'">(String.class, createPath(integerAttribute), createPath(stringAttribute))</error>;
|
||||
construct1(String.class, createPath<error descr="'createPath(TestIDEA128101.Attribute<Y>)' in 'TestIDEA128101' cannot be applied to '(TestIDEA128101.Attribute<java.lang.Integer>)'">(integerAttribute)</error>, createPath<error descr="'createPath(TestIDEA128101.Attribute<Y>)' in 'TestIDEA128101' cannot be applied to '(TestIDEA128101.Attribute<java.lang.String>)'">(stringAttribute)</error>);
|
||||
construct2(String.class, createPath(integerAttribute), createPath(stringAttribute));
|
||||
<error descr="Type parameter K has incompatible upper bounds: Integer and String">construct3(String.class, createPath(integerAttribute), createPath(stringAttribute));</error>
|
||||
<error descr="Type parameter K has incompatible upper bounds: Integer and String">construct4(String.class, createPath(integerAttribute), createPath(stringAttribute));</error>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Demo {
|
||||
|
||||
public void f1() {
|
||||
f2<error descr="Cannot resolve method 'f2(int, <lambda expression>)'">(2, input -> input)</error>;
|
||||
f2(2, <error descr="Target type of a lambda conversion must be an interface">input -> input</error>);
|
||||
}
|
||||
|
||||
public void f2() {
|
||||
|
||||
Reference in New Issue
Block a user