From bf416e5f9a0ed5640f9e3c03571f551ef0bd247f Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 5 Dec 2012 11:53:00 +0100 Subject: [PATCH] IDEA-96387 Code completion popup prefers unimported static method to local variable when appending to a string literal --- .../codeInsight/ExpectedTypesProvider.java | 23 +++---------------- .../NoExpectedTypeInStringConcatenation.java | 8 +++++++ .../NormalCompletionOrderingTest.groovy | 4 ++++ 3 files changed, 15 insertions(+), 20 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/normalSorting/NoExpectedTypeInStringConcatenation.java diff --git a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java index 9970b8db643f..ebc4714f3084 100644 --- a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java @@ -654,28 +654,11 @@ public class ExpectedTypesProvider { } } else if (i == JavaTokenType.PLUS) { - if (anotherType == null) { + if (anotherType == null || anotherType.equalsToText(CommonClassNames.JAVA_LANG_STRING)) { myResult = ExpectedTypeInfo.EMPTY_ARRAY; } - else { - if (anotherType.equalsToText(CommonClassNames.JAVA_LANG_STRING)) { - PsiType objType = PsiType.getJavaLangObject(myExpr.getManager(), myExpr.getResolveScope()); - ExpectedTypeInfo info = createInfoImpl(objType, ExpectedTypeInfo.TYPE_OR_SUBTYPE, anotherType, - TailType.NONE); - ExpectedTypeInfo info1 = createInfoImpl(PsiType.DOUBLE, ExpectedTypeInfo.TYPE_OR_SUBTYPE, - PsiType.INT, TailType.NONE); - PsiType booleanType = PsiType.BOOLEAN; - ExpectedTypeInfo info2 = createInfoImpl(booleanType, ExpectedTypeInfo.TYPE_STRICTLY, booleanType, - TailType.NONE); - myResult = new ExpectedTypeInfo[]{info, info1, info2}; - } - else { - if (PsiType.DOUBLE.isAssignableFrom(anotherType)) { - ExpectedTypeInfoImpl info = createInfoImpl(PsiType.DOUBLE, ExpectedTypeInfo.TYPE_OR_SUBTYPE, - anotherType, TailType.NONE); - myResult = new ExpectedTypeInfo[]{info}; - } - } + else if (PsiType.DOUBLE.isAssignableFrom(anotherType)) { + myResult = new ExpectedTypeInfo[]{createInfoImpl(PsiType.DOUBLE, ExpectedTypeInfo.TYPE_OR_SUBTYPE, anotherType, TailType.NONE)}; } } else if (i == JavaTokenType.EQEQ || i == JavaTokenType.NE) { diff --git a/java/java-tests/testData/codeInsight/completion/normalSorting/NoExpectedTypeInStringConcatenation.java b/java/java-tests/testData/codeInsight/completion/normalSorting/NoExpectedTypeInStringConcatenation.java new file mode 100644 index 000000000000..17188eeb3675 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normalSorting/NoExpectedTypeInStringConcatenation.java @@ -0,0 +1,8 @@ +import java.lang.String; + +public class Foo { + + void foo(Object vx) { + String s = "" + v + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy index 236f7c7bef8c..672380906285 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy @@ -504,4 +504,8 @@ import java.lang.annotation.Target; checkPreferredItems(0, 'PsiElement', 'psiElement') } + public void testNoExpectedTypeInStringConcatenation() { + checkPreferredItems(0, 'vx') + } + }