void (PsiMethod method) { PsiClass containingClass = method.getContainingClass(); PsiClass base = containingClass == null ? null : containingClass.getSuperClass(); PsiMethod overridden = base == null ? null : base.findMethodBySignature(method, true); boolean emptyTemplate = true; PsiCodeBlock body = method.getBody(); if (body != null) { PsiJavaToken lBrace = body.getLBrace(); int left = lBrace != null ? lBrace.getStartOffsetInParent() + 1 : 0; PsiJavaToken rBrace = body.getRBrace(); int right = rBrace != null ? rBrace.getStartOffsetInParent() : body.getTextLength(); emptyTemplate = StringUtil.isEmptyOrSpaces(body.getText().substring(left, right)); } if (overridden == null) { if (emptyTemplate) { CreateFromUsageUtils.setupMethodBody(method); } return; } PsiSubstitutor classSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(base, containingClass, PsiSubstitutor.EMPTY); PsiElementFactory factory = JavaPsiFacade.getElementFactory(method.getProject()); String throwsList = Arrays.stream(overridden.getThrowsList().getReferencedTypes()) .map(classSubstitutor::substitute) .filter(Objects::nonNull) .map(type -> type.getCanonicalText()) .collect(Collectors.joining(", ")); if (throwsList.isEmpty()) { method.getThrowsList().delete(); } else { method.getThrowsList().replace(factory.createMethodFromText("void m() throws " + throwsList + ";", method).getThrowsList()); } if (emptyTemplate) { OverrideImplementUtil.setupMethodBody(method, overridden, containingClass); } OverrideImplementUtil.annotateOnOverrideImplement(method, base, overridden); }