mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
Methods to implement will be printed in the same order as shown in dialog (PY-25906)
Every of them was inserted after statement list so the last method becomes the first. The problem is fixed by reverting writing order.
This commit is contained in:
@@ -146,9 +146,7 @@ public class PyOverrideImplementUtil {
|
||||
}.execute();
|
||||
}
|
||||
|
||||
private static void write(@NotNull final PyClass pyClass,
|
||||
@NotNull final List<PyMethodMember> newMembers,
|
||||
@NotNull final Editor editor, boolean implement) {
|
||||
private static void write(@NotNull PyClass pyClass, @NotNull List<PyMethodMember> newMembers, @NotNull Editor editor, boolean implement) {
|
||||
final PyStatementList statementList = pyClass.getStatementList();
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
PsiElement anchor = null;
|
||||
@@ -161,10 +159,11 @@ public class PyOverrideImplementUtil {
|
||||
}
|
||||
|
||||
PyFunction element = null;
|
||||
for (PyMethodMember newMember : newMembers) {
|
||||
PyFunction baseFunction = (PyFunction)newMember.getPsiElement();
|
||||
final LanguageLevel languageLevel = LanguageLevel.forElement(statementList);
|
||||
for (PyMethodMember newMember : Lists.reverse(newMembers)) {
|
||||
final PyFunction baseFunction = (PyFunction)newMember.getPsiElement();
|
||||
final PyFunctionBuilder builder = buildOverriddenFunction(pyClass, baseFunction, implement);
|
||||
PyFunction function = builder.addFunctionAfter(statementList, anchor, LanguageLevel.forElement(statementList));
|
||||
final PyFunction function = builder.addFunctionAfter(statementList, anchor, languageLevel);
|
||||
element = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(function);
|
||||
}
|
||||
|
||||
|
||||
15
python/testData/override/implementationOrder.py
Normal file
15
python/testData/override/implementationOrder.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
|
||||
class Abstract:
|
||||
@abstractmethod
|
||||
def foo(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def bar(self):
|
||||
pass
|
||||
|
||||
|
||||
class Impl(Abstract):
|
||||
pass
|
||||
20
python/testData/override/implementationOrder_after.py
Normal file
20
python/testData/override/implementationOrder_after.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
|
||||
class Abstract:
|
||||
@abstractmethod
|
||||
def foo(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def bar(self):
|
||||
pass
|
||||
|
||||
|
||||
class Impl(Abstract):
|
||||
def foo(self):
|
||||
pass
|
||||
|
||||
def bar(self):
|
||||
pass
|
||||
|
||||
@@ -5,6 +5,7 @@ package com.jetbrains.python;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.codeInsight.override.PyMethodMember;
|
||||
import com.jetbrains.python.codeInsight.override.PyOverrideImplementUtil;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
@@ -14,6 +15,7 @@ import com.jetbrains.python.psi.PyFile;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.psi.stubs.PyClassNameIndex;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
@@ -119,6 +121,21 @@ public class PyOverrideTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-25906
|
||||
public void testImplementationOrder() {
|
||||
myFixture.configureByFile("override/" + getTestName(true) + ".py");
|
||||
|
||||
final PyFunction[] toImplement = getTopLevelClass(0).getMethods();
|
||||
assertEquals(Arrays.asList("foo", "bar"), ContainerUtil.map(toImplement, PyFunction::getName));
|
||||
|
||||
PyOverrideImplementUtil.overrideMethods(myFixture.getEditor(),
|
||||
getTopLevelClass(1),
|
||||
ContainerUtil.map(toImplement, PyMethodMember::new),
|
||||
true);
|
||||
|
||||
myFixture.checkResultByFile("override/" + getTestName(true) + "_after.py", true);
|
||||
}
|
||||
|
||||
public void testPy3k() {
|
||||
doTest3k();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user