private static void addResult( CompletionResultSet result, Collection<Lookup> collection, PsiElement position, int offset) { result = result.withPrefixMatcher(findPrefixStatic(position, offset)); for (Lookup lookup : collection) { final LookupItem<Lookup> item = new LookupItem<>(lookup, lookup.toString()); item.setInsertHandler(INSERT_HANDLER); if (lookup.isKeyword()) { item.setBold(); } result.addElement(item); } }
public static LookupElement objectToLookupItem(Object object) { if (object instanceof LookupElement) return (LookupElement) object; String s = null; TailType tailType = TailType.NONE; if (object instanceof PsiElement) { s = PsiUtilBase.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(); } else { LOG.assertTrue( false, "Null string for object: " + object + " of class " + (object != null ? object.getClass() : null)); } LookupItem item = new LookupItem(object, s); if (object instanceof LookupValueWithUIHint && ((LookupValueWithUIHint) object).isBold()) { item.setBold(); } if (object instanceof LookupValueWithTail) { item.setAttribute( LookupItem.TAIL_TEXT_ATTR, " " + ((LookupValueWithTail) object).getTailText()); } item.setAttribute(CompletionUtil.TAIL_TYPE_ATTR, tailType); return item; }