Search in sources :

Example 1 with PresentableLookupValue

use of com.intellij.codeInsight.lookup.PresentableLookupValue in project intellij-community by JetBrains.

the class CompletionData method objectToLookupItem.

public static LookupElement objectToLookupItem(@NotNull final Object object) {
    if (object instanceof LookupElement)
        return (LookupElement) object;
    String s = null;
    TailType tailType = TailType.NONE;
    if (object instanceof PsiElement) {
        s = PsiUtilCore.getName((PsiElement) object);
    } else if (object instanceof PsiMetaData) {
        s = ((PsiMetaData) object).getName();
    } else if (object instanceof String) {
        s = (String) object;
    } else if (object instanceof Template) {
        s = ((Template) object).getKey();
    } else if (object instanceof PresentableLookupValue) {
        s = ((PresentableLookupValue) object).getPresentation();
    }
    if (s == null) {
        throw new AssertionError("Null string for object: " + object + " of class " + object.getClass());
    }
    LookupItem item = new LookupItem(object, s);
    if (object instanceof LookupValueWithUIHint && ((LookupValueWithUIHint) object).isBold()) {
        item.setBold();
    }
    item.setAttribute(LookupItem.TAIL_TYPE_ATTR, tailType);
    return item;
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) LookupValueWithUIHint(com.intellij.codeInsight.lookup.LookupValueWithUIHint) LookupItem(com.intellij.codeInsight.lookup.LookupItem) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PresentableLookupValue(com.intellij.codeInsight.lookup.PresentableLookupValue) TailType(com.intellij.codeInsight.TailType) Template(com.intellij.codeInsight.template.Template)

Aggregations

TailType (com.intellij.codeInsight.TailType)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupItem (com.intellij.codeInsight.lookup.LookupItem)1 LookupValueWithUIHint (com.intellij.codeInsight.lookup.LookupValueWithUIHint)1 PresentableLookupValue (com.intellij.codeInsight.lookup.PresentableLookupValue)1 Template (com.intellij.codeInsight.template.Template)1 PsiMetaData (com.intellij.psi.meta.PsiMetaData)1