Package org.codehaus.commons.compiler

Examples of org.codehaus.commons.compiler.Location


     * <pre>
     *   EmptyStatement := ';'
     * </pre>
     */
    public Java.Statement parseEmptyStatement() throws CompileException, IOException {
        Location location = this.location();
        this.readOperator(";");
        return new Java.EmptyStatement(location);
    }
View Full Code Here


    public Java.Atom parseAssignmentExpression() throws CompileException, IOException  {
        Java.Atom a = this.parseConditionalExpression();
        if (this.peekOperator(
            new String[] { "=", "+=", "-=", "*=", "/=", "&=", "|=", "^=", "%=", "<<=", ">>=", ">>>=" }
        )) {
            Location location = this.location();
            String operator = this.readOperator();
            final Java.Lvalue lhs = a.toLvalueOrPE();
            final Java.Rvalue rhs = this.parseAssignmentExpression().toRvalueOrPE();
            return new Java.Assignment(location, lhs, operator, rhs);
        }
View Full Code Here

     * </pre>
     */
    public Java.Atom parseConditionalExpression() throws CompileException, IOException  {
        Java.Atom a = this.parseConditionalOrExpression();
        if (!this.peekOperator("?")) return a;
        Location location = this.location();
        this.eatToken();

        Java.Rvalue lhs = a.toRvalueOrPE();
        Java.Rvalue mhs = this.parseExpression().toRvalueOrPE();
        this.readOperator(":");
View Full Code Here

     * </pre>
     */
    public Java.Atom parseConditionalOrExpression() throws CompileException, IOException  {
        Java.Atom a = this.parseConditionalAndExpression();
        while (this.peekOperator("||")) {
            Location location = this.location();
            this.eatToken();
            a = new Java.BinaryOperation(
                location,
                a.toRvalueOrPE(),
                "||",
View Full Code Here

     * </pre>
     */
    public Java.Atom parseConditionalAndExpression() throws CompileException, IOException  {
        Java.Atom a = this.parseInclusiveOrExpression();
        while (this.peekOperator("&&")) {
            Location location = this.location();
            this.eatToken();
            a = new Java.BinaryOperation(
                location,
                a.toRvalueOrPE(),
                "&&",
View Full Code Here

     * </pre>
     */
    public Java.Atom parseInclusiveOrExpression() throws CompileException, IOException  {
        Java.Atom a = this.parseExclusiveOrExpression();
        while (this.peekOperator("|")) {
            Location location = this.location();
            this.eatToken();
            a = new Java.BinaryOperation(
                location,
                a.toRvalueOrPE(),
                "|",
View Full Code Here

     * </pre>
     */
    public Java.Atom parseExclusiveOrExpression() throws CompileException, IOException  {
        Java.Atom a = this.parseAndExpression();
        while (this.peekOperator("^")) {
            Location location = this.location();
            this.eatToken();
            a = new Java.BinaryOperation(
                location,
                a.toRvalueOrPE(),
                "^",
View Full Code Here

     * </pre>
     */
    public Java.Atom parseAndExpression() throws CompileException, IOException  {
        Java.Atom a = this.parseEqualityExpression();
        while (this.peekOperator("&")) {
            Location location = this.location();
            this.eatToken();
            a = new Java.BinaryOperation(
                location,
                a.toRvalueOrPE(),
                "&",
View Full Code Here

    public Java.Atom parseRelationalExpression() throws CompileException, IOException  {
        Java.Atom a = this.parseShiftExpression();

        for (;;) {
            if (this.peekKeyword("instanceof")) {
                Location location = this.location();
                this.eatToken();
                a = new Java.Instanceof(
                    location,
                    a.toRvalueOrPE(),
                    this.parseType()
View Full Code Here

            // Literal
            return this.parseLiteral();
        }

        if (this.scanner.peek().isIdentifier()) {
            Location location = this.location();
            String[] qi = this.parseQualifiedIdentifier();
            if (this.peekOperator("(")) {
                // Name Arguments
                return new Java.MethodInvocation(
                    this.location(),                                // location
                    qi.length == 1 ? null : new Java.AmbiguousName( // optionalTarget
                        location,       // location
                        qi,             // identifiers
                        qi.length - 1   // n
                    ),
                    qi[qi.length - 1],                              // methodName
                    this.parseArguments()                           // arguments
                );
            }
            if (
                this.peekOperator("[")
                && this.scanner.peekNextButOne().isOperator("]")
            ) {
                // Name '[]' { '[]' }
                // Name '[]' { '[]' } '.' 'class'
                Java.Type res = new Java.ReferenceType(
                    location, // location
                    qi        // identifiers
                );
                int brackets = this.parseBracketsOpt();
                for (int i = 0; i < brackets; ++i) res = new Java.ArrayType(res);
                if (
                    this.peekOperator(".")
                    && this.scanner.peekNextButOne().isKeyword("class")
                ) {
                    this.eatToken();
                    Location location2 = this.location();
                    this.eatToken();
                    return new Java.ClassLiteral(location2, res);
                } else {
                    return res;
                }
            }
            // Name
            return new Java.AmbiguousName(
                this.location(), // location
                qi               // identifiers
            );
        }

        if (this.peekKeyword("this")) {
            Location location = this.location();
            this.eatToken();
            if (this.peekOperator("(")) {

                // 'this' Arguments
                // Alternate constructor invocation (JLS 8.8.5.1)
                return new Java.AlternateConstructorInvocation(
                    location,             // location
                    this.parseArguments() // arguments
                );
            } else
            {

                // 'this'
                return new Java.ThisReference(location);
            }
        }

        if (this.peekKeyword("super")) {
            this.eatToken();
            if (this.peekOperator("(")) {

                // 'super' Arguments
                // Unqualified superclass constructor invocation (JLS 8.8.5.1)
                return new Java.SuperConstructorInvocation(
                    this.location(),      // location
                    (Java.Rvalue) null,   // optionalQualification
                    this.parseArguments() // arguments
                );
            }
            this.readOperator(".");
            String name = this.readIdentifier();
            if (this.peekOperator("(")) {

                // 'super' '.' Identifier Arguments
                return new Java.SuperclassMethodInvocation(
                    this.location(),      // location
                    name,                 // methodName
                    this.parseArguments() // arguments
                );
            } else {

                // 'super' '.' Identifier
                return new Java.SuperclassFieldAccessExpression(
                    this.location()// location
                    (Java.Type) null, // optionalQualification
                    name              // fieldName
                );
            }
        }

        // 'new'
        if (this.peekKeyword("new")) {
            Location location = this.location();
            this.eatToken();
            Java.Type type = this.parseType();
            if (type instanceof Java.ArrayType) {
                // 'new' ArrayType ArrayInitializer
                return new Java.NewInitializedArray(location, (Java.ArrayType) type, this.parseArrayInitializer());
            }
            if (
                type instanceof Java.ReferenceType
                && this.peekOperator("(")
            ) {
                // 'new' ReferenceType Arguments [ ClassBody ]
                Java.Rvalue[] arguments = this.parseArguments();
                if (this.peekOperator("{")) {
                    // 'new' ReferenceType Arguments ClassBody
                    final Java.AnonymousClassDeclaration anonymousClassDeclaration = new Java.AnonymousClassDeclaration(
                        this.location(), // location
                        type             // baseType
                    );
                    this.parseClassBody(anonymousClassDeclaration);
                    return new Java.NewAnonymousClassInstance(
                        location,                  // location
                        (Java.Rvalue) null,        // optionalQualification
                        anonymousClassDeclaration, // anonymousClassDeclaration
                        arguments                  // arguments
                    );
                } else {
                    // 'new' ReferenceType Arguments
                    return new Java.NewClassInstance(
                        location,           // location
                        (Java.Rvalue) null, // optionalQualification
                        type,               // type
                        arguments           // arguments
                    );
                }
            }
            // 'new' Type DimExprs { '[]' }
            return new Java.NewArray(
                location,               // location
                type,                   // type
                this.parseDimExprs(),   // dimExprs
                this.parseBracketsOpt() // dims
            );
        }

        // BasicType
        if (this.peekKeyword(new String[] { "boolean", "char", "byte", "short", "int", "long", "float", "double", })) {
            Java.Type res = this.parseType();
            int brackets = this.parseBracketsOpt();
            for (int i = 0; i < brackets; ++i) res = new Java.ArrayType(res);
            if (
                this.peekOperator(".")
                && this.scanner.peekNextButOne().isKeyword("class")
            ) {
                // BasicType { '[]' } '.' 'class'
                this.eatToken();
                Location location = this.location();
                this.eatToken();
                return new Java.ClassLiteral(location, res);
            }
            // BasicType { '[]' }
            return res;
        }

        // 'void'
        if (this.peekKeyword("void")) {
            this.eatToken();
            if (
                this.peekOperator(".")
                && this.scanner.peekNextButOne().isKeyword("class")
            ) {
                // 'void' '.' 'class'
                this.eatToken();
                Location location = this.location();
                this.eatToken();
                return new Java.ClassLiteral(location, new Java.BasicType(location, Java.BasicType.VOID));
            }
            this.throwCompileException("\"void\" encountered in wrong context");
        }
View Full Code Here

TOP

Related Classes of org.codehaus.commons.compiler.Location

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.