KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > BriefUnitPrinter


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003, 2004 Ondrej Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 package soot;
21 import soot.jimple.*;
22
23 /**
24 * UnitPrinter implementation for normal (full) Jimple, Grimp, and Baf
25 */

26 public class BriefUnitPrinter extends LabeledUnitPrinter {
27     public BriefUnitPrinter( Body body ) {
28         super(body);
29     }
30
31     private boolean baf;
32     public void startUnit( Unit u ) {
33         super.startUnit(u);
34         if( u instanceof Stmt ) {
35             baf = false;
36         } else {
37             baf = true;
38         }
39     }
40
41     public void methodRef( SootMethodRef m ) {
42         handleIndent();
43         if( !baf && m.resolve().isStatic() ){
44             output.append( m.declaringClass().getName() );
45             literal(".");
46         }
47         output.append( m.name() );
48     }
49     public void fieldRef( SootFieldRef f ) {
50         handleIndent();
51         if( baf || f.resolve().isStatic() ){
52             output.append( f.declaringClass().getName() );
53             literal(".");
54         }
55         output.append(f.name());
56     }
57     public void identityRef( IdentityRef r ) {
58         handleIndent();
59         if( r instanceof ThisRef ) {
60             literal("@this");
61         } else if( r instanceof ParameterRef ) {
62             ParameterRef pr = (ParameterRef) r;
63             literal("@parameter"+pr.getIndex());
64         } else if( r instanceof CaughtExceptionRef ) {
65             literal("@caughtexception");
66         } else throw new RuntimeException JavaDoc();
67     }
68
69     private boolean eatSpace = false;
70     public void literal( String JavaDoc s ) {
71         handleIndent();
72         if( eatSpace && s.equals(" ") ) {
73             eatSpace = false;
74             return;
75         }
76         eatSpace = false;
77         if( !baf ) {
78             if( false
79             || s.equals( Jimple.STATICINVOKE )
80             || s.equals( Jimple.VIRTUALINVOKE )
81             || s.equals( Jimple.INTERFACEINVOKE )
82               ) {
83                 eatSpace = true;
84                 return;
85             }
86         }
87         output.append(s);
88     }
89
90     public void type( Type t ) {
91         handleIndent();
92         output.append( t.toString() );
93     }
94 }
95
96
Popular Tags