From e869310a923c94838c8c095c11ab4c586e01bb81 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 21 Feb 2013 13:27:29 +0100 Subject: [PATCH] ambiguous method call: choose one method if both are from the same hierarchy as the actual problem is there (IDEA-101529) --- .../JavaMethodsConflictResolver.java | 4 +++- .../pck/AmbiguousMethodCall.java | 13 +++++++++++++ .../codeInsight/daemon/AdvHighlightingJdk7Test.java | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/ambiguousMethodsFromSameClassAccess/pck/AmbiguousMethodCall.java diff --git a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java index 5a67a6a61f20..fdf4f44b08cc 100644 --- a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java +++ b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java @@ -550,7 +550,9 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ } if (isMoreSpecific == null) { if (!JavaVersionService.getInstance().isAtLeast(myArgumentsList, JavaSdkVersion.JDK_1_7) || - !MethodSignatureUtil.areParametersErasureEqual(method1, method2)) { + !MethodSignatureUtil.areParametersErasureEqual(method1, method2) || + InheritanceUtil.isInheritorOrSelf(class1, class2, true) || + InheritanceUtil.isInheritorOrSelf(class2, class1, true)) { if (typeParameters1.length < typeParameters2.length) return Specifics.FIRST; if (typeParameters1.length > typeParameters2.length) return Specifics.SECOND; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/ambiguousMethodsFromSameClassAccess/pck/AmbiguousMethodCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/ambiguousMethodsFromSameClassAccess/pck/AmbiguousMethodCall.java new file mode 100644 index 000000000000..7b468c8e1042 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/ambiguousMethodsFromSameClassAccess/pck/AmbiguousMethodCall.java @@ -0,0 +1,13 @@ +package pck; + +class A { + public void bar(I a, Class any) { + System.out.println(a.with(any)); + } + + interface I { + T with(Class aClass); + long with(Class aClass); + } +} + diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingJdk7Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingJdk7Test.java index 92c4d7c351b2..85f4fcaa4697 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingJdk7Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingJdk7Test.java @@ -191,4 +191,8 @@ public class AdvHighlightingJdk7Test extends DaemonAnalyzerTestCase { public void testAmbiguousIDEA87672() throws Exception { doTestAmbiguous(); } + + public void testAmbiguousMethodsFromSameClassAccess() throws Exception { + doTestAmbiguous(); + } }