mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[lang] Make getElement API protected in PsiElementBaseIntentionAction
Can be used to retrieve element in intention preview. GitOrigin-RevId: c1fe0e4b83d941259ad3504639af05b58488fe41
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e63a35f6f3
commit
e5fea5533b
+1
-2
@@ -10,7 +10,6 @@ import com.intellij.java.JavaBundle;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.editor.CaretModel;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
@@ -67,7 +66,7 @@ public class ExtractSetFromComparisonChainAction extends PsiElementBaseIntention
|
||||
|
||||
@Override
|
||||
public @NotNull IntentionPreviewInfo generatePreview(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
|
||||
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
PsiElement element = getElement(editor, file);
|
||||
if (element == null) return IntentionPreviewInfo.EMPTY;
|
||||
extract(project, editor, element);
|
||||
return IntentionPreviewInfo.DIFF;
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class ConvertToSingleReturnAction extends PsiElementBaseIntentionAction {
|
||||
|
||||
@Override
|
||||
public @NotNull IntentionPreviewInfo generatePreview(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
|
||||
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
PsiElement element = getElement(editor, file);
|
||||
PsiCodeBlock block = findBlock(element);
|
||||
if (block == null) return IntentionPreviewInfo.EMPTY;
|
||||
PsiCodeBlock replacement = generateBody(project, block, new EmptyProgressIndicator());
|
||||
|
||||
+8
-1
@@ -77,8 +77,15 @@ public abstract class PsiElementBaseIntentionAction extends BaseIntentionAction
|
||||
*/
|
||||
public abstract boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element);
|
||||
|
||||
/**
|
||||
* Retrieves the element this intention was invoked on.
|
||||
*
|
||||
* @param editor the editor in which the intention was invoked, can be preview editor.
|
||||
* @param file the file in which the intention was invoked.
|
||||
* @return the element under caret.
|
||||
*/
|
||||
@Nullable
|
||||
private static PsiElement getElement(@NotNull Editor editor, @NotNull PsiFile file) {
|
||||
protected static PsiElement getElement(@NotNull Editor editor, @NotNull PsiFile file) {
|
||||
CaretModel caretModel = editor.getCaretModel();
|
||||
int position = caretModel.getOffset();
|
||||
return file.findElementAt(position);
|
||||
|
||||
Reference in New Issue
Block a user