void (PsiMember memberCopy, PsiClass targetClass) { if (memberCopy instanceof PsiTypeParameterListOwner && !memberCopy.hasModifierProperty(PsiModifier.STATIC)) { UniqueNameGenerator nameGenerator = new UniqueNameGenerator(); PsiUtil.typeParametersIterable(targetClass).forEach(param -> { String paramName = param.getName(); if (paramName != null) { nameGenerator.addExistingName(paramName); } }); PsiSubstitutor substitutor = PsiSubstitutor.EMPTY; PsiElementFactory factory = JavaPsiFacade.getElementFactory(memberCopy.getProject()); for (PsiTypeParameter parameter : ((PsiTypeParameterListOwner)memberCopy).getTypeParameters()) { String parameterName = parameter.getName(); if (parameterName == null) continue; if (!nameGenerator.isUnique(parameterName)) { substitutor = substitutor.put(parameter, PsiSubstitutor.EMPTY.substitute( factory.createTypeParameter(nameGenerator.generateUniqueName(parameterName), PsiClassType.EMPTY_ARRAY))); } } if (!PsiSubstitutor.EMPTY.equals(substitutor)) { replaceMovedMemberTypeParameters(memberCopy, PsiUtil.typeParametersIterable((PsiTypeParameterListOwner)memberCopy), substitutor, factory);//rename usages in the method for (Map.Entry<PsiTypeParameter, PsiType> entry : substitutor.getSubstitutionMap().entrySet()) { entry.getKey().setName(entry.getValue().getCanonicalText()); //rename declaration after all usages renamed } } } }