gnu.java.lang.reflect
Class TypeSignature
This class provides static methods that can be used to compute
type-signatures of Class
s or Member
s.
More specific methods are also provided for computing the
type-signature of Constructor
s and
Method
s. Methods are also provided to go in the
reverse direction.
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
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.
type_code
- the class name to decodedescriptor
- if the string is in descriptor format
- the corresponding Class object
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.
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.
- the corresponding Class object.
getEncodingOfClass
public static String getEncodingOfClass(Class<T> clazz)
Gets the descriptor encoding for a class.
clazz
- the class to encode
- 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.
clazz
- the class to encodedescriptor
- true to return objects in descriptor format
- 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 + ";"
type
- the class name to encodedescriptor
- true to return objects in descriptor format
- 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.
c
- the constructor to encode
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.
mem
- the member to encode
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.
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.