mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
correctly implement getFamilyName() for Python quickfixes; remove some of PSI elements stored in quickfix instances
This commit is contained in:
@@ -39,7 +39,7 @@ public class AddCallSuperQuickFix implements LocalQuickFix {
|
||||
@NonNls
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class AddEncodingQuickFix implements LocalQuickFix {
|
||||
@NonNls
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class AddFieldQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return "Add field to class";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -43,7 +43,7 @@ public class AddFunctionQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return "Create function in module";
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -24,7 +24,7 @@ public class AddGlobalQuickFix implements LocalQuickFix {
|
||||
@NonNls
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public class AddMethodQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return "Add method to class";
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class AddSelfQuickFix implements LocalQuickFix {
|
||||
@NonNls
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return "Add parameter";
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -24,10 +24,6 @@ import java.util.List;
|
||||
* for instance, i = i + 1 --> i +=1
|
||||
*/
|
||||
public class AugmentedAssignmentQuickFix implements LocalQuickFix {
|
||||
|
||||
public AugmentedAssignmentQuickFix() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return PyBundle.message("QFIX.augment.assignment");
|
||||
@@ -35,7 +31,7 @@ public class AugmentedAssignmentQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ChainedComparisonsQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ComparisonWithNoneQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -19,10 +19,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* QuickFix to replace statement that has no effect with function call
|
||||
*/
|
||||
public class CompatibilityPrintCallQuickFix implements LocalQuickFix {
|
||||
|
||||
public CompatibilityPrintCallQuickFix() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return PyBundle.message("QFIX.statement.effect");
|
||||
@@ -30,7 +26,7 @@ public class CompatibilityPrintCallQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -18,9 +18,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* For consistency, always use """triple double quotes""" around docstrings.
|
||||
*/
|
||||
public class ConvertDocstringQuickFix implements LocalQuickFix {
|
||||
public ConvertDocstringQuickFix() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return PyBundle.message("QFIX.convert.single.quoted.docstring");
|
||||
@@ -28,7 +25,7 @@ public class ConvertDocstringQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -35,7 +35,7 @@ public class DictCreationQuickFix implements LocalQuickFix {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -55,7 +55,7 @@ public class DocstringQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return "Fix docstring";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -51,7 +51,7 @@ public class GenerateBinaryStubsFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return "GenerateBinaryStubs";
|
||||
return "Generate binary stubs";
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class ListCreationQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -23,7 +23,7 @@ public class MoveFromFutureImportQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class PyDefaultArgumentQuickFix implements LocalQuickFix {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,7 @@ public class RedundantParenthesesQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class RemoveArgumentEqualDefaultQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -20,7 +20,7 @@ public class RemoveDecoratorQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -24,7 +24,7 @@ public class RemoveLeadingUQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.Family.migration.to.python3");
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,7 @@ public class RemoveTrailingLQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.Family.migration.to.python3");
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,7 @@ public class RemoveTrailingSemicolonQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -24,7 +24,7 @@ public class RemoveUnnecessaryBackslashQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.jetbrains.python.actions;
|
||||
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
@@ -16,7 +15,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* Date: Nov 30, 2008 6:10:13 AM
|
||||
*/
|
||||
public class RenameParameterQuickFix implements LocalQuickFix {
|
||||
private static final Logger LOG = Logger.getInstance("#" + RenameParameterQuickFix.class.getName());
|
||||
private final String myNewName;
|
||||
|
||||
public RenameParameterQuickFix(String newName) {
|
||||
@@ -32,7 +30,7 @@ public class RenameParameterQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("QFIX.NAME.parameters");
|
||||
return "Rename parameter";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ReplaceBackquoteExpressionQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.Family.migration.to.python3");
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ReplaceExceptPartQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.Family.migration.to.python3");
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.inspections.PySetFunctionToLiteralInspection;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -14,11 +15,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* set literal if applicable
|
||||
*/
|
||||
public class ReplaceFunctionWithSetLiteralQuickFix implements LocalQuickFix {
|
||||
PyElement[] myElements;
|
||||
public ReplaceFunctionWithSetLiteralQuickFix(PyElement[] elements) {
|
||||
myElements = elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
@@ -28,18 +24,19 @@ public class ReplaceFunctionWithSetLiteralQuickFix implements LocalQuickFix {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
PyElement[] elements = PySetFunctionToLiteralInspection.getSetCallArguments((PyCallExpression)descriptor.getPsiElement());
|
||||
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
PsiElement functionCall = descriptor.getPsiElement();
|
||||
StringBuilder str = new StringBuilder("{");
|
||||
for (int i = 0; i != myElements.length; ++i) {
|
||||
PyElement e = myElements[i];
|
||||
for (int i = 0; i != elements.length; ++i) {
|
||||
PyElement e = elements[i];
|
||||
str.append(e.getText());
|
||||
if (i != myElements.length-1)
|
||||
if (i != elements.length-1)
|
||||
str.append(", ");
|
||||
}
|
||||
str.append("}");
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ReplaceListComprehensionsQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.Family.migration.to.python3");
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ReplaceNotEqOperatorQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.Family.migration.to.python3");
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ReplaceOctalNumericLiteralQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.Family.migration.to.python3");
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,7 @@ public class ReplaceRaiseStatementQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INTN.Family.migration.to.python3");
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -49,7 +49,7 @@ public class SimplifyBooleanCheckQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return "Simplify boolean expression";
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -15,10 +15,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* QuickFix to move misplaced docstring
|
||||
*/
|
||||
public class StatementEffectDocstringQuickFix implements LocalQuickFix {
|
||||
|
||||
public StatementEffectDocstringQuickFix() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return PyBundle.message("QFIX.statement.effect.move.docstring");
|
||||
@@ -26,7 +22,7 @@ public class StatementEffectDocstringQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -18,10 +18,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* QuickFix to replace statement that has no effect with function call
|
||||
*/
|
||||
public class StatementEffectFunctionCallQuickFix implements LocalQuickFix {
|
||||
|
||||
public StatementEffectFunctionCallQuickFix() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return PyBundle.message("QFIX.statement.effect");
|
||||
@@ -29,7 +25,7 @@ public class StatementEffectFunctionCallQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
+9
-13
@@ -18,11 +18,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* Quickfix to introduce variable if statement seems to have no effect
|
||||
*/
|
||||
public class StatementEffectIntroduceVariableQuickFix implements LocalQuickFix {
|
||||
PsiElement myExpression;
|
||||
public StatementEffectIntroduceVariableQuickFix(PyExpression expression) {
|
||||
myExpression = expression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return PyBundle.message("QFIX.introduce.variable");
|
||||
@@ -31,19 +26,20 @@ public class StatementEffectIntroduceVariableQuickFix implements LocalQuickFix {
|
||||
@NonNls
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
if (myExpression != null && myExpression.isValid()) {
|
||||
PsiElement expression = descriptor.getPsiElement();
|
||||
if (expression != null && expression.isValid()) {
|
||||
final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
final PyAssignmentStatement assignment = elementGenerator.createFromText(LanguageLevel.forElement(myExpression), PyAssignmentStatement.class,
|
||||
"var = " + myExpression.getText());
|
||||
final PyAssignmentStatement assignment = elementGenerator.createFromText(LanguageLevel.forElement(expression), PyAssignmentStatement.class,
|
||||
"var = " + expression.getText());
|
||||
|
||||
myExpression = myExpression.replace(assignment);
|
||||
myExpression = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(myExpression);
|
||||
final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(myExpression);
|
||||
builder.replaceElement(((PyAssignmentStatement)myExpression).getLeftHandSideExpression(), "var");
|
||||
expression = expression.replace(assignment);
|
||||
expression = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(expression);
|
||||
final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(expression);
|
||||
builder.replaceElement(((PyAssignmentStatement)expression).getLeftHandSideExpression(), "var");
|
||||
builder.run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class TransformClassicClassQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -14,11 +15,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* QuickFix to add 'from __future__ import with_statement'' if python version is less than 2.6
|
||||
*/
|
||||
public class UnresolvedRefAddFutureImportQuickFix implements LocalQuickFix {
|
||||
private PyReferenceExpression myElement;
|
||||
public UnresolvedRefAddFutureImportQuickFix(PyReferenceExpression element) {
|
||||
myElement = element;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return PyBundle.message("QFIX.unresolved.reference.add.future");
|
||||
@@ -26,14 +22,15 @@ public class UnresolvedRefAddFutureImportQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
PyFile file = (PyFile)myElement.getContainingFile();
|
||||
PsiElement element = descriptor.getPsiElement();
|
||||
PyFile file = (PyFile)element.getContainingFile();
|
||||
if (!CodeInsightUtilBase.prepareFileForWrite(file)) return;
|
||||
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
PyFromImportStatement statement = elementGenerator.createFromText(LanguageLevel.forElement(myElement), PyFromImportStatement.class,
|
||||
PyFromImportStatement statement = elementGenerator.createFromText(LanguageLevel.forElement(element), PyFromImportStatement.class,
|
||||
"from __future__ import with_statement");
|
||||
file.addBefore(statement, file.getStatements().get(0));
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class UnresolvedRefCreateFunctionQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class UnresolvedRefTrueFalseQuickFix implements LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return "Replace with True or False";
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class UnresolvedReferenceAddSelfQuickFix implements LocalQuickFix, HighPr
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return PyBundle.message("INSP.GROUP.python");
|
||||
return "Add 'self'";
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
|
||||
@@ -49,25 +49,10 @@ public class PySetFunctionToLiteralInspection extends PyInspection {
|
||||
if (node.isCalleeText(PyNames.SET) && isInBuiltins(callee)) {
|
||||
PyExpression[] arguments = node.getArguments();
|
||||
if (arguments.length == 1) {
|
||||
PyExpression argument= arguments[0];
|
||||
PyElement[] elements = {};
|
||||
if (argument instanceof PyStringLiteralExpression) {
|
||||
return;
|
||||
}
|
||||
if ((argument instanceof PySequenceExpression || (argument instanceof PyParenthesizedExpression &&
|
||||
((PyParenthesizedExpression)argument).getContainedExpression() instanceof PyTupleExpression))) {
|
||||
|
||||
if (argument instanceof PySequenceExpression)
|
||||
elements = ((PySequenceExpression)argument).getElements();
|
||||
if (argument instanceof PyParenthesizedExpression) {
|
||||
PyExpression tuple = ((PyParenthesizedExpression)argument).getContainedExpression();
|
||||
if (tuple instanceof PyTupleExpression)
|
||||
elements = ((PyTupleExpression)(tuple)).getElements();
|
||||
}
|
||||
}
|
||||
PyElement[] elements = getSetCallArguments(node);
|
||||
if (elements.length != 0)
|
||||
registerProblem(node, PyBundle.message("INSP.NAME.set.function.to.literal"),
|
||||
new ReplaceFunctionWithSetLiteralQuickFix(elements));
|
||||
new ReplaceFunctionWithSetLiteralQuickFix());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,4 +72,21 @@ public class PySetFunctionToLiteralInspection extends PyInspection {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static PyElement[] getSetCallArguments(PyCallExpression node) {
|
||||
PyExpression argument = node.getArguments()[0];
|
||||
if (argument instanceof PyStringLiteralExpression) {
|
||||
return PyElement.EMPTY_ARRAY;
|
||||
}
|
||||
if ((argument instanceof PySequenceExpression || (argument instanceof PyParenthesizedExpression &&
|
||||
((PyParenthesizedExpression)argument).getContainedExpression() instanceof PyTupleExpression))) {
|
||||
|
||||
if (argument instanceof PySequenceExpression)
|
||||
return ((PySequenceExpression)argument).getElements();
|
||||
PyExpression tuple = ((PyParenthesizedExpression)argument).getContainedExpression();
|
||||
if (tuple instanceof PyTupleExpression)
|
||||
return ((PyTupleExpression)(tuple)).getElements();
|
||||
}
|
||||
return PyElement.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class PyStatementEffectInspection extends PyInspection {
|
||||
if (checkStringLiteral(expression))
|
||||
return;
|
||||
registerProblem(expression, "Statement seems to have no effect",
|
||||
new StatementEffectIntroduceVariableQuickFix(expression));
|
||||
new StatementEffectIntroduceVariableQuickFix());
|
||||
}
|
||||
|
||||
private boolean checkStringLiteral(PyExpression expression) {
|
||||
|
||||
@@ -395,7 +395,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
else {
|
||||
if (LanguageLevel.forElement(node).isOlderThan(LanguageLevel.PYTHON26)) {
|
||||
if ("with".equals(refname)) {
|
||||
actions.add(new UnresolvedRefAddFutureImportQuickFix(refex));
|
||||
actions.add(new UnresolvedRefAddFutureImportQuickFix());
|
||||
}
|
||||
}
|
||||
if (ref_text.equals("true") || ref_text.equals("false")) {
|
||||
|
||||
Reference in New Issue
Block a user