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

Java.LocalVariable org::codehaus::janino::UnitCompiler::findLocalVariable ( Java.BlockStatement  blockStatement,
String  name 
) throws CompileException [inline, private]

Find a local variable declared by the given blockStatement or any enclosing scope up to the Java.FunctionDeclarator.

Definition at line 5389 of file UnitCompiler.java.

                              {
        for (Java.Scope s = blockStatement; !(s instanceof Java.CompilationUnit);) {
            Java.Scope es = s.getEnclosingScope();
            {
                if (s instanceof Java.ForStatement) {
                    Java.BlockStatement optionalForInit = ((Java.ForStatement) s).optionalInit;
                    if (optionalForInit instanceof Java.LocalVariableDeclarationStatement) {
                        Java.LocalVariable lv = this.findLocalVariable((Java.LocalVariableDeclarationStatement) optionalForInit, name);
                        if (lv != null) return lv;
                    }
                }
                if (es instanceof Java.Block) {
                    Java.Block b = (Java.Block) es;
                    for (Iterator it = b.statements.iterator();;) {
                        Java.BlockStatement bs2 = (Java.BlockStatement) it.next();
                        if (bs2 instanceof Java.LocalVariableDeclarationStatement) {
                            Java.LocalVariable lv = this.findLocalVariable((Java.LocalVariableDeclarationStatement) bs2, name);
                            if (lv != null) return lv;
                        }
                        if (bs2 == s) break;
                    }
                }
                if (es instanceof Java.SwitchStatement) {
                    Java.SwitchStatement ss = (Java.SwitchStatement) es;
                    SBSGS: for (Iterator it2 = ss.sbsgs.iterator();;) {
                        Java.SwitchStatement.SwitchBlockStatementGroup sbgs = (Java.SwitchStatement.SwitchBlockStatementGroup) it2.next();
                        for (Iterator it = sbgs.blockStatements.iterator(); it.hasNext();) {
                            Java.BlockStatement bs2 = (Java.BlockStatement) it.next();
                            if (bs2 instanceof Java.LocalVariableDeclarationStatement) {
                                Java.LocalVariable lv = this.findLocalVariable((Java.LocalVariableDeclarationStatement) bs2, name);
                                if (lv != null) return lv;
                            }
                            if (bs2 == s) break SBSGS;
                        }
                    }
                }
                if (s instanceof Java.FunctionDeclarator) {
                    Java.FunctionDeclarator fd = (Java.FunctionDeclarator) s;
                    Java.FunctionDeclarator.FormalParameter[] fps = fd.formalParameters;
                    for (int i = 0; i < fps.length; ++i) {
                        if (fps[i].name.equals(name)) return this.getLocalVariable(fps[i]);
                    }
                    return null;
                }
                if (s instanceof Java.CatchClause) {
                    Java.CatchClause cc = (Java.CatchClause) s;
                    if (cc.caughtException.name.equals(name)) return this.getLocalVariable(cc.caughtException);
                }
            }
            s = es;
        }
        return null;
    }


Generated by  Doxygen 1.6.0   Back to index