Search in sources :

Example 21 with PyExpression

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

the class PyWithItemImpl method getTarget.

@Override
public PyExpression getTarget() {
    ASTNode[] children = getNode().getChildren(null);
    boolean foundAs = false;
    for (ASTNode child : children) {
        if (child.getElementType() == PyTokenTypes.AS_KEYWORD) {
            foundAs = true;
        } else if (foundAs && child.getPsi() instanceof PyExpression) {
            return (PyExpression) child.getPsi();
        }
    }
    return null;
}
Also used : ASTNode(com.intellij.lang.ASTNode) PyExpression(com.jetbrains.python.psi.PyExpression)

Example 22 with PyExpression

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

the class PyYieldExpressionImpl method getType.

@Override
public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) {
    final PyExpression e = getExpression();
    PyType type = e != null ? context.getType(e) : null;
    if (isDelegating()) {
        final PyClassLikeType classType = as(type, PyClassLikeType.class);
        final PyCollectionType collectionType = as(type, PyCollectionType.class);
        if (classType != null && collectionType != null) {
            if (PyTypingTypeProvider.GENERATOR.equals(classType.getClassQName())) {
                final List<PyType> elementTypes = collectionType.getElementTypes(context);
                if (elementTypes.size() == 3) {
                    return elementTypes.get(2);
                }
            }
        }
        return PyNoneType.INSTANCE;
    }
    return type;
}
Also used : PyExpression(com.jetbrains.python.psi.PyExpression)

Example 23 with PyExpression

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

the class PyConditionalExpressionImpl method getType.

public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) {
    final PyExpression truePart = getTruePart();
    final PyExpression falsePart = getFalsePart();
    if (truePart == null || falsePart == null) {
        return null;
    }
    return PyUnionType.union(context.getType(truePart), context.getType(falsePart));
}
Also used : PyExpression(com.jetbrains.python.psi.PyExpression)

Example 24 with PyExpression

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

the class PyListLiteralExpressionImpl method add.

public PsiElement add(@NotNull PsiElement psiElement) throws IncorrectOperationException {
    checkPyExpression(psiElement);
    PyExpression element = (PyExpression) psiElement;
    PyExpression[] els = getElements();
    PyExpression lastArg = els.length == 0 ? null : els[els.length - 1];
    return PyElementGenerator.getInstance(getProject()).insertItemIntoList(this, lastArg, element);
}
Also used : PyExpression(com.jetbrains.python.psi.PyExpression)

Example 25 with PyExpression

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

the class PyFunctionTypeAnnotationParsingTest method testEllipsis.

public void testEllipsis() {
    doCodeTest("(...) -> None");
    final PyFunctionTypeAnnotation annotation = getParsedAnnotation();
    final List<PyExpression> paramTypes = annotation.getParameterTypeList().getParameterTypes();
    assertSize(1, paramTypes);
    assertInstanceOf(paramTypes.get(0), PyNoneLiteralExpression.class);
    final PyExpression returnType = annotation.getReturnType();
    assertNotNull(returnType);
}
Also used : PyFunctionTypeAnnotation(com.jetbrains.python.codeInsight.functionTypeComments.psi.PyFunctionTypeAnnotation) PyExpression(com.jetbrains.python.psi.PyExpression)

Aggregations

PyExpression (com.jetbrains.python.psi.PyExpression)48 PsiElement (com.intellij.psi.PsiElement)22 PyElementGenerator (com.jetbrains.python.psi.PyElementGenerator)9 Pair (com.intellij.openapi.util.Pair)8 PyAssignmentStatement (com.jetbrains.python.psi.PyAssignmentStatement)8 PyTargetExpression (com.jetbrains.python.psi.PyTargetExpression)7 PyBinaryExpression (com.jetbrains.python.psi.PyBinaryExpression)4 Nullable (org.jetbrains.annotations.Nullable)4 PyFunctionTypeAnnotation (com.jetbrains.python.codeInsight.functionTypeComments.psi.PyFunctionTypeAnnotation)3 PyClass (com.jetbrains.python.psi.PyClass)3 PyType (com.jetbrains.python.psi.types.PyType)3 ASTNode (com.intellij.lang.ASTNode)2 Document (com.intellij.openapi.editor.Document)2 PyArgumentList (com.jetbrains.python.psi.PyArgumentList)2 PyCallExpression (com.jetbrains.python.psi.PyCallExpression)2 PyPathEvaluator (com.jetbrains.python.psi.impl.PyPathEvaluator)2 TypeEvalContext (com.jetbrains.python.psi.types.TypeEvalContext)2 NotNull (org.jetbrains.annotations.NotNull)2 TemplateBuilder (com.intellij.codeInsight.template.TemplateBuilder)1 Editor (com.intellij.openapi.editor.Editor)1