PsiMethod (@NotNull Project project, PsiMethod method, int methodParameterIndex, // -1 if no parameter to change @NotNull PsiClassType newParameterExtends) { JavaDummyHolder dummyHolder = (JavaDummyHolder)DummyHolderFactory.createHolder(PsiManager.getInstance(project), method); PsiMethod methodCopy = (PsiMethod)dummyHolder.add(method); // force this dummy holder resolve recursive method calls to this "methodCopy" instead of original method dummyHolder.setInjectedDeclarations((processor, state, lastParent, place) -> processor.execute(methodCopy, state)); if (methodParameterIndex != -1) { PsiTypeElement paramTE = Objects.requireNonNull(methodCopy.getParameterList().getParameter(methodParameterIndex)).getTypeElement(); ReplaceWithQuestionTFix.replaceType(project, paramTE, newParameterExtends); } return methodCopy; }