prefer instanceofed variants in java completion (IDEA-138937)

This commit is contained in:
peter
2015-04-08 18:13:15 +02:00
parent 4ec8011316
commit 8bf079ca59
5 changed files with 28 additions and 5 deletions
@@ -421,9 +421,6 @@ public class JavaCompletionSorting {
if (lookupItem != null) {
return lookupItem.getBracketsCount() * 10 + (lookupItem.isAddArrayInitializer() ? 1 : 0);
}
if (element.as(CastingLookupElementDecorator.CLASS_CONDITION_KEY) != null) {
return 239;
}
return 0;
}
}
@@ -135,6 +135,7 @@ public class PreferByKindWeigher extends LookupElementWeigher {
enum MyResult {
annoMethod,
probableKeyword,
castVariable,
localOrParameter,
qualifiedWithField,
qualifiedWithGetter,
@@ -174,6 +175,10 @@ public class PreferByKindWeigher extends LookupElementWeigher {
}
}
if (item.as(CastingLookupElementDecorator.CLASS_CONDITION_KEY) != null) {
return MyResult.castVariable;
}
if (object instanceof PsiLocalVariable || object instanceof PsiParameter || object instanceof PsiThisExpression) {
return MyResult.localOrParameter;
}
@@ -0,0 +1,18 @@
import java.lang.Object;
import java.util.List;
interface Intf {
}
public class Aaaaaaa implements Intf {
void foo(List<Object> src, List<Intf> dst) {
for (Object value : src) {
if (value instanceof Intf) {
dst.add(<caret>);
}
}
}
}
@@ -233,8 +233,8 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "local", "Foo.class", "Bar.class");
}
public void testDontPreferCasted() throws Throwable {
checkPreferredItems(0, "b", "_o");
public void testPreferInstanceofed() throws Throwable {
checkPreferredItems(0, "_o", "b");
}
public void testInnerClassesProximity() throws Throwable {
@@ -314,6 +314,9 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
public void testPreferLocalOverFactoryMatchingName() {
checkPreferredItems 0, 'e', 'createEvent'
}
public void testPreferLocalOverThis() {
checkPreferredItems 0, 'value', 'this', 'hashCode'
}
public void testGetLogger() {
checkPreferredItems 0, 'Foo.class', 'forName'