mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 10:20:15 +07:00
[java-intentions] MethodParameterFix: preview-friendly
GitOrigin-RevId: 14945eb9ea25a46005d9bfb77bf8c525d9e142f1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
942d8db752
commit
9d10cf9e58
@@ -1,9 +1,10 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// 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.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo;
|
||||
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
|
||||
import com.intellij.openapi.command.undo.UndoUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -14,6 +15,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.SuggestedNameInfo;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.refactoring.JavaRefactoringFactory;
|
||||
@@ -127,4 +129,15 @@ public class MethodParameterFix extends LocalQuickFixAndIntentionActionOnPsiElem
|
||||
}
|
||||
return result.toArray(new ParameterInfoImpl[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull IntentionPreviewInfo generatePreview(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
|
||||
final PsiMethod method = PsiTreeUtil.findSameElementInCopy((PsiMethod)getStartElement(), file);
|
||||
PsiTypeElement typeElement = method.getParameterList().getParameters()[myIndex].getTypeElement();
|
||||
if (typeElement == null) return IntentionPreviewInfo.EMPTY;
|
||||
PsiElementFactory factory = PsiElementFactory.getInstance(project);
|
||||
PsiTypeElement newTypeElement = factory.createTypeElement(myParameterType);
|
||||
typeElement.replace(newTypeElement);
|
||||
return IntentionPreviewInfo.DIFF;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Make 'VarArgMismatch' take parameter of type 'int...' here" "true-preview"
|
||||
record VarArgMismatch(int... x) {
|
||||
public VarArgMismatch(int... x) {
|
||||
this.x = x;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Make 'VarArgMismatch2' take parameter of type 'int[]' here" "true-preview"
|
||||
record VarArgMismatch2(int[] x) {
|
||||
public VarArgMismatch2(int[] x) {
|
||||
this.x = x;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Make 'VarArgMismatch' take parameter of type 'int...' here" "true-preview"
|
||||
record VarArgMismatch(int... x) {
|
||||
public VarArgMismatch(int<caret>[] x) {
|
||||
this.x = x;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Make 'VarArgMismatch2' take parameter of type 'int[]' here" "true-preview"
|
||||
record VarArgMismatch2(int[] x) {
|
||||
public VarArgMismatch2(int..<caret>. x) {
|
||||
this.x = x;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// 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.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
|
||||
public class MethodParameterFixTest extends LightQuickFixParameterizedTestCase {
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/methodParameter";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user