mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Migrate PyReplaceTupleWithListQuickFix and UnresolvedRefTrueFalseQuickFix to ModCommand
PY-65297 GitOrigin-RevId: e0abfb5676823e1a70d5aac605da7844ca170ee4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bf7b728383
commit
007259a141
+5
-6
@@ -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.resolve.PyResolveContext;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PyReplaceTupleWithListQuickFix implements LocalQuickFix {
|
||||
public class PyReplaceTupleWithListQuickFix extends PsiUpdateModCommandQuickFix {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
@@ -33,15 +33,14 @@ public class PyReplaceTupleWithListQuickFix implements LocalQuickFix {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
PsiElement element = descriptor.getPsiElement();
|
||||
public void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
assert element instanceof PyAssignmentStatement;
|
||||
PyExpression[] targets = ((PyAssignmentStatement)element).getTargets();
|
||||
if (targets.length == 1 && targets[0] instanceof PySubscriptionExpression subscriptionExpression) {
|
||||
if (subscriptionExpression.getOperand() instanceof PyReferenceExpression referenceExpression) {
|
||||
final TypeEvalContext context = TypeEvalContext.userInitiated(project, element.getContainingFile());
|
||||
final PyResolveContext resolveContext = PyResolveContext.defaultContext(context);
|
||||
element = referenceExpression.followAssignmentsChain(resolveContext).getElement();
|
||||
element = updater.getWritable(referenceExpression.followAssignmentsChain(resolveContext).getElement());
|
||||
if (element instanceof PyParenthesizedExpression) {
|
||||
final PyExpression expression = ((PyParenthesizedExpression)element).getContainedExpression();
|
||||
replaceWithListLiteral(element, (PyTupleExpression)expression);
|
||||
|
||||
+6
-9
@@ -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.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -17,7 +17,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* <p>
|
||||
* QuickFix to replace true with True, false with False
|
||||
*/
|
||||
public class UnresolvedRefTrueFalseQuickFix implements LocalQuickFix {
|
||||
public class UnresolvedRefTrueFalseQuickFix extends PsiUpdateModCommandQuickFix {
|
||||
String newName;
|
||||
|
||||
public UnresolvedRefTrueFalseQuickFix(@NotNull String oldName) {
|
||||
@@ -37,13 +37,10 @@ public class UnresolvedRefTrueFalseQuickFix implements LocalQuickFix {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
public void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
if (element != null) {
|
||||
PyExpression expression = elementGenerator.createExpressionFromText(LanguageLevel.forElement(element), newName);
|
||||
element.replace(expression);
|
||||
}
|
||||
PyExpression expression = elementGenerator.createExpressionFromText(LanguageLevel.forElement(element), newName);
|
||||
element.replace(expression);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user