KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > flow > CreateForInitializer


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

19
20 package jode.flow;
21 import jode.GlobalOptions;
22 import jode.expr.*;
23
24 public class CreateForInitializer {
25
26     /**
27      * This combines an variable initializer into a for statement
28      * @param forBlock the for block
29      * @param last the lastModified of the flow block.
30      */

31     public static boolean transform(LoopBlock forBlock, StructuredBlock last) {
32
33         if (!(last.outer instanceof SequentialBlock))
34             return false;
35
36         SequentialBlock sequBlock = (SequentialBlock) last.outer;
37
38         if (!(sequBlock.subBlocks[0] instanceof InstructionBlock))
39             return false;
40
41         InstructionBlock init = (InstructionBlock) sequBlock.subBlocks[0];
42             
43         if (!init.getInstruction().isVoid()
44         || !(init.getInstruction() instanceof CombineableOperator)
45             || !forBlock.conditionMatches((CombineableOperator)
46                       init.getInstruction()))
47             return false;
48
49         if (GlobalOptions.verboseLevel > 0)
50             GlobalOptions.err.print('f');
51
52         forBlock.setInit((InstructionBlock) sequBlock.subBlocks[0]);
53         return true;
54     }
55 }
56
Popular Tags