overloaded calls are not recursive (IDEA-112451)

This commit is contained in:
peter
2013-08-21 15:21:59 +02:00
parent c65ae380a1
commit c545510805
3 changed files with 34 additions and 10 deletions
@@ -130,16 +130,21 @@ class RecursionWeigher extends LookupElementWeigher {
if (myExpectedInfos != null) {
final PsiType itemType = JavaCompletionUtil.getLookupElementType(element);
for (final ExpectedTypeInfo expectedInfo : myExpectedInfos) {
PsiMethod calledMethod = expectedInfo.getCalledMethod();
if (itemType != null &&
calledMethod != null &&
calledMethod.equals(myPositionMethod) &&
expectedInfo.getType().isAssignableFrom(itemType)) {
return myDelegate ? Result.delegation : Result.recursive;
if (itemType != null) {
boolean hasRecursiveInvocations = false;
boolean hasOtherInvocations = false;
for (final ExpectedTypeInfo expectedInfo : myExpectedInfos) {
PsiMethod calledMethod = expectedInfo.getCalledMethod();
if (!expectedInfo.getType().isAssignableFrom(itemType)) continue;
if (calledMethod != null && calledMethod.equals(myPositionMethod) || isGetterSetterAssignment(object, calledMethod)) {
hasRecursiveInvocations = true;
} else if (calledMethod != null) {
hasOtherInvocations = true;
}
}
String propertyName = getSetterPropertyName(calledMethod);
if (propertyName != null && isGetterSetterAssignment(object, propertyName)) {
if (hasRecursiveInvocations && !hasOtherInvocations) {
return myDelegate ? Result.delegation : Result.recursive;
}
}
@@ -178,7 +183,10 @@ class RecursionWeigher extends LookupElementWeigher {
return null;
}
private static boolean isGetterSetterAssignment(Object lookupObject, String prop) {
private boolean isGetterSetterAssignment(Object lookupObject, @Nullable PsiMethod calledMethod) {
String prop = getSetterPropertyName(calledMethod);
if (prop == null) return false;
if (lookupObject instanceof PsiField &&
prop.equals(PropertyUtil.suggestPropertyName((PsiField)lookupObject))) {
return true;
@@ -0,0 +1,12 @@
class SearchParameters {
public SearchParameters(PsiElement element) {
this(e<caret>);
}
public SearchParameters(final PsiElement element, final boolean checkDeep) {
}
}
class PsiElement {}
@@ -36,6 +36,10 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "return", "register");
}
public void testDelegatingConstructorCall() {
checkPreferredItems 0, 'element', 'equals'
}
public void testPreferAnnotationMethods() throws Throwable {
checkPreferredItems(0, "name", "value", "Foo", "Anno");
}