Source Code Cross Referenced for ClassModifier.java in  » Code-Analyzer » JBlanket » csdl » jblanket » modifier » 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 » JBlanket » csdl.jblanket.modifier 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package csdl.jblanket.modifier;
002:
003:        import csdl.jblanket.JBlanketException;
004:        import csdl.jblanket.methodset.MethodSetManager;
005:        import csdl.jblanket.util.MethodCategories;
006:
007:        import java.io.File;
008:        import java.io.IOException;
009:
010:        import org.apache.bcel.classfile.ClassParser;
011:        import org.apache.bcel.classfile.JavaClass;
012:        import org.apache.bcel.classfile.Method;
013:        import org.apache.bcel.generic.ConstantPoolGen;
014:        import org.apache.bcel.generic.MethodGen;
015:        import org.apache.bcel.generic.ObjectType;
016:        import org.apache.bcel.generic.Type;
017:
018:        /**
019:         * Provides a Modifer for Java byte code in class files.  Methods in a class are modified only
020:         * once.  However, even though a class was previously modified, it still needs to be processed by
021:         * this class so that all of its methods can be recorded in the set of total methods.
022:         * 
023:         * @author Joy M. Agustin
024:         * @version $Id: ClassModifier.java,v 1.4 2005/02/19 05:55:19 timshadel Exp $
025:         */
026:        class ClassModifier {
027:
028:            /** Describes if JBlanket should execute in verbose mode */
029:            private boolean verbose;
030:            /** Grammar for names of test classes */
031:            private String testGrammar;
032:
033:            /** Describes if one-line methods should be excluded from the coverage measurement */
034:            private boolean excludeOneLineMethods;
035:            /** Describes if constructors should be excluded from the coverage measurement */
036:            private boolean excludeConstructors;
037:            /** Describes if a file should be used to exclude methods from the coverage measurement */
038:            private boolean excludeIndividualMethods;
039:
040:            /** Counts the methods found in the system */
041:            private MethodCounter counter;
042:
043:            /** File to modify */
044:            private File classFile;
045:            /** JavaClass for classFile */
046:            private JavaClass clazz;
047:
048:            /**
049:             * Constructs a new ClassModifier object.
050:             * @param verbose describes if JBlanke should execute in verbose mode.
051:             * @param testGrammar the grammar describing test class names.
052:             * @param excludeOneLineMethods describes exclusion of one-line methods.
053:             * @param excludeConstructors describes exclusion of constructors.
054:             * @param excludeIndividualMethods TODO
055:             * @param counter the MethodCounter collecting all method type signatures.
056:             * @param classFile the fully qualified path to a class file to process.
057:             * 
058:             * @throws JBlanketException if unable to get byte code from <code>classFile</code>.
059:             */
060:            public ClassModifier(boolean verbose, String testGrammar,
061:                    boolean excludeOneLineMethods, boolean excludeConstructors,
062:                    boolean excludeIndividualMethods, MethodCounter counter,
063:                    File classFile) throws JBlanketException {
064:
065:                this .verbose = verbose;
066:                this .testGrammar = testGrammar;
067:
068:                this .excludeOneLineMethods = excludeOneLineMethods;
069:                this .excludeConstructors = excludeConstructors;
070:                this .excludeIndividualMethods = excludeIndividualMethods;
071:
072:                this .counter = counter;
073:
074:                this .classFile = classFile;
075:
076:                // retrieve class byte code -- throws IOException
077:                try {
078:                    this .clazz = (new ClassParser(this .classFile
079:                            .getAbsolutePath())).parse();
080:                } catch (IOException e) {
081:                    throw new JBlanketException("Unable to parse "
082:                            + this .classFile.getAbsolutePath(), e);
083:                }
084:            }
085:
086:            /**
087:             * Constructs a new ClassModifier object.
088:             * 
089:             * @param verbose describes if JBlanke should execute in verbose mode.
090:             * @param counter the MethodCounter collecting all method type signatures.
091:             * @param classFile the fully qualified path to a class file to process.
092:             * @throws JBlanketException if unable to get byte code from <code>classFile</code>.
093:             */
094:            public ClassModifier(boolean verbose, MethodCounter counter,
095:                    File classFile) throws JBlanketException {
096:                this (verbose, null, false, false, false, counter, classFile);
097:            }
098:
099:            /**
100:             * Modifies byte code in the class represented by this ClassModifier.
101:             * 
102:             * @throws JBlanketException if unable to store modified byte code.
103:             */
104:            public void modifyMethods() throws JBlanketException {
105:
106:                Method[] methods = clazz.getMethods();
107:
108:                // count all methods in the class
109:                this .counter.findAllMethods(clazz, this .excludeConstructors);
110:
111:                // modify methods if they weren't previously modified
112:                //    if (!isModified()) {
113:
114:                // process methods
115:                ConstantPoolGen pool = new ConstantPoolGen(clazz
116:                        .getConstantPool());
117:                for (int j = 0; j < methods.length; j++) {
118:                    MethodGen method = new MethodGen(methods[j], clazz
119:                            .getClassName(), pool);
120:
121:                    // TODO: Add "excluded individual methods"
122:                    MethodModifier methodModifier = new MethodModifier(
123:                            this .verbose, this .testGrammar,
124:                            this .excludeOneLineMethods,
125:                            this .excludeIndividualMethods,
126:                            this .excludeConstructors, method);
127:                    methods[j] = methodModifier.processMethod(pool,
128:                            isModified());
129:                }
130:                clazz.setConstantPool(pool.getFinalConstantPool());
131:                //}
132:
133:                // dump the modified class back into its current directory
134:                try {
135:                    clazz.dump(this .classFile.getAbsoluteFile());
136:                } catch (IOException e) {
137:                    throw new JBlanketException("Unable to save modified file "
138:                            + this .classFile.getAbsolutePath());
139:                }
140:            }
141:
142:            /**
143:             * Checks if a class has already been modified.
144:             * <p>
145:             * If <code>clazz</code> references the <code>MethodCollector.storeMethodTypeSignature</code>
146:             * method, then all methods in the class were previously modified.
147:             * 
148:             * NOTE: method is package private for testing, else should be private.
149:             *
150:             * @return true if the class was previously modified or cannot be modified, false otherwise.
151:             */
152:            boolean isModified() {
153:
154:                ConstantPoolGen pool = new ConstantPoolGen(clazz
155:                        .getConstantPool());
156:
157:                // will not modify native classes; abstract classes can have non-abstract methods.
158:                // catch the abstract methods when modifying them.
159:                if (clazz.isNative()) {
160:                    return true;
161:                }
162:
163:                Type[] parameters = new Type[] { Type.STRING, Type.STRING,
164:                        new ObjectType("java.util.ArrayList"), Type.STRING };
165:                String methodSignature = Type.getMethodSignature(Type.VOID,
166:                        parameters);
167:
168:                int result = pool.lookupMethodref(
169:                        "csdl.jblanket.modifier.MethodCollector",
170:                        "storeMethodTypeSignature", methodSignature);
171:                return result != -1;
172:            }
173:
174:            /**
175:             * Records the excluded methods in the class represented by this ClassModifier.
176:             */
177:            public void excludeMethods() {
178:
179:                Method[] methods = clazz.getMethods();
180:
181:                // process methods
182:                ConstantPoolGen pool = new ConstantPoolGen(clazz
183:                        .getConstantPool());
184:                for (int j = 0; j < methods.length; j++) {
185:                    MethodGen method = new MethodGen(methods[j], clazz
186:                            .getClassName(), pool);
187:                    MethodModifier methodModifier = new MethodModifier(
188:                            this .verbose, this .testGrammar,
189:                            this .excludeOneLineMethods, false,
190:                            this .excludeConstructors, method);
191:                    methodModifier.excludeMethod(MethodSetManager.getInstance()
192:                            .getMethodSet(
193:                                    MethodCategories.getInstance().getFileName(
194:                                            "excludedFile")));
195:                }
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.