mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-9794 Change signature: loses parameter in function call when rearranging arguments so simple parameter gets after keyword parameter in call
This commit is contained in:
+11
-7
@@ -214,6 +214,7 @@ public class PyChangeSignatureUsageProcessor implements ChangeSignatureUsageProc
|
||||
final PyKeywordArgument keywordArgument = argumentList.getKeywordArgument(paramName);
|
||||
if (keywordArgument != null) {
|
||||
params.add(keywordArgument.getText());
|
||||
useKeywords = true;
|
||||
return currentIndex + 1;
|
||||
}
|
||||
else if (currentIndex < arguments.length) {
|
||||
@@ -222,14 +223,14 @@ public class PyChangeSignatureUsageProcessor implements ChangeSignatureUsageProc
|
||||
params.add(currentParameter.getText());
|
||||
}
|
||||
else if (oldIndex < arguments.length && (
|
||||
!info.getDefaultInSignature() || !(currentParameter instanceof PyKeywordArgument))) {
|
||||
addOldPositionParameter(params, arguments[oldIndex], info);
|
||||
!(info.getDefaultInSignature() && arguments[oldIndex].getText().equals(info.getDefaultValue())) || !(currentParameter instanceof PyKeywordArgument))) {
|
||||
return addOldPositionParameter(params, arguments[oldIndex], info, currentIndex);
|
||||
}
|
||||
else
|
||||
return currentIndex;
|
||||
}
|
||||
else if (oldIndex < arguments.length) {
|
||||
addOldPositionParameter(params, arguments[oldIndex], info);
|
||||
return addOldPositionParameter(params, arguments[oldIndex], info, currentIndex);
|
||||
}
|
||||
else if (!info.getDefaultInSignature()) {
|
||||
params.add( useKeywords ? paramName + " = " + info.getDefaultValue()
|
||||
@@ -242,9 +243,9 @@ public class PyChangeSignatureUsageProcessor implements ChangeSignatureUsageProc
|
||||
return currentIndex + 1;
|
||||
}
|
||||
|
||||
private void addOldPositionParameter(List<String> params,
|
||||
PyExpression argument,
|
||||
PyParameterInfo info) {
|
||||
private int addOldPositionParameter(List<String> params,
|
||||
PyExpression argument,
|
||||
PyParameterInfo info, int currentIndex) {
|
||||
final String paramName = info.getName();
|
||||
if (argument instanceof PyKeywordArgument) {
|
||||
final PyExpression valueExpression = ((PyKeywordArgument)argument).getValueExpression();
|
||||
@@ -252,6 +253,8 @@ public class PyChangeSignatureUsageProcessor implements ChangeSignatureUsageProc
|
||||
if (!paramName.equals(argument.getName()) && !StringUtil.isEmptyOrSpaces(info.getDefaultValue())) {
|
||||
if (!info.getDefaultInSignature())
|
||||
params.add(useKeywords ? info.getName() + " = " + info.getDefaultValue() : info.getDefaultValue());
|
||||
else
|
||||
return currentIndex;
|
||||
}
|
||||
else {
|
||||
params.add(valueExpression == null ? paramName : paramName + " = " + valueExpression.getText());
|
||||
@@ -259,8 +262,9 @@ public class PyChangeSignatureUsageProcessor implements ChangeSignatureUsageProc
|
||||
}
|
||||
}
|
||||
else {
|
||||
params.add(useKeywords ? paramName + " = " + argument.getText() : argument.getText());
|
||||
params.add(useKeywords && !argument.getText().equals(info.getDefaultValue())? paramName + " = " + argument.getText() : argument.getText());
|
||||
}
|
||||
return currentIndex + 1;
|
||||
}
|
||||
|
||||
private static boolean isPythonUsage(UsageInfo info) {
|
||||
|
||||
@@ -2,4 +2,4 @@ def func(a, b):
|
||||
pass
|
||||
|
||||
|
||||
func(a=1, 2)
|
||||
func(a=1, b=2)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
def f1(b=2, a=1):
|
||||
pass
|
||||
|
||||
|
||||
f1(b=3, a=2)
|
||||
@@ -0,0 +1,4 @@
|
||||
def f1(a=1, b=2):
|
||||
pass
|
||||
|
||||
f1(2, b=3)
|
||||
+4
@@ -129,6 +129,10 @@ public class PyChangeSignatureTest extends PyTestCase {
|
||||
new PyParameterInfo(2, "opt2", "None", true),
|
||||
new PyParameterInfo(3, "**extra_info", null, false)));
|
||||
}
|
||||
public void testMoveParam() {
|
||||
doChangeSignatureTest("f1", Arrays.asList(new PyParameterInfo(1, "b", "2", true),
|
||||
new PyParameterInfo(0, "a", "1", true)));
|
||||
}
|
||||
|
||||
public void testMoveRenameParam() {
|
||||
final PyParameterInfo b = new PyParameterInfo(-1, "b", "1", false);
|
||||
|
||||
Reference in New Issue
Block a user