src/share/classes/sun/rmi/rmic/iiop/PrimitiveType.java

Mon, 26 Mar 2012 14:01:40 +0100

author
coffeys
date
Mon, 26 Mar 2012 14:01:40 +0100
changeset 370
5222b7d658d4
parent 158
91006f157c46
child 748
6845b95cba6b
permissions
-rw-r--r--

7143851: Improve IIOP stub and tie generation in RMIC
7149048: Changes to corba rmic stubGenerator class are not used during jdk build process
Reviewed-by: mschoene, robm

duke@1 1 /*
ohair@158 2 * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@158 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@158 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@158 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@158 22 * or visit www.oracle.com if you need additional information or have any
ohair@158 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 /*
duke@1 27 * Licensed Materials - Property of IBM
duke@1 28 * RMI-IIOP v1.0
duke@1 29 * Copyright IBM Corp. 1998 1999 All Rights Reserved
duke@1 30 *
duke@1 31 */
duke@1 32
duke@1 33 package sun.rmi.rmic.iiop;
duke@1 34
duke@1 35 import sun.tools.java.CompilerError;
duke@1 36 import sun.tools.java.Identifier;
duke@1 37 import sun.tools.java.ClassDefinition;
duke@1 38
duke@1 39 /**
duke@1 40 * PrimitiveType wraps primitive types and void.
duke@1 41 * <p>
duke@1 42 * The static forPrimitive(...) method must be used to obtain an instance, and
duke@1 43 * will return null if the type is non-conforming.
duke@1 44 *
duke@1 45 * @author Bryan Atsatt
duke@1 46 */
duke@1 47 public class PrimitiveType extends Type {
duke@1 48
duke@1 49 //_____________________________________________________________________
duke@1 50 // Public Interfaces
duke@1 51 //_____________________________________________________________________
duke@1 52
duke@1 53 /**
duke@1 54 * Create a PrimitiveType object for the given type.
duke@1 55 *
duke@1 56 * If the type is not a properly formed or if some other error occurs, the
duke@1 57 * return value will be null, and errors will have been reported to the
duke@1 58 * supplied BatchEnvironment.
duke@1 59 */
duke@1 60 public static PrimitiveType forPrimitive(sun.tools.java.Type type,
duke@1 61 ContextStack stack) {
duke@1 62
duke@1 63 if (stack.anyErrors()) return null;
duke@1 64
duke@1 65 // Do we already have it?
duke@1 66
duke@1 67 Type existing = getType(type,stack);
duke@1 68
duke@1 69 if (existing != null) {
duke@1 70
duke@1 71 if (!(existing instanceof PrimitiveType)) return null; // False hit.
duke@1 72
duke@1 73 // Yep, so return it...
duke@1 74
duke@1 75 return (PrimitiveType) existing;
duke@1 76 }
duke@1 77
duke@1 78 int typeCode;
duke@1 79
duke@1 80 switch (type.getTypeCode()) {
duke@1 81 case TC_VOID: typeCode = TYPE_VOID; break;
duke@1 82 case TC_BOOLEAN: typeCode = TYPE_BOOLEAN; break;
duke@1 83 case TC_BYTE: typeCode = TYPE_BYTE; break;
duke@1 84 case TC_CHAR: typeCode = TYPE_CHAR; break;
duke@1 85 case TC_SHORT: typeCode = TYPE_SHORT; break;
duke@1 86 case TC_INT: typeCode = TYPE_INT; break;
duke@1 87 case TC_LONG: typeCode = TYPE_LONG; break;
duke@1 88 case TC_FLOAT: typeCode = TYPE_FLOAT; break;
duke@1 89 case TC_DOUBLE: typeCode = TYPE_DOUBLE; break;
duke@1 90 default: return null;
duke@1 91 }
duke@1 92
duke@1 93 PrimitiveType it = new PrimitiveType(stack,typeCode);
duke@1 94
duke@1 95 // Add it...
duke@1 96
duke@1 97 putType(type,it,stack);
duke@1 98
duke@1 99 // Do the stack thing in case tracing on...
duke@1 100
duke@1 101 stack.push(it);
duke@1 102 stack.pop(true);
duke@1 103
duke@1 104 return it;
duke@1 105 }
duke@1 106
duke@1 107 /**
duke@1 108 * Return signature for this type (e.g. com.acme.Dynamite
duke@1 109 * would return "com.acme.Dynamite", byte = "B")
duke@1 110 */
duke@1 111 public String getSignature() {
duke@1 112 switch (getTypeCode()) {
duke@1 113 case TYPE_VOID: return SIG_VOID;
duke@1 114 case TYPE_BOOLEAN: return SIG_BOOLEAN;
duke@1 115 case TYPE_BYTE: return SIG_BYTE;
duke@1 116 case TYPE_CHAR: return SIG_CHAR;
duke@1 117 case TYPE_SHORT: return SIG_SHORT;
duke@1 118 case TYPE_INT: return SIG_INT;
duke@1 119 case TYPE_LONG: return SIG_LONG;
duke@1 120 case TYPE_FLOAT: return SIG_FLOAT;
duke@1 121 case TYPE_DOUBLE: return SIG_DOUBLE;
duke@1 122 default: return null;
duke@1 123 }
duke@1 124 }
duke@1 125
duke@1 126 /**
duke@1 127 * Return a string describing this type.
duke@1 128 */
duke@1 129 public String getTypeDescription () {
duke@1 130 return "Primitive";
duke@1 131 }
duke@1 132
duke@1 133 /**
duke@1 134 * IDL_Naming
duke@1 135 * Return the fully qualified IDL name for this type (e.g. com.acme.Dynamite would
duke@1 136 * return "com::acme::Dynamite").
duke@1 137 * @param global If true, prepends "::".
duke@1 138 */
duke@1 139 public String getQualifiedIDLName(boolean global) {
duke@1 140 return super.getQualifiedIDLName(false);
duke@1 141 }
duke@1 142
duke@1 143 //_____________________________________________________________________
duke@1 144 // Subclass/Internal Interfaces
duke@1 145 //_____________________________________________________________________
duke@1 146
duke@1 147 /*
duke@1 148 * Load a Class instance. Return null if fail.
duke@1 149 */
duke@1 150 protected Class loadClass() {
duke@1 151 switch (getTypeCode()) {
duke@1 152 case TYPE_VOID: return Null.class;
duke@1 153 case TYPE_BOOLEAN: return boolean.class;
duke@1 154 case TYPE_BYTE: return byte.class;
duke@1 155 case TYPE_CHAR: return char.class;
duke@1 156 case TYPE_SHORT: return short.class;
duke@1 157 case TYPE_INT: return int.class;
duke@1 158 case TYPE_LONG: return long.class;
duke@1 159 case TYPE_FLOAT: return float.class;
duke@1 160 case TYPE_DOUBLE: return double.class;
duke@1 161 default: throw new CompilerError("Not a primitive type");
duke@1 162 }
duke@1 163 }
duke@1 164
duke@1 165 /**
duke@1 166 * IDL_Naming
duke@1 167 * Create an PrimitiveType instance for the given class.
duke@1 168 */
duke@1 169 private PrimitiveType(ContextStack stack, int typeCode) {
duke@1 170 super(stack,typeCode | TM_PRIMITIVE);
duke@1 171
duke@1 172 // Validate type and set names...
duke@1 173
duke@1 174 String idlName = IDLNames.getTypeName(typeCode,false);
duke@1 175 Identifier id = null;
duke@1 176
duke@1 177 switch (typeCode) {
duke@1 178 case TYPE_VOID: id = idVoid; break;
duke@1 179 case TYPE_BOOLEAN: id = idBoolean; break;
duke@1 180 case TYPE_BYTE: id = idByte; break;
duke@1 181 case TYPE_CHAR: id = idChar; break;
duke@1 182 case TYPE_SHORT: id = idShort; break;
duke@1 183 case TYPE_INT: id = idInt; break;
duke@1 184 case TYPE_LONG: id = idLong; break;
duke@1 185 case TYPE_FLOAT: id = idFloat; break;
duke@1 186 case TYPE_DOUBLE: id = idDouble; break;
duke@1 187 default: throw new CompilerError("Not a primitive type");
duke@1 188 }
duke@1 189
duke@1 190 setNames(id,null,idlName);
duke@1 191 setRepositoryID();
duke@1 192 }
duke@1 193 }
duke@1 194
duke@1 195 class Null {}

mercurial