Search in sources :

Example 71 with IElementType

use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.

the class StatementParsing method parseStatement.

public void parseStatement() {
    while (myBuilder.getTokenType() == PyTokenTypes.STATEMENT_BREAK) {
        myBuilder.advanceLexer();
    }
    final IElementType firstToken;
    firstToken = myBuilder.getTokenType();
    if (firstToken == null)
        return;
    if (firstToken == PyTokenTypes.WHILE_KEYWORD) {
        parseWhileStatement();
        return;
    }
    if (firstToken == PyTokenTypes.IF_KEYWORD) {
        parseIfStatement(PyTokenTypes.IF_KEYWORD, PyTokenTypes.ELIF_KEYWORD, PyTokenTypes.ELSE_KEYWORD, PyElementTypes.IF_STATEMENT);
        return;
    }
    if (firstToken == PyTokenTypes.FOR_KEYWORD) {
        parseForStatement(myBuilder.mark());
        return;
    }
    if (firstToken == PyTokenTypes.TRY_KEYWORD) {
        parseTryStatement();
        return;
    }
    if (firstToken == PyTokenTypes.DEF_KEYWORD) {
        getFunctionParser().parseFunctionDeclaration(myBuilder.mark(), false);
        return;
    }
    if (firstToken == PyTokenTypes.AT) {
        getFunctionParser().parseDecoratedDeclaration();
        return;
    }
    if (firstToken == PyTokenTypes.CLASS_KEYWORD) {
        parseClassDeclaration();
        return;
    }
    if (firstToken == PyTokenTypes.WITH_KEYWORD) {
        parseWithStatement(myBuilder.mark());
        return;
    }
    if (firstToken == PyTokenTypes.ASYNC_KEYWORD) {
        parseAsyncStatement();
        return;
    }
    parseSimpleStatement();
}
Also used : IElementType(com.intellij.psi.tree.IElementType)

Example 72 with IElementType

use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.

the class ExpressionParsing method parseUnaryExpression.

