mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-intentions] IntroduceVariableErrorFixAction: preview-friendly
GitOrigin-RevId: 9db632643fe116f835b32ec42b1b03be917f9000
This commit is contained in:
committed by
intellij-monorepo-bot
parent
30d9784c64
commit
13c0dc41a1
+16
-1
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// 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.codeInsight.intention.impl;
|
||||
|
||||
import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo;
|
||||
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
|
||||
import com.intellij.java.JavaBundle;
|
||||
import com.intellij.lang.LanguageRefactoringSupport;
|
||||
@@ -10,6 +11,8 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.PreviewableRefactoringActionHandler;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.introduceVariable.JavaIntroduceVariableHandlerBase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -46,4 +49,16 @@ public class IntroduceVariableErrorFixAction extends LocalQuickFixAndIntentionAc
|
||||
public @NotNull String getFamilyName() {
|
||||
return getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull IntentionPreviewInfo generatePreview(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
|
||||
PsiElement element = PsiTreeUtil.findSameElementInCopy(myStartElement.getElement(), file);
|
||||
if (element == null) return IntentionPreviewInfo.EMPTY;
|
||||
RefactoringActionHandler handler = LanguageRefactoringSupport.INSTANCE.forLanguage(JavaLanguage.INSTANCE).getIntroduceVariableHandler();
|
||||
assert handler != null;
|
||||
if (handler instanceof PreviewableRefactoringActionHandler previewableRefactoringActionHandler) {
|
||||
return previewableRefactoringActionHandler.generatePreview(project, element);
|
||||
}
|
||||
return IntentionPreviewInfo.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Introduce local variable" "true"
|
||||
// "Introduce local variable" "true-preview"
|
||||
class a {
|
||||
void a() {
|
||||
list.add(new Runnable(){
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Introduce local variable" "true"
|
||||
// "Introduce local variable" "true-preview"
|
||||
class a {
|
||||
void a() {
|
||||
list.add(new Runnable(){
|
||||
|
||||
Reference in New Issue
Block a user