members declared in the qualifier class go first in the completion list (IDEA-13030)

This commit is contained in:
peter
2011-02-07 12:49:27 +01:00
parent 158364953b
commit 456b8d2356
5 changed files with 29 additions and 13 deletions
@@ -728,14 +728,14 @@ public class JavaCompletionUtil {
return item;
}
private static LookupElementDecorator<LookupElement> highlight(LookupElement decorator) {
return LookupElementDecorator.withRenderer(decorator, new LookupElementRenderer<LookupElementDecorator<LookupElement>>() {
private static LookupElement highlight(LookupElement decorator) {
return PrioritizedLookupElement.withGrouping(LookupElementDecorator.withRenderer(decorator, new LookupElementRenderer<LookupElementDecorator<LookupElement>>() {
@Override
public void renderElement(LookupElementDecorator<LookupElement> element, LookupElementPresentation presentation) {
element.getDelegate().renderElement(presentation);
presentation.setItemTextBold(true);
}
});
}), 1);
}
private static LookupItem<?> createLookupElement(CompletionElement completionElement, PsiType qualifierType) {
@@ -58,8 +58,9 @@ public class SmartCompletionDecorator extends TailTypeDecorator<LookupElement> {
return defType;
}
LookupElement item = getDelegate();
Object object = item.getObject();
LookupElement delegate = getDelegate();
LookupItem item = as(LookupItem.class);
Object object = delegate.getObject();
if (!CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && (object instanceof PsiMethod || object instanceof PsiClass)) {
return TailType.NONE;
}
@@ -67,8 +68,8 @@ public class SmartCompletionDecorator extends TailTypeDecorator<LookupElement> {
final PsiExpression enclosing = PsiTreeUtil.getContextOfType(myPosition, PsiExpression.class, true);
if (enclosing != null && object instanceof PsiElement) {
final PsiType type = getItemType(item);
final TailType itemType = item instanceof LookupItem ? ((LookupItem)item).getTailType() : TailType.NONE;
final PsiType type = JavaCompletionUtil.getLookupElementType(delegate);
final TailType itemType = item != null ? item.getTailType() : TailType.NONE;
TailType cached = itemType;
int cachedPrior = 0;
if (type != null && type.isValid()) {
@@ -108,11 +109,6 @@ public class SmartCompletionDecorator extends TailTypeDecorator<LookupElement> {
return null;
}
@Nullable
private PsiType getItemType(LookupElement element) {
return JavaCompletionUtil.getLookupElementType(element);
}
@Override
public void handleInsert(InsertionContext context) {
myPosition = getPosition(context, this);
@@ -0,0 +1,15 @@
class Foo {
void fromSuper() {}
void overridden() {}
}
class FooImpl extends Foo {
void overridden() {}
void fromThis() {}
}
class Bar {
{
new FooImpl().<caret>
}
}
@@ -170,4 +170,9 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
assertEquals("foo.Foo", ((JavaPsiClassReferenceElement)getLookup().getCurrentItem()).getQualifiedName());
}
public void testDeclaredMembersGoFirst() throws Exception {
invokeCompletion(getBasePath() + "/" + getTestName(false) + ".java");
assertStringItems("fromThis", "overridden", "fromSuper", "equals", "getClass", "hashCode", "notify", "notifyAll", "toString", "wait", "wait", "wait");
}
}
@@ -372,7 +372,7 @@ public class LookupItem<T> extends MutableLookupElement<T> implements Comparable
}
public static @Nullable LookupItem from(LookupElement lookupElement) {
if (lookupElement instanceof LookupElementDecorator) {
while (lookupElement instanceof LookupElementDecorator) {
lookupElement = ((LookupElementDecorator)lookupElement).getDelegate();
}
if (lookupElement instanceof LookupItem) return (LookupItem)lookupElement;