fixed PY-7713 PyCharm asks me to convert set literals back and forth

This commit is contained in:
Ekaterina Tuzova
2013-09-20 14:23:13 +04:00
parent 2e6bf2bdea
commit 3bb3a09cc0
@@ -1,7 +1,12 @@
package com.jetbrains.python.inspections;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.LocalInspectionToolSession;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.openapi.util.JDOMExternalizableStringList;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiReference;
@@ -44,18 +49,32 @@ public class PySetFunctionToLiteralInspection extends PyInspection {
@Override
public void visitPyCallExpression(final PyCallExpression node) {
if (LanguageLevel.forElement(node).supportsSetLiterals()) {
PyExpression callee = node.getCallee();
if (node.isCalleeText(PyNames.SET) && isInBuiltins(callee)) {
PyExpression[] arguments = node.getArguments();
if (arguments.length == 1) {
PyElement[] elements = getSetCallArguments(node);
if (elements.length != 0)
registerProblem(node, PyBundle.message("INSP.NAME.set.function.to.literal"),
new ReplaceFunctionWithSetLiteralQuickFix());
if (!isAvailable(node)) return;
PyExpression callee = node.getCallee();
if (node.isCalleeText(PyNames.SET) && isInBuiltins(callee)) {
PyExpression[] arguments = node.getArguments();
if (arguments.length == 1) {
PyElement[] elements = getSetCallArguments(node);
if (elements.length != 0)
registerProblem(node, PyBundle.message("INSP.NAME.set.function.to.literal"),
new ReplaceFunctionWithSetLiteralQuickFix());
}
}
}
private static boolean isAvailable(PyCallExpression node) {
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(node.getProject()).getInspectionProfile();
final InspectionToolWrapper inspectionTool = profile.getInspectionTool("PyCompatibilityInspection", node.getProject());
if (inspectionTool != null) {
final InspectionProfileEntry inspection = inspectionTool.getTool();
if (inspection instanceof PyCompatibilityInspection) {
final JDOMExternalizableStringList versions = ((PyCompatibilityInspection)inspection).ourVersions;
for (String s : versions) {
if (!LanguageLevel.fromPythonVersion(s).supportsSetLiterals()) return false;
}
}
}
return LanguageLevel.forElement(node).supportsSetLiterals();
}
private static boolean isInBuiltins(PyExpression callee) {