Logo Search packages:      
Sourcecode: janino version File versions  Download package

Java.BlockStatement org::codehaus::janino::Parser::parseBlockStatement (  )  throws ParseException, Scanner.ScanException, IOException [inline]

   BlockStatement := { Identifier ':' } (
     ( Modifiers Type | ModifiersOpt BasicType ) LocalVariableDeclarators ';' |
     'class' ... |
     Statement |
     'final' Type LocalVariableDeclarators ';' |
     Expression ';' |
     Expression LocalVariableDeclarators ';'   (1)
   )
 

(1) "Expression" must pose a type, and has optional trailing brackets.

Definition at line 923 of file Parser.java.

References org::codehaus::janino::Scanner::doc(), parseClassDeclarationRest(), parseExpression(), parseLocalVariableDeclarators(), parseStatement(), parseType(), org::codehaus::janino::Scanner::peek(), org::codehaus::janino::Scanner::peekNextButOne(), and warning().

Referenced by org::codehaus::janino::ScriptEvaluator::makeBlock(), and parseBlockStatements().

                                                                                                               {

        // Statement?
        if (
            (
                this.scanner.peek().isIdentifier() &&
                this.scanner.peekNextButOne().isOperator(":")
            ) ||
            this.peekKeyword(new String[] {
                "if", "for", "while", "do", "try", "switch", "synchronized",
                "return", "throw", "break", "continue"
            }) ||
            this.peekOperator(new String[] { "{", ";" })
        ) return this.parseStatement();

        // Local class declaration?
        if (this.peekKeyword("class")) {
            // JAVADOC[TM] ignores doc comments for local classes, but we
            // don't...
            String optionalDocComment = this.scanner.doc();
            if (optionalDocComment == null) this.warning("LCDCM", "Local class doc comment missing", this.location());

            this.eatToken();
            final Java.LocalClassDeclaration lcd = (Java.LocalClassDeclaration) this.parseClassDeclarationRest(
                optionalDocComment,                // optionalDocComment
                (short) (Mod.FINAL | Mod.PRIVATE), // modifiers
                ClassDeclarationContext.BLOCK      // context
            );
            return new Java.LocalClassDeclarationStatement(lcd);
        }

        // 'final' Type LocalVariableDeclarators ';'
        if (this.peekKeyword("final")) {
            Location location = this.location();
            this.eatToken();
            Java.Type variableType = this.parseType();
            Java.LocalVariableDeclarationStatement lvds = new Java.LocalVariableDeclarationStatement(
                location,                            // location
                Mod.FINAL,                           // modifiers
                variableType,                        // type
                this.parseLocalVariableDeclarators() // variableDeclarators
            );
            this.readOperator(";");
            return lvds;
        }

        // It's either a non-final local variable declaration or an expression statement. We can
        // only tell after parsing an expression.
        Java.Atom a = this.parseExpression();

        // Expression ';'
        if (this.peekOperator(";")) {
            this.eatToken();
            return new Java.ExpressionStatement(a.toRvalueOrPE());
        }

        // Expression LocalVariableDeclarators ';'
        Java.Type variableType = a.toTypeOrPE();
        Java.LocalVariableDeclarationStatement lvds = new Java.LocalVariableDeclarationStatement(
            a.getLocation(),                     // location
            Mod.NONE,                            // modifiers
            variableType,                        // type
            this.parseLocalVariableDeclarators() // variableDeclarators
        );
        this.readOperator(";");
        return lvds;
    }


Generated by  Doxygen 1.6.0   Back to index