diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/PreferLocalVariablesLiteralsAndAnnoMethodsWeigher.java b/java/java-impl/src/com/intellij/codeInsight/completion/PreferLocalVariablesLiteralsAndAnnoMethodsWeigher.java index 92e695b8f45d..4d9450ad5f64 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/PreferLocalVariablesLiteralsAndAnnoMethodsWeigher.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/PreferLocalVariablesLiteralsAndAnnoMethodsWeigher.java @@ -18,7 +18,6 @@ package com.intellij.codeInsight.completion; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.psi.*; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * @author peter @@ -36,10 +35,11 @@ public class PreferLocalVariablesLiteralsAndAnnoMethodsWeigher extends Completio public MyResult weigh(@NotNull final LookupElement item, @NotNull final CompletionLocation location) { final Object object = item.getObject(); + if (object instanceof PsiLocalVariable || object instanceof PsiParameter || object instanceof PsiThisExpression) { + return MyResult.localOrParameter; + } + if (location.getCompletionType() == CompletionType.SMART) { - if (object instanceof PsiLocalVariable || object instanceof PsiParameter || object instanceof PsiThisExpression) { - return MyResult.localOrParameter; - } if (object instanceof String && item.getUserData(JavaCompletionUtil.SUPER_METHOD_PARAMETERS) == Boolean.TRUE) { return MyResult.superMethodParameters; } diff --git a/java/java-tests/testData/codeInsight/completion/normalSorting/LocalVarsOverMethods.java b/java/java-tests/testData/codeInsight/completion/normalSorting/LocalVarsOverMethods.java new file mode 100644 index 000000000000..7dabcde7687d --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normalSorting/LocalVarsOverMethods.java @@ -0,0 +1,8 @@ +class SomeComponent extends javax.swing.JPanel { + @Nullable + public String getSelectedItemString() { + final Object value = getList().getSelectedValue(); + return valx + } + +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionSortingTestCase.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionSortingTestCase.java index 91309e5ddf32..21b7f846a585 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionSortingTestCase.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionSortingTestCase.java @@ -30,7 +30,7 @@ public abstract class CompletionSortingTestCase extends LightFixtureCompletionTe protected abstract String getBasePath(); - protected void checkPreferredItems(final int selected, @NonNls final String... expected) throws Exception { + protected void checkPreferredItems(final int selected, @NonNls final String... expected) { invokeCompletion(getTestName(false) + ".java"); assertPreferredItems(selected, expected); } @@ -39,7 +39,7 @@ public abstract class CompletionSortingTestCase extends LightFixtureCompletionTe myFixture.assertPreferredCompletionItems(selected, expected); } - protected LookupImpl invokeCompletion(final String path) throws Exception { + protected LookupImpl invokeCompletion(final String path) { myFixture.configureFromExistingVirtualFile( myFixture.copyFileToProject(path, com.intellij.openapi.util.text.StringUtil.getShortName(path, '/'))); myFixture.complete(myType); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java index fd00117eb194..1e61d005d9b5 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java @@ -174,4 +174,8 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase { assertStringItems("fromThis", "overridden", "fromSuper", "equals", "getClass", "hashCode", "notify", "notifyAll", "toString", "wait", "wait", "wait"); } + public void testLocalVarsOverMethods() { + checkPreferredItems(0, "value"); + } + } \ No newline at end of file