ModCommand (@NotNull ActionContext context, @NotNull PsiMethod myMethod) { PsiJavaCodeReferenceElement[] referenceElements = myMethod.getThrowsList().getReferenceElements(); boolean alreadyThrows = ContainerUtil.exists(referenceElements, referenceElement -> referenceElement.getCanonicalText().equals(myThrowsCanonicalText)); if (alreadyThrows) return ModCommand.nop(); final PsiElementFactory factory = JavaPsiFacade.getElementFactory(myMethod.getProject()); final PsiClassType type = (PsiClassType)factory.createTypeFromText(myThrowsCanonicalText, myMethod); JavaCodeStyleManager manager = JavaCodeStyleManager.getInstance(context.project()); PsiElement ref = manager.shortenClassReferences(factory.createReferenceElementByType(type)); return ModCommand.psiUpdate(myMethod, method -> method.getThrowsList().add(ref)); }