Source Code Cross Referenced for AssertClassMethodSource.java in  » Code-Analyzer » soot » soot » javaToJimple » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » soot » soot.javaToJimple 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Soot - a J*va Optimization Framework
002:         * Copyright (C) 2004 Jennifer Lhotak
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the
016:         * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017:         * Boston, MA 02111-1307, USA.
018:         */
019:
020:        package soot.javaToJimple;
021:
022:        import java.util.*;
023:
024:        public class AssertClassMethodSource implements  soot.MethodSource {
025:
026:            public soot.Body getBody(soot.SootMethod sootMethod,
027:                    String phaseName) {
028:
029:                soot.Body classBody = soot.jimple.Jimple.v()
030:                        .newBody(sootMethod);
031:
032:                // static invoke of forName
033:                soot.jimple.ParameterRef paramRef = soot.jimple.Jimple.v()
034:                        .newParameterRef(soot.RefType.v("java.lang.String"), 0);
035:
036:                soot.Local paramLocal = soot.jimple.Jimple.v().newLocal("$r0",
037:                        soot.RefType.v("java.lang.String"));
038:                classBody.getLocals().add(paramLocal);
039:                soot.jimple.Stmt stmt = soot.jimple.Jimple.v().newIdentityStmt(
040:                        paramLocal, paramRef);
041:                classBody.getUnits().add(stmt);
042:
043:                ArrayList paramTypes = new ArrayList();
044:                paramTypes.add(soot.RefType.v("java.lang.String"));
045:                soot.SootMethodRef methodToInvoke = soot.Scene.v()
046:                        .makeMethodRef(
047:                                soot.Scene.v().getSootClass("java.lang.Class"),
048:                                "forName", paramTypes,
049:                                soot.RefType.v("java.lang.Class"), true);
050:                soot.Local invokeLocal = soot.jimple.Jimple.v().newLocal("$r1",
051:                        soot.RefType.v("java.lang.Class"));
052:                classBody.getLocals().add(invokeLocal);
053:                ArrayList params = new ArrayList();
054:                params.add(paramLocal);
055:                soot.jimple.Expr invokeExpr = soot.jimple.Jimple.v()
056:                        .newStaticInvokeExpr(methodToInvoke, params);
057:                soot.jimple.Stmt assign = soot.jimple.Jimple.v().newAssignStmt(
058:                        invokeLocal, invokeExpr);
059:                classBody.getUnits().add(assign);
060:
061:                // return
062:                soot.jimple.Stmt retStmt = soot.jimple.Jimple.v()
063:                        .newReturnStmt(invokeLocal);
064:                classBody.getUnits().add(retStmt);
065:
066:                // catch
067:                soot.Local catchRefLocal = soot.jimple.Jimple.v().newLocal(
068:                        "$r2",
069:                        soot.RefType.v("java.lang.ClassNotFoundException"));
070:                classBody.getLocals().add(catchRefLocal);
071:                soot.jimple.CaughtExceptionRef caughtRef = soot.jimple.Jimple
072:                        .v().newCaughtExceptionRef();
073:                soot.jimple.Stmt caughtIdentity = soot.jimple.Jimple.v()
074:                        .newIdentityStmt(catchRefLocal, caughtRef);
075:                classBody.getUnits().add(caughtIdentity);
076:
077:                // new no class def found error
078:                soot.Local noClassDefLocal = soot.jimple.Jimple.v()
079:                        .newLocal(
080:                                "$r3",
081:                                soot.RefType
082:                                        .v("java.lang.NoClassDefFoundError"));
083:                classBody.getLocals().add(noClassDefLocal);
084:                soot.jimple.Expr newExpr = soot.jimple.Jimple.v().newNewExpr(
085:                        soot.RefType.v("java.lang.NoClassDefFoundError"));
086:                soot.jimple.Stmt noClassDefAssign = soot.jimple.Jimple.v()
087:                        .newAssignStmt(noClassDefLocal, newExpr);
088:                classBody.getUnits().add(noClassDefAssign);
089:
090:                // no class def found invoke
091:                paramTypes = new ArrayList();
092:                soot.SootMethodRef initMethToInvoke = soot.Scene.v()
093:                        .makeMethodRef(
094:                                soot.Scene.v().getSootClass(
095:                                        "java.lang.NoClassDefFoundError"),
096:                                "<init>", paramTypes, soot.VoidType.v(), false);
097:                params = new ArrayList();
098:                soot.jimple.Expr initInvoke = soot.jimple.Jimple.v()
099:                        .newSpecialInvokeExpr(noClassDefLocal,
100:                                initMethToInvoke, params);
101:                soot.jimple.Stmt initStmt = soot.jimple.Jimple.v()
102:                        .newInvokeStmt(initInvoke);
103:                classBody.getUnits().add(initStmt);
104:
105:                // get exception message
106:                soot.Local throwLocal = soot.jimple.Jimple.v().newLocal("$r4",
107:                        soot.RefType.v("java.lang.Throwable"));
108:                classBody.getLocals().add(throwLocal);
109:                paramTypes = new ArrayList();
110:                paramTypes.add(soot.RefType.v("java.lang.Throwable"));
111:                params = new ArrayList();
112:                params.add(catchRefLocal);
113:                soot.SootMethodRef messageMethToInvoke = soot.Scene.v()
114:                        .makeMethodRef(
115:                                soot.Scene.v().getSootClass(
116:                                        "java.lang.Throwable"), "initCause",
117:                                paramTypes,
118:                                soot.RefType.v("java.lang.Throwable"), false);
119:
120:                soot.jimple.Expr messageInvoke = soot.jimple.Jimple.v()
121:                        .newVirtualInvokeExpr(noClassDefLocal,
122:                                messageMethToInvoke, params);
123:                soot.jimple.Stmt messageAssign = soot.jimple.Jimple.v()
124:                        .newAssignStmt(throwLocal, messageInvoke);
125:                classBody.getUnits().add(messageAssign);
126:
127:                // throw            
128:                soot.jimple.Stmt throwStmt = soot.jimple.Jimple.v()
129:                        .newThrowStmt(throwLocal);
130:                throwStmt.addTag(new soot.tagkit.ThrowCreatedByCompilerTag());
131:                classBody.getUnits().add(throwStmt);
132:
133:                // trap
134:                soot.Trap trap = soot.jimple.Jimple.v().newTrap(
135:                        soot.Scene.v().getSootClass(
136:                                "java.lang.ClassNotFoundException"), assign,
137:                        retStmt, caughtIdentity);
138:                classBody.getTraps().add(trap);
139:
140:                return classBody;
141:
142:            }
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.