KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > flow > EmptyBlock


1 /* EmptyBlock 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: EmptyBlock.java,v 3.6.4.2 2002/05/28 17:34:09 hoenicke Exp $
18  */

19
20 package jode.flow;
21 import jode.decompiler.TabbedPrintWriter;
22
23 /**
24  * This is the structured block for an empty block.
25  */

26 public class EmptyBlock extends StructuredBlock {
27     public EmptyBlock() {
28     }
29
30     public EmptyBlock(Jump jump) {
31         setJump(jump);
32     }
33
34     /**
35      * Tells if this block is empty and only changes control flow.
36      */

37     public boolean isEmpty() {
38         return true;
39     }
40
41     /**
42      * Appends a block to this block.
43      * @return the new combined block.
44      */

45     public StructuredBlock appendBlock(StructuredBlock block) {
46     if (outer instanceof ConditionalBlock) {
47         IfThenElseBlock ifBlock =
48         new IfThenElseBlock(((ConditionalBlock)outer).
49                     getInstruction());
50         ifBlock.moveDefinitions(outer, this);
51         ifBlock.replace(outer);
52         ifBlock.moveJump(outer.jump);
53         ifBlock.setThenBlock(this);
54     }
55     block.replace(this);
56     return block;
57     }
58
59     /**
60      * Prepends a block to this block.
61      * @return the new combined block.
62      */

63     public StructuredBlock prependBlock(StructuredBlock block) {
64     /* For empty blocks: append == prepend modulo jump */
65     block = appendBlock(block);
66     block.moveJump(this.jump);
67     return block;
68     }
69
70     public void dumpInstruction(TabbedPrintWriter writer)
71     throws java.io.IOException JavaDoc
72     {
73     /* Only print the comment if jump null, since otherwise the block
74      * isn't completely empty ;-)
75      */

76         if (jump == null)
77         writer.println("/* empty */");
78     }
79 }
80
Popular Tags