KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > nativequery > bloat > BloatUtil


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.nativequery.bloat;
22
23 import java.util.*;
24
25 import EDU.purdue.cs.bloat.cfg.*;
26 import EDU.purdue.cs.bloat.context.*;
27 import EDU.purdue.cs.bloat.editor.*;
28 import EDU.purdue.cs.bloat.file.*;
29 import EDU.purdue.cs.bloat.reflect.*;
30
31 public class BloatUtil {
32     private ClassFileLoader loader;
33     private CachingBloatContext context;
34     
35     public BloatUtil(ClassFileLoader loader) {
36         this.loader=loader;
37         context=new CachingBloatContext(loader,new LinkedList(),false);
38     }
39     
40     public FlowGraph flowGraph(String JavaDoc className, String JavaDoc methodName) throws ClassNotFoundException JavaDoc {
41         ClassEditor classEdit = classEditor(className);
42         return flowGraph(classEdit, methodName);
43     }
44
45     // FIXME handle overloaded
46
public FlowGraph flowGraph(ClassEditor classEdit, String JavaDoc methodName) throws ClassNotFoundException JavaDoc {
47         MethodInfo[] methods = classEdit.methods();
48         for (int methodIdx = 0; methodIdx < methods.length; methodIdx++) {
49             MethodInfo methodInfo=methods[methodIdx];
50             MethodEditor methodEdit = new MethodEditor(classEdit, methodInfo);
51             if (methodEdit.name().equals(methodName)) {
52                 // methodEdit.print(System.out);
53
return new FlowGraph(methodEdit);
54             }
55         }
56         Type superType = classEdit.superclass();
57         if(superType!=null) {
58             return flowGraph(normalizedClassName(superType),methodName);
59         }
60         return null;
61     }
62
63     public ClassEditor classEditor(String JavaDoc className) throws ClassNotFoundException JavaDoc {
64         return new ClassEditor(context, loader.loadClass(className));
65     }
66
67     public String JavaDoc normalizedClassName(Type type) {
68         return type.className().replace('/', '.');
69     }
70 }
71
Popular Tags