Search in sources :

Example 1 with PyDecorator

use of com.jetbrains.python.psi.PyDecorator in project intellij-community by JetBrains.

the class PyArgumentListFixer method doApply.

@Override
public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyArgumentList arguments) throws IncorrectOperationException {
    final PsiElement rBrace = PyPsiUtils.getChildByFilter(arguments, PyTokenTypes.CLOSE_BRACES, 0);
    if (arguments.getParent() instanceof PyClass || arguments.getParent() instanceof PyDecorator) {
        final PsiElement lBrace = PyPsiUtils.getChildByFilter(arguments, PyTokenTypes.OPEN_BRACES, 0);
        if (lBrace != null && rBrace == null) {
            final Document document = editor.getDocument();
            document.insertString(arguments.getTextRange().getEndOffset(), ")");
        }
    } else {
        if (rBrace == null) {
            final Document document = editor.getDocument();
            document.insertString(arguments.getTextRange().getEndOffset(), ")");
        }
    }
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyDecorator(com.jetbrains.python.psi.PyDecorator) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement)

Example 2 with PyDecorator

use of com.jetbrains.python.psi.PyDecorator 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();
    }
}
Also used : PyArgumentList(com.jetbrains.python.psi.PyArgumentList) PyCallExpression(com.jetbrains.python.psi.PyCallExpression) PyDecorator(com.jetbrains.python.psi.PyDecorator) PsiElement(com.intellij.psi.PsiElement)

Example 3 with PyDecorator

use of com.jetbrains.python.psi.PyDecorator in project intellij-community by JetBrains.

the class PyDecoratorTest method testDecoCall.

public void testDecoCall() 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());
    assertFalse(deco.hasArgumentList());
}
Also used : PyFunction(com.jetbrains.python.psi.PyFunction) PyDecorator(com.jetbrains.python.psi.PyDecorator) PsiElement(com.intellij.psi.PsiElement)

Example 4 with PyDecorator

use of com.jetbrains.python.psi.PyDecorator 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());
}
Also used : PyArgumentList(com.jetbrains.python.psi.PyArgumentList) PyFunction(com.jetbrains.python.psi.PyFunction) PyExpression(com.jetbrains.python.psi.PyExpression) PyDecorator(com.jetbrains.python.psi.PyDecorator) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)4 PyDecorator (com.jetbrains.python.psi.PyDecorator)4 PyArgumentList (com.jetbrains.python.psi.PyArgumentList)2 PyFunction (com.jetbrains.python.psi.PyFunction)2 Document (com.intellij.openapi.editor.Document)1 PyCallExpression (com.jetbrains.python.psi.PyCallExpression)1 PyClass (com.jetbrains.python.psi.PyClass)1 PyExpression (com.jetbrains.python.psi.PyExpression)1