Search in sources :

Example 6 with Position

use of com.github.javaparser.Position in project javaparser by javaparser.

the class ASTParser method IfStatement.

public final IfStmt IfStatement() {
    Expression condition;
    Statement thenStmt;
    Statement elseStmt = null;
    Position begin;
    Comment thenCmmt = null;
    Comment elseCmmt = null;
    jj_consume_token(IF);
    begin = tokenBegin();
    jj_consume_token(LPAREN);
    condition = Expression();
    jj_consume_token(RPAREN);
    thenStmt = Statement();
    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
        case ELSE:
            {
                jj_consume_token(ELSE);
                elseStmt = Statement();
                break;
            }
        default:
            jj_la1[135] = jj_gen;
            ;
    }
    IfStmt tmp = new IfStmt(range(begin, tokenEnd()), condition, thenStmt, elseStmt);
    // TODO comment is always null
    thenStmt.setComment(thenCmmt);
    if (elseStmt != null)
        // TODO comment is always null
        elseStmt.setComment(elseCmmt);
    return tmp;
}
Also used : Position(com.github.javaparser.Position)

Example 7 with Position

use of com.github.javaparser.Position in project javaparser by javaparser.

the class ASTParser method InitializerDeclaration.

public final InitializerDeclaration InitializerDeclaration() {
    BlockStmt block;
    Position begin = INVALID;
    boolean isStatic = false;
    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
        case STATIC:
            {
                jj_consume_token(STATIC);
                isStatic = true;
                begin = tokenBegin();
                break;
            }
        default:
            jj_la1[54] = jj_gen;
            ;
    }
    block = Block();
    begin = begin.orIfInvalid(block.getBegin());
    return new InitializerDeclaration(range(begin, tokenEnd()), isStatic, block);
}
Also used : Position(com.github.javaparser.Position)

Example 8 with Position

use of com.github.javaparser.Position in project javaparser by javaparser.

the class ASTParser method AnnotationTypeDeclaration.

/* Annotation Types. */
public final AnnotationDeclaration AnnotationTypeDeclaration(ModifierHolder modifier) {
    NameExpr name;
    List<BodyDeclaration<?>> members;
    Position begin = modifier.begin;
    jj_consume_token(AT);
    begin = begin.orIfInvalid(tokenBegin());
    jj_consume_token(INTERFACE);
    name = Name();
    members = AnnotationTypeBody();
    AnnotationDeclaration tmp = new AnnotationDeclaration(range(begin, tokenEnd()), modifier.modifiers, modifier.annotations, null, members);
    tmp.setNameExpr(name);
    return tmp;
}
Also used : Position(com.github.javaparser.Position)

Example 9 with Position

use of com.github.javaparser.Position in project javaparser by javaparser.

the class ASTParser method SingleMemberAnnotation.

public final SingleMemberAnnotationExpr SingleMemberAnnotation() {
    NameExpr name;
    Expression memberVal;
    Position begin;
    jj_consume_token(AT);
    begin = tokenBegin();
    name = Name();
    jj_consume_token(LPAREN);
    memberVal = MemberValue();
    jj_consume_token(RPAREN);
    return new SingleMemberAnnotationExpr(range(begin, tokenEnd()), name, memberVal);
}
Also used : Position(com.github.javaparser.Position)

Example 10 with Position

use of com.github.javaparser.Position in project javaparser by javaparser.

the class ASTParser method ForStatement.

