IDEA-66892 'else' variant in completion should be preferred in this case

This commit is contained in:
peter
2011-03-28 17:26:38 +02:00
parent 943c822123
commit bb32018645
3 changed files with 18 additions and 3 deletions
@@ -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>
}
}
@@ -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 {}");