-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
SafeDeleteProcessorDelegate.java
120 lines (105 loc) · 5.71 KB
/
SafeDeleteProcessorDelegate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.refactoring.safeDelete;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.refactoring.BaseRefactoringProcessor;
import com.intellij.usageView.UsageInfo;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.List;
import static com.intellij.openapi.util.NlsContexts.DialogMessage;
/**
* An extension point for "Safe Delete" refactoring.
* <p>
* Delegates are processed one by one, the first delegate which agrees to handle element ({@link #handlesElement(PsiElement)}) will be used, rest are ignored.
* Natural loading order can be changed by providing attribute "order" during registration in plugin.xml.
*/
public interface SafeDeleteProcessorDelegate {
ExtensionPointName<SafeDeleteProcessorDelegate> EP_NAME = ExtensionPointName.create("com.intellij.refactoring.safeDeleteProcessor");
/**
* @return {@code true} if delegates can process {@code element}.
*/
boolean handlesElement(PsiElement element);
/**
* Find usages of the {@code element} and fill {@code result} with them.
* Is called during {@link BaseRefactoringProcessor#findUsages()} under modal progress in read action.
*
* @param element an element selected for deletion.
* @param allElementsToDelete all elements selected for deletion.
* @param result list of {@link UsageInfo} to store found usages
* @return {@code null} if element should not be searched in text occurrences/comments though corresponding settings were enabled, otherwise
* bean with the information how to detect if an element is inside all elements to delete (e.g. {@link SafeDeleteProcessor#getDefaultInsideDeletedCondition(PsiElement[])})
* and current element.
*/
@Nullable
NonCodeUsageSearchInfo findUsages(@NotNull PsiElement element, PsiElement @NotNull [] allElementsToDelete, @NotNull List<? super UsageInfo> result);
/**
* Returns elements that are searched for usages of the element selected for deletion. Called before the refactoring dialog is shown.
* May show UI to ask if additional elements should be deleted along with the specified selected element.
*
* @param element an element selected for deletion.
* @param allElementsToDelete all elements selected for deletion.
* @return additional elements to search for usages, or null if the user has cancelled the refactoring.
*/
@Nullable
Collection<? extends PsiElement> getElementsToSearch(@NotNull PsiElement element, @NotNull Collection<? extends PsiElement> allElementsToDelete);
/**
* Returns the list of additional elements to be deleted. Called after the refactoring dialog is shown.
* May show UI to ask the user if some additional elements should be deleted along with the
* specified selected element.
*
* @param element an element selected for deletion.
* @param allElementsToDelete all elements selected for deletion.
* @return additional elements to search for usages, or null if no additional elements were chosen.
*/
@Nullable
Collection<PsiElement> getAdditionalElementsToDelete(@NotNull PsiElement element, @NotNull Collection<? extends PsiElement> allElementsToDelete, boolean askUser);
/**
* Detects usages which are not safe to delete.
*
* @param element an element selected for deletion.
* @param allElementsToDelete all elements selected for deletion.
* @return collection of conflict messages which would be shown to the user before delete can be performed.
*/
@Nullable
Collection<@DialogMessage String> findConflicts(@NotNull PsiElement element, PsiElement @NotNull [] allElementsToDelete);
/**
* Called after the user has confirmed the refactoring. Can filter out some of the usages
* found by the refactoring. May show UI to ask the user if some of the usages should
* be excluded.
*
* @param project the project where the refactoring happens.
* @param usages all usages to be processed by the refactoring.
* @return the filtered list of usages, or null if the user has cancelled the refactoring.
*/
UsageInfo @Nullable [] preprocessUsages(@NotNull Project project, UsageInfo @NotNull [] usages);
/**
* Prepares an element for deletion e.g., normalizing declaration so the element declared in the same declaration won't be affected by deletion.
*
* Called during {@link BaseRefactoringProcessor#performRefactoring(UsageInfo[])} under write action
*
* @param element an element selected for deletion.
*/
void prepareForDeletion(@NotNull PsiElement element) throws IncorrectOperationException;
/**
* Called to set initial value for "Search in comments" checkbox.
* @return {@code true} if previous safe delete was executed with "Search in comments" option on.
*/
boolean isToSearchInComments(PsiElement element);
/**
* Called to save chosen for given {@code element} "Search in comments" value.
*/
void setToSearchInComments(PsiElement element, boolean enabled);
/**
* Called to set initial value for "Search for text occurrence" checkbox.
* @return {@code true} if previous safe delete was executed with "Search for test occurrences" option on.
*/
boolean isToSearchForTextOccurrences(PsiElement element);
/**
* Called to save chosen for given {@code element} "Search for text occurrences" value.
*/
void setToSearchForTextOccurrences(PsiElement element, boolean enabled);
}