PsiMethod (@NotNull Project project, @Nullable PsiField field, @NotNull PsiClass containingClass, @NotNull PsiMethod method, @NotNull PsiMethod methodCopy, @NotNull PsiClassType newParameterExtends) { JavaDummyHolder dummyHolder = (JavaDummyHolder)DummyHolderFactory.createHolder(PsiManager.getInstance(project), containingClass); PsiClass classCopy = (PsiClass)dummyHolder.add(containingClass); if (field != null) { PsiField fieldCopy = classCopy.findFieldByName(field.getName(), false); ReplaceWithQuestionTFix.replaceType(project, fieldCopy.getTypeElement(), newParameterExtends); } int methodIndex = ArrayUtil.indexOf(containingClass.getMethods(), method); PsiMethod methodInClassCopy = classCopy.getMethods()[methodIndex]; PsiMethod result = (PsiMethod)methodInClassCopy.replace(methodCopy); // patch method parameter type patchThisExpression(result, containingClass); return result; }