use of com.jetbrains.python.psi.PyKeywordArgument in project intellij-community by JetBrains.
the class PyKeywordArgumentManipulator method handleContentChange.
@Override
public PyKeywordArgument handleContentChange(@NotNull PyKeywordArgument element, @NotNull TextRange range, String newContent) throws IncorrectOperationException {
final ASTNode keywordNode = element.getKeywordNode();
if (keywordNode != null && keywordNode.getTextRange().shiftRight(-element.getTextRange().getStartOffset()).equals(range)) {
final LanguageLevel langLevel = LanguageLevel.forElement(element);
final PyElementGenerator generator = PyElementGenerator.getInstance(element.getProject());
final PyCallExpression callExpression = (PyCallExpression) generator.createExpressionFromText(langLevel, "foo(" + newContent + "=None)");
final PyKeywordArgument kwArg = callExpression.getArgumentList().getKeywordArgument(newContent);
element.getKeywordNode().getPsi().replace(kwArg.getKeywordNode().getPsi());
return element;
}
throw new IncorrectOperationException("unsupported manipulation on keyword argument");
}
Aggregations