mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
prefer instanceofed variants in java completion (IDEA-138937)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
+18
@@ -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>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-2
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user