|
1 /* |
|
2 * Portions Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 /* |
|
27 * Licensed Materials - Property of IBM |
|
28 * RMI-IIOP v1.0 |
|
29 * Copyright IBM Corp. 1998 1999 All Rights Reserved |
|
30 * |
|
31 */ |
|
32 |
|
33 package sun.rmi.rmic.iiop; |
|
34 |
|
35 import sun.tools.java.ClassNotFound; |
|
36 import sun.tools.java.CompilerError; |
|
37 import sun.tools.java.Identifier; |
|
38 import sun.tools.java.ClassDefinition; |
|
39 |
|
40 /** |
|
41 * SpecialClassType represents any one of the following types: |
|
42 * <pre> |
|
43 * java.lang.Object |
|
44 * java.lang.String |
|
45 * </pre> |
|
46 * all of which are treated as special cases. |
|
47 * <p> |
|
48 * The static forSpecial(...) method must be used to obtain an instance, and |
|
49 * will return null if the type is non-conforming. |
|
50 * |
|
51 * @author Bryan Atsatt |
|
52 */ |
|
53 public class SpecialClassType extends ClassType { |
|
54 |
|
55 //_____________________________________________________________________ |
|
56 // Public Interfaces |
|
57 //_____________________________________________________________________ |
|
58 |
|
59 /** |
|
60 * Create a SpecialClassType object for the given class. |
|
61 * |
|
62 * If the class is not a properly formed or if some other error occurs, the |
|
63 * return value will be null, and errors will have been reported to the |
|
64 * supplied BatchEnvironment. |
|
65 */ |
|
66 public static SpecialClassType forSpecial (ClassDefinition theClass, |
|
67 ContextStack stack) { |
|
68 if (stack.anyErrors()) return null; |
|
69 |
|
70 sun.tools.java.Type type = theClass.getType(); |
|
71 |
|
72 // Do we already have it? |
|
73 |
|
74 String typeKey = type.toString() + stack.getContextCodeString(); |
|
75 |
|
76 Type existing = getType(typeKey,stack); |
|
77 |
|
78 if (existing != null) { |
|
79 |
|
80 if (!(existing instanceof SpecialClassType)) return null; // False hit. |
|
81 |
|
82 // Yep, so return it... |
|
83 |
|
84 return (SpecialClassType) existing; |
|
85 } |
|
86 |
|
87 // Is it a special type? |
|
88 |
|
89 int typeCode = getTypeCode(type,theClass,stack); |
|
90 |
|
91 if (typeCode != TYPE_NONE) { |
|
92 |
|
93 // Yes... |
|
94 |
|
95 SpecialClassType result = new SpecialClassType(stack,typeCode,theClass); |
|
96 putType(typeKey,result,stack); |
|
97 stack.push(result); |
|
98 stack.pop(true); |
|
99 return result; |
|
100 |
|
101 } else { |
|
102 |
|
103 return null; |
|
104 } |
|
105 } |
|
106 |
|
107 /** |
|
108 * Return a string describing this type. |
|
109 */ |
|
110 public String getTypeDescription () { |
|
111 return "Special class"; |
|
112 } |
|
113 |
|
114 //_____________________________________________________________________ |
|
115 // Subclass/Internal Interfaces |
|
116 //_____________________________________________________________________ |
|
117 |
|
118 /** |
|
119 * Create an SpecialClassType instance for the given class. |
|
120 */ |
|
121 private SpecialClassType(ContextStack stack, int typeCode, |
|
122 ClassDefinition theClass) { |
|
123 super(stack,typeCode | TM_SPECIAL_CLASS | TM_CLASS | TM_COMPOUND, theClass); |
|
124 Identifier id = theClass.getName(); |
|
125 String idlName = null; |
|
126 String[] idlModuleName = null; |
|
127 boolean constant = stack.size() > 0 && stack.getContext().isConstant(); |
|
128 |
|
129 // Set names... |
|
130 |
|
131 switch (typeCode) { |
|
132 case TYPE_STRING: { |
|
133 idlName = IDLNames.getTypeName(typeCode,constant); |
|
134 if (!constant) { |
|
135 idlModuleName = IDL_CORBA_MODULE; |
|
136 } |
|
137 break; |
|
138 } |
|
139 |
|
140 case TYPE_ANY: { |
|
141 idlName = IDL_JAVA_LANG_OBJECT; |
|
142 idlModuleName = IDL_JAVA_LANG_MODULE; |
|
143 break; |
|
144 } |
|
145 } |
|
146 |
|
147 setNames(id,idlModuleName,idlName); |
|
148 |
|
149 // Init parents... |
|
150 |
|
151 if (!initParents(stack)) { |
|
152 |
|
153 // Should not be possible! |
|
154 |
|
155 throw new CompilerError("SpecialClassType found invalid parent."); |
|
156 } |
|
157 |
|
158 // Initialize CompoundType... |
|
159 |
|
160 initialize(null,null,null,stack,false); |
|
161 } |
|
162 |
|
163 private static int getTypeCode(sun.tools.java.Type type, ClassDefinition theClass, ContextStack stack) { |
|
164 if (type.isType(TC_CLASS)) { |
|
165 Identifier id = type.getClassName(); |
|
166 if (id == idJavaLangString) return TYPE_STRING; |
|
167 if (id == idJavaLangObject) return TYPE_ANY; |
|
168 } |
|
169 return TYPE_NONE; |
|
170 } |
|
171 } |