mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-21220 Handle moved classes that contain both __init__ and __new__
I changed behavior of PyClassImpl#NameFinder processor, so that it always tries to find an element with the first of the names passed to its constructor. In particular, #findInitOrNew() returns __init__ unless there was only __new__ defined in the class. Otherwise its behavior contradicts with the method's javadoc.
This commit is contained in:
@@ -30,6 +30,7 @@ import com.jetbrains.python.psi.impl.PyBuiltinCache;
|
||||
import com.jetbrains.python.psi.impl.PyPsiUtils;
|
||||
import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher;
|
||||
import com.jetbrains.python.psi.resolve.ImportedResolveResult;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
|
||||
public class PyResolveTest extends PyResolveTestCase {
|
||||
@Override
|
||||
@@ -70,6 +71,22 @@ public class PyResolveTest extends PyResolveTestCase {
|
||||
assertEquals(PyNames.INIT, ((PyFunction)target).getName());
|
||||
}
|
||||
|
||||
public void testInitOrNewReturnsInitWhenNewIsFirst() {
|
||||
doTestInitOrNewReturnsInit();
|
||||
}
|
||||
|
||||
public void testInitOrNewReturnsInitWhenNewIsLast() {
|
||||
doTestInitOrNewReturnsInit();
|
||||
}
|
||||
|
||||
private void doTestInitOrNewReturnsInit() {
|
||||
myFixture.configureByFile("resolve/" + getTestName(false) + ".py");
|
||||
final PyClass pyClass = PsiTreeUtil.findChildOfType(myFixture.getFile(), PyClass.class);
|
||||
assertNotNull(pyClass);
|
||||
final PyFunction init = pyClass.findInitOrNew(false, TypeEvalContext.userInitiated(myFixture.getProject(), myFixture.getFile()));
|
||||
assertEquals(PyNames.INIT, init.getName());
|
||||
}
|
||||
|
||||
public void testToConstructorInherited() {
|
||||
ResolveResult[] targets = multiResolve();
|
||||
assertEquals(2, targets.length); // to class, to init
|
||||
|
||||
@@ -376,6 +376,11 @@ public class PyMoveTest extends PyTestCase {
|
||||
doMoveSymbolTest("FOO", "b.py");
|
||||
}
|
||||
|
||||
// PY-21220
|
||||
public void testReferenceToClassWithNewInMovedSymbol() {
|
||||
doMoveSymbolTest("fnToMove", "toFile.py");
|
||||
}
|
||||
|
||||
private void doMoveFileTest(String fileName, String toDirName) {
|
||||
Project project = myFixture.getProject();
|
||||
PsiManager manager = PsiManager.getInstance(project);
|
||||
|
||||
Reference in New Issue
Block a user