void (@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement element) { final PsiAnnotation annotation = (PsiAnnotation)findMatchingElement(element); if (annotation == null) return; final String annotationName = annotation.getQualifiedName(); if (annotationName == null) { return; } final NullableNotNullManager notNullManager = NullableNotNullManager.getInstance(project); final List<String> notNulls = notNullManager.getNotNulls(); final List<String> nullables = notNullManager.getNullables(); final List<String> annotationsToRemove; if (notNulls.contains(annotationName)) { annotationsToRemove = nullables; } else if (nullables.contains(annotationName)) { annotationsToRemove = notNulls; } else { annotationsToRemove = Collections.emptyList(); } final PsiElement parent = annotation.getParent(); final PsiElement grandParent = parent.getParent(); final PsiMethod method; final int parameterIndex; if (!(grandParent instanceof PsiMethod)) { if (!(grandParent instanceof PsiParameter parameter)) { return; } final PsiElement greatGrandParent = grandParent.getParent(); if (!(greatGrandParent instanceof PsiParameterList parameterList)) { return; } parameterIndex = parameterList.getParameterIndex(parameter); final PsiElement greatGreatGrandParent = greatGrandParent.getParent(); if (!(greatGreatGrandParent instanceof PsiMethod)) { return; } method = (PsiMethod)greatGreatGrandParent; } else { parameterIndex = -1; method = (PsiMethod)grandParent; } final Collection<PsiMethod> overridingMethods = OverridingMethodsSearch.search(method).findAll(); final List<PsiMethod> prepare = new ArrayList<>(); final ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(project); final Map<PsiMethod, ExternalAnnotationsManager.AnnotationPlace> annotationPlaces = new LinkedHashMap<>(); for (PsiMethod overridingMethod : overridingMethods) { annotationPlaces.put(overridingMethod, annotationsManager.chooseAnnotationsPlaceNoUi(overridingMethod)); } askAboutSourceRootsWithoutExternalAnnotations(project, overridingMethods, annotationsManager, annotationPlaces); for (PsiMethod overridingMethod : overridingMethods) { if (annotationPlaces.get(overridingMethod) == ExternalAnnotationsManager.AnnotationPlace.IN_CODE) { prepare.add(overridingMethod); } } if (!FileModificationService.getInstance().preparePsiElementsForWrite(prepare)) { return; } final PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes(); try { for (PsiMethod overridingMethod : overridingMethods) { if (parameterIndex == -1) { annotate(overridingMethod, annotationName, attributes, annotationsToRemove, annotationPlaces.get(overridingMethod), annotationsManager); } else { final PsiParameterList parameterList = overridingMethod.getParameterList(); final PsiParameter[] parameters = parameterList.getParameters(); final PsiParameter parameter = parameters[parameterIndex]; annotate(parameter, annotationName, attributes, annotationsToRemove, annotationPlaces.get(overridingMethod), annotationsManager); } } } catch (ExternalAnnotationsManager.CanceledConfigurationException ignored) { //escape on configuring root cancel further annotations } if (!prepare.isEmpty()) { UndoUtil.markPsiFileForUndo(annotation.getContainingFile()); } }