From ac293f3fc77932c1a050a0754c44db89e4154d80 Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 3 Feb 2013 22:40:15 +0100 Subject: [PATCH] disprefer rarely used Object methods --- .../intellij/psi/util/proximity/KnownElementWeigher.java | 6 ++++-- .../smartType/SemicolonInCodeBlocBodyInLocalVariable.java | 2 +- .../SemicolonInExpressionBodyInExpressionList.java | 2 +- .../SemicolonInExpressionBodyInLocalVariable.java | 2 +- .../codeInsight/completion/JavadocCompletionTest.java | 2 +- .../completion/NormalCompletionOrderingTest.groovy | 2 +- .../completion/SmartTypeCompletionOrderingTest.groovy | 8 ++++---- .../codeInsight/completion/SmartTypeCompletionTest.java | 2 +- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/util/proximity/KnownElementWeigher.java b/java/java-impl/src/com/intellij/psi/util/proximity/KnownElementWeigher.java index 73e8f14b5f50..4f492e818a20 100644 --- a/java/java-impl/src/com/intellij/psi/util/proximity/KnownElementWeigher.java +++ b/java/java-impl/src/com/intellij/psi/util/proximity/KnownElementWeigher.java @@ -48,12 +48,14 @@ public class KnownElementWeigher extends ProximityWeigher { final PsiMethod method = (PsiMethod)element; final PsiClass containingClass = method.getContainingClass(); if (containingClass != null) { - if ("finalize".equals(method.getName()) || "registerNatives".equals(method.getName())) { + String methodName = method.getName(); + if ("finalize".equals(methodName) || "registerNatives".equals(methodName) || "getClass".equals(methodName) || + methodName.startsWith("wait") || methodName.startsWith("notify")) { if (CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) { return -1; } } - if ("subSequence".equals(method.getName())) { + if ("subSequence".equals(methodName)) { if (CommonClassNames.JAVA_LANG_STRING.equals(containingClass.getQualifiedName())) { return -1; } diff --git a/java/java-tests/testData/codeInsight/completion/smartType/SemicolonInCodeBlocBodyInLocalVariable.java b/java/java-tests/testData/codeInsight/completion/smartType/SemicolonInCodeBlocBodyInLocalVariable.java index fa6f209bf19b..e98107784592 100644 --- a/java/java-tests/testData/codeInsight/completion/smartType/SemicolonInCodeBlocBodyInLocalVariable.java +++ b/java/java-tests/testData/codeInsight/completion/smartType/SemicolonInCodeBlocBodyInLocalVariable.java @@ -1,5 +1,5 @@ class Test { public void foo() { - Runnable r = () -> {}; + Runnable r = () -> {n}; } } diff --git a/java/java-tests/testData/codeInsight/completion/smartType/SemicolonInExpressionBodyInExpressionList.java b/java/java-tests/testData/codeInsight/completion/smartType/SemicolonInExpressionBodyInExpressionList.java index 7b403c035879..a9a9766a2724 100644 --- a/java/java-tests/testData/codeInsight/completion/smartType/SemicolonInExpressionBodyInExpressionList.java +++ b/java/java-tests/testData/codeInsight/completion/smartType/SemicolonInExpressionBodyInExpressionList.java @@ -1,5 +1,5 @@ class Test { public void foo() { - new Thread(() -> ); + new Thread(() -> n); } } diff --git a/java/java-tests/testData/codeInsight/completion/smartType/SemicolonInExpressionBodyInLocalVariable.java b/java/java-tests/testData/codeInsight/completion/smartType/SemicolonInExpressionBodyInLocalVariable.java index e41c2a19a0d3..b0dee48e23d7 100644 --- a/java/java-tests/testData/codeInsight/completion/smartType/SemicolonInExpressionBodyInLocalVariable.java +++ b/java/java-tests/testData/codeInsight/completion/smartType/SemicolonInExpressionBodyInLocalVariable.java @@ -1,5 +1,5 @@ class Test { public void foo() { - Runnable r = () -> + Runnable r = () -> n } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavadocCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavadocCompletionTest.java index 1f16310242b1..3f704281dc90 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavadocCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavadocCompletionTest.java @@ -74,7 +74,7 @@ public class JavadocCompletionTest extends LightFixtureCompletionTestCase { public void testSee0() throws Exception { configureByFile("See0.java"); - assertStringItems("foo", "clone", "equals", "getClass", "hashCode", "notify", "notifyAll", "Object", "toString", "wait", "wait", "wait", "finalize", "registerNatives"); + myFixture.assertPreferredCompletionItems(0, "foo", "clone", "equals", "hashCode"); } public void testSee1() throws Exception { 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 98dbce0c065a..6b5607b47cc1 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy @@ -195,7 +195,7 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase { public void testDeclaredMembersGoFirst() throws Exception { invokeCompletion(getTestName(false) + ".java"); - assertStringItems("fromThis", "overridden", "fromSuper", "equals", "getClass", "hashCode", "notify", "notifyAll", "toString", "wait", + assertStringItems("fromThis", "overridden", "fromSuper", "equals", "hashCode", "toString", "getClass", "notify", "notifyAll", "wait", "wait", "wait"); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy index b14a645bc5ae..fa418ec9c5fb 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy @@ -95,7 +95,7 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase { } public void testDontPreferKeywords() throws Throwable { - checkPreferredItems(0, "o1", "foo", "name", "this", "getClass"); + checkPreferredItems(0, "o1", "foo", "name", "this"); } public void testEnumValueOf() throws Throwable { @@ -129,11 +129,11 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase { } public void testSmartEquals2() throws Throwable { - checkPreferredItems(0, "foo", "this", "o", "s", "getClass"); + checkPreferredItems(0, "foo", "this", "o", "s"); } public void testSmartEquals3() throws Throwable { - checkPreferredItems(0, "b", "this", "a", "z", "getClass"); + checkPreferredItems(0, "b", "this", "a", "z"); } public void testSmartCollectionsNew() throws Throwable { @@ -222,7 +222,7 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase { } public void testFactoryMethodForDefaultType() throws Throwable { - checkPreferredItems(0, "create", "this", "getClass"); + checkPreferredItems(0, "create", "this"); } public void testLocalVarsBeforeClassLiterals() throws Throwable { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java index 6b971c14f233..a8fc06a8faad 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java @@ -471,7 +471,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { public void testVoidExpectedType() throws Throwable { configureByTestName(); - assertStringItems("notify", "notifyAll", "wait", "wait", "wait", "getClass", "equals", "hashCode", "toString"); + assertStringItems("notify", "notifyAll", "wait", "wait", "wait", "equals", "hashCode", "toString", "getClass"); type("eq"); assertEquals("equals", assertOneElement(getLookup().getItems()).getLookupString()); select();