com.bluemarsh.jswat.util
Class ClassUtils

java.lang.Object
  |
  +--com.bluemarsh.jswat.util.ClassUtils
All Implemented Interfaces:
com.bluemarsh.config.ConfigureListener, java.util.EventListener

public class ClassUtils
extends java.lang.Object
implements com.bluemarsh.config.ConfigureListener

Class ClassUtils provides a set of utility functions for dealing with classes.

Author:
Nathan Fiedler

Field Summary
protected static ClassUtils instance
          Reference to the single instance of this class.
protected static boolean trimClassNames
          Indicates whether we shoud trim class names or not.
 
Constructor Summary
protected ClassUtils()
          Constructor that sets up the instance to listen for configuration changes.
 
Method Summary
static java.lang.String callToString(com.sun.jdi.ObjectReference obj, com.sun.jdi.ThreadReference thread)
          Call the toString() method on the given object.
 void configurationChanged()
          Invoked when the configuration has been accepted by the user.
static com.sun.jdi.Method findMethod(com.sun.jdi.ReferenceType clazz, java.lang.String methodId, java.util.List methodArgs)
          Attempt an unambiguous match of the method name and argument specification to a method.
protected static com.sun.jdi.ReferenceType getReferenceFromName(java.lang.String cname, com.sun.jdi.VirtualMachine vm)
          Find the ReferenceType object for a given class.
static ClassUtils instanceOf()
          Returns the reference to the single instance of this class.
static boolean isJavaIdentifier(java.lang.String s)
          Determine if the given string is a valid Java identifier.
static boolean isPrimitive(java.lang.String s)
          Returns true if the passed string is a primitive type.
static java.lang.String justTheName(java.lang.String cname)
          Returns just the name of the class, without the package name.
protected static java.lang.String normalizeArgTypeName(java.lang.String name, com.sun.jdi.VirtualMachine vm)
          Remove unneeded spaces and expand class names to fully qualified names, if necessary and possible.
protected static boolean tryPrimitives(java.lang.String candidate, java.lang.String given)
          Compare the named types to determine if they are compatible by one being a class type representing the primitive form of the other.
protected static boolean tryUpCasting(java.lang.String candidate, java.lang.String given)
          Compare the named types to determine if up-casting is possible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

protected static ClassUtils instance
Reference to the single instance of this class.

trimClassNames

protected static boolean trimClassNames
Indicates whether we shoud trim class names or not.
Constructor Detail

ClassUtils

protected ClassUtils()
Constructor that sets up the instance to listen for configuration changes.
Method Detail

callToString

public static java.lang.String callToString(com.sun.jdi.ObjectReference obj,
                                            com.sun.jdi.ThreadReference thread)
Call the toString() method on the given object.
Parameters:
obj - object on which to call toString().
thread - thread on which to call toString() on obj.
Returns:
Return value from obj.toString(), or null if there was any problem.

configurationChanged

public void configurationChanged()
Invoked when the configuration has been accepted by the user.
Specified by:
configurationChanged in interface com.bluemarsh.config.ConfigureListener

findMethod

public static com.sun.jdi.Method findMethod(com.sun.jdi.ReferenceType clazz,
                                            java.lang.String methodId,
                                            java.util.List methodArgs)
                                     throws AmbiguousClassSpecException,
                                            AmbiguousMethodException,
                                            java.lang.NoSuchMethodException
Attempt an unambiguous match of the method name and argument specification to a method. If no arguments are specified, the method must not be overloaded. Otherwise, the argument types must match exactly.
Parameters:
clazz - class in which to find method.
methodId - name of method to find.
methodArgs - list of method argument types.
Returns:
Method if found, null otherwise.
Throws:
AmbiguousClassSpecException - Thrown if the given pattern matches more than one class.
AmbiguousMethodException - Thrown if the method is overloaded.
java.lang.NoSuchMethodException - Thrown if the method could not be found.

getReferenceFromName

protected static com.sun.jdi.ReferenceType getReferenceFromName(java.lang.String cname,
                                                                com.sun.jdi.VirtualMachine vm)
                                                         throws AmbiguousClassSpecException
Find the ReferenceType object for a given class.
Parameters:
cname - Class identifier for which to get reference.
vm - Virtual machine from which to get reference.
Returns:
ReferenceType for this class, or null if none.
Throws:
AmbiguousClassSpecException - Thrown if the given pattern matches more than one class.

instanceOf

public static ClassUtils instanceOf()
Returns the reference to the single instance of this class. If an instance does not exist it will be created.
Returns:
the instance of this class.

isJavaIdentifier

public static boolean isJavaIdentifier(java.lang.String s)
Determine if the given string is a valid Java identifier.
Parameters:
s - string to validate.
Returns:
true if string is a valid Java identifier.

isPrimitive

public static boolean isPrimitive(java.lang.String s)
Returns true if the passed string is a primitive type.
Parameters:
s - string suspected of naming a primitive type.
Returns:
true if 's' names a primitive, false otherwise.

justTheName

public static java.lang.String justTheName(java.lang.String cname)
Returns just the name of the class, without the package name.
Parameters:
cname - Name of class, possibly fully-qualified.
Returns:
Just the class name.

normalizeArgTypeName

protected static java.lang.String normalizeArgTypeName(java.lang.String name,
                                                       com.sun.jdi.VirtualMachine vm)
                                                throws AmbiguousClassSpecException
Remove unneeded spaces and expand class names to fully qualified names, if necessary and possible.
Parameters:
name - Name of class.
vm - Virtual machine to normalize against.
Returns:
Fully qualified name of class.
Throws:
AmbiguousClassSpecException - Thrown if the given pattern matches more than one class.

tryPrimitives

protected static boolean tryPrimitives(java.lang.String candidate,
                                       java.lang.String given)
Compare the named types to determine if they are compatible by one being a class type representing the primitive form of the other. That is, if one argument is a primitive type and the other is the class type that represents that primitive, return true. Otherwise, return false.
Parameters:
candidate - type we are trying to match.
given - type the user specified, which may be up-cast.
Returns:
true if types are equivalent, false otherwise.

tryUpCasting

protected static boolean tryUpCasting(java.lang.String candidate,
                                      java.lang.String given)
Compare the named types to determine if up-casting is possible. Note that this only works with class types that represent primitive numeric types (byte, short, integer, long, float, double).
Parameters:
candidate - type we are trying to match.
given - type the user specified, which may be up-cast.
Returns:
true if up-cast is possible, false otherwise.