PsiMethod (PsiMethod method, PsiReference ref) { Supplier<PsiCodeBlock> specialization = forReference(ref); if (specialization == null) return method; PsiElementFactory factory = JavaPsiFacade.getElementFactory(method.getProject()); String parameters = method.getParameterList().getText(); PsiType returnType = method.getReturnType(); String type = returnType == null ? "" : returnType.getCanonicalText(true); PsiMethod copy = factory.createMethodFromText(type + " " + method.getName() + parameters + " {}", method); Objects.requireNonNull(copy.getBody()).replace(specialization.get()); return copy; }