Source Code Cross Referenced for SimpleVerifier.java in  » Net » Terracotta » com » tc » asm » tree » analysis » 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 » Net » Terracotta » com.tc.asm.tree.analysis 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***
002:         * ASM: a very small and fast Java bytecode manipulation framework
003:         * Copyright (c) 2000-2005 INRIA, 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 com.tc.asm.tree.analysis;
030:
031:        import java.util.List;
032:
033:        import com.tc.asm.Type;
034:
035:        /**
036:         * An extended {@link BasicVerifier} that performs more precise verifications.
037:         * This verifier computes exact class types, instead of using a single "object
038:         * reference" type (as done in the {@link BasicVerifier}).
039:         * 
040:         * @author Eric Bruneton
041:         * @author Bing Ran
042:         */
043:        public class SimpleVerifier extends BasicVerifier {
044:
045:            /**
046:             * The class that is verified.
047:             */
048:            private final Type currentClass;
049:
050:            /**
051:             * The super class of the class that is verified.
052:             */
053:            private final Type currentSuperClass;
054:
055:            /**
056:             * The interfaces implemented by the class that is verified.
057:             */
058:            private final List currentClassInterfaces;
059:
060:            /**
061:             * If the class that is verified is an interface.
062:             */
063:            private final boolean isInterface;
064:
065:            /**
066:             * Constructs a new {@link SimpleVerifier}.
067:             */
068:            public SimpleVerifier() {
069:                this (null, null, false);
070:            }
071:
072:            /**
073:             * Constructs a new {@link SimpleVerifier} to verify a specific class. This
074:             * class will not be loaded into the JVM since it may be incorrect.
075:             * 
076:             * @param currentClass the class that is verified.
077:             * @param currentSuperClass the super class of the class that is verified.
078:             * @param isInterface if the class that is verified is an interface.
079:             */
080:            public SimpleVerifier(final Type currentClass,
081:                    final Type currentSuperClass, final boolean isInterface) {
082:                this (currentClass, currentSuperClass, null, isInterface);
083:            }
084:
085:            /**
086:             * Constructs a new {@link SimpleVerifier} to verify a specific class. This
087:             * class will not be loaded into the JVM since it may be incorrect.
088:             * 
089:             * @param currentClass the class that is verified.
090:             * @param currentSuperClass the super class of the class that is verified.
091:             * @param currentClassInterfaces the interfaces implemented by the class
092:             *        that is verified.
093:             * @param isInterface if the class that is verified is an interface.
094:             */
095:            public SimpleVerifier(final Type currentClass,
096:                    final Type currentSuperClass,
097:                    final List currentClassInterfaces, final boolean isInterface) {
098:                this .currentClass = currentClass;
099:                this .currentSuperClass = currentSuperClass;
100:                this .currentClassInterfaces = currentClassInterfaces;
101:                this .isInterface = isInterface;
102:            }
103:
104:            public Value newValue(final Type type) {
105:                if (type == null) {
106:                    return BasicValue.UNINITIALIZED_VALUE;
107:                }
108:
109:                boolean isArray = type.getSort() == Type.ARRAY;
110:                if (isArray) {
111:                    switch (type.getElementType().getSort()) {
112:                    case Type.BOOLEAN:
113:                    case Type.CHAR:
114:                    case Type.BYTE:
115:                    case Type.SHORT:
116:                        return new BasicValue(type);
117:                    }
118:                }
119:
120:                Value v = super .newValue(type);
121:                if (v == BasicValue.REFERENCE_VALUE) {
122:                    if (isArray) {
123:                        v = newValue(type.getElementType());
124:                        String desc = ((BasicValue) v).getType()
125:                                .getDescriptor();
126:                        for (int i = 0; i < type.getDimensions(); ++i) {
127:                            desc = "[" + desc;
128:                        }
129:                        v = new BasicValue(Type.getType(desc));
130:                    } else {
131:                        v = new BasicValue(type);
132:                    }
133:                }
134:                return v;
135:            }
136:
137:            protected boolean isArrayValue(final Value value) {
138:                Type t = ((BasicValue) value).getType();
139:                return t != null
140:                        && (t.getDescriptor().equals("Lnull;") || t.getSort() == Type.ARRAY);
141:            }
142:
143:            protected Value getElementValue(final Value objectArrayValue)
144:                    throws AnalyzerException {
145:                Type arrayType = ((BasicValue) objectArrayValue).getType();
146:                if (arrayType != null) {
147:                    if (arrayType.getSort() == Type.ARRAY) {
148:                        return newValue(Type.getType(arrayType.getDescriptor()
149:                                .substring(1)));
150:                    } else if (arrayType.getDescriptor().equals("Lnull;")) {
151:                        return objectArrayValue;
152:                    }
153:                }
154:                throw new Error("Internal error");
155:            }
156:
157:            protected boolean isSubTypeOf(final Value value,
158:                    final Value expected) {
159:                Type expectedType = ((BasicValue) expected).getType();
160:                Type type = ((BasicValue) value).getType();
161:                switch (expectedType.getSort()) {
162:                case Type.INT:
163:                case Type.FLOAT:
164:                case Type.LONG:
165:                case Type.DOUBLE:
166:                    return type == expectedType;
167:                case Type.ARRAY:
168:                case Type.OBJECT:
169:                    if (type.getDescriptor().equals("Lnull;")) {
170:                        return true;
171:                    } else if (type.getSort() == Type.OBJECT
172:                            || type.getSort() == Type.ARRAY) {
173:                        return isAssignableFrom(expectedType, type);
174:                    } else {
175:                        return false;
176:                    }
177:                default:
178:                    throw new Error("Internal error");
179:                }
180:            }
181:
182:            public Value merge(final Value v, final Value w) {
183:                if (!v.equals(w)) {
184:                    Type t = ((BasicValue) v).getType();
185:                    Type u = ((BasicValue) w).getType();
186:                    if (t != null
187:                            && (t.getSort() == Type.OBJECT || t.getSort() == Type.ARRAY)) {
188:                        if (u != null
189:                                && (u.getSort() == Type.OBJECT || u.getSort() == Type.ARRAY)) {
190:                            if (t.getDescriptor().equals("Lnull;")) {
191:                                return w;
192:                            }
193:                            if (u.getDescriptor().equals("Lnull;")) {
194:                                return v;
195:                            }
196:                            if (isAssignableFrom(t, u)) {
197:                                return v;
198:                            }
199:                            if (isAssignableFrom(u, t)) {
200:                                return w;
201:                            }
202:                            // TODO case of array classes of the same dimension
203:                            // TODO should we look also for a common super interface?
204:                            // problem: there may be several possible common super
205:                            // interfaces
206:                            do {
207:                                if (t == null || isInterface(t)) {
208:                                    return BasicValue.REFERENCE_VALUE;
209:                                }
210:                                t = getSuperClass(t);
211:                                if (isAssignableFrom(t, u)) {
212:                                    return newValue(t);
213:                                }
214:                            } while (true);
215:                        }
216:                    }
217:                    return BasicValue.UNINITIALIZED_VALUE;
218:                }
219:                return v;
220:            }
221:
222:            protected boolean isInterface(final Type t) {
223:                if (currentClass != null && t.equals(currentClass)) {
224:                    return isInterface;
225:                }
226:                return getClass(t).isInterface();
227:            }
228:
229:            protected Type getSuperClass(final Type t) {
230:                if (currentClass != null && t.equals(currentClass)) {
231:                    return currentSuperClass;
232:                }
233:                Class c = getClass(t).getSuperclass();
234:                return c == null ? null : Type.getType(c);
235:            }
236:
237:            protected boolean isAssignableFrom(final Type t, final Type u) {
238:                if (t.equals(u)) {
239:                    return true;
240:                }
241:                if (currentClass != null && t.equals(currentClass)) {
242:                    if (getSuperClass(u) == null) {
243:                        return false;
244:                    } else {
245:                        return isAssignableFrom(t, getSuperClass(u));
246:                    }
247:                }
248:                if (currentClass != null && u.equals(currentClass)) {
249:                    if (isAssignableFrom(t, currentSuperClass)) {
250:                        return true;
251:                    }
252:                    if (currentClassInterfaces != null) {
253:                        for (int i = 0; i < currentClassInterfaces.size(); ++i) {
254:                            Type v = (Type) currentClassInterfaces.get(i);
255:                            if (isAssignableFrom(t, v)) {
256:                                return true;
257:                            }
258:                        }
259:                    }
260:                    return false;
261:                }
262:                return getClass(t).isAssignableFrom(getClass(u));
263:            }
264:
265:            protected Class getClass(final Type t) {
266:                try {
267:                    if (t.getSort() == Type.ARRAY) {
268:                        return Class.forName(t.getDescriptor()
269:                                .replace('/', '.'));
270:                    }
271:                    return Class.forName(t.getClassName());
272:                } catch (ClassNotFoundException e) {
273:                    throw new RuntimeException(e.toString());
274:                }
275:            }
276:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.