Search in sources :

Example 86 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.

the class ExpressionParser method parsePrimaryExpressionStart.

@Nullable
private PsiBuilder.Marker parsePrimaryExpressionStart(final PsiBuilder builder) {
    IElementType tokenType = builder.getTokenType();
    if (LITERALS.contains(tokenType)) {
        final PsiBuilder.Marker literal = builder.mark();
        builder.advanceLexer();
        literal.done(JavaElementType.LITERAL_EXPRESSION);
        return literal;
    }
    if (tokenType == JavaTokenType.LBRACE) {
        return parseArrayInitializer(builder);
    }
    if (tokenType == JavaTokenType.NEW_KEYWORD) {
        return parseNew(builder, null);
    }
    if (tokenType == JavaTokenType.LPARENTH) {
        final PsiBuilder.Marker lambda = parseLambdaAfterParenth(builder);
        if (lambda != null) {
            return lambda;
        }
        final PsiBuilder.Marker parenth = builder.mark();
        builder.advanceLexer();
        final PsiBuilder.Marker inner = parse(builder);
        if (inner == null) {
            error(builder, JavaErrorMessages.message("expected.expression"));
        }
        if (!expect(builder, JavaTokenType.RPARENTH)) {
            if (inner != null) {
                error(builder, JavaErrorMessages.message("expected.rparen"));
            }
        }
        parenth.done(JavaElementType.PARENTH_EXPRESSION);
        return parenth;
    }
    if (TYPE_START.contains(tokenType)) {
        final PsiBuilder.Marker mark = builder.mark();
        final ReferenceParser.TypeInfo typeInfo = myParser.getReferenceParser().parseTypeInfo(builder, 0);
        if (typeInfo != null) {
            boolean optionalClassKeyword = typeInfo.isPrimitive || typeInfo.isArray;
            if (optionalClassKeyword || !typeInfo.hasErrors && typeInfo.isParameterized) {
                final PsiBuilder.Marker result = parseClassAccessOrMethodReference(builder, mark, optionalClassKeyword);
                if (result != null) {
                    return result;
                }
            }
        }
        mark.rollbackTo();
    }
    PsiBuilder.Marker annotation = null;
    if (tokenType == JavaTokenType.AT) {
        annotation = myParser.getDeclarationParser().parseAnnotations(builder);
        tokenType = builder.getTokenType();
    }
    if (tokenType == JavaTokenType.IDENTIFIER) {
        if (builder.lookAhead(1) == JavaTokenType.ARROW) {
            return parseLambdaExpression(builder, false);
        }
        final PsiBuilder.Marker refExpr;
        if (annotation != null) {
            final PsiBuilder.Marker refParam = annotation.precede();
            refParam.doneBefore(JavaElementType.REFERENCE_PARAMETER_LIST, annotation);
            refExpr = refParam.precede();
        } else {
            refExpr = builder.mark();
            builder.mark().done(JavaElementType.REFERENCE_PARAMETER_LIST);
        }
        builder.advanceLexer();
        refExpr.done(JavaElementType.REFERENCE_EXPRESSION);
        return refExpr;
    }
    if (annotation != null) {
        annotation.rollbackTo();
        tokenType = builder.getTokenType();
    }
    PsiBuilder.Marker expr = null;
    if (tokenType == JavaTokenType.LT) {
        expr = builder.mark();
        if (!myParser.getReferenceParser().parseReferenceParameterList(builder, false, false)) {
            expr.rollbackTo();
            return null;
        }
        tokenType = builder.getTokenType();
        if (!THIS_OR_SUPER.contains(tokenType)) {
            expr.rollbackTo();
            return null;
        }
    }
    if (THIS_OR_SUPER.contains(tokenType)) {
        if (expr == null) {
            expr = builder.mark();
            builder.mark().done(JavaElementType.REFERENCE_PARAMETER_LIST);
        }
        builder.advanceLexer();
        expr.done(builder.getTokenType() == JavaTokenType.LPARENTH ? JavaElementType.REFERENCE_EXPRESSION : tokenType == JavaTokenType.THIS_KEYWORD ? JavaElementType.THIS_EXPRESSION : JavaElementType.SUPER_EXPRESSION);
        return expr;
    }
    return null;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder) Nullable(org.jetbrains.annotations.Nullable)