protected boolean parseUnaryExpression(boolean isTargetExpression) {
    final IElementType tokenType = myBuilder.getTokenType();
    if (PyTokenTypes.UNARY_OPERATIONS.contains(tokenType)) {
        final PsiBuilder.Marker expr = myBuilder.mark();
        myBuilder.advanceLexer();
        if (!parseUnaryExpression(isTargetExpression)) {
            myBuilder.error(message("PARSE.expected.expression"));
        }
        expr.done(PyElementTypes.PREFIX_EXPRESSION);
        return true;
    } else {
        return parsePowerExpression(isTargetExpression);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 73 with IElementType

use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.

the class StatementParsing method parseFromImportStatement.

/*
  Really parses two forms:
  from identifier import id, id... -- may be either relative or absolute
  from . import identifier -- only relative
   */
private void parseFromImportStatement() {
    PsiBuilder builder = myContext.getBuilder();
    assertCurrentToken(PyTokenTypes.FROM_KEYWORD);
    myFutureImportPhase = Phase.FROM;
    final PsiBuilder.Marker fromImportStatement = builder.mark();
    builder.advanceLexer();
    boolean from_future = false;
    boolean had_dots = parseRelativeImportDots();
    IElementType statementType = PyElementTypes.FROM_IMPORT_STATEMENT;
    if (had_dots && parseOptionalDottedName() || parseDottedName()) {
        final ImportTypes types = checkFromImportKeyword();
        statementType = types.statement;
        final IElementType elementType = types.element;
        if (myFutureImportPhase == Phase.FUTURE) {
            myFutureImportPhase = Phase.IMPORT;
            from_future = true;
        }
        if (builder.getTokenType() == PyTokenTypes.MULT) {
            final PsiBuilder.Marker star_import_mark = builder.mark();
            builder.advanceLexer();
            star_import_mark.done(types.starElement);
        } else if (builder.getTokenType() == PyTokenTypes.LPAR) {
            builder.advanceLexer();
            parseImportElements(elementType, false, true, from_future);
            checkMatches(PyTokenTypes.RPAR, ") expected");
        } else {
            parseImportElements(elementType, false, false, from_future);
        }
    } else if (had_dots) {
        // from . import ...
        final ImportTypes types = checkFromImportKeyword();
        statementType = types.statement;
        parseImportElements(types.element, false, false, from_future);
    }
    checkEndOfStatement();
    fromImportStatement.done(statementType);
    myFutureImportPhase = Phase.NONE;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 74 with IElementType

use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.

the class StatementParsing method parseAsyncStatement.

private void parseAsyncStatement() {
    assertCurrentToken(PyTokenTypes.ASYNC_KEYWORD);
    final PsiBuilder.Marker marker = myBuilder.mark();
    myBuilder.advanceLexer();
    final IElementType token = myBuilder.getTokenType();
    if (token == PyTokenTypes.DEF_KEYWORD) {
        getFunctionParser().parseFunctionDeclaration(marker, true);
    } else if (token == PyTokenTypes.WITH_KEYWORD) {
        parseWithStatement(marker);
    } else if (token == PyTokenTypes.FOR_KEYWORD) {
        parseForStatement(marker);
    } else {
        marker.drop();
        myBuilder.error("'def' or 'with' or 'for' expected");
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 75 with IElementType

use of com.intellij.psi.tree.IElementType in project kotlin by JetBrains.

the class BasicExpressionTypingVisitor method visitBinaryWithTypeRHSExpression.

@Override
public KotlinTypeInfo visitBinaryWithTypeRHSExpression(@NotNull KtBinaryExpressionWithTypeRHS expression, ExpressionTypingContext context) {
    ExpressionTypingContext contextWithNoExpectedType = context.replaceExpectedType(NO_EXPECTED_TYPE).replaceContextDependency(INDEPENDENT);
    KtExpression left = expression.getLeft();
    KtTypeReference right = expression.getRight();
    if (right == null) {
        return facade.getTypeInfo(left, contextWithNoExpectedType).clearType();
    }
    IElementType operationType = expression.getOperationReference().getReferencedNameElementType();
    boolean allowBareTypes = BARE_TYPES_ALLOWED.contains(operationType);
    TypeResolutionContext typeResolutionContext = new TypeResolutionContext(context.scope, context.trace, true, allowBareTypes, context.isDebuggerContext);
    PossiblyBareType possiblyBareTarget = components.typeResolver.resolvePossiblyBareType(typeResolutionContext, right);
    KotlinTypeInfo typeInfo = facade.getTypeInfo(left, contextWithNoExpectedType);
    KotlinType subjectType = typeInfo.getType();
    KotlinType targetType = reconstructBareType(right, possiblyBareTarget, subjectType, context.trace, components.builtIns);
    if (subjectType != null) {
        checkBinaryWithTypeRHS(expression, contextWithNoExpectedType, targetType, subjectType);
        DataFlowInfo dataFlowInfo = typeInfo.getDataFlowInfo();
        if (operationType == AS_KEYWORD) {
            DataFlowValue value = createDataFlowValue(left, subjectType, context);
            typeInfo = typeInfo.replaceDataFlowInfo(dataFlowInfo.establishSubtyping(value, targetType, components.languageVersionSettings));
        }
    }
    KotlinType result = operationType == AS_SAFE ? TypeUtils.makeNullable(targetType) : targetType;
    KotlinTypeInfo resultTypeInfo = components.dataFlowAnalyzer.checkType(typeInfo.replaceType(result), expression, context);
    RttiExpressionInformation rttiInformation = new RttiExpressionInformation(expression.getLeft(), subjectType, result, operationType == AS_SAFE ? RttiOperation.SAFE_AS : RttiOperation.AS);
    for (RttiExpressionChecker checker : components.rttiExpressionCheckers) {
        checker.check(rttiInformation, expression, context.trace);
    }
    return resultTypeInfo;
}
Also used : DataFlowValue(org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue) DataFlowValueFactory.createDataFlowValue(org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory.createDataFlowValue) IElementType(com.intellij.psi.tree.IElementType) DataFlowInfo(org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo)

Aggregations

IElementType (com.intellij.psi.tree.IElementType)843 ASTNode (com.intellij.lang.ASTNode)127 PsiBuilder (com.intellij.lang.PsiBuilder)121 Nullable (org.jetbrains.annotations.Nullable)100 NotNull (org.jetbrains.annotations.NotNull)78 PsiElement (com.intellij.psi.PsiElement)77 TextRange (com.intellij.openapi.util.TextRange)43 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)26 ArrayList (java.util.ArrayList)22 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)22 Lexer (com.intellij.lexer.Lexer)17 GrBinaryExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression)15 NonNls (org.jetbrains.annotations.NonNls)14 Document (com.intellij.openapi.editor.Document)13 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)13 LighterASTNode (com.intellij.lang.LighterASTNode)12 BracePair (com.intellij.lang.BracePair)10 Project (com.intellij.openapi.project.Project)9 PsiFile (com.intellij.psi.PsiFile)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)9