gnu.java.lang.reflect

Class TypeSignature


public class TypeSignature
extends Object

This class provides static methods that can be used to compute type-signatures of Classs or Members. More specific methods are also provided for computing the type-signature of Constructors and Methods. Methods are also provided to go in the reverse direction.

Method Summary

static Class<T>
getClassForEncoding(String type_code)
Gets the Class object for a type name.
static Class<T>
getClassForEncoding(String type_code, boolean descriptor)
This function is the inverse of getEncodingOfClass.
static Class<T>
getClassForEncoding(String type_code, boolean descriptor, ClassLoader loader)
This function is the inverse of getEncodingOfClass.
static String
getEncodingOfClass(Class<T> clazz)
Gets the descriptor encoding for a class.
static String
getEncodingOfClass(Class<T> clazz, boolean descriptor)
Gets the descriptor encoding for a class.
static String
getEncodingOfClass(String type, boolean descriptor)
Returns a String representing the type-encoding of a class.
static String
getEncodingOfConstructor(Constructor<T> c)
Returns a String representing the type-encoding of a constructor.
static String
getEncodingOfMember(Member mem)
Returns a String representing the type-encoding of a class member.
static String
getEncodingOfMethod(Method m)
Returns a String representing the type-encoding of a method.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Details

getClassForEncoding

public static Class<T> getClassForEncoding(String type_code)
            throws ClassNotFoundException
Gets the Class object for a type name.
Parameters:
type_code - the class name to decode
Returns:
the corresponding Class object
Throws:
ClassNotFoundException - if the class cannot be located

getClassForEncoding

public static Class<T> getClassForEncoding(String type_code,
                                        boolean descriptor)
            throws ClassNotFoundException
This function is the inverse of getEncodingOfClass. This accepts both object and descriptor formats, but must know which style of string is being passed in (usually, descriptor should be true). In descriptor format, "I" is treated as int.class, in object format, it is treated as a class named I in the unnamed package. This method is strictly equivalent to getClassForEncoding(String,boolean,ClassLoader) with a class loader equal to null. In that case, it uses the default class loader on the calling stack.
Parameters:
type_code - the class name to decode
descriptor - if the string is in descriptor format
Returns:
the corresponding Class object
Throws:
ClassNotFoundException - if the class cannot be located

getClassForEncoding

public static Class<T> getClassForEncoding(String type_code,
                                        boolean descriptor,
                                        ClassLoader loader)
            throws ClassNotFoundException
This function is the inverse of getEncodingOfClass. This accepts both object and descriptor formats, but must know which style of string is being passed in (usually, descriptor should be true). In descriptor format, "I" is treated as int.class, in object format, it is treated as a class named I in the unnamed package.
Parameters:
type_code - The class name to decode.
descriptor - If the string is in descriptor format.
loader - The class loader when resolving generic object name. If loader is null then it uses the default class loader on the calling stack.
Returns:
the corresponding Class object.
Throws:
ClassNotFoundException - if the class cannot be located.

getEncodingOfClass

public static String getEncodingOfClass(Class<T> clazz)
Gets the descriptor encoding for a class.
Parameters:
clazz - the class to encode
Returns:
the class name, as it appears in bytecode constant pools

getEncodingOfClass

public static String getEncodingOfClass(Class<T> clazz,
                                        boolean descriptor)
Gets the descriptor encoding for a class.
Parameters:
clazz - the class to encode
descriptor - true to return objects in descriptor format
Returns:
the class name, as it appears in bytecode constant pools

getEncodingOfClass

public static String getEncodingOfClass(String type,
                                        boolean descriptor)
Returns a String representing the type-encoding of a class. The .class file format has different encodings for classes, depending on whether it must be disambiguated from primitive types or not; hence the descriptor parameter to choose between them. If you are planning on decoding primitive types along with classes, then descriptor should be true for correct results. Type-encodings are computed as follows:
 boolean -> "Z"
 byte    -> "B"
 char    -> "C"
 double  -> "D"
 float   -> "F"
 int     -> "I"
 long    -> "J"
 short   -> "S"
 void    -> "V"
 arrays  -> "[" + descriptor format of component type
 object  -> class format: fully qualified name with '.' replaced by '/'
            descriptor format: "L" + class format + ";"
 
Parameters:
type - the class name to encode
descriptor - true to return objects in descriptor format
Returns:
the class name, as it appears in bytecode constant pools

getEncodingOfConstructor

public static String getEncodingOfConstructor(Constructor<T> c)
Returns a String representing the type-encoding of a constructor. The type-encoding of a method is: "(" + parameter type descriptors + ")V" XXX This could be faster if it were implemented natively.
Parameters:
c - the constructor to encode
Returns:
the encoding

getEncodingOfMember

public static String getEncodingOfMember(Member mem)
Returns a String representing the type-encoding of a class member. This appropriately handles Constructors, Methods, and Fields.
Parameters:
mem - the member to encode
Returns:
the encoding

getEncodingOfMethod

public static String getEncodingOfMethod(Method m)
Returns a String representing the type-encoding of a method. The type-encoding of a method is: "(" + parameter type descriptors + ")" + return type descriptor XXX This could be faster if it were implemented natively.
Parameters:
m - the method to encode
Returns:
the encoding

TypeSignature.java -- Class used to compute type signatures Copyright (C) 1998, 2000, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.