use of com.jetbrains.python.refactoring.changeSignature.PyMethodDescriptor in project intellij-community by JetBrains.
the class PyChangeSignatureQuickFix method applyFix.
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final PyFunction function = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PyFunction.class);
if (function == null)
return;
final PyClass cls = function.getContainingClass();
assert cls != null;
final String functionName = function.getName();
final String complementaryName = PyNames.NEW.equals(functionName) ? PyNames.INIT : PyNames.NEW;
final TypeEvalContext context = TypeEvalContext.userInitiated(project, descriptor.getEndElement().getContainingFile());
final PyFunction complementaryMethod = myOverridenMethod ? (PyFunction) PySuperMethodsSearch.search(function, context).findFirst() : cls.findMethodByName(complementaryName, true, null);
assert complementaryMethod != null;
final PyMethodDescriptor methodDescriptor = new PyMethodDescriptor(function) {
@Override
public List<PyParameterInfo> getParameters() {
final List<PyParameterInfo> parameterInfos = super.getParameters();
final int paramLength = function.getParameterList().getParameters().length;
final int complementaryParamLength = complementaryMethod.getParameterList().getParameters().length;
if (complementaryParamLength > paramLength)
parameterInfos.add(new PyParameterInfo(-1, "**kwargs", "", false));
return parameterInfos;
}
};
final PyChangeSignatureDialog dialog = new PyChangeSignatureDialog(project, methodDescriptor);
dialog.show();
}
Aggregations