KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > flow > FinallyBlock


1 /* FinallyBlock Copyright (C) 1998-2002 Jochen Hoenicke.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; see the file COPYING.LESSER. If not, write to
15  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * $Id: FinallyBlock.java,v 3.6.2.1 2002/05/28 17:34:09 hoenicke Exp $
18  */

19
20 package jode.flow;
21
22 /**
23  *
24  * @author Jochen Hoenicke
25  */

26 public class FinallyBlock extends StructuredBlock {
27     /**
28      * The catch block.
29      */

30     StructuredBlock subBlock;
31
32     public FinallyBlock() {
33     }
34
35     /**
36      * Sets the catch block.
37      * @param subBlock the catch block.
38      */

39     public void setCatchBlock(StructuredBlock subBlock) {
40         this.subBlock = subBlock;
41         subBlock.outer = this;
42         subBlock.setFlowBlock(flowBlock);
43     }
44
45     /* The implementation of getNext[Flow]Block is the standard
46      * implementation */

47
48     /**
49      * Replaces the given sub block with a new block.
50      * @param oldBlock the old sub block.
51      * @param newBlock the new sub block.
52      * @return false, if oldBlock wasn't a direct sub block.
53      */

54     public boolean replaceSubBlock(StructuredBlock oldBlock,
55                                    StructuredBlock newBlock) {
56         if (subBlock == oldBlock)
57             subBlock = newBlock;
58         else
59             return false;
60         return true;
61     }
62
63     /**
64      * Returns all sub block of this structured block.
65      */

66     public StructuredBlock[] getSubBlocks() {
67         return new StructuredBlock[] { subBlock };
68     }
69
70     /**
71      * A finally block starts with empty stack. It must return with empty
72      * stack too, but that need not to be checked. If the JSR's aren't
73      * correctly determined this may even not be true.
74      *
75      * @param stack the stack before the instruction is called
76      * @return stack the stack afterwards. */

77     public VariableStack mapStackToLocal(VariableStack stack) {
78     super.mapStackToLocal(stack);
79     return null;
80     }
81
82     /**
83      * Returns the block where the control will normally flow to, when
84      * the given sub block is finished (<em>not</em> ignoring the jump
85      * after this block). FinallyBlock have a special behaviour, since
86      * the finally block has no default successor at all (it is more a
87      * subroutine) that will be called by try or any exception.
88      *
89      * @return null, if the control flows to another FlowBlock.
90      */

91     public StructuredBlock getNextBlock(StructuredBlock subBlock) {
92         return null;
93     }
94
95     public FlowBlock getNextFlowBlock(StructuredBlock subBlock) {
96         return null;
97     }
98
99     public void dumpInstruction(jode.decompiler.TabbedPrintWriter writer)
100         throws java.io.IOException JavaDoc {
101     writer.closeBraceContinue();
102         writer.print("finally");
103     writer.openBrace();
104         writer.tab();
105         subBlock.dumpSource(writer);
106         writer.untab();
107     }
108 }
109
Popular Tags