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