diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/completion/scope/CompletionElement.java b/java/java-psi-impl/src/com/intellij/codeInsight/completion/scope/CompletionElement.java index ccc52139e7f7..dbfaaf2a9d22 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/completion/scope/CompletionElement.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/completion/scope/CompletionElement.java @@ -93,13 +93,19 @@ public class CompletionElement{ return myEqualityObject != null ? myEqualityObject.hashCode() : 0; } - public boolean isMoreSpecificThan(@NotNull CompletionElement prev) { - Object prevElement = prev.getElement(); - if (!(prevElement instanceof PsiMethod && myElement instanceof PsiMethod)) return false; + public boolean isMoreSpecificThan(@NotNull CompletionElement another) { + Object anotherElement = another.getElement(); + if (!(anotherElement instanceof PsiMethod && myElement instanceof PsiMethod)) return false; - PsiType prevType = prev.getSubstitutor().substitute(((PsiMethod)prevElement).getReturnType()); + if (isInterfaceMethod((PsiMethod)myElement) && !isInterfaceMethod((PsiMethod)anotherElement)) return false; + + PsiType prevType = another.getSubstitutor().substitute(((PsiMethod)anotherElement).getReturnType()); PsiType candidateType = mySubstitutor.substitute(((PsiMethod)myElement).getReturnType()); return prevType != null && candidateType != null && !prevType.equals(candidateType) && prevType.isAssignableFrom(candidateType); } + private static boolean isInterfaceMethod(PsiMethod anotherElement) { + PsiClass aClass = anotherElement.getContainingClass(); + return aClass != null && aClass.isInterface(); + } } diff --git a/java/java-tests/testData/codeInsight/completion/normal/ShowMostSpecificOverrideOnlyFromClass.java b/java/java-tests/testData/codeInsight/completion/normal/ShowMostSpecificOverrideOnlyFromClass.java new file mode 100644 index 000000000000..51a28bb64d04 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/ShowMostSpecificOverrideOnlyFromClass.java @@ -0,0 +1,24 @@ +class Test { + + public static void main(String[] args) { + MyCar myCar=new MyCar(); + myCar.get + } + +} + +class MyCar extends AbstractCar implements Car{ } + +abstract class AbstractCar { + public C get() {} +} + +interface Car { + public CarDoor get(); +} + +interface MyDoor extends CarDoor{} + +interface CarDoor extends Door{} + +interface Door {} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy index 55fbc2cd80cb..78c673e52601 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy @@ -134,7 +134,7 @@ class NormalCompletionTest extends LightFixtureCompletionTestCase { assert presentation.itemTextBold } - private LookupElementPresentation renderElement(LookupElement element) { + private static LookupElementPresentation renderElement(LookupElement element) { return LookupElementPresentation.renderElement(element) } @@ -1718,6 +1718,11 @@ class Bar { assert 'B' == LookupElementPresentation.renderElement(myFixture.lookup.items[0]).typeText } + void testShowMostSpecificOverrideOnlyFromClass() { + configure() + assert 'Door' == LookupElementPresentation.renderElement(myFixture.lookup.items[0]).typeText + } + void testShowVarInitializers() { configure() assert LookupElementPresentation.renderElement(myFixture.lookup.items[0]).tailText == '( "x")'