public final Statement ForStatement() {
    VariableDeclarationExpr varExpr = null;
    Expression expr = null;
    List<Expression> init = null;
    List<Expression> update = null;
    Statement body;
    Position begin;
    jj_consume_token(FOR);
    begin = tokenBegin();
    jj_consume_token(LPAREN);
    if (jj_2_37(2147483647)) {
        varExpr = VariableDeclarationExpression();
        jj_consume_token(COLON);
        expr = Expression();
    } else {
        switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
            case ABSTRACT:
            case BOOLEAN:
            case BYTE:
            case CHAR:
            case DOUBLE:
            case FALSE:
            case FINAL:
            case FLOAT:
            case INT:
            case LONG:
            case NATIVE:
            case NEW:
            case NULL:
            case PRIVATE:
            case PROTECTED:
            case PUBLIC:
            case SHORT:
            case STATIC:
            case STRICTFP:
            case SUPER:
            case SYNCHRONIZED:
            case THIS:
            case TRANSIENT:
            case TRUE:
            case VOID:
            case VOLATILE:
            case LONG_LITERAL:
            case INTEGER_LITERAL:
            case FLOATING_POINT_LITERAL:
            case CHARACTER_LITERAL:
            case STRING_LITERAL:
            case IDENTIFIER:
            case LPAREN:
            case SEMICOLON:
            case AT:
            case BANG:
            case TILDE:
            case INCR:
            case DECR:
            case PLUS:
            case MINUS:
                {
                    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                        case ABSTRACT:
                        case BOOLEAN:
                        case BYTE:
                        case CHAR:
                        case DOUBLE:
                        case FALSE:
                        case FINAL:
                        case FLOAT:
                        case INT:
                        case LONG:
                        case NATIVE:
                        case NEW:
                        case NULL:
                        case PRIVATE:
                        case PROTECTED:
                        case PUBLIC:
                        case SHORT:
                        case STATIC:
                        case STRICTFP:
                        case SUPER:
                        case SYNCHRONIZED:
                        case THIS:
                        case TRANSIENT:
                        case TRUE:
                        case VOID:
                        case VOLATILE:
                        case LONG_LITERAL:
                        case INTEGER_LITERAL:
                        case FLOATING_POINT_LITERAL:
                        case CHARACTER_LITERAL:
                        case STRING_LITERAL:
                        case IDENTIFIER:
                        case LPAREN:
                        case AT:
                        case BANG:
                        case TILDE:
                        case INCR:
                        case DECR:
                        case PLUS:
                        case MINUS:
                            {
                                init = ForInit();
                                break;
                            }
                        default:
                            jj_la1[136] = jj_gen;
                            ;
                    }
                    jj_consume_token(SEMICOLON);
                    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                        case BOOLEAN:
                        case BYTE:
                        case CHAR:
                        case DOUBLE:
                        case FALSE:
                        case FLOAT:
                        case INT:
                        case LONG:
                        case NEW:
                        case NULL:
                        case SHORT:
                        case SUPER:
                        case THIS:
                        case TRUE:
                        case VOID:
                        case LONG_LITERAL:
                        case INTEGER_LITERAL:
                        case FLOATING_POINT_LITERAL:
                        case CHARACTER_LITERAL:
                        case STRING_LITERAL:
                        case IDENTIFIER:
                        case LPAREN:
                        case BANG:
                        case TILDE:
                        case INCR:
                        case DECR:
                        case PLUS:
                        case MINUS:
                            {
                                expr = Expression();
                                break;
                            }
                        default:
                            jj_la1[137] = jj_gen;
                            ;
                    }
                    jj_consume_token(SEMICOLON);
                    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                        case BOOLEAN:
                        case BYTE:
                        case CHAR:
                        case DOUBLE:
                        case FALSE:
                        case FLOAT:
                        case INT:
                        case LONG:
                        case NEW:
                        case NULL:
                        case SHORT:
                        case SUPER:
                        case THIS:
                        case TRUE:
                        case VOID:
                        case LONG_LITERAL:
                        case INTEGER_LITERAL:
                        case FLOATING_POINT_LITERAL:
                        case CHARACTER_LITERAL:
                        case STRING_LITERAL:
                        case IDENTIFIER:
                        case LPAREN:
                        case BANG:
                        case TILDE:
                        case INCR:
                        case DECR:
                        case PLUS:
                        case MINUS:
                            {
                                update = ForUpdate();
                                break;
                            }
                        default:
                            jj_la1[138] = jj_gen;
                            ;
                    }
                    break;
                }
            default:
                jj_la1[139] = jj_gen;
                jj_consume_token(-1);
                throw new ParseException();
        }
    }
    jj_consume_token(RPAREN);
    body = Statement();
    if (varExpr != null) {
        return new ForeachStmt(range(begin, tokenEnd()), varExpr, expr, body);
    }
    return new ForStmt(range(begin, tokenEnd()), init, expr, update, body);
}
Also used : Position(com.github.javaparser.Position)

Aggregations

Position (com.github.javaparser.Position)56 ArrayType (com.github.javaparser.ast.type.ArrayType)10 SimpleName (com.github.javaparser.ast.expr.SimpleName)2 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 BodyDeclaration (com.github.javaparser.ast.body.BodyDeclaration)1 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)1 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)1 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 Parameter (com.github.javaparser.ast.body.Parameter)1 TypeDeclaration (com.github.javaparser.ast.body.TypeDeclaration)1 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)1 PositionUtils.sortByBeginPosition (com.github.javaparser.utils.PositionUtils.sortByBeginPosition)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1