Template (Project project, String exprText, final PsiType[] suggestedTypes) { final TemplateManager templateManager = TemplateManager.getInstance(project); final Template template = templateManager.createTemplate("", ""); template.setToReformat(true); Set<LookupElement> itemSet = new LinkedHashSet<>(); for (PsiType type : suggestedTypes) { itemSet.add(PsiTypeLookupItem.createLookupItem(type, null)); } final Result result = suggestedTypes.length > 0 ? new PsiTypeResult(suggestedTypes[0], project) : null; Expression expr = new ConstantNode(result).withLookupItems(itemSet.size() > 1 ? itemSet : Collections.emptySet()); template.addTextSegment("(("); template.addVariable(TYPE_TEMPLATE_VARIABLE, expr, expr, true); template.addTextSegment(")" + exprText + ")"); template.addEndVariable(); return template; }