Source Code Cross Referenced for ReferenceVerifyingVisitor.java in  » Development » Retrotranslator » net » sf » retrotranslator » transformer » 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 » Development » Retrotranslator » net.sf.retrotranslator.transformer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***
002:         * Retrotranslator: a Java bytecode transformer that translates Java classes
003:         * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004:         *
005:         * Copyright (c) 2005 - 2008 Taras Puchko
006:         * All rights reserved.
007:         *
008:         * Redistribution and use in source and binary forms, with or without
009:         * modification, are permitted provided that the following conditions
010:         * are met:
011:         * 1. Redistributions of source code must retain the above copyright
012:         *    notice, this list of conditions and the following disclaimer.
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         *    notice, this list of conditions and the following disclaimer in the
015:         *    documentation and/or other materials provided with the distribution.
016:         * 3. Neither the name of the copyright holders nor the names of its
017:         *    contributors may be used to endorse or promote products derived from
018:         *    this software without specific prior written permission.
019:         *
020:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030:         * THE POSSIBILITY OF SUCH DAMAGE.
031:         */package net.sf.retrotranslator.transformer;
032:
033:        import java.util.*;
034:        import net.sf.retrotranslator.runtime.asm.*;
035:        import net.sf.retrotranslator.runtime.impl.*;
036:
037:        /**
038:         * @author Taras Puchko
039:         */
040:        class ReferenceVerifyingVisitor extends GenericClassVisitor {
041:
042:            private final ClassVersion target;
043:            private final TargetEnvironment environment;
044:            private final SystemLogger logger;
045:            private Set<String> warnings;
046:
047:            public ReferenceVerifyingVisitor(ClassVersion target,
048:                    TargetEnvironment environment, SystemLogger logger) {
049:                super (new EmptyVisitor());
050:                this .target = target;
051:                this .environment = environment;
052:                this .logger = logger;
053:            }
054:
055:            public int verify(byte[] bytes) {
056:                warnings = new LinkedHashSet<String>();
057:                new ClassReader(bytes).accept(this , true);
058:                return warnings.size();
059:            }
060:
061:            public void visit(int version, int access, String name,
062:                    String signature, String super Name, String[] interfaces) {
063:                checkVersion(version, name);
064:                super .visit(version, access, name, signature, super Name,
065:                        interfaces);
066:            }
067:
068:            private void checkVersion(int version, String name) {
069:                if (target.isBefore(version)) {
070:                    println("Incompatible class: "
071:                            + RuntimeTools.getDisplayClassName(name));
072:                }
073:            }
074:
075:            protected String typeName(String s) {
076:                if (s == null)
077:                    return null;
078:                try {
079:                    environment.getClassReader(s);
080:                } catch (ClassNotFoundException e) {
081:                    printClassNotFound(e);
082:                }
083:                return s;
084:            }
085:
086:            private void printClassNotFound(ClassNotFoundException e) {
087:                println("Class not found: "
088:                        + RuntimeTools.getDisplayClassName(e.getMessage()));
089:            }
090:
091:            protected void visitFieldInstruction(MethodVisitor visitor,
092:                    int opcode, String owner, String name, String desc) {
093:                super .visitFieldInstruction(visitor, opcode, owner, name, desc);
094:                boolean stat = (opcode == Opcodes.GETSTATIC || opcode == Opcodes.PUTSTATIC);
095:                try {
096:                    int found = findMember(false, stat, name, desc, owner);
097:                    if (found == 0) {
098:                        println(getFieldInfo(owner, stat, name, desc,
099:                                "not found"));
100:                    } else if (found > 1) {
101:                        println(getFieldInfo(owner, stat, name, desc,
102:                                "duplicated"));
103:                    }
104:                } catch (ClassNotFoundException e) {
105:                    cannotVerify(getFieldInfo(owner, stat, name, desc,
106:                            "not verified"), e);
107:                }
108:            }
109:
110:            protected void visitMethodInstruction(MethodVisitor visitor,
111:                    int opcode, String owner, String name, String desc) {
112:                super 
113:                        .visitMethodInstruction(visitor, opcode, owner, name,
114:                                desc);
115:                if (owner.startsWith("["))
116:                    return;
117:                boolean stat = (opcode == Opcodes.INVOKESTATIC);
118:                try {
119:                    int found = findMember(true, stat, name, desc, owner);
120:                    if (found == 0) {
121:                        println(getMethodInfo(owner, stat, name, desc,
122:                                "not found"));
123:                    } else if (found > 1) {
124:                        println(getMethodInfo(owner, stat, name, desc,
125:                                "duplicated"));
126:                    }
127:                } catch (ClassNotFoundException e) {
128:                    cannotVerify(getMethodInfo(owner, stat, name, desc,
129:                            "not verified"), e);
130:                }
131:            }
132:
133:            private int findMember(boolean method, boolean stat, String name,
134:                    String desc, String owner) throws ClassNotFoundException {
135:                return new MemberFinder(environment, method, stat, name, desc) {
136:                    public void visit(int version, int access, String name,
137:                            String signature, String super Name,
138:                            String[] interfaces) {
139:                        checkVersion(version, name);
140:                        super .visit(version, access, name, signature,
141:                                super Name, interfaces);
142:                    }
143:                }.findIn(owner, null);
144:            }
145:
146:            private void cannotVerify(String text, ClassNotFoundException e) {
147:                printClassNotFound(e);
148:                println(text);
149:            }
150:
151:            private void println(String text) {
152:                if (!warnings.contains(text)) {
153:                    warnings.add(text);
154:                    logger.logForFile(Level.WARNING, text);
155:                }
156:            }
157:
158:            private static String getFieldInfo(String owner, boolean stat,
159:                    String name, String desc, String message) {
160:                StringBuffer buffer = new StringBuffer("Field ")
161:                        .append(message).append(": ");
162:                if (stat)
163:                    buffer.append("static ");
164:                buffer.append(Type.getType(desc).getClassName()).append(' ');
165:                buffer.append(RuntimeTools.getDisplayClassName(owner)).append(
166:                        '.').append(name);
167:                return buffer.toString();
168:            }
169:
170:            private static String getMethodInfo(String owner, boolean stat,
171:                    String name, String desc, String message) {
172:                StringBuffer buffer = new StringBuffer();
173:                if (name.equals(RuntimeTools.CONSTRUCTOR_NAME)) {
174:                    buffer.append("Constructor ").append(message).append(": ");
175:                    buffer.append(RuntimeTools.getDisplayClassName(owner));
176:                } else {
177:                    buffer.append("Method ").append(message).append(": ");
178:                    if (stat)
179:                        buffer.append("static ");
180:                    buffer.append(Type.getReturnType(desc).getClassName());
181:                    buffer.append(' ').append(
182:                            RuntimeTools.getDisplayClassName(owner))
183:                            .append('.').append(name);
184:                }
185:                buffer.append('(');
186:                boolean first = true;
187:                for (Type type : Type.getArgumentTypes(desc)) {
188:                    buffer.append(first ? "" : ",").append(type.getClassName());
189:                    first = false;
190:                }
191:                return buffer.append(')').toString();
192:            }
193:
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.