complete keyword arguments taken from __init__ of superclass (PY-505)

This commit is contained in:
Dmitry Jemerov
2010-03-16 18:36:42 +03:00
parent 17badef5d2
commit 709caf3efb
6 changed files with 52 additions and 12 deletions
@@ -505,18 +505,13 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
if (callee instanceof PyReferenceExpression) {
PsiElement def = ((PyReferenceExpression)callee).resolve();
if (def instanceof PyFunction) {
((PyFunction)def).getParameterList().acceptChildren(
new PyElementVisitor() {
@Override
public void visitPyParameter(PyParameter par) {
PyNamedParameter n_param = par.getAsNamed();
assert n_param != null;
if (! n_param.isKeywordContainer() && ! n_param.isPositionalContainer()) {
ret.add(LookupElementBuilder.create(n_param.getName() + "=").setIcon(n_param.getIcon(0)));
}
}
}
);
addKeywordArgumentVariants((PyFunction) def, ret);
}
else if (def instanceof PyClass) {
PyFunction init = ((PyClass) def).findMethodByName(PyNames.INIT, true); // search in superclasses
if (init != null) {
addKeywordArgumentVariants(init, ret);
}
}
}
}
@@ -552,6 +547,21 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
return ret.toArray();
}
private static void addKeywordArgumentVariants(PyFunction def, final List<Object> ret) {
def.getParameterList().acceptChildren(
new PyElementVisitor() {
@Override
public void visitPyParameter(PyParameter par) {
PyNamedParameter n_param = par.getAsNamed();
assert n_param != null;
if (! n_param.isKeywordContainer() && ! n_param.isPositionalContainer()) {
ret.add(LookupElementBuilder.create(n_param.getName() + "=").setIcon(n_param.getIcon(0)));
}
}
}
);
}
public boolean isSoft() {
return false;
}
@@ -0,0 +1,4 @@
class C:
def __init__(self, auno=True): pass
c = C(auno=)
+4
View File
@@ -0,0 +1,4 @@
class C:
def __init__(self, auno=True): pass
c = C(au<caret>)
@@ -0,0 +1,7 @@
class B:
def __init__(self, auno=True): pass
class C(B):
pass
c = C(auno=)
@@ -0,0 +1,7 @@
class B:
def __init__(self, auno=True): pass
class C(B):
pass
c = C(au<caret>)
@@ -35,6 +35,14 @@ public class PythonCompletionTest extends PyLightFixtureTestCase {
doTest();
}
public void testInitParams() throws Exception {
doTest();
}
public void testSuperInitParams() throws Exception { // PY-505
doTest();
}
public void testPredefinedMethodName() throws Exception {
doTest();
}