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


001:        /*
002:         * Copyright 2006 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.codemodel.internal;
027:
028:        /**
029:         * A representation of a type in codeModel.
030:         *
031:         * A type is always either primitive ({@link JPrimitiveType}) or
032:         * a reference type ({@link JClass}).
033:         */
034:        public abstract class JType implements  JGenerable, Comparable {
035:
036:            /**
037:             * Obtains a reference to the primitive type object from a type name.
038:             */
039:            public static JPrimitiveType parse(JCodeModel codeModel,
040:                    String typeName) {
041:                if (typeName.equals("void"))
042:                    return codeModel.VOID;
043:                else if (typeName.equals("boolean"))
044:                    return codeModel.BOOLEAN;
045:                else if (typeName.equals("byte"))
046:                    return codeModel.BYTE;
047:                else if (typeName.equals("short"))
048:                    return codeModel.SHORT;
049:                else if (typeName.equals("char"))
050:                    return codeModel.CHAR;
051:                else if (typeName.equals("int"))
052:                    return codeModel.INT;
053:                else if (typeName.equals("float"))
054:                    return codeModel.FLOAT;
055:                else if (typeName.equals("long"))
056:                    return codeModel.LONG;
057:                else if (typeName.equals("double"))
058:                    return codeModel.DOUBLE;
059:                else
060:                    throw new IllegalArgumentException("Not a primitive type: "
061:                            + typeName);
062:            }
063:
064:            /** Gets the owner code model object. */
065:            public abstract JCodeModel owner();
066:
067:            /**
068:             * Gets the full name of the type.
069:             *
070:             * See http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html#25430 for the details.
071:             *
072:             * @return
073:             *      Strings like "int", "java.lang.String",
074:             *      "java.io.File[]". Never null.
075:             */
076:            public abstract String fullName();
077:
078:            /**
079:             * Gets the binary name of the type.
080:             *
081:             * See http://java.sun.com/docs/books/jls/third_edition/html/binaryComp.html#44909
082:             *
083:             * @return
084:             *      Name like "Foo$Bar", "int", "java.lang.String", "java.io.File[]". Never null.
085:             */
086:            public String binaryName() {
087:                return fullName();
088:            }
089:
090:            /**
091:             * Gets the name of this type.
092:             *
093:             * @return
094:             *     Names like "int", "void", "BigInteger".
095:             */
096:            public abstract String name();
097:
098:            /**
099:             * Create an array type of this type.
100:             * 
101:             * This method is undefined for primitive void type, which
102:             * doesn't have any corresponding array representation.
103:             *
104:             * @return A {@link JClass} representing the array type
105:             *         whose element type is this type
106:             */
107:            public abstract JClass array();
108:
109:            /** Tell whether or not this is an array type. */
110:            public boolean isArray() {
111:                return false;
112:            }
113:
114:            /** Tell whether or not this is a built-in primitive type, such as int or void. */
115:            public boolean isPrimitive() {
116:                return false;
117:            }
118:
119:            /**
120:             * If this class is a primitive type, return the boxed class. Otherwise return <tt>this</tt>.
121:             *
122:             * <p>
123:             * For example, for "int", this method returns "java.lang.Integer".
124:             */
125:            public abstract JClass boxify();
126:
127:            /**
128:             * If this class is a wrapper type for a primitive, return the primitive type.
129:             * Otherwise return <tt>this</tt>.
130:             *
131:             * <p>
132:             * For example, for "java.lang.Integer", this method returns "int".
133:             */
134:            public abstract JType unboxify();
135:
136:            /**
137:             * Returns the erasure of this type.
138:             */
139:            public JType erasure() {
140:                return this ;
141:            }
142:
143:            /**
144:             * Returns true if this is a referenced type.
145:             */
146:            public final boolean isReference() {
147:                return !isPrimitive();
148:            }
149:
150:            /**
151:             * If this is an array, returns the component type of the array.
152:             * (T of T[])
153:             */
154:            public JType elementType() {
155:                throw new IllegalArgumentException("Not an array type");
156:            }
157:
158:            public String toString() {
159:                return this .getClass().getName() + '(' + fullName() + ')';
160:            }
161:
162:            /**
163:             * Compare two JTypes by FQCN, giving sorting precedence to types
164:             * that belong to packages java and javax over all others.
165:             *
166:             * This method is used to sort generated import statments in a
167:             * conventional way for readability.
168:             */
169:            public int compareTo(Object o) {
170:                final String rhs = ((JType) o).fullName();
171:                boolean p = fullName().startsWith("java");
172:                boolean q = rhs.startsWith("java");
173:
174:                if (p && !q) {
175:                    return -1;
176:                } else if (!p && q) {
177:                    return 1;
178:                } else {
179:                    return fullName().compareTo(rhs);
180:                }
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.