Search in sources :

Example 46 with Position

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

the class ASTParser method EmptyImportDeclaration.

public final ImportDeclaration EmptyImportDeclaration() {
    Position begin;
    jj_consume_token(SEMICOLON);
    begin = tokenBegin();
    return ImportDeclaration.createEmptyDeclaration(range(begin, tokenEnd()));
}
Also used : Position(com.github.javaparser.Position)

Example 47 with Position

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

the class ASTParser method DoStatement.

public final DoStmt DoStatement() {
    Expression condition;
    Statement body;
    Position begin;
    jj_consume_token(DO);
    begin = tokenBegin();
    body = Statement();
    jj_consume_token(WHILE);
    jj_consume_token(LPAREN);
    condition = Expression();
    jj_consume_token(RPAREN);
    jj_consume_token(SEMICOLON);
    return new DoStmt(range(begin, tokenEnd()), body, condition);
}
Also used : Position(com.github.javaparser.Position)

Example 48 with Position

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

the class ASTParser method AllocationExpression.

public final Expression AllocationExpression(Expression scope) {
    Expression ret;
    Type type;
    RangedList<Type<?>> typeArgs = new RangedList<Type<?>>(null);
    List<BodyDeclaration<?>> anonymousBody = null;
    List<Expression> args;
    Position begin;
    List<AnnotationExpr> annotations = null;
    jj_consume_token(NEW);
    if (scope == null) {
        begin = tokenBegin();
    } else {
        begin = scope.getBegin();
    }
    annotations = Annotations();
    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:
            {
                type = PrimitiveType();
                type.setAnnotations(annotations);
                ret = ArrayCreation(begin, type);
                break;
            }
        case IDENTIFIER:
        case AT:
        case LT:
            {
                switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                    case LT:
                        {
                            typeArgs = TypeArguments();
                            annotations = Annotations();
                            break;
                        }
                    default:
                        jj_la1[117] = jj_gen;
                        ;
                }
                type = AnnotatedClassOrInterfaceType();
                switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                    case LBRACKET:
                    case AT:
                        {
                            ret = ArrayCreation(begin, type);
                            break;
                        }
                    case LPAREN:
                        {
                            args = Arguments();
                            if (jj_2_32(2)) {
                                anonymousBody = ClassOrInterfaceBody(false);
                            } else {
                                ;
                            }
                            ret = new ObjectCreationExpr(range(begin, tokenEnd()), scope, (ClassOrInterfaceType) type, typeArgs.list, args, anonymousBody);
                            break;
                        }
                    default:
                        jj_la1[118] = jj_gen;
                        jj_consume_token(-1);
                        throw new ParseException();
                }
                break;
            }
        default:
            jj_la1[119] = jj_gen;
            jj_consume_token(-1);
            throw new ParseException();
    }
    return ret;
}
Also used : Position(com.github.javaparser.Position) ArrayType(com.github.javaparser.ast.type.ArrayType)

Example 49 with Position

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

the class ASTParser method ClassOrInterfaceType.

public final ClassOrInterfaceType ClassOrInterfaceType() {
    ClassOrInterfaceType ret;
    String name;
    RangedList<Type<?>> typeArgs = new RangedList<Type<?>>(null);
    Position begin;
    List<AnnotationExpr> annotations = null;
    jj_consume_token(IDENTIFIER);
    begin = tokenBegin();
    name = token.image;
    if (jj_2_14(2)) {
        typeArgs = TypeArguments();
    } else {
        ;
    }
    ret = new ClassOrInterfaceType(range(begin, tokenEnd()), null, name, typeArgs.list);
    label_25: while (true) {
        if (jj_2_15(2)) {
            ;
        } else {
            break label_25;
        }
        jj_consume_token(DOT);
        annotations = Annotations();
        jj_consume_token(IDENTIFIER);
        name = token.image;
        if (jj_2_16(2)) {
            typeArgs = TypeArguments();
        } else {
            ;
        }
        ret = new ClassOrInterfaceType(range(begin, tokenEnd()), ret, name, typeArgs.list);
        ret.setAnnotations(annotations);
        annotations = null;
    }
    return ret;
}
Also used : ArrayType(com.github.javaparser.ast.type.ArrayType) Position(com.github.javaparser.Position)

Example 50 with Position

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

the class ASTParser method TypeParameter.

public final TypeParameter TypeParameter() {
    String name;
    List<ClassOrInterfaceType> typeBound = null;
    Position begin;
    jj_consume_token(IDENTIFIER);
    name = token.image;
    begin = tokenBegin();
    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
        case EXTENDS:
            {
                typeBound = TypeBound();
                break;
            }
        default:
            jj_la1[24] = jj_gen;
            ;
    }
    return new TypeParameter(range(begin, tokenEnd()), name, typeBound);
}
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