KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > dava > Dava


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

20
21 package soot.dava;
22
23
24 import java.io.BufferedWriter JavaDoc;
25 import java.io.FileNotFoundException JavaDoc;
26 import java.io.FileOutputStream JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.io.OutputStreamWriter JavaDoc;
29 import java.io.PrintStream JavaDoc;
30 import java.io.UnsupportedEncodingException JavaDoc;
31 import java.io.Writer JavaDoc;
32
33 import soot.Body;
34 import soot.CompilationDeathException;
35 import soot.G;
36 import soot.Local;
37 import soot.Singletons;
38 import soot.SootMethod;
39 import soot.Type;
40 import soot.jimple.Jimple;
41 import soot.util.IterableSet;
42
43
44
45 public class Dava
46 {
47     public Dava( Singletons.Global g ) {}
48     public static Dava v() { return G.v().soot_dava_Dava(); }
49     private static final String JavaDoc LOG_TO_FILE = null;
50     private static final PrintStream JavaDoc LOG_TO_SCREEN = null;
51
52     private Writer JavaDoc iOut = null;
53     private IterableSet currentPackageContext = null;
54     private String JavaDoc currentPackage;
55     
56     public void set_CurrentPackage( String JavaDoc cp)
57     {
58     currentPackage = cp;
59     }
60
61     public String JavaDoc get_CurrentPackage()
62     {
63     return currentPackage;
64     }
65
66     public void set_CurrentPackageContext( IterableSet cpc)
67     {
68     currentPackageContext = cpc;
69     }
70
71     public IterableSet get_CurrentPackageContext()
72     {
73     return currentPackageContext;
74     }
75
76     public DavaBody newBody(SootMethod m)
77     {
78         return new DavaBody( m);
79     }
80
81     /** Returns a DavaBody constructed from the given body b. */
82     public DavaBody newBody(Body b)
83     {
84         return new DavaBody(b);
85     }
86     
87     public Local newLocal(String JavaDoc name, Type t)
88     {
89         return Jimple.v().newLocal(name, t);
90     }
91
92     public void log( String JavaDoc s)
93     {
94     if (LOG_TO_SCREEN != null) {
95         LOG_TO_SCREEN.println( s);
96         LOG_TO_SCREEN.flush();
97     }
98
99     if (LOG_TO_FILE != null) {
100         if (iOut == null)
101         try {
102             iOut = new BufferedWriter JavaDoc( new OutputStreamWriter JavaDoc( new FileOutputStream JavaDoc( LOG_TO_FILE), "US-ASCII"));
103         }
104         catch (FileNotFoundException JavaDoc fnfe) {
105             G.v().out.println( "Unable to open " + LOG_TO_FILE);
106             fnfe.printStackTrace();
107                     throw new CompilationDeathException(CompilationDeathException.COMPILATION_ABORTED);
108         }
109         catch (UnsupportedEncodingException JavaDoc uee) {
110             G.v().out.println( "This system doesn't support US-ASCII encoding!!");
111             uee.printStackTrace();
112                     throw new CompilationDeathException(CompilationDeathException.COMPILATION_ABORTED);
113         }
114
115         try {
116         iOut.write( s);
117         iOut.write( "\n");
118         iOut.flush();
119         }
120         catch (IOException JavaDoc ioe) {
121         G.v().out.println( "Unable to write to " + LOG_TO_FILE);
122         ioe.printStackTrace();
123                 throw new CompilationDeathException(CompilationDeathException.COMPILATION_ABORTED);
124         }
125     }
126     }
127 }
128
129
130
131
132
133
134
Popular Tags