LookupElement (final @NotNull Object object) { if (object instanceof LookupElement) return (LookupElement)object; String s = null; TailType tailType = TailTypes.noneType(); 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 PresentableLookupValue) { s = ((PresentableLookupValue)object).getPresentation(); } if (s == null) { throw PluginException.createByClass("Null string for object: " + object + " of " + object.getClass(), null, object.getClass()); } LookupItem<?> item = new LookupItem<>(object, s); item.setAttribute(LookupItem.TAIL_TYPE_ATTR, tailType); return item; }