use of com.jetbrains.python.psi.PyArgumentList in project intellij-community by JetBrains.
the class PyClassFixer method doApply.
public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyClass pyClass) throws IncorrectOperationException {
final PsiElement colon = PyPsiUtils.getFirstChildOfType(pyClass, PyTokenTypes.COLON);
if (colon == null) {
final PyArgumentList argList = PsiTreeUtil.getChildOfType(pyClass, PyArgumentList.class);
final int colonOffset = sure(argList).getTextRange().getEndOffset();
String textToInsert = ":";
if (pyClass.getNameNode() == null) {
int newCaretOffset = argList.getTextOffset();
if (argList.getTextLength() == 0) {
newCaretOffset += 1;
textToInsert = " :";
}
processor.registerUnresolvedError(newCaretOffset);
}
editor.getDocument().insertString(colonOffset, textToInsert);
}
}
use of com.jetbrains.python.psi.PyArgumentList in project intellij-community by JetBrains.
the class PyChangeBaseClassQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement element = descriptor.getPsiElement();
final PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class);
assert pyClass != null;
final PyArgumentList expressionList = pyClass.getSuperClassExpressionList();
if (expressionList != null && expressionList.getArguments().length != 0) {
final PyExpression argument = expressionList.getArguments()[0];
final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(argument);
builder.replaceElement(argument, argument.getText());
final VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
if (virtualFile != null) {
final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile), true);
assert editor != null;
builder.run(editor, false);
}
}
}
use of com.jetbrains.python.psi.PyArgumentList in project intellij-community by JetBrains.
the class PyRemoveCallQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement call = descriptor.getPsiElement();
assert call instanceof PyCallExpression;
if (call instanceof PyDecorator) {
call.delete();
} else {
final PyArgumentList argumentList = ((PyCallExpression) call).getArgumentList();
assert argumentList != null;
argumentList.delete();
}
}
use of com.jetbrains.python.psi.PyArgumentList in project intellij-community by JetBrains.
the class PyDeclarationRangeHandler method getDeclarationRange.
@NotNull
@Override
public TextRange getDeclarationRange(@NotNull PsiElement container) {
int start = container.getTextRange().getStartOffset();
if (container instanceof PyFunction) {
PyParameterList parameterList = ((PyFunction) container).getParameterList();
return new TextRange(start, parameterList.getTextRange().getEndOffset());
}
if (container instanceof PyClass) {
PyArgumentList argumentList = ((PyClass) container).getSuperClassExpressionList();
if (argumentList != null) {
return new TextRange(start, argumentList.getTextRange().getEndOffset());
}
ASTNode nameNode = ((PyClass) container).getNameNode();
if (nameNode != null) {
return new TextRange(start, nameNode.getStartOffset() + nameNode.getTextLength());
}
}
return container.getTextRange();
}
use of com.jetbrains.python.psi.PyArgumentList in project intellij-community by JetBrains.
the class PyDecoratorTest method testDecoParamCall.
public void testDecoParamCall() throws Exception {
PsiElement targetElement = find().getParent();
assertTrue(targetElement instanceof PyDecorator);
PyDecorator deco = (PyDecorator) targetElement;
PyFunction decofun = deco.getTarget();
assertNotNull(decofun);
assertEquals("foo", decofun.getName());
assertFalse(deco.isBuiltin());
assertTrue(deco.hasArgumentList());
PyArgumentList arglist = deco.getArgumentList();
assertNotNull(arglist);
PyExpression[] args = arglist.getArguments();
assertEquals("argument count", 1, args.length);
assertEquals("argument value", "1", args[0].getText());
}
Aggregations