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

     1 /*
     2  * Copyright (c) 1998, 2007, Oracle and/or its affiliates. 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.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 /*
    27  * Licensed Materials - Property of IBM
    28  * RMI-IIOP v1.0
    29  * Copyright IBM Corp. 1998 1999  All Rights Reserved
    30  *
    31  */
    33 package sun.rmi.rmic.iiop;
    35 import sun.tools.java.CompilerError;
    36 import sun.tools.java.Identifier;
    37 import sun.tools.java.ClassDefinition;
    39 /**
    40  * PrimitiveType wraps primitive types and void.
    41  * <p>
    42  * The static forPrimitive(...) method must be used to obtain an instance, and
    43  * will return null if the type is non-conforming.
    44  *
    45  * @author      Bryan Atsatt
    46  */
    47 public class PrimitiveType extends Type {
    49     //_____________________________________________________________________
    50     // Public Interfaces
    51     //_____________________________________________________________________
    53     /**
    54      * Create a PrimitiveType object for the given type.
    55      *
    56      * If the type is not a properly formed or if some other error occurs, the
    57      * return value will be null, and errors will have been reported to the
    58      * supplied BatchEnvironment.
    59      */
    60     public static PrimitiveType forPrimitive(sun.tools.java.Type type,
    61                                              ContextStack stack) {
    63         if (stack.anyErrors()) return null;
    65         // Do we already have it?
    67         Type existing = getType(type,stack);
    69         if (existing != null) {
    71             if (!(existing instanceof PrimitiveType)) return null; // False hit.
    73             // Yep, so return it...
    75             return (PrimitiveType) existing;
    76         }
    78         int typeCode;
    80         switch (type.getTypeCode()) {
    81         case TC_VOID:           typeCode = TYPE_VOID; break;
    82         case TC_BOOLEAN:        typeCode = TYPE_BOOLEAN; break;
    83         case TC_BYTE:           typeCode = TYPE_BYTE; break;
    84         case TC_CHAR:           typeCode = TYPE_CHAR; break;
    85         case TC_SHORT:          typeCode = TYPE_SHORT; break;
    86         case TC_INT:            typeCode = TYPE_INT; break;
    87         case TC_LONG:           typeCode = TYPE_LONG; break;
    88         case TC_FLOAT:          typeCode = TYPE_FLOAT; break;
    89         case TC_DOUBLE:         typeCode = TYPE_DOUBLE; break;
    90         default: return null;
    91         }
    93         PrimitiveType it = new PrimitiveType(stack,typeCode);
    95         // Add it...
    97         putType(type,it,stack);
    99         // Do the stack thing in case tracing on...
   101         stack.push(it);
   102         stack.pop(true);
   104         return it;
   105     }
   107     /**
   108      * Return signature for this type  (e.g. com.acme.Dynamite
   109      * would return "com.acme.Dynamite", byte = "B")
   110      */
   111     public String getSignature() {
   112         switch (getTypeCode()) {
   113         case TYPE_VOID:         return SIG_VOID;
   114         case TYPE_BOOLEAN:      return SIG_BOOLEAN;
   115         case TYPE_BYTE:         return SIG_BYTE;
   116         case TYPE_CHAR:         return SIG_CHAR;
   117         case TYPE_SHORT:    return SIG_SHORT;
   118         case TYPE_INT:          return SIG_INT;
   119         case TYPE_LONG:         return SIG_LONG;
   120         case TYPE_FLOAT:        return SIG_FLOAT;
   121         case TYPE_DOUBLE:       return SIG_DOUBLE;
   122         default:            return null;
   123         }
   124     }
   126     /**
   127      * Return a string describing this type.
   128      */
   129     public String getTypeDescription () {
   130         return "Primitive";
   131     }
   133     /**
   134      * IDL_Naming
   135      * Return the fully qualified IDL name for this type (e.g. com.acme.Dynamite would
   136      * return "com::acme::Dynamite").
   137      * @param global If true, prepends "::".
   138      */
   139     public String getQualifiedIDLName(boolean global) {
   140         return super.getQualifiedIDLName(false);
   141     }
   143     //_____________________________________________________________________
   144     // Subclass/Internal Interfaces
   145     //_____________________________________________________________________
   147     /*
   148      * Load a Class instance. Return null if fail.
   149      */
   150     protected Class loadClass() {
   151         switch (getTypeCode()) {
   152         case TYPE_VOID:         return Null.class;
   153         case TYPE_BOOLEAN:      return boolean.class;
   154         case TYPE_BYTE:         return byte.class;
   155         case TYPE_CHAR:         return char.class;
   156         case TYPE_SHORT:        return short.class;
   157         case TYPE_INT:          return int.class;
   158         case TYPE_LONG:         return long.class;
   159         case TYPE_FLOAT:        return float.class;
   160         case TYPE_DOUBLE:       return double.class;
   161         default:            throw new CompilerError("Not a primitive type");
   162         }
   163     }
   165     /**
   166      * IDL_Naming
   167      * Create an PrimitiveType instance for the given class.
   168      */
   169     private PrimitiveType(ContextStack stack, int typeCode) {
   170         super(stack,typeCode | TM_PRIMITIVE);
   172         // Validate type and set names...
   174         String idlName = IDLNames.getTypeName(typeCode,false);
   175         Identifier id = null;
   177         switch (typeCode) {
   178         case TYPE_VOID:         id = idVoid; break;
   179         case TYPE_BOOLEAN:      id = idBoolean; break;
   180         case TYPE_BYTE:         id = idByte; break;
   181         case TYPE_CHAR:         id = idChar; break;
   182         case TYPE_SHORT:        id = idShort; break;
   183         case TYPE_INT:          id = idInt; break;
   184         case TYPE_LONG:         id = idLong; break;
   185         case TYPE_FLOAT:        id = idFloat; break;
   186         case TYPE_DOUBLE:       id = idDouble; break;
   187         default:            throw new CompilerError("Not a primitive type");
   188         }
   190         setNames(id,null,idlName);
   191         setRepositoryID();
   192     }
   193 }
   195 class Null {}

mercurial