corba/src/jdk.rmic/share/classes/sun/rmi/rmic/iiop/SpecialClassType.java
author gtriantafill
Wed, 14 Sep 2016 08:17:50 -0400
changeset 41092 c388d897472d
parent 25862 a5e25d68f971
permissions -rw-r--r--
8165889: Remove jdk.test.lib.unsafe.UnsafeHelper Summary: Remove use of setAccessible() to get Unsafe. Reviewed-by: shade, lfoltan
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.ClassNotFound;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import sun.tools.java.CompilerError;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import sun.tools.java.Identifier;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import sun.tools.java.ClassDefinition;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
 * SpecialClassType represents any one of the following types:
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
 * <pre>
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
 *    java.lang.Object
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
 *    java.lang.String
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
 * </pre>
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
 * all of which are treated as special cases.
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
 * The static forSpecial(...) method must be used to obtain an instance, and
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
 * will return null if the type is non-conforming.
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
 * @author      Bryan Atsatt
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
public class SpecialClassType extends ClassType {
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
    // Public Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
     * Create a SpecialClassType object for the given class.
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
     * If the class is not a properly formed or if some other error occurs, the
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
     * return value will be null, and errors will have been reported to the
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
     * supplied BatchEnvironment.
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
    public static SpecialClassType forSpecial (ClassDefinition theClass,
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
                                               ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
        if (stack.anyErrors()) return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
        sun.tools.java.Type type = theClass.getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
        // Do we already have it?
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
        String typeKey = type.toString() + stack.getContextCodeString();
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        Type existing = getType(typeKey,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
        if (existing != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
            if (!(existing instanceof SpecialClassType)) return null; // False hit.
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
            // Yep, so return it...
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
            return (SpecialClassType) existing;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
        // Is it a special type?
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
        int typeCode = getTypeCode(type,theClass,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
        if (typeCode != TYPE_NONE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
            // Yes...
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
            SpecialClassType result = new SpecialClassType(stack,typeCode,theClass);
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
            putType(typeKey,result,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
            stack.push(result);
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
            stack.pop(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
            return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
            return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
        }
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 a string describing this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
    public String getTypeDescription () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
        return "Special class";
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
    // Subclass/Internal Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
     * Create an SpecialClassType instance for the given class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    private SpecialClassType(ContextStack stack, int typeCode,
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
                             ClassDefinition theClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
        super(stack,typeCode | TM_SPECIAL_CLASS | TM_CLASS | TM_COMPOUND, theClass);
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
        Identifier id = theClass.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
        String idlName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
        String[] idlModuleName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
        boolean constant = stack.size() > 0 && stack.getContext().isConstant();
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
        // Set names...
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
        switch (typeCode) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
        case TYPE_STRING:   {
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
            idlName = IDLNames.getTypeName(typeCode,constant);
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
            if (!constant) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
                idlModuleName = IDL_CORBA_MODULE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
        case TYPE_ANY:   {
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
            idlName = IDL_JAVA_LANG_OBJECT;
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
            idlModuleName = IDL_JAVA_LANG_MODULE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        setNames(id,idlModuleName,idlName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
        // Init parents...
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
        if (!initParents(stack)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
            // Should not be possible!
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
            throw new CompilerError("SpecialClassType found invalid parent.");
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        // Initialize CompoundType...
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        initialize(null,null,null,stack,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    private static int getTypeCode(sun.tools.java.Type type, ClassDefinition theClass, ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
        if (type.isType(TC_CLASS)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
            Identifier id = type.getClassName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
            if (id == idJavaLangString) return TYPE_STRING;
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
            if (id == idJavaLangObject) return TYPE_ANY;
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
        return TYPE_NONE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
}