duke@1: /* ohair@158: * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@158: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@158: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@158: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@158: * or visit www.oracle.com if you need additional information or have any ohair@158: * questions. duke@1: */ duke@1: duke@1: /* duke@1: * Licensed Materials - Property of IBM duke@1: * RMI-IIOP v1.0 duke@1: * Copyright IBM Corp. 1998 1999 All Rights Reserved duke@1: * duke@1: */ duke@1: duke@1: package sun.rmi.rmic.iiop; duke@1: duke@1: import sun.tools.java.ClassNotFound; duke@1: import sun.tools.java.CompilerError; duke@1: import sun.tools.java.Identifier; duke@1: import sun.tools.java.ClassDefinition; duke@1: duke@1: /** duke@1: * SpecialClassType represents any one of the following types: duke@1: *
duke@1:  *    java.lang.Object
duke@1:  *    java.lang.String
duke@1:  * 
duke@1: * all of which are treated as special cases. duke@1: *

duke@1: * The static forSpecial(...) method must be used to obtain an instance, and duke@1: * will return null if the type is non-conforming. duke@1: * duke@1: * @author Bryan Atsatt duke@1: */ duke@1: public class SpecialClassType extends ClassType { duke@1: duke@1: //_____________________________________________________________________ duke@1: // Public Interfaces duke@1: //_____________________________________________________________________ duke@1: duke@1: /** duke@1: * Create a SpecialClassType object for the given class. duke@1: * duke@1: * If the class is not a properly formed or if some other error occurs, the duke@1: * return value will be null, and errors will have been reported to the duke@1: * supplied BatchEnvironment. duke@1: */ duke@1: public static SpecialClassType forSpecial (ClassDefinition theClass, duke@1: ContextStack stack) { duke@1: if (stack.anyErrors()) return null; duke@1: duke@1: sun.tools.java.Type type = theClass.getType(); duke@1: duke@1: // Do we already have it? duke@1: duke@1: String typeKey = type.toString() + stack.getContextCodeString(); duke@1: duke@1: Type existing = getType(typeKey,stack); duke@1: duke@1: if (existing != null) { duke@1: duke@1: if (!(existing instanceof SpecialClassType)) return null; // False hit. duke@1: duke@1: // Yep, so return it... duke@1: duke@1: return (SpecialClassType) existing; duke@1: } duke@1: duke@1: // Is it a special type? duke@1: duke@1: int typeCode = getTypeCode(type,theClass,stack); duke@1: duke@1: if (typeCode != TYPE_NONE) { duke@1: duke@1: // Yes... duke@1: duke@1: SpecialClassType result = new SpecialClassType(stack,typeCode,theClass); duke@1: putType(typeKey,result,stack); duke@1: stack.push(result); duke@1: stack.pop(true); duke@1: return result; duke@1: duke@1: } else { duke@1: duke@1: return null; duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Return a string describing this type. duke@1: */ duke@1: public String getTypeDescription () { duke@1: return "Special class"; duke@1: } duke@1: duke@1: //_____________________________________________________________________ duke@1: // Subclass/Internal Interfaces duke@1: //_____________________________________________________________________ duke@1: duke@1: /** duke@1: * Create an SpecialClassType instance for the given class. duke@1: */ duke@1: private SpecialClassType(ContextStack stack, int typeCode, duke@1: ClassDefinition theClass) { duke@1: super(stack,typeCode | TM_SPECIAL_CLASS | TM_CLASS | TM_COMPOUND, theClass); duke@1: Identifier id = theClass.getName(); duke@1: String idlName = null; duke@1: String[] idlModuleName = null; duke@1: boolean constant = stack.size() > 0 && stack.getContext().isConstant(); duke@1: duke@1: // Set names... duke@1: duke@1: switch (typeCode) { duke@1: case TYPE_STRING: { duke@1: idlName = IDLNames.getTypeName(typeCode,constant); duke@1: if (!constant) { duke@1: idlModuleName = IDL_CORBA_MODULE; duke@1: } duke@1: break; duke@1: } duke@1: duke@1: case TYPE_ANY: { duke@1: idlName = IDL_JAVA_LANG_OBJECT; duke@1: idlModuleName = IDL_JAVA_LANG_MODULE; duke@1: break; duke@1: } duke@1: } duke@1: duke@1: setNames(id,idlModuleName,idlName); duke@1: duke@1: // Init parents... duke@1: duke@1: if (!initParents(stack)) { duke@1: duke@1: // Should not be possible! duke@1: duke@1: throw new CompilerError("SpecialClassType found invalid parent."); duke@1: } duke@1: duke@1: // Initialize CompoundType... duke@1: duke@1: initialize(null,null,null,stack,false); duke@1: } duke@1: duke@1: private static int getTypeCode(sun.tools.java.Type type, ClassDefinition theClass, ContextStack stack) { duke@1: if (type.isType(TC_CLASS)) { duke@1: Identifier id = type.getClassName(); duke@1: if (id == idJavaLangString) return TYPE_STRING; duke@1: if (id == idJavaLangObject) return TYPE_ANY; duke@1: } duke@1: return TYPE_NONE; duke@1: } duke@1: }