com.claritysys.util
Class Java

java.lang.Object
  extended by com.claritysys.util.Java

public final class Java
extends java.lang.Object

A collection of utility methods dealing with Java class issues.

Version:
$Revision: 2348 $ $Date: 2004-12-01 16:12:21 -0800 (Wed, 01 Dec 2004) $

Constructor Summary
Java()
           
 
Method Summary
static java.lang.String getDeclaration(java.lang.Class type)
          Return a proper Java type declaration given a class.
static java.lang.String getPackageName(java.lang.Class theClass)
          Return the package name for the given class, null if it isn't in a package.
static java.lang.String getPackageName(java.lang.String theClass)
          Return the name of the package for the given class, or null if it isn't in a package.
static java.lang.String getShortName(java.lang.Class type)
          Get the "short" name of the given class, ie the name without the package prefix.
static java.lang.String getShortName(java.lang.String name)
          Get the "short" name of the given class, ie the name without the package prefix.
static java.lang.String getShortNameInternal(java.lang.String name)
          Get the "short" name of the given class, ie the name without the package prefix, based on the input String being in Java internal format, using "/" instead of "." as a separator.
static java.lang.String getVmSignature(java.lang.Class type)
          Return the VM type signature for the given class.
static java.lang.String getVmSignature(java.lang.Class[] paramTypes, java.lang.Class returnType)
          Generate a Virtual Machine formed method signature given the classes of the parameters and return type, as from invoking Method.getParameterTypes()/Method.getReturnType ().
static void getVmSignature(java.lang.Class type, java.lang.StringBuffer s)
          Convert the given Class type to an internal signature, such as "I" for Integer.TYPE, or "Ljava/lang/String;" for String.class.
static java.lang.Class toAbstractClass(java.lang.Class implClass)
          Return the first abstract superclass of the class, or the class itself if it is abstract.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Java

public Java()
Method Detail

getDeclaration

public static java.lang.String getDeclaration(java.lang.Class type)
Return a proper Java type declaration given a class.

This is needed because a class may represent an array, in which case its name is "[b foobar" or similar.

The returned declaration String is suitable for generating Java source code.

Parameters:
type - A Java class.
Returns:
A legal Java type declaration, suitable for code generation (Java source code).

getShortName

public static java.lang.String getShortName(java.lang.Class type)
Get the "short" name of the given class, ie the name without the package prefix.

If the class is not in a package its name is returned, otherwise the package name is stripped off and the short name is returned.

Array types do not have a short name.

Parameters:
type - A Java class.
Returns:
The short classname, ie the classname without a package name.

getShortName

public static java.lang.String getShortName(java.lang.String name)
Get the "short" name of the given class, ie the name without the package prefix.

If the class is not in a package its name is returned, otherwise the package name is stripped off and the short name is returned.

Array types do not have a short name.

Parameters:
name - The short or full classname to convert to simply a short name.
Returns:
The short classname, ie the classname without a package name.

getShortNameInternal

public static java.lang.String getShortNameInternal(java.lang.String name)
Get the "short" name of the given class, ie the name without the package prefix, based on the input String being in Java internal format, using "/" instead of "." as a separator.

If the class is not in a package its name is returned, otherwise the package name is stripped off and the short name is returned.

Array types do not have a short name.

Parameters:
name - The short or full classname to convert to simply a short name.
Returns:
The short classname, ie the classname without a package name.

toAbstractClass

public static java.lang.Class toAbstractClass(java.lang.Class implClass)
Return the first abstract superclass of the class, or the class itself if it is abstract.

This is useful when handed an implementation of a class, and it is desired to find the abstract class being implemented.

Parameters:
implClass - A Java class.
Returns:
the first abstract superclass of the class, or the class itself if it is abstract.

getPackageName

public static java.lang.String getPackageName(java.lang.Class theClass)
Return the package name for the given class, null if it isn't in a package.

Parameters:
theClass - The Class for which to compute a package name.
Returns:
the name of the package for the given class or null (if its in the default package).

getPackageName

public static java.lang.String getPackageName(java.lang.String theClass)
Return the name of the package for the given class, or null if it isn't in a package.

Parameters:
theClass - The class name as a String.
Returns:
the name of the package for the given class or null (if its in the default package).

getVmSignature

public static java.lang.String getVmSignature(java.lang.Class[] paramTypes,
                                              java.lang.Class returnType)
Generate a Virtual Machine formed method signature given the classes of the parameters and return type, as from invoking Method.getParameterTypes()/Method.getReturnType ().

For example, this will translate the reflected Method "System.out.println (String)" into "(Ljava/lang/String;)V".

Parameters:
paramTypes - Non-null but possibly zero length array of Class for types of parameters.
returnType - Non-null Class describing method return type.
Returns:
VM signature, such as "()V".

getVmSignature

public static void getVmSignature(java.lang.Class type,
                                  java.lang.StringBuffer s)
Convert the given Class type to an internal signature, such as "I" for Integer.TYPE, or "Ljava/lang/String;" for String.class.

Parameters:
type - The type to convert, a Class or Integer.TYPE, etc.
s - The StringBuffer to append to.

getVmSignature

public static java.lang.String getVmSignature(java.lang.Class type)
Return the VM type signature for the given class.

Parameters:
type - An object or primitive class type.
Returns:
VM type signature such as "I" or "Ljava/lang/String;".


Copyright ? 2002 Clarity Systems Group, LLC. All Rights Reserved.