Source Code Cross Referenced for LocalVariablesSorterTest2.java in  » Byte-Code » asm » org » objectweb » asm » commons » 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 » Byte Code » asm » org.objectweb.asm.commons 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***
002:         * ASM tests
003:         * Copyright (c) 2002-2005 France Telecom
004:         * All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         * 1. Redistributions of source code must retain the above copyright
010:         *    notice, this list of conditions and the following disclaimer.
011:         * 2. Redistributions in binary form must reproduce the above copyright
012:         *    notice, this list of conditions and the following disclaimer in the
013:         *    documentation and/or other materials provided with the distribution.
014:         * 3. Neither the name of the copyright holders nor the names of its
015:         *    contributors may be used to endorse or promote products derived from
016:         *    this software without specific prior written permission.
017:         *
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
028:         * THE POSSIBILITY OF SUCH DAMAGE.
029:         */package org.objectweb.asm.commons;
030:
031:        import java.io.InputStream;
032:        import java.io.PrintWriter;
033:        import java.io.StringWriter;
034:        import java.lang.instrument.ClassFileTransformer;
035:        import java.lang.instrument.IllegalClassFormatException;
036:        import java.lang.instrument.Instrumentation;
037:        import java.security.ProtectionDomain;
038:
039:        import junit.framework.TestSuite;
040:
041:        import org.objectweb.asm.AbstractTest;
042:        import org.objectweb.asm.ClassAdapter;
043:        import org.objectweb.asm.ClassReader;
044:        import org.objectweb.asm.ClassVisitor;
045:        import org.objectweb.asm.ClassWriter;
046:        import org.objectweb.asm.MethodVisitor;
047:        import org.objectweb.asm.util.TraceClassVisitor;
048:
049:        /**
050:         * LocalVariablesSorter tests.
051:         * 
052:         * @author Eric Bruneton
053:         */
054:        public class LocalVariablesSorterTest2 extends AbstractTest {
055:
056:            public static void premain(final String agentArgs,
057:                    final Instrumentation inst) {
058:                inst.addTransformer(new ClassFileTransformer() {
059:                    public byte[] transform(final ClassLoader loader,
060:                            final String className,
061:                            final Class classBeingRedefined,
062:                            final ProtectionDomain domain,
063:                            final byte[] classFileBuffer)
064:                            throws IllegalClassFormatException {
065:                        String n = className.replace('/', '.');
066:                        if (agentArgs.length() == 0
067:                                || n.indexOf(agentArgs) != -1) {
068:                            return transformClass(classFileBuffer);
069:                        } else {
070:                            return null;
071:                        }
072:                    }
073:                });
074:            }
075:
076:            private static byte[] transformClass(final byte[] clazz) {
077:                ClassReader cr = new ClassReader(clazz);
078:                ClassWriter cw = new ClassWriter(0);
079:                cr.accept(new ClassAdapter(cw) {
080:
081:                    public MethodVisitor visitMethod(final int access,
082:                            final String name, final String desc,
083:                            final String signature, final String[] exceptions) {
084:                        return new LocalVariablesSorter(access, desc, cv
085:                                .visitMethod(access, name, desc, signature,
086:                                        exceptions));
087:                    }
088:
089:                }, ClassReader.EXPAND_FRAMES);
090:                return cw.toByteArray();
091:            }
092:
093:            public static TestSuite suite() throws Exception {
094:                return new LocalVariablesSorterTest2().getSuite();
095:            }
096:
097:            public void test() throws Exception {
098:                try {
099:                    Class.forName(n, true, getClass().getClassLoader());
100:                } catch (NoClassDefFoundError ncdfe) {
101:                    // ignored
102:                } catch (UnsatisfiedLinkError ule) {
103:                    // ignored
104:                } catch (ClassFormatError cfe) {
105:                    fail(cfe.getMessage());
106:                } catch (VerifyError ve) {
107:                    String s = n.replace('.', '/') + ".class";
108:                    InputStream is = getClass().getClassLoader()
109:                            .getResourceAsStream(s);
110:                    ClassReader cr = new ClassReader(is);
111:                    byte[] b = transformClass(cr.b);
112:                    StringWriter sw1 = new StringWriter();
113:                    StringWriter sw2 = new StringWriter();
114:                    sw2.write(ve.toString() + "\n");
115:                    ClassVisitor cv1 = new TraceClassVisitor(new PrintWriter(
116:                            sw1));
117:                    ClassVisitor cv2 = new TraceClassVisitor(new PrintWriter(
118:                            sw2));
119:                    cr.accept(cv1, 0);
120:                    new ClassReader(b).accept(cv2, 0);
121:                    String s1 = sw1.toString();
122:                    String s2 = sw2.toString();
123:                    assertEquals("different data", s1, s2);
124:                }
125:            }
126:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.