Search in sources :

Example 51 with Position

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

the class ASTParser method FieldDeclaration.

public final FieldDeclaration FieldDeclaration(ModifierHolder modifier) {
    Type type;
    List<VariableDeclarator> variables = new LinkedList<VariableDeclarator>();
    VariableDeclarator val;
    // Modifiers are already matched in the caller
    type = Type();
    val = VariableDeclarator();
    variables.add(val);
    label_12: while (true) {
        switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
            case COMMA:
                {
                    ;
                    break;
                }
            default:
                jj_la1[31] = jj_gen;
                break label_12;
        }
        jj_consume_token(COMMA);
        val = VariableDeclarator();
        variables.add(val);
    }
    jj_consume_token(SEMICOLON);
    Position begin = modifier.begin.orIfInvalid(type.getBegin());
    Pair<Type, List<ArrayBracketPair>> typeListPair = unwrapArrayTypes(type);
    return new FieldDeclaration(range(begin, tokenEnd()), modifier.modifiers, modifier.annotations, typeListPair.a, variables, typeListPair.b);
}
Also used : ArrayType(com.github.javaparser.ast.type.ArrayType) Position(com.github.javaparser.Position)

Example 52 with Position

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

the class ASTParser method ArrayBracketPair.

public final ArrayBracketPair ArrayBracketPair() {
    List<AnnotationExpr> annotations = null;
    Position begin = INVALID;
    annotations = Annotations();
    jj_consume_token(LBRACKET);
    begin = begin.orIfInvalid(tokenBegin());
    jj_consume_token(RBRACKET);
    return new ArrayBracketPair(range(begin, tokenEnd()), annotations);
}
Also used : Position(com.github.javaparser.Position)

Example 53 with Position

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

the class ASTParser method AssertStatement.

public final AssertStmt AssertStatement() {
    Expression check;
    Expression msg = null;
    Position begin;
    jj_consume_token(ASSERT);
    begin = tokenBegin();
    check = Expression();
    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
        case COLON:
            {
                jj_consume_token(COLON);
                msg = Expression();
                break;
            }
        default:
            jj_la1[124] = jj_gen;
            ;
    }
    jj_consume_token(SEMICOLON);
    return new AssertStmt(range(begin, tokenEnd()), check, msg);
}
Also used : Position(com.github.javaparser.Position)

Example 54 with Position

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

the class ASTParser method TryStatement.

public final TryStmt TryStatement() {
    List<VariableDeclarationExpr> resources = null;
    BlockStmt tryBlock;
    BlockStmt finallyBlock = null;
    List<CatchClause> catchs = null;
    BlockStmt catchBlock;
    ModifierHolder exceptModifier;
    ReferenceType exceptionType;
    List<ReferenceType> exceptionTypes = new LinkedList<ReferenceType>();
    VariableDeclaratorId exceptId;
    Position begin;
    Position catchBegin;
    Type type;
    jj_consume_token(TRY);
    begin = tokenBegin();
    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
        case LPAREN:
            {
                resources = ResourceSpecification();
                break;
            }
        default:
            jj_la1[145] = jj_gen;
            ;
    }
    tryBlock = Block();
    label_46: while (true) {
        switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
            case CATCH:
                {
                    ;
                    break;
                }
            default:
                jj_la1[146] = jj_gen;
                break label_46;
        }
        jj_consume_token(CATCH);
        catchBegin = tokenBegin();
        jj_consume_token(LPAREN);
        exceptModifier = Modifiers();
        exceptionType = ReferenceType();
        exceptionTypes.add(exceptionType);
        label_47: while (true) {
            switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                case BIT_OR:
                    {
                        ;
                        break;
                    }
                default:
                    jj_la1[147] = jj_gen;
                    break label_47;
            }
            jj_consume_token(BIT_OR);
            exceptionType = ReferenceTypeWithAnnotations();
            exceptionTypes.add(exceptionType);
        }
        exceptId = VariableDeclaratorId();
        jj_consume_token(RPAREN);
        catchBlock = Block();
        if (exceptionTypes.size() > 1) {
            type = new UnionType(exceptionTypes);
        } else {
            type = (Type) exceptionTypes.get(0);
        }
        catchs = add(catchs, new CatchClause(range(catchBegin, tokenEnd()), exceptModifier.modifiers, exceptModifier.annotations, type, exceptId, catchBlock));
        exceptionTypes = new LinkedList<ReferenceType>();
    }
    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
        case FINALLY:
            {
                jj_consume_token(FINALLY);
                finallyBlock = Block();
                break;
            }
        default:
            jj_la1[148] = jj_gen;
            ;
    }
    if (finallyBlock == null && catchs == null && resources == null) {
        addProblem("Try has no finally, no catch, and no resources");
    }
    return new TryStmt(range(begin, tokenEnd()), resources, tryBlock, catchs, finallyBlock);
}
Also used : Position(com.github.javaparser.Position) ArrayType(com.github.javaparser.ast.type.ArrayType)

Example 55 with Position

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

the class ASTParser method ReturnStatement.

public final ReturnStmt ReturnStatement() {
    Expression expr = null;
    Position begin;
    jj_consume_token(RETURN);
    begin = tokenBegin();
    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[144] = jj_gen;
            ;
    }
    jj_consume_token(SEMICOLON);
    return new ReturnStmt(range(begin, tokenEnd()), expr);
}
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