Source Code Cross Referenced for SignatureReader.java in  » Development » Retrotranslator » net » sf » retrotranslator » runtime » asm » signature » 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.runtime.asm.signature 
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 net.sf.retrotranslator.runtime.asm.signature;
030:
031:        /**
032:         * A type signature parser to make a signature visitor visit an existing
033:         * signature.
034:         * 
035:         * @author Thomas Hallgren
036:         * @author Eric Bruneton
037:         */
038:        public class SignatureReader {
039:
040:            /**
041:             * The signature to be read.
042:             */
043:            private final String signature;
044:
045:            /**
046:             * Constructs a {@link SignatureReader} for the given signature.
047:             * 
048:             * @param signature A <i>ClassSignature</i>, <i>MethodTypeSignature</i>,
049:             *        or <i>FieldTypeSignature</i>.
050:             */
051:            public SignatureReader(final String signature) {
052:                this .signature = signature;
053:            }
054:
055:            /**
056:             * Makes the given visitor visit the signature of this
057:             * {@link SignatureReader}. This signature is the one specified in the
058:             * constructor (see {@link #SignatureReader(String) SignatureReader}). This
059:             * method is intended to be called on a {@link SignatureReader} that was
060:             * created using a <i>ClassSignature</i> (such as the
061:             * <code>signature</code> parameter of the
062:             * {@link net.sf.retrotranslator.runtime.asm.ClassVisitor#visit ClassVisitor.visit} method)
063:             * or a <i>MethodTypeSignature</i> (such as the <code>signature</code>
064:             * parameter of the
065:             * {@link net.sf.retrotranslator.runtime.asm.ClassVisitor#visitMethod ClassVisitor.visitMethod}
066:             * method).
067:             * 
068:             * @param v the visitor that must visit this signature.
069:             */
070:            public void accept(final SignatureVisitor v) {
071:                String signature = this .signature;
072:                int len = signature.length();
073:                int pos;
074:                char c;
075:
076:                if (signature.charAt(0) == '<') {
077:                    pos = 2;
078:                    do {
079:                        int end = signature.indexOf(':', pos);
080:                        v.visitFormalTypeParameter(signature.substring(pos - 1,
081:                                end));
082:                        pos = end + 1;
083:
084:                        c = signature.charAt(pos);
085:                        if (c == 'L' || c == '[' || c == 'T') {
086:                            pos = parseType(signature, pos, v.visitClassBound());
087:                        }
088:
089:                        for (;;) {
090:                            if ((c = signature.charAt(pos++)) == ':') {
091:                                pos = parseType(signature, pos, v
092:                                        .visitInterfaceBound());
093:                            } else {
094:                                break;
095:                            }
096:                        }
097:                    } while (c != '>');
098:                } else {
099:                    pos = 0;
100:                }
101:
102:                if (signature.charAt(pos) == '(') {
103:                    pos = pos + 1;
104:                    while (signature.charAt(pos) != ')') {
105:                        pos = parseType(signature, pos, v.visitParameterType());
106:                    }
107:                    pos = parseType(signature, pos + 1, v.visitReturnType());
108:                    while (pos < len) {
109:                        pos = parseType(signature, pos + 1, v
110:                                .visitExceptionType());
111:                    }
112:                } else {
113:                    pos = parseType(signature, pos, v.visitSuperclass());
114:                    while (pos < len) {
115:                        pos = parseType(signature, pos, v.visitInterface());
116:                    }
117:                }
118:            }
119:
120:            /**
121:             * Makes the given visitor visit the signature of this
122:             * {@link SignatureReader}. This signature is the one specified in the
123:             * constructor (see {@link #SignatureReader(String) SignatureReader}). This
124:             * method is intended to be called on a {@link SignatureReader} that was
125:             * created using a <i>FieldTypeSignature</i>, such as the
126:             * <code>signature</code> parameter of the
127:             * {@link net.sf.retrotranslator.runtime.asm.ClassVisitor#visitField
128:             * ClassVisitor.visitField} or {@link 
129:             * net.sf.retrotranslator.runtime.asm.MethodVisitor#visitLocalVariable
130:             * MethodVisitor.visitLocalVariable} methods.
131:             * 
132:             * @param v the visitor that must visit this signature.
133:             */
134:            public void acceptType(final SignatureVisitor v) {
135:                parseType(this .signature, 0, v);
136:            }
137:
138:            /**
139:             * Parses a field type signature and makes the given visitor visit it.
140:             * 
141:             * @param signature a string containing the signature that must be parsed.
142:             * @param pos index of the first character of the signature to parsed.
143:             * @param v the visitor that must visit this signature.
144:             * @return the index of the first character after the parsed signature.
145:             */
146:            private static int parseType(final String signature, int pos,
147:                    final SignatureVisitor v) {
148:                char c;
149:                int start, end;
150:                boolean visited, inner;
151:                String name;
152:
153:                switch (c = signature.charAt(pos++)) {
154:                case 'Z':
155:                case 'C':
156:                case 'B':
157:                case 'S':
158:                case 'I':
159:                case 'F':
160:                case 'J':
161:                case 'D':
162:                case 'V':
163:                    v.visitBaseType(c);
164:                    return pos;
165:
166:                case '[':
167:                    return parseType(signature, pos, v.visitArrayType());
168:
169:                case 'T':
170:                    end = signature.indexOf(';', pos);
171:                    v.visitTypeVariable(signature.substring(pos, end));
172:                    return end + 1;
173:
174:                default: // case 'L':
175:                    start = pos;
176:                    visited = false;
177:                    inner = false;
178:                    for (;;) {
179:                        switch (c = signature.charAt(pos++)) {
180:                        case '.':
181:                        case ';':
182:                            if (!visited) {
183:                                name = signature.substring(start, pos - 1);
184:                                if (inner) {
185:                                    v.visitInnerClassType(name);
186:                                } else {
187:                                    v.visitClassType(name);
188:                                }
189:                            }
190:                            if (c == ';') {
191:                                v.visitEnd();
192:                                return pos;
193:                            }
194:                            start = pos;
195:                            visited = false;
196:                            inner = true;
197:                            break;
198:
199:                        case '<':
200:                            name = signature.substring(start, pos - 1);
201:                            if (inner) {
202:                                v.visitInnerClassType(name);
203:                            } else {
204:                                v.visitClassType(name);
205:                            }
206:                            visited = true;
207:                            top: for (;;) {
208:                                switch (c = signature.charAt(pos)) {
209:                                case '>':
210:                                    break top;
211:                                case '*':
212:                                    ++pos;
213:                                    v.visitTypeArgument();
214:                                    break;
215:                                case '+':
216:                                case '-':
217:                                    pos = parseType(signature, pos + 1, v
218:                                            .visitTypeArgument(c));
219:                                    break;
220:                                default:
221:                                    pos = parseType(signature, pos, v
222:                                            .visitTypeArgument('='));
223:                                    break;
224:                                }
225:                            }
226:                        }
227:                    }
228:                }
229:            }
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.