Search in sources :

Example 21 with Position

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

the class ASTParser method ExplicitConstructorInvocation.

public final ExplicitConstructorInvocationStmt ExplicitConstructorInvocation() {
    boolean isThis = false;
    List<Expression> args;
    Expression expr = null;
    RangedList<Type<?>> typeArgs = new RangedList<Type<?>>(null);
    Position begin = INVALID;
    if (jj_2_10(2147483647)) {
        switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
            case LT:
                {
                    typeArgs = TypeArguments();
                    begin = typeArgs.range.begin;
                    break;
                }
            default:
                jj_la1[50] = jj_gen;
                ;
        }
        jj_consume_token(THIS);
        begin = begin.orIfInvalid(tokenBegin());
        isThis = true;
        args = Arguments();
        jj_consume_token(SEMICOLON);
    } else {
        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 LT:
                {
                    if (jj_2_9(2147483647)) {
                        expr = PrimaryExpressionWithoutSuperSuffix();
                        jj_consume_token(DOT);
                        begin = expr.getBegin();
                    } else {
                        ;
                    }
                    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                        case LT:
                            {
                                typeArgs = TypeArguments();
                                begin = begin.orIfInvalid(typeArgs.range.begin);
                                break;
                            }
                        default:
                            jj_la1[51] = jj_gen;
                            ;
                    }
                    jj_consume_token(SUPER);
                    begin = begin.orIfInvalid(tokenBegin());
                    args = Arguments();
                    jj_consume_token(SEMICOLON);
                    break;
                }
            default:
                jj_la1[52] = jj_gen;
                jj_consume_token(-1);
                throw new ParseException();
        }
    }
    return new ExplicitConstructorInvocationStmt(range(begin, tokenEnd()), typeArgs.list, isThis, expr, args);
}
Also used : ArrayType(com.github.javaparser.ast.type.ArrayType) Position(com.github.javaparser.Position)

Example 22 with Position

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

the class ASTParser method ConstructorDeclaration.

public final ConstructorDeclaration ConstructorDeclaration(ModifierHolder modifier) {
    RangedList<TypeParameter> typeParameters = new RangedList<TypeParameter>(null);
    NameExpr name;
    List<Parameter> parameters;
    List<ReferenceType> throws_ = null;
    ExplicitConstructorInvocationStmt exConsInv = null;
    List<Statement> stmts;
    Position begin = modifier.begin;
    Position blockBegin = INVALID;
    ReferenceType throwType;
    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
        case LT:
            {
                typeParameters = TypeParameters();
                begin = begin.orIfInvalid(typeParameters.range.begin);
                break;
            }
        default:
            jj_la1[47] = jj_gen;
            ;
    }
    // Modifiers matched in the caller
    name = SimpleName();
    begin = begin.orIfInvalid(typeParameters.range.begin);
    parameters = FormalParameters();
    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
        case THROWS:
            {
                jj_consume_token(THROWS);
                throwType = ReferenceTypeWithAnnotations();
                throws_ = add(throws_, throwType);
                label_20: while (true) {
                    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                        case COMMA:
                            {
                                ;
                                break;
                            }
                        default:
                            jj_la1[48] = jj_gen;
                            break label_20;
                    }
                    jj_consume_token(COMMA);
                    throwType = ReferenceTypeWithAnnotations();
                    throws_ = add(throws_, throwType);
                }
                break;
            }
        default:
            jj_la1[49] = jj_gen;
            ;
    }
    jj_consume_token(LBRACE);
    blockBegin = tokenBegin();
    if (jj_2_8(2147483647)) {
        exConsInv = ExplicitConstructorInvocation();
    } else {
        ;
    }
    stmts = Statements();
    jj_consume_token(RBRACE);
    if (exConsInv != null) {
        stmts = add(0, stmts, exConsInv);
    }
    ConstructorDeclaration tmp = new ConstructorDeclaration(range(begin, pos(token.endLine, token.endColumn)), modifier.modifiers, modifier.annotations, typeParameters.list, null, parameters, throws_, new BlockStmt(range(blockBegin, tokenEnd()), stmts));
    tmp.setNameExpr(name);
    return tmp;
}
Also used : Position(com.github.javaparser.Position)

Example 23 with Position

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

the class ASTParser method IntersectionType.

public final IntersectionType IntersectionType() {
    Position begin;
    ReferenceType elementType;
    List<ReferenceType> elements = null;
    elementType = ReferenceType();
    begin = elementType.getBegin();
    elements = add(elements, elementType);
    jj_consume_token(BIT_AND);
    label_24: while (true) {
        elementType = ReferenceType();
        elements = add(elements, elementType);
        switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
            case BOOLEAN:
            case BYTE:
            case CHAR:
            case DOUBLE:
            case FLOAT:
            case INT:
            case LONG:
            case SHORT:
            case IDENTIFIER:
                {
                    ;
                    break;
                }
            default:
                jj_la1[57] = jj_gen;
                break label_24;
        }
    }
    return new IntersectionType(range(begin, tokenEnd()), elements);
}
Also used : Position(com.github.javaparser.Position)

Example 24 with Position

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

the class ASTParser method CastExpression.

public final Expression CastExpression() {
    Expression ret;
    ReferenceType referenceType;
    PrimitiveType primitiveType;
    Position begin = INVALID;
    List<AnnotationExpr> annotations = null;
    List<ReferenceType> typesOfMultiCast = null;
    jj_consume_token(LPAREN);
    begin = tokenBegin();
    annotations = Annotations();
    if (jj_2_24(2)) {
        primitiveType = PrimitiveType();
        jj_consume_token(RPAREN);
        ret = UnaryExpression();
        primitiveType.setAnnotations(annotations);
        ret = new CastExpr(range(begin, tokenEnd()), primitiveType, ret);
    } else {
        switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
            case BOOLEAN:
            case BYTE:
            case CHAR:
            case DOUBLE:
            case FLOAT:
            case INT:
            case LONG:
            case SHORT:
            case IDENTIFIER:
                {
                    referenceType = ReferenceType();
                    typesOfMultiCast = add(typesOfMultiCast, referenceType);
                    referenceType.setAnnotations(annotations);
                    label_38: while (true) {
                        switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                            case BIT_AND:
                                {
                                    ;
                                    break;
                                }
                            default:
                                jj_la1[92] = jj_gen;
                                break label_38;
                        }
                        jj_consume_token(BIT_AND);
                        referenceType = ReferenceType();
                        typesOfMultiCast = add(typesOfMultiCast, referenceType);
                    }
                    jj_consume_token(RPAREN);
                    ret = UnaryExpressionNotPlusMinus();
                    if (typesOfMultiCast.size() > 1) {
                        ret = new CastExpr(range(begin, tokenEnd()), new IntersectionType(range(begin, tokenEnd()), typesOfMultiCast), ret);
                    }
                    ret = new CastExpr(range(begin, tokenEnd()), referenceType, ret);
                    break;
                }
            default:
                jj_la1[93] = jj_gen;
                jj_consume_token(-1);
                throw new ParseException();
        }
    }
    return ret;
}
Also used : Position(com.github.javaparser.Position)

Example 25 with Position

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

the class ASTParser method PackageDeclaration.

public final PackageDeclaration PackageDeclaration() {
    List<AnnotationExpr> annotations = null;
    NameExpr name;
    Position begin;
    annotations = Annotations();
    jj_consume_token(PACKAGE);
    begin = tokenBegin();
    name = Name();
    jj_consume_token(SEMICOLON);
    return new PackageDeclaration(range(begin, tokenEnd()), annotations, name);
}
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