Migrate RemoveUnnecessaryBackslashQuickFix and ReplaceBackquoteExpressionQuickFix to ModCommand

PY-65297

GitOrigin-RevId: 4ce00d9b64e1ec4df6ef95784df9f9cd54e21dfa
This commit is contained in:
Georgii Ustinov
2024-01-04 16:12:11 +02:00
committed by intellij-monorepo-bot
parent 9beee6f18c
commit cf043445b0
2 changed files with 14 additions and 18 deletions

View File

@@ -1,8 +1,8 @@
// Copyright 2000-2018 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.
package com.jetbrains.python.inspections.quickfix;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.modcommand.ModPsiUpdater;
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiWhiteSpace;
@@ -18,7 +18,7 @@ import org.jetbrains.annotations.NotNull;
*
* QuickFix to remove all unnecessary backslashes in expression
*/
public class RemoveUnnecessaryBackslashQuickFix implements LocalQuickFix {
public class RemoveUnnecessaryBackslashQuickFix extends PsiUpdateModCommandQuickFix {
@Override
@NotNull
public String getFamilyName() {
@@ -26,12 +26,9 @@ public class RemoveUnnecessaryBackslashQuickFix implements LocalQuickFix {
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement problemElement = descriptor.getPsiElement();
if (problemElement != null) {
PsiElement parent = PsiTreeUtil.getParentOfType(problemElement, PyEditorHandlerConfig.IMPLICIT_WRAP_CLASSES);
public void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
PsiElement parent = PsiTreeUtil.getParentOfType(element, PyEditorHandlerConfig.IMPLICIT_WRAP_CLASSES);
removeBackSlash(parent);
}
}
public static void removeBackSlash(PsiElement parent) {

View File

@@ -15,8 +15,8 @@
*/
package com.jetbrains.python.inspections.quickfix;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.modcommand.ModPsiUpdater;
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.jetbrains.python.PyPsiBundle;
@@ -25,7 +25,7 @@ import com.jetbrains.python.psi.PyElementGenerator;
import com.jetbrains.python.psi.PyReprExpression;
import org.jetbrains.annotations.NotNull;
public class ReplaceBackquoteExpressionQuickFix implements LocalQuickFix {
public class ReplaceBackquoteExpressionQuickFix extends PsiUpdateModCommandQuickFix {
@NotNull
@Override
public String getFamilyName() {
@@ -33,13 +33,12 @@ public class ReplaceBackquoteExpressionQuickFix implements LocalQuickFix {
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement problemElement = descriptor.getPsiElement();
if (problemElement instanceof PyReprExpression) {
if (((PyReprExpression)problemElement).getExpression() != null) {
final LanguageLevel level = LanguageLevel.forElement(problemElement);
final String text = "repr(" + ((PyReprExpression)problemElement).getExpression().getText() + ")";
problemElement.replace(PyElementGenerator.getInstance(project).createExpressionFromText(level, text));
public void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
if (element instanceof PyReprExpression) {
if (((PyReprExpression)element).getExpression() != null) {
final LanguageLevel level = LanguageLevel.forElement(element);
final String text = "repr(" + ((PyReprExpression)element).getExpression().getText() + ")";
element.replace(PyElementGenerator.getInstance(project).createExpressionFromText(level, text));
}
}
}