Search in sources :

Example 1 with PyCallExpression

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

the class PySmartStepIntoHandler method computeSmartStepVariants.

@Override
@NotNull
public List<PySmartStepIntoVariant> computeSmartStepVariants(@NotNull XSourcePosition position) {
    final Document document = FileDocumentManager.getInstance().getDocument(position.getFile());
    final List<PySmartStepIntoVariant> variants = Lists.newArrayList();
    final Set<PyCallExpression> visitedCalls = Sets.newHashSet();
    final int line = position.getLine();
    XDebuggerUtil.getInstance().iterateLine(mySession.getProject(), document, line, psiElement -> {
        addVariants(document, line, psiElement, variants, visitedCalls);
        return true;
    });
    return variants;
}
Also used : PyCallExpression(com.jetbrains.python.psi.PyCallExpression) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PyCallExpression

use of com.jetbrains.python.psi.PyCallExpression 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 PyCallExpression

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

the class PyPackageUtilTest method doTestSetupPyReading.

private void doTestSetupPyReading(boolean hasFile, boolean hasCall, boolean requires) {
    final Module module = myFixture.getModule();
    if (hasFile) {
        assertTrue(PyPackageUtil.hasSetupPy(module));
        final PyFile setupPy = PyPackageUtil.findSetupPy(module);
        assertNotNull(setupPy);
        if (hasCall) {
            final PyCallExpression callByModule = PyPackageUtil.findSetupCall(module);
            final PyCallExpression callByFile = PyPackageUtil.findSetupCall(setupPy);
            assertNotNull(callByModule);
            assertNotNull(callByFile);
            assertSame(callByFile, callByModule);
            if (requires) {
                checkRequirements(PyPackageUtil.findSetupPyRequires(module));
            } else {
                final List<PyRequirement> requirements = PyPackageUtil.findSetupPyRequires(module);
                assertNotNull(requirements);
                assertEmpty(requirements);
            }
        } else {
            assertNull(PyPackageUtil.findSetupCall(module));
            assertNull(PyPackageUtil.findSetupCall(setupPy));
            assertNull(PyPackageUtil.findSetupPyRequires(module));
        }
    } else {
        assertFalse(PyPackageUtil.hasSetupPy(module));
        assertNull(PyPackageUtil.findSetupPy(module));
        assertNull(PyPackageUtil.findSetupCall(module));
        assertNull(PyPackageUtil.findSetupPyRequires(module));
    }
}
Also used : PyCallExpression(com.jetbrains.python.psi.PyCallExpression) PyFile(com.jetbrains.python.psi.PyFile) Module(com.intellij.openapi.module.Module)

Example 4 with PyCallExpression

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

the class PyPackageUtilTest method checkSetupArgumentText.

private static void checkSetupArgumentText(@NotNull Module module, @NotNull String keyword, @Nullable String text) {
    final PyCallExpression setupCall = PyPackageUtil.findSetupCall(module);
    assertNotNull(setupCall);
    final PyExpression argument = setupCall.getKeywordArgument(keyword);
    if (text == null) {
        assertNull(argument);
    } else {
        assertNotNull(argument);
        assertEquals(text, argument.getText());
    }
}
Also used : PyExpression(com.jetbrains.python.psi.PyExpression) PyCallExpression(com.jetbrains.python.psi.PyCallExpression)

Example 5 with PyCallExpression

use of com.jetbrains.python.psi.PyCallExpression 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");
}
Also used : LanguageLevel(com.jetbrains.python.psi.LanguageLevel) ASTNode(com.intellij.lang.ASTNode) PyCallExpression(com.jetbrains.python.psi.PyCallExpression) PyKeywordArgument(com.jetbrains.python.psi.PyKeywordArgument) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PyElementGenerator(com.jetbrains.python.psi.PyElementGenerator)

Aggregations

PyCallExpression (com.jetbrains.python.psi.PyCallExpression)7 PyExpression (com.jetbrains.python.psi.PyExpression)2 NotNull (org.jetbrains.annotations.NotNull)2 ASTNode (com.intellij.lang.ASTNode)1 Document (com.intellij.openapi.editor.Document)1 Module (com.intellij.openapi.module.Module)1 PsiElement (com.intellij.psi.PsiElement)1 PsiReference (com.intellij.psi.PsiReference)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 LanguageLevel (com.jetbrains.python.psi.LanguageLevel)1 PyArgumentList (com.jetbrains.python.psi.PyArgumentList)1 PyDecorator (com.jetbrains.python.psi.PyDecorator)1 PyElementGenerator (com.jetbrains.python.psi.PyElementGenerator)1 PyFile (com.jetbrains.python.psi.PyFile)1 PyKeywordArgument (com.jetbrains.python.psi.PyKeywordArgument)1 PyResolveContext (com.jetbrains.python.psi.resolve.PyResolveContext)1 TypeEvalContext (com.jetbrains.python.psi.types.TypeEvalContext)1