Collection<PsiElement> (@NotNull PsiElement element, @NotNull Collection<? extends PsiElement> allElementsToDelete, boolean askUser) { if (element instanceof PsiField field) { Project project = element.getProject(); String propertyName = JavaCodeStyleManager.getInstance(project).variableNameToPropertyName(field.getName(), VariableKind.FIELD); PsiClass aClass = field.getContainingClass(); if (aClass != null) { boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC); PsiMethod[] getters = GetterSetterPrototypeProvider.findGetters(aClass, propertyName, isStatic); if (getters != null) { List<PsiMethod> validGetters = new ArrayList<>(1); for (PsiMethod getter : getters) { if (getter != null && !allElementsToDelete.contains(getter) && getter.isPhysical()) { validGetters.add(getter); } } getters = validGetters.isEmpty() ? null : validGetters.toArray(PsiMethod.EMPTY_ARRAY); } PsiMethod setter = PropertyUtilBase.findPropertySetter(aClass, propertyName, isStatic, false); if (setter != null && (allElementsToDelete.contains(setter) || !setter.isPhysical())) { setter = null; } if (askUser && (getters != null || setter != null)) { String message = RefactoringMessageUtil.getGetterSetterMessage(field.getName(), RefactoringBundle.message("delete.title"), getters != null ? getters[0] : null, setter); if (!ApplicationManager.getApplication().isUnitTestMode() && Messages.showYesNoDialog(project, message, RefactoringBundle.message("safe.delete.title"), Messages.getQuestionIcon()) != Messages.YES) { getters = null; setter = null; } } List<PsiElement> elements = new ArrayList<>(); if (setter != null) elements.add(setter); if (getters != null) Collections.addAll(elements, getters); return elements; } } return null; }