public static PsiSubstitutor obtainFinalSubstitutor( @NotNull PsiClass candidateClass, @NotNull PsiSubstitutor candidateSubstitutor, @NotNull PsiClass aClass, @NotNull PsiSubstitutor substitutor, @NotNull PsiElementFactory elementFactory, @NotNull LanguageLevel languageLevel) { if (PsiUtil.isRawSubstitutor(aClass, substitutor)) { return elementFactory.createRawSubstitutor(candidateClass); } final PsiType containingType = elementFactory.createType(candidateClass, candidateSubstitutor, languageLevel); PsiType type = substitutor.substitute(containingType); if (!(type instanceof PsiClassType)) return candidateSubstitutor; return ((PsiClassType) type).resolveGenerics().getSubstitutor(); }
private static LookupElementBuilder createGenerateMethodElement( PsiMethod prototype, PsiSubstitutor substitutor, Icon icon, String typeText, InsertHandler<LookupElement> insertHandler) { String methodName = prototype.getName(); String visibility = VisibilityUtil.getVisibilityModifier(prototype.getModifierList()); String modifiers = (visibility == PsiModifier.PACKAGE_LOCAL ? "" : visibility + " "); PsiType type = substitutor.substitute(prototype.getReturnType()); String signature = modifiers + (type == null ? "" : type.getPresentableText() + " ") + methodName; String parameters = PsiFormatUtil.formatMethod( prototype, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME); String overrideSignature = " @Override " + signature; // leading space to make it a middle match, under all annotation // suggestions LookupElementBuilder element = LookupElementBuilder.create(prototype, signature) .withLookupString(methodName) .withLookupString(signature) .withLookupString(overrideSignature) .withInsertHandler(insertHandler) .appendTailText(parameters, false) .appendTailText(" {...}", true) .withTypeText(typeText) .withIcon(icon); element.putUserData(GENERATE_ELEMENT, true); return element; }