void (@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { final PsiModifierListOwner modifierListOwner = (PsiModifierListOwner)startElement; final PsiAnnotationOwner target = AnnotationTargetUtil.getTarget(modifierListOwner, myExistsTypeUseTarget); if (target == null || myHasApplicableAnnotations) { return; } final ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(project); final AnnotationPlace place = myAnnotationPlace == AnnotationPlace.NEED_ASK_USER ? annotationsManager.chooseAnnotationsPlace(modifierListOwner) : myAnnotationPlace; switch (place) { case NOWHERE -> { } case EXTERNAL -> { for (String fqn : myAnnotationsToRemove) { annotationsManager.deannotate(modifierListOwner, fqn); } try { annotationsManager.annotateExternally(modifierListOwner, myAnnotation, file, myPairs); } catch (ExternalAnnotationsManager.CanceledConfigurationException ignored) { } } case IN_CODE -> { final PsiFile containingFile = modifierListOwner.getContainingFile(); Runnable command = () -> { removePhysicalAnnotations(modifierListOwner, myAnnotationsToRemove); PsiAnnotation inserted = addPhysicalAnnotationTo(addAnnotation(target, myAnnotation), myPairs); if (inserted != null) JavaCodeStyleManager.getInstance(project).shortenClassReferences(inserted); }; if (!containingFile.isPhysical()) { command.run(); } else { WriteCommandAction.runWriteCommandAction(project, null, null, command, containingFile); } if (containingFile != file) { UndoUtil.markPsiFileForUndo(file); } } } }