Example 87 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.

the class ExpressionParser method parseAssignment.

@Nullable
private PsiBuilder.Marker parseAssignment(final PsiBuilder builder) {
    final PsiBuilder.Marker left = parseConditional(builder);
    if (left == null)
        return null;
    final IElementType tokenType = getGtTokenType(builder);
    if (ASSIGNMENT_OPS.contains(tokenType) && tokenType != null) {
        final PsiBuilder.Marker assignment = left.precede();
        advanceGtToken(builder, tokenType);
        final PsiBuilder.Marker right = parse(builder);
        if (right == null) {
            error(builder, JavaErrorMessages.message("expected.expression"));
        }
        assignment.done(JavaElementType.ASSIGNMENT_EXPRESSION);
        return assignment;
    }
    return left;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder) Nullable(org.jetbrains.annotations.Nullable)

Example 88 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.

the class JavadocParser method parseMethodRef.

private static void parseMethodRef(@NotNull final PsiBuilder builder, @NotNull final PsiBuilder.Marker refStart) {
    if (getTokenType(builder) == JavaDocTokenType.DOC_TAG_VALUE_SHARP_TOKEN) {
        builder.advanceLexer();
    }
    if (getTokenType(builder) != JavaDocTokenType.DOC_TAG_VALUE_TOKEN) {
        refStart.done(JavaDocElementType.DOC_METHOD_OR_FIELD_REF);
        return;
    }
    builder.advanceLexer();
    if (getTokenType(builder) == JavaDocTokenType.DOC_TAG_VALUE_LPAREN) {
        builder.advanceLexer();
        final PsiBuilder.Marker subValue = builder.mark();
        IElementType tokenType;
        while (TAG_VALUES_SET.contains(tokenType = getTokenType(builder))) {
            if (tokenType == JavaDocTokenType.DOC_TAG_VALUE_TOKEN) {
                builder.remapCurrentToken(JavaDocElementType.DOC_TYPE_HOLDER);
                builder.advanceLexer();
                while (TAG_VALUES_SET.contains(tokenType = getTokenType(builder)) && tokenType != JavaDocTokenType.DOC_TAG_VALUE_COMMA && tokenType != JavaDocTokenType.DOC_TAG_VALUE_RPAREN) {
                    builder.advanceLexer();
                }
            } else if (tokenType == JavaDocTokenType.DOC_TAG_VALUE_RPAREN) {
                subValue.done(JavaDocElementType.DOC_TAG_VALUE_ELEMENT);
                builder.advanceLexer();
                refStart.done(JavaDocElementType.DOC_METHOD_OR_FIELD_REF);
                return;
            } else {
                builder.advanceLexer();
            }
        }
        subValue.done(JavaDocElementType.DOC_TAG_VALUE_ELEMENT);
    }
    refStart.done(JavaDocElementType.DOC_METHOD_OR_FIELD_REF);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 89 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.

the class JavadocParser method parseTag.

private static void parseTag(@NotNull final PsiBuilder builder) {
    final String tagName = builder.getTokenText();
    final PsiBuilder.Marker tag = builder.mark();
    builder.advanceLexer();
    while (true) {
        final IElementType tokenType = getTokenType(builder);
        if (tokenType == null || tokenType == JavaDocTokenType.DOC_TAG_NAME || tokenType == JavaDocTokenType.DOC_COMMENT_END)
            break;
        parseDataItem(builder, tagName, false);
    }
    tag.done(JavaDocElementType.DOC_TAG);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 90 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.

the class JavadocParser method parseDataItem.

private static void parseDataItem(@NotNull final PsiBuilder builder, @Nullable final String tagName, final boolean isInline) {
    IElementType tokenType = getTokenType(builder);
    if (tokenType == JavaDocTokenType.DOC_INLINE_TAG_START) {
        int braceScope = getBraceScope(builder);
        if (braceScope > 0) {
            setBraceScope(builder, braceScope + 1);
            builder.remapCurrentToken(JavaDocTokenType.DOC_COMMENT_DATA);
            builder.advanceLexer();
            return;
        }
        final PsiBuilder.Marker tag = builder.mark();
        builder.advanceLexer();
        tokenType = getTokenType(builder);
        if (tokenType != JavaDocTokenType.DOC_TAG_NAME && tokenType != JavaDocTokenType.DOC_COMMENT_BAD_CHARACTER) {
            tag.rollbackTo();
            builder.remapCurrentToken(JavaDocTokenType.DOC_COMMENT_DATA);
            builder.advanceLexer();
            return;
        }
        setBraceScope(builder, braceScope + 1);
        String inlineTagName = "";
        while (true) {
            tokenType = getTokenType(builder);
            if (tokenType == JavaDocTokenType.DOC_TAG_NAME) {
                inlineTagName = builder.getTokenText();
            } else if (tokenType == null || tokenType == JavaDocTokenType.DOC_COMMENT_END) {
                break;
            }
            parseDataItem(builder, inlineTagName, true);
            if (tokenType == JavaDocTokenType.DOC_INLINE_TAG_END) {
                braceScope = getBraceScope(builder);
                if (braceScope > 0)
                    setBraceScope(builder, --braceScope);
                if (braceScope == 0)
                    break;
            }
        }
        tag.done(JavaDocElementType.DOC_INLINE_TAG);
    } else if (TAG_VALUES_SET.contains(tokenType)) {
        if (SEE_TAG.equals(tagName) && !isInline || LINK_TAG.equals(tagName) && isInline) {
            parseSeeTagValue(builder, false);
        } else {
            if (JavaParserUtil.getLanguageLevel(builder).isAtLeast(LanguageLevel.JDK_1_4) && LINK_PLAIN_TAG.equals(tagName) && isInline) {
                parseSeeTagValue(builder, false);
            } else if (!isInline && (THROWS_TAG.equals(tagName) || EXCEPTION_TAG.equals(tagName))) {
                final PsiBuilder.Marker tagValue = builder.mark();
                builder.remapCurrentToken(JavaDocElementType.DOC_REFERENCE_HOLDER);
                builder.advanceLexer();
                tagValue.done(JavaDocElementType.DOC_TAG_VALUE_ELEMENT);
            } else if (!isInline && tagName != null && tagName.equals(PARAM_TAG)) {
                parseSimpleTagValue(builder, true);
            } else {
                if (JavaParserUtil.getLanguageLevel(builder).isAtLeast(LanguageLevel.JDK_1_5) && VALUE_TAG.equals(tagName) && isInline) {
                    parseSeeTagValue(builder, true);
                } else {
                    parseSimpleTagValue(builder, false);
                }
            }
        }
    } else {
        remapAndAdvance(builder);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Aggregations

PsiBuilder (com.intellij.lang.PsiBuilder)124 IElementType (com.intellij.psi.tree.IElementType)90 Nullable (org.jetbrains.annotations.Nullable)18 NotNull (org.jetbrains.annotations.NotNull)16 Project (com.intellij.openapi.project.Project)7 LighterASTNode (com.intellij.lang.LighterASTNode)6 GroovyElementType (org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType)5 Language (com.intellij.lang.Language)3 ASTNode (com.intellij.lang.ASTNode)2 PsiElement (com.intellij.psi.PsiElement)2 ILazyParseableElementType (com.intellij.psi.tree.ILazyParseableElementType)2 ParsingContext (com.jetbrains.python.parsing.ParsingContext)2 StatementParsing (com.jetbrains.python.parsing.StatementParsing)2 ParserDefinition (com.intellij.lang.ParserDefinition)1 PsiParser (com.intellij.lang.PsiParser)1 HtmlParsing (com.intellij.lang.html.HtmlParsing)1 Lexer (com.intellij.lexer.Lexer)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1