Source Code Cross Referenced for TypeSignature.java in  » 6.0-JDK-Modules-com.sun » tools » com » sun » tools » javah » 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 » 6.0 JDK Modules com.sun » tools » com.sun.tools.javah 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2003 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package com.sun.tools.javah;
027:
028:        import com.sun.javadoc.*;
029:        import java.io.*;
030:        import java.util.*;
031:
032:        /**
033:         * Returns internal type signature.
034:         *
035:         * @author Sucheta Dambalkar
036:         */
037:
038:        public class TypeSignature {
039:
040:            RootDoc root = null;
041:
042:            /* Signature Characters */
043:
044:            private static final String SIG_VOID = "V";
045:            private static final String SIG_BOOLEAN = "Z";
046:            private static final String SIG_BYTE = "B";
047:            private static final String SIG_CHAR = "C";
048:            private static final String SIG_SHORT = "S";
049:            private static final String SIG_INT = "I";
050:            private static final String SIG_LONG = "J";
051:            private static final String SIG_FLOAT = "F";
052:            private static final String SIG_DOUBLE = "D";
053:            private static final String SIG_ARRAY = "[";
054:            private static final String SIG_CLASS = "L";
055:
056:            public TypeSignature(RootDoc root) {
057:                this .root = root;
058:            }
059:
060:            /*
061:             * Returns the type signature of a field according to JVM specs
062:             */
063:            public String getTypeSignature(String javasignature) {
064:                return getParamJVMSignature(javasignature);
065:            }
066:
067:            /*
068:             * Returns the type signature of a method according to JVM specs
069:             */
070:            public String getTypeSignature(String javasignature, Type returnType) {
071:
072:                String signature = null; //Java type signature.
073:                String typeSignature = null; //Internal type signature.
074:                Vector params = new Vector(); //List of parameters.
075:                String paramsig = null; //Java parameter signature.
076:                String paramJVMSig = null; //Internal parameter signature.
077:                String returnSig = null; //Java return type signature.
078:                String returnJVMType = null; //Internal return type signature.
079:                String dimension = null; //Array dimension.
080:
081:                int startIndex = -1;
082:                int endIndex = -1;
083:                StringTokenizer st = null;
084:                int i = 0;
085:
086:                // Gets the actual java signature without parentheses.
087:                if (javasignature != null) {
088:                    startIndex = javasignature.indexOf("(");
089:                    endIndex = javasignature.indexOf(")");
090:                }
091:
092:                if (((startIndex != -1) && (endIndex != -1))
093:                        && (startIndex + 1 < javasignature.length())
094:                        && (endIndex < javasignature.length())) {
095:
096:                    signature = javasignature.substring(startIndex + 1,
097:                            endIndex);
098:                }
099:
100:                // Separates parameters.
101:                if (signature != null) {
102:                    if (signature.indexOf(",") != -1) {
103:                        st = new StringTokenizer(signature, ",");
104:                        if (st != null) {
105:                            while (st.hasMoreTokens()) {
106:                                params.add(st.nextToken());
107:                            }
108:                        }
109:                    } else {
110:                        params.add(signature);
111:                    }
112:                }
113:
114:                /* JVM type signature. */
115:                typeSignature = "(";
116:
117:                // Gets indivisual internal parameter signature. 
118:                while (params.isEmpty() != true) {
119:                    paramsig = ((String) params.remove(i)).trim();
120:                    paramJVMSig = getParamJVMSignature(paramsig);
121:                    if (paramJVMSig != null) {
122:                        typeSignature += paramJVMSig;
123:                    }
124:                }
125:
126:                typeSignature += ")";
127:
128:                // Get internal return type signature.
129:
130:                returnJVMType = "";
131:                if (returnType != null) {
132:                    dimension = returnType.dimension();
133:                }
134:
135:                if (dimension != null) {
136:
137:                    //Gets array dimension of return type.
138:                    while (dimension.indexOf("[]") != -1) {
139:                        returnJVMType += "[";
140:                        int stindex = dimension.indexOf("]") + 1;
141:                        if (stindex <= dimension.length()) {
142:                            dimension = dimension.substring(stindex);
143:                        } else
144:                            dimension = "";
145:                    }
146:                }
147:                if (returnType != null) {
148:                    returnSig = returnType.qualifiedTypeName();
149:                    returnJVMType += getComponentType(returnSig);
150:                } else {
151:                    System.out.println("Invalid return type.");
152:                }
153:
154:                typeSignature += returnJVMType;
155:                return typeSignature;
156:            }
157:
158:            /*
159:             * Returns internal signature of a parameter.
160:             */
161:            private String getParamJVMSignature(String paramsig) {
162:                String paramJVMSig = "";
163:                String componentType = "";
164:
165:                if (paramsig != null) {
166:
167:                    if (paramsig.indexOf("[]") != -1) {
168:                        // Gets array dimension. 
169:                        int endindex = paramsig.indexOf("[]");
170:                        componentType = paramsig.substring(0, endindex);
171:                        String dimensionString = paramsig.substring(endindex);
172:                        if (dimensionString != null) {
173:                            while (dimensionString.indexOf("[]") != -1) {
174:                                paramJVMSig += "[";
175:                                int beginindex = dimensionString.indexOf("]") + 1;
176:                                if (beginindex < dimensionString.length()) {
177:                                    dimensionString = dimensionString
178:                                            .substring(beginindex);
179:                                } else
180:                                    dimensionString = "";
181:                            }
182:                        }
183:                    } else
184:                        componentType = paramsig;
185:
186:                    paramJVMSig += getComponentType(componentType);
187:                }
188:                return paramJVMSig;
189:            }
190:
191:            /*
192:             * Returns internal signature of a component.
193:             */
194:            private String getComponentType(String componentType) {
195:
196:                String JVMSig = "";
197:
198:                if (componentType != null) {
199:                    if (componentType.equals("void"))
200:                        JVMSig += SIG_VOID;
201:                    else if (componentType.equals("boolean"))
202:                        JVMSig += SIG_BOOLEAN;
203:                    else if (componentType.equals("byte"))
204:                        JVMSig += SIG_BYTE;
205:                    else if (componentType.equals("char"))
206:                        JVMSig += SIG_CHAR;
207:                    else if (componentType.equals("short"))
208:                        JVMSig += SIG_SHORT;
209:                    else if (componentType.equals("int"))
210:                        JVMSig += SIG_INT;
211:                    else if (componentType.equals("long"))
212:                        JVMSig += SIG_LONG;
213:                    else if (componentType.equals("float"))
214:                        JVMSig += SIG_FLOAT;
215:                    else if (componentType.equals("double"))
216:                        JVMSig += SIG_DOUBLE;
217:                    else {
218:                        if (!componentType.equals("")) {
219:                            ClassDoc classNameDoc = root
220:                                    .classNamed(componentType);
221:
222:                            if (classNameDoc == null) {
223:                                System.out.println("Invalid class type");
224:                            } else {
225:                                String classname = classNameDoc.qualifiedName();
226:                                String newclassname = classname.replace('.',
227:                                        '/');
228:                                JVMSig += "L";
229:                                JVMSig += newclassname;
230:                                JVMSig += ";";
231:                            }
232:                        }
233:                    }
234:                }
235:                return JVMSig;
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.