1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/sun/rmi/rmic/iiop/SpecialClassType.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,171 @@ 1.4 +/* 1.5 + * Portions Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +/* 1.30 + * Licensed Materials - Property of IBM 1.31 + * RMI-IIOP v1.0 1.32 + * Copyright IBM Corp. 1998 1999 All Rights Reserved 1.33 + * 1.34 + */ 1.35 + 1.36 +package sun.rmi.rmic.iiop; 1.37 + 1.38 +import sun.tools.java.ClassNotFound; 1.39 +import sun.tools.java.CompilerError; 1.40 +import sun.tools.java.Identifier; 1.41 +import sun.tools.java.ClassDefinition; 1.42 + 1.43 +/** 1.44 + * SpecialClassType represents any one of the following types: 1.45 + * <pre> 1.46 + * java.lang.Object 1.47 + * java.lang.String 1.48 + * </pre> 1.49 + * all of which are treated as special cases. 1.50 + * <p> 1.51 + * The static forSpecial(...) method must be used to obtain an instance, and 1.52 + * will return null if the type is non-conforming. 1.53 + * 1.54 + * @author Bryan Atsatt 1.55 + */ 1.56 +public class SpecialClassType extends ClassType { 1.57 + 1.58 + //_____________________________________________________________________ 1.59 + // Public Interfaces 1.60 + //_____________________________________________________________________ 1.61 + 1.62 + /** 1.63 + * Create a SpecialClassType object for the given class. 1.64 + * 1.65 + * If the class is not a properly formed or if some other error occurs, the 1.66 + * return value will be null, and errors will have been reported to the 1.67 + * supplied BatchEnvironment. 1.68 + */ 1.69 + public static SpecialClassType forSpecial (ClassDefinition theClass, 1.70 + ContextStack stack) { 1.71 + if (stack.anyErrors()) return null; 1.72 + 1.73 + sun.tools.java.Type type = theClass.getType(); 1.74 + 1.75 + // Do we already have it? 1.76 + 1.77 + String typeKey = type.toString() + stack.getContextCodeString(); 1.78 + 1.79 + Type existing = getType(typeKey,stack); 1.80 + 1.81 + if (existing != null) { 1.82 + 1.83 + if (!(existing instanceof SpecialClassType)) return null; // False hit. 1.84 + 1.85 + // Yep, so return it... 1.86 + 1.87 + return (SpecialClassType) existing; 1.88 + } 1.89 + 1.90 + // Is it a special type? 1.91 + 1.92 + int typeCode = getTypeCode(type,theClass,stack); 1.93 + 1.94 + if (typeCode != TYPE_NONE) { 1.95 + 1.96 + // Yes... 1.97 + 1.98 + SpecialClassType result = new SpecialClassType(stack,typeCode,theClass); 1.99 + putType(typeKey,result,stack); 1.100 + stack.push(result); 1.101 + stack.pop(true); 1.102 + return result; 1.103 + 1.104 + } else { 1.105 + 1.106 + return null; 1.107 + } 1.108 + } 1.109 + 1.110 + /** 1.111 + * Return a string describing this type. 1.112 + */ 1.113 + public String getTypeDescription () { 1.114 + return "Special class"; 1.115 + } 1.116 + 1.117 + //_____________________________________________________________________ 1.118 + // Subclass/Internal Interfaces 1.119 + //_____________________________________________________________________ 1.120 + 1.121 + /** 1.122 + * Create an SpecialClassType instance for the given class. 1.123 + */ 1.124 + private SpecialClassType(ContextStack stack, int typeCode, 1.125 + ClassDefinition theClass) { 1.126 + super(stack,typeCode | TM_SPECIAL_CLASS | TM_CLASS | TM_COMPOUND, theClass); 1.127 + Identifier id = theClass.getName(); 1.128 + String idlName = null; 1.129 + String[] idlModuleName = null; 1.130 + boolean constant = stack.size() > 0 && stack.getContext().isConstant(); 1.131 + 1.132 + // Set names... 1.133 + 1.134 + switch (typeCode) { 1.135 + case TYPE_STRING: { 1.136 + idlName = IDLNames.getTypeName(typeCode,constant); 1.137 + if (!constant) { 1.138 + idlModuleName = IDL_CORBA_MODULE; 1.139 + } 1.140 + break; 1.141 + } 1.142 + 1.143 + case TYPE_ANY: { 1.144 + idlName = IDL_JAVA_LANG_OBJECT; 1.145 + idlModuleName = IDL_JAVA_LANG_MODULE; 1.146 + break; 1.147 + } 1.148 + } 1.149 + 1.150 + setNames(id,idlModuleName,idlName); 1.151 + 1.152 + // Init parents... 1.153 + 1.154 + if (!initParents(stack)) { 1.155 + 1.156 + // Should not be possible! 1.157 + 1.158 + throw new CompilerError("SpecialClassType found invalid parent."); 1.159 + } 1.160 + 1.161 + // Initialize CompoundType... 1.162 + 1.163 + initialize(null,null,null,stack,false); 1.164 + } 1.165 + 1.166 + private static int getTypeCode(sun.tools.java.Type type, ClassDefinition theClass, ContextStack stack) { 1.167 + if (type.isType(TC_CLASS)) { 1.168 + Identifier id = type.getClassName(); 1.169 + if (id == idJavaLangString) return TYPE_STRING; 1.170 + if (id == idJavaLangObject) return TYPE_ANY; 1.171 + } 1.172 + return TYPE_NONE; 1.173 + } 1.174 +}