mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-66892 'else' variant in completion should be preferred in this case
This commit is contained in:
+6
-3
@@ -33,7 +33,7 @@ public class PreferLocalVariablesLiteralsAndAnnoMethodsWeigher extends LookupEle
|
||||
|
||||
enum MyResult {
|
||||
annoMethod,
|
||||
returnKeyword,
|
||||
probableKeyword,
|
||||
localOrParameter,
|
||||
superMethodParameters,
|
||||
normal,
|
||||
@@ -46,8 +46,11 @@ public class PreferLocalVariablesLiteralsAndAnnoMethodsWeigher extends LookupEle
|
||||
public MyResult weigh(@NotNull LookupElement item) {
|
||||
final Object object = item.getObject();
|
||||
|
||||
if (object instanceof PsiKeyword && PsiKeyword.RETURN.equals(((PsiKeyword)object).getText())) {
|
||||
return MyResult.returnKeyword;
|
||||
if (object instanceof PsiKeyword) {
|
||||
String keyword = ((PsiKeyword)object).getText();
|
||||
if (PsiKeyword.RETURN.equals(keyword) || PsiKeyword.ELSE.equals(keyword) || PsiKeyword.FINALLY.equals(keyword)) {
|
||||
return MyResult.probableKeyword;
|
||||
}
|
||||
}
|
||||
|
||||
if (object instanceof PsiLocalVariable || object instanceof PsiParameter || object instanceof PsiThisExpression) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class Foo {
|
||||
{
|
||||
Object element;
|
||||
if (true) {}
|
||||
el<caret>
|
||||
}
|
||||
|
||||
}
|
||||
+4
@@ -217,6 +217,10 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
checkPreferredItems(0, "private", "protected", "public", "paaa", "paab");
|
||||
}
|
||||
|
||||
public void testPreferElse() {
|
||||
checkPreferredItems(0, "else", "element");
|
||||
}
|
||||
|
||||
public void testPreferSamePackageOverImported() {
|
||||
myFixture.addClass("package bar; public class Bar1 {}");
|
||||
myFixture.addClass("package bar; public class Bar2 {}");
|
||||
|
||||
Reference in New Issue
Block a user