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

Wed, 28 Mar 2012 02:50:50 -0700

author
mbankal
date
Wed, 28 Mar 2012 02:50:50 -0700
changeset 371
e324dfb90c9e
parent 158
91006f157c46
child 748
6845b95cba6b
permissions
-rw-r--r--

7079902: Refine CORBA data models
Reviewed-by: coffeys

     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 java.util.Vector;
    36 import java.util.HashSet;
    37 import sun.tools.java.CompilerError;
    38 import sun.tools.java.Identifier;
    39 import sun.tools.java.ClassDefinition;
    40 import java.lang.reflect.Array;
    42 /**
    43  * ArrayType is a wrapper for any of the other types. The getElementType()
    44  * method can be used to get the array element type.  The getArrayDimension()
    45  * method can be used to get the array dimension.
    46  *
    47  * @author      Bryan Atsatt
    48  */
    49 public class ArrayType extends Type {
    51     private Type type;
    52     private int arrayDimension;
    53     private String brackets;
    54     private String bracketsSig;
    56     //_____________________________________________________________________
    57     // Public Interfaces
    58     //_____________________________________________________________________
    60     /**
    61      * Create an ArrayType object for the given type.
    62      *
    63      * If the class is not a properly formed or if some other error occurs, the
    64      * return value will be null, and errors will have been reported to the
    65      * supplied BatchEnvironment.
    66      */
    67     public static ArrayType forArray(   sun.tools.java.Type theType,
    68                                         ContextStack stack) {
    71         ArrayType result = null;
    72         sun.tools.java.Type arrayType = theType;
    74         if (arrayType.getTypeCode() == TC_ARRAY) {
    76             // Find real type...
    78             while (arrayType.getTypeCode() == TC_ARRAY) {
    79                 arrayType = arrayType.getElementType();
    80             }
    82             // Do we already have it?
    84             Type existing = getType(theType,stack);
    85             if (existing != null) {
    87                 if (!(existing instanceof ArrayType)) return null; // False hit.
    89                                 // Yep, so return it...
    91                 return (ArrayType) existing;
    92             }
    94             // Now try to make a Type from it...
    96             Type temp = CompoundType.makeType(arrayType,null,stack);
    98             if (temp != null) {
   100                                 // Got a valid one. Make an array type...
   102                 result = new ArrayType(stack,temp,theType.getArrayDimension());
   104                                 // Add it...
   106                 putType(theType,result,stack);
   108                 // Do the stack thing in case tracing on...
   110                 stack.push(result);
   111                 stack.pop(true);
   112             }
   113         }
   115         return result;
   116     }
   118     /**
   119      * Return signature for this type  (e.g. com.acme.Dynamite
   120      * would return "com.acme.Dynamite", byte = "B")
   121      */
   122     public String getSignature() {
   123         return bracketsSig + type.getSignature();
   124     }
   126     /**
   127      * Get element type. Returns null if not an array.
   128      */
   129     public Type getElementType () {
   130         return type;
   131     }
   133     /**
   134      * Get array dimension. Returns zero if not an array.
   135      */
   136     public int getArrayDimension () {
   137         return arrayDimension;
   138     }
   140     /**
   141      * Get brackets string. Returns "" if not an array.
   142      */
   143     public String getArrayBrackets () {
   144         return brackets;
   145     }
   147     /**
   148      * Return a string representation of this type.
   149      */
   150     public String toString () {
   151         return getQualifiedName() + brackets;
   152     }
   154     /**
   155      * Return a string describing this type.
   156      */
   157     public String getTypeDescription () {
   158         return "Array of " + type.getTypeDescription();
   159     }
   162     /**
   163      * Return the name of this type. For arrays, will include "[]" if useIDLNames == false.
   164      * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
   165      * @param useIDLNames If true, print IDL names; otherwise, print java names.
   166      * @param globalIDLNames If true and useIDLNames true, prepends "::".
   167      */
   168     public String getTypeName ( boolean useQualifiedNames,
   169                                 boolean useIDLNames,
   170                                 boolean globalIDLNames) {
   171         if (useIDLNames) {
   172             return super.getTypeName(useQualifiedNames,useIDLNames,globalIDLNames);
   173         } else {
   174             return super.getTypeName(useQualifiedNames,useIDLNames,globalIDLNames) + brackets;
   175         }
   176     }
   178     //_____________________________________________________________________
   179     // Subclass/Internal Interfaces
   180     //_____________________________________________________________________
   183     /**
   184      * Convert all invalid types to valid ones.
   185      */
   186     protected void swapInvalidTypes () {
   187         if (type.getStatus() != STATUS_VALID) {
   188             type = getValidType(type);
   189         }
   190     }
   192     /*
   193      * Add matching types to list. Return true if this type has not
   194      * been previously checked, false otherwise.
   195      */
   196     protected boolean addTypes (int typeCodeFilter,
   197                                 HashSet checked,
   198                                 Vector matching) {
   200         // Check self.
   202         boolean result = super.addTypes(typeCodeFilter,checked,matching);
   204         // Have we been checked before?
   206         if (result) {
   208             // No, so add element type...
   210             getElementType().addTypes(typeCodeFilter,checked,matching);
   211         }
   213         return result;
   214     }
   216     /**
   217      * Create an ArrayType instance for the given type.  The resulting
   218      * object is not yet completely initialized.
   219      */
   220     private ArrayType(ContextStack stack, Type type, int arrayDimension) {
   221         super(stack,TYPE_ARRAY);
   222         this.type = type;
   223         this.arrayDimension = arrayDimension;
   225         // Create our brackets string...
   227         brackets = "";
   228         bracketsSig = "";
   229         for (int i = 0; i < arrayDimension; i ++) {
   230             brackets += "[]";
   231             bracketsSig += "[";
   232         }
   234         // Now set our names...
   236         String idlName = IDLNames.getArrayName(type,arrayDimension);
   237         String[] module = IDLNames.getArrayModuleNames(type);
   238         setNames(type.getIdentifier(),module,idlName);
   240         // Set our repositoryID...
   242         setRepositoryID();
   243     }
   246     /*
   247      * Load a Class instance. Return null if fail.
   248      */
   249     protected Class loadClass() {
   250         Class result = null;
   251         Class elementClass = type.getClassInstance();
   252         if (elementClass != null) {
   253             result = Array.newInstance(elementClass, new int[arrayDimension]).getClass();
   254         }
   255         return result;
   256     }
   258     /**
   259      * Release all resources
   260      */
   261     protected void destroy () {
   262         super.destroy();
   263         if (type != null) {
   264             type.destroy();
   265             type = null;
   266         }
   267         brackets = null;
   268         bracketsSig = null;
   269     }
   270 }

mercurial