fixed PY-9407 Method can be static: false positive for methods with first parameter other then self

This commit is contained in:
Ekaterina Tuzova
2013-04-10 18:39:30 +04:00
parent 9ccbc0852a
commit 7def3e17f2
3 changed files with 22 additions and 1 deletions
@@ -65,12 +65,23 @@ public class PyMethodMayBeStaticInspection extends PyInspection {
if (statements.length == 1 && statements[0] instanceof PyPassStatement) return;
final PyParameter[] parameters = node.getParameterList().getParameters();
final String selfName;
if (parameters.length > 0) {
final String name = parameters[0].getName();
selfName = name != null ? name : parameters[0].getText();
}
else {
selfName = PyNames.CANONICAL_SELF;
}
final boolean[] mayBeStatic = {true};
PyRecursiveElementVisitor visitor = new PyRecursiveElementVisitor() {
@Override
public void visitPyReferenceExpression(PyReferenceExpression node) {
super.visitPyReferenceExpression(node);
if (PyNames.CANONICAL_SELF.equals(node.getName())) {
if (selfName.equals(node.getName())) {
mayBeStatic[0] = false;
}
}
@@ -0,0 +1,6 @@
__author__ = 'ktisha'
class A():
def my_method(my_inst):
my_inst.do_smth()
@@ -39,6 +39,10 @@ public class PyMethodMayBeStaticInspectionTest extends PyTestCase {
doTest();
}
public void testSelfName() {
doTest();
}
private void doTest() {
myFixture.configureByFile("inspections/PyMethodMayBeStaticInspection/" + getTestName(true) + ".py");
myFixture.enableInspections(PyMethodMayBeStaticInspection.class);