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

Thu, 31 Aug 2017 18:10:36 +0800

author
aoqi
date
Thu, 31 Aug 2017 18:10:36 +0800
changeset 748
6845b95cba6b
parent 158
91006f157c46
parent 0
7ef37b2cdcad
permissions
-rw-r--r--

merge

     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.ClassNotFound;
    36 import sun.tools.java.CompilerError;
    37 import sun.tools.java.Identifier;
    38 import sun.tools.java.ClassDefinition;
    40 /**
    41  * SpecialClassType represents any one of the following types:
    42  * <pre>
    43  *    java.lang.Object
    44  *    java.lang.String
    45  * </pre>
    46  * all of which are treated as special cases.
    47  * <p>
    48  * The static forSpecial(...) method must be used to obtain an instance, and
    49  * will return null if the type is non-conforming.
    50  *
    51  * @author      Bryan Atsatt
    52  */
    53 public class SpecialClassType extends ClassType {
    55     //_____________________________________________________________________
    56     // Public Interfaces
    57     //_____________________________________________________________________
    59     /**
    60      * Create a SpecialClassType object for the given class.
    61      *
    62      * If the class is not a properly formed or if some other error occurs, the
    63      * return value will be null, and errors will have been reported to the
    64      * supplied BatchEnvironment.
    65      */
    66     public static SpecialClassType forSpecial (ClassDefinition theClass,
    67                                                ContextStack stack) {
    68         if (stack.anyErrors()) return null;
    70         sun.tools.java.Type type = theClass.getType();
    72         // Do we already have it?
    74         String typeKey = type.toString() + stack.getContextCodeString();
    76         Type existing = getType(typeKey,stack);
    78         if (existing != null) {
    80             if (!(existing instanceof SpecialClassType)) return null; // False hit.
    82             // Yep, so return it...
    84             return (SpecialClassType) existing;
    85         }
    87         // Is it a special type?
    89         int typeCode = getTypeCode(type,theClass,stack);
    91         if (typeCode != TYPE_NONE) {
    93             // Yes...
    95             SpecialClassType result = new SpecialClassType(stack,typeCode,theClass);
    96             putType(typeKey,result,stack);
    97             stack.push(result);
    98             stack.pop(true);
    99             return result;
   101         } else {
   103             return null;
   104         }
   105     }
   107     /**
   108      * Return a string describing this type.
   109      */
   110     public String getTypeDescription () {
   111         return "Special class";
   112     }
   114     //_____________________________________________________________________
   115     // Subclass/Internal Interfaces
   116     //_____________________________________________________________________
   118     /**
   119      * Create an SpecialClassType instance for the given class.
   120      */
   121     private SpecialClassType(ContextStack stack, int typeCode,
   122                              ClassDefinition theClass) {
   123         super(stack,typeCode | TM_SPECIAL_CLASS | TM_CLASS | TM_COMPOUND, theClass);
   124         Identifier id = theClass.getName();
   125         String idlName = null;
   126         String[] idlModuleName = null;
   127         boolean constant = stack.size() > 0 && stack.getContext().isConstant();
   129         // Set names...
   131         switch (typeCode) {
   132         case TYPE_STRING:   {
   133             idlName = IDLNames.getTypeName(typeCode,constant);
   134             if (!constant) {
   135                 idlModuleName = IDL_CORBA_MODULE;
   136             }
   137             break;
   138         }
   140         case TYPE_ANY:   {
   141             idlName = IDL_JAVA_LANG_OBJECT;
   142             idlModuleName = IDL_JAVA_LANG_MODULE;
   143             break;
   144         }
   145         }
   147         setNames(id,idlModuleName,idlName);
   149         // Init parents...
   151         if (!initParents(stack)) {
   153             // Should not be possible!
   155             throw new CompilerError("SpecialClassType found invalid parent.");
   156         }
   158         // Initialize CompoundType...
   160         initialize(null,null,null,stack,false);
   161     }
   163     private static int getTypeCode(sun.tools.java.Type type, ClassDefinition theClass, ContextStack stack) {
   164         if (type.isType(TC_CLASS)) {
   165             Identifier id = type.getClassName();
   166             if (id == idJavaLangString) return TYPE_STRING;
   167             if (id == idJavaLangObject) return TYPE_ANY;
   168         }
   169         return TYPE_NONE;
   170     }
   171 }

mercurial