mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
ambiguity: prefer non arrays (IDEA-97983)
This commit is contained in:
+23
-11
@@ -22,7 +22,6 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiSuperMethodImplUtil;
|
||||
import com.intellij.psi.LambdaUtil;
|
||||
import com.intellij.psi.infos.CandidateInfo;
|
||||
import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.scope.PsiConflictResolver;
|
||||
@@ -566,25 +565,26 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
PsiSubstitutor classSubstitutor2,
|
||||
PsiType type1,
|
||||
PsiType type2) {
|
||||
final PsiClass aClass1 = PsiUtil.resolveClassInClassTypeOnly(type1);
|
||||
final PsiClass aClass2 = PsiUtil.resolveClassInClassTypeOnly(type2);
|
||||
final PsiClass aClass1 = PsiUtil.resolveClassInType(type1);
|
||||
final PsiClass aClass2 = PsiUtil.resolveClassInType(type2);
|
||||
if (aClass1 instanceof PsiTypeParameter && aClass2 instanceof PsiTypeParameter) {
|
||||
return checkTypeParams(method1, method2, classSubstitutor1, classSubstitutor2, type1, type2, (PsiTypeParameter)aClass1, (PsiTypeParameter)aClass2);
|
||||
}
|
||||
if (aClass1 instanceof PsiTypeParameter || aClass2 instanceof PsiTypeParameter) return null;
|
||||
if (aClass1 instanceof PsiTypeParameter) {
|
||||
return chooseHigherDimension(type1, type2);
|
||||
}
|
||||
else if (aClass2 instanceof PsiTypeParameter) {
|
||||
return chooseHigherDimension(type2, type1);
|
||||
}
|
||||
|
||||
final Map<PsiTypeParameter, PsiType> map1 = classSubstitutor1.getSubstitutionMap();
|
||||
final Map<PsiTypeParameter, PsiType> map2 = classSubstitutor2.getSubstitutionMap();
|
||||
if (map1.size() == 1 && map2.size() == 1) {
|
||||
final PsiType t1 = map1.values().iterator().next();
|
||||
final PsiType t2 = map2.values().iterator().next();
|
||||
int d1 = t1 != null ? t1.getArrayDimensions() : 0;
|
||||
int d2 = t2 != null ? t2.getArrayDimensions() : 0;
|
||||
if (d1 > d2) {
|
||||
return Specifics.SECOND;
|
||||
}
|
||||
else if (d2 > d1) {
|
||||
return Specifics.FIRST;
|
||||
final Specifics substArraySpecifics = chooseHigherDimension(t1, t2);
|
||||
if (substArraySpecifics != null) {
|
||||
return substArraySpecifics;
|
||||
}
|
||||
else {
|
||||
final PsiTypeParameter p1 = map1.keySet().iterator().next();
|
||||
@@ -595,6 +595,18 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Specifics chooseHigherDimension(PsiType type1, PsiType type2) {
|
||||
int d1 = type1 != null ? type1.getArrayDimensions() : 0;
|
||||
int d2 = type2 != null ? type2.getArrayDimensions() : 0;
|
||||
if (d1 > d2) {
|
||||
return Specifics.SECOND;
|
||||
}
|
||||
else if (d2 > d1) {
|
||||
return Specifics.FIRST;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Specifics checkTypeParams(PsiMethod method1,
|
||||
PsiMethod method2,
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
class Test {
|
||||
public static void foo(int[] i1, int[] i2) {
|
||||
}
|
||||
|
||||
public static <T> void foo(T i1, T i2) {
|
||||
}
|
||||
|
||||
public static final void main(String[] args) throws Exception {
|
||||
int[] i = null;
|
||||
foo(i, i);
|
||||
}
|
||||
}
|
||||
class Test1 {
|
||||
public static void foo(int i1, int i2) {
|
||||
}
|
||||
|
||||
public static <T> void foo(T i1, T i2) {
|
||||
}
|
||||
|
||||
public static final void main(String[] args) throws Exception {
|
||||
int[] i = null;
|
||||
foo(i, i);
|
||||
}
|
||||
}
|
||||
+1
@@ -161,4 +161,5 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testDefaultMethodVisibility() throws Exception { doTest(true, false); }
|
||||
public void testEnclosingInstance() throws Exception { doTest(false, false); }
|
||||
public void testWrongArgsAndUnknownTypeParams() throws Exception { doTest(false, false); }
|
||||
public void testAmbiguousMethodCallIDEA97983() throws Exception { doTest(false, false); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user