|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.jpf.JPFHelper
Class JPFHelper collects utility methods that
in earlier releases of the Java Power Framework were located
in various other classes of the jpf package.
To support applets, earlier methods that directly used the
JPT console object that is defined in the
interface ConsoleAware have been refactored to
remove such references and to instead return String
data that may be used as desired by the caller.
In 2.7.0, this class used getDeclaredMethods
from class Class. It turns out that calling this
method in an applet in a browser causes a security exception.
Hence, this revision (2.7.0a) uses getMethods
from class Class instead. The name of the method
getExtraMethods has been changed to
getPublicMethods to emphasize that we now extract
only public methods.
Also, in 2.7.0a, we added a method getClassChain
that gets the chain of super classes starting from a given class.
| Field Summary | |
private static Object[][] |
primitivePairs
The array primitivePairs pairs
a primitive type,
the Java wrapper for a primitive type, or
the Stringable wrapper for a primitive type
with its corresponding Stringable wrapper. |
private static QuickHashtable |
primitiveTable
The hash table primitiveTable pairs
a primitive type,
the Java wrapper for a primitive type, or
the Stringable wrapper for a primitive type
with its corresponding Stringable wrapper. |
| Constructor Summary | |
private |
JPFHelper()
Prevent instantiation. |
| Method Summary | |
static void |
acceptJPFMethods(Method[] methods)
Retains those methods in the given methods array that are JPF methods and sets the other array slots to null. |
static String |
className(Class c)
Returns the unqualified name of the given Class. |
static String |
classQualifier(Class c)
Returns the qualifier of the given Class. |
static String |
getAdaptedExceptionTrace(Throwable exception,
Method method)
Returns an adapted exception trace string for an exception that is thrown in the execution of a JPF method with the given method name. |
static Class[] |
getClassChain(Class c,
Class d)
Returns the chain of classes starting with the given class c first and proceeding back to but not including class d. |
static String |
getMethodToolTip(Method method)
Returns a tool tip appropriate for the given method. |
static String |
getParameterNames(Method method)
Returns a String representing the parameters of the method. |
static Class |
getPrimitiveStringable(Class c)
If the given class is similar to a primitive type, then returns the associated Stringable class. |
static Method[] |
getPublicMethods(Class c,
Class d)
Returns the public methods in Class c that
do not come from the base Class d. |
static boolean |
isAbstract(Method method)
Returns true if the method is abstract. |
static boolean |
isAcceptableTypeForParameter(Class c)
Returns true if the type is acceptable for a method parameter in the JPF. |
static boolean |
isAcceptableTypeForReturn(Class c)
Returns true if the type is acceptable for a method return in the JPF. |
static boolean |
isDuplicate(Method method1,
Method method2)
Returns true if the two methods have the same signature. |
static boolean |
isDuplicateParameterList(Method method1,
Method method2)
Returns true if the two methods have the same parameter list types in the same order. |
static boolean |
isGUIMethod(Method method)
Returns true if the method should be converted to a button with a method GUI in the JPF. |
static boolean |
isJPFMethod(Method method)
Returns true if the method should define a button in the JPF. |
static boolean |
isPublic(Method method)
Returns true if the method is public. |
static boolean |
isSimilarToPrimitive(Class c)
Returns true if the given class corresponds to a primitive type, the Java wrapper for a primitive type, or the Stringable wrapper for a primitive type. |
static boolean |
isSimpleMethod(Method method)
Returns true if the method should be converted to a simple button in the JPF. |
static boolean |
isStatic(Method method)
Returns true if the method is static. |
static Method[] |
joinMethodArrays(Method[] listA,
Method[] listB)
Joins two Method arrays into one. |
static String |
nameQualifier(String name)
Returns the substring of the given string that corresponds to the qualifier of a qualified name. |
static void |
removeDuplicateVirtualMethods(Method[] methods)
Removes duplicate virtual methods defined in several classes. |
static String |
simpleName(String name)
Returns the substring of the given string that corresponds to a simple name, that is, one with all qualifiers removed. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private static Object[][] primitivePairs
The array primitivePairs pairs
a primitive type,
the Java wrapper for a primitive type, or
the Stringable wrapper for a primitive type
with its corresponding Stringable wrapper.
Specifically, the types that are paired are:
| Primitive | Java wrapper | Stringable |
byte |
Byte |
XByte |
short |
Short |
XShort |
int |
Integer |
XInt |
long |
Long |
XLong |
float |
Float |
XFloat |
double |
Double |
XDouble |
char |
Character |
XChar |
boolean |
Boolean |
XBoolean |
A Stringable type is paired with itself.
This array is used to construct the corresponding hash table that makes the same mapping.
private static QuickHashtable primitiveTable
The hash table primitiveTable pairs
a primitive type,
the Java wrapper for a primitive type, or
the Stringable wrapper for a primitive type
with its corresponding Stringable wrapper.
Specifically, the types that are paired are:
| Primitive | Java wrapper | Stringable |
byte |
Byte |
XByte |
short |
Short |
XShort |
int |
Integer |
XInt |
long |
Long |
XLong |
float |
Float |
XFloat |
double |
Double |
XDouble |
char |
Character |
XChar |
boolean |
Boolean |
XBoolean |
A Stringable type is paired with itself.
| Constructor Detail |
private JPFHelper()
| Method Detail |
public static boolean isPublic(Method method)
Returns true if the method is public.
method - the method to testpublic static boolean isStatic(Method method)
Returns true if the method is static.
method - the method to testpublic static boolean isAbstract(Method method)
Returns true if the method is abstract.
method - the method to testpublic static boolean isJPFMethod(Method method)
Returns true if the method should define a button in the JPF.
Critera:
null methodmainpublicEquivalently, either isSimpleMethod or isGUIMethod
must return true.
method - the method to testisAcceptableTypeForParameter(Class),
isAcceptableTypeForReturn(Class),
isSimpleMethod(Method),
isGUIMethod(Method)public static boolean isSimpleMethod(Method method)
Returns true if the method should be converted to a simple button in the JPF.
Critera:
null methodmainpublicvoid
method - the method to testisJPFMethod(Method)public static boolean isGUIMethod(Method method)
Returns true if the method should be converted to a button with a method GUI in the JPF.
Critera:
null methodmainpublicvoid and has no parameters
method - the method to testisAcceptableTypeForParameter(Class),
isAcceptableTypeForReturn(Class),
isJPFMethod(Method)public static boolean isSimilarToPrimitive(Class c)
Returns true if the given class corresponds to
a primitive type,
the Java wrapper for a primitive type, or
the Stringable wrapper for a primitive type.
Specifically, this method returns true for the
Class object of one of the following types:
| Primitive | Java wrapper | Stringable |
byte |
Byte |
XByte |
short |
Short |
XShort |
int |
Integer |
XInt |
long |
Long |
XLong |
float |
Float |
XFloat |
double |
Double |
XDouble |
char |
Character |
XChar |
boolean |
Boolean |
XBoolean |
Remark: The Java class Class has a method
isPrimitive() that returns true for the 8
primitive class types and also for void.class.
This method does not follow that convention but rather
returns false for void.class.
c - the class of the type to testgetPrimitiveStringable(Class)public static Class getPrimitiveStringable(Class c)
Stringable class.
c - the class of the type to testisSimilarToPrimitive(Class)public static boolean isAcceptableTypeForParameter(Class c)
Returns true if the type is acceptable for a method parameter in the JPF.
Critera:
nullStringableStringBigIntegerBigDecimalColor
c - the class to testisAcceptableTypeForReturn(Class)public static boolean isAcceptableTypeForReturn(Class c)
Returns true if the type is acceptable for a method return in the JPF.
Critera:
null classStringableStringBigIntegerBigDecimalPaintvoid
c - the class to testisAcceptableTypeForParameter(Class)
public static Class[] getClassChain(Class c,
Class d)
Returns the chain of classes starting with the given class c first and proceeding back to but not including class d.
Returns an empty array if c is null
or c equals d.
c - the start classd - the stop class
public static Method[] getPublicMethods(Class c,
Class d)
Returns the public methods in Class c that
do not come from the base Class d.
Calls the Java method getMethods() in
class Class. This Java method returns all
public methods from the Class c used in its
call. The purpose of this method is to prune the methods
arising from Class d or its super classes.
The methods will also be sorted so that the methods of
Class c are first, then the super class of c,
etc. This is actually the current organization of the
returned methods from getMethods() but since
the Java documentation does not guarantee this order, we
do not assume this in our code.
Within methods declared in a given class, the ordering
of the methods returned will be identical to the ordering
supplied by the Java method getMethods().
This method will work if the base class is null.
In that case, it will return all methods defined in c or in its
super classes.
This method may return an empty Method[] but
will never return null.
c - a possible derived classd - a possible base class for c
public static Method[] joinMethodArrays(Method[] listA,
Method[] listB)
Joins two Method arrays into one.
listA - method array 1listB - method array 2public static void acceptJPFMethods(Method[] methods)
Retains those methods in the given methods array that are JPF
methods and sets the other array slots to null.
In particular, the given methods array object is unchanged but
some of its array slots may be set to null.
Note that the non-null methods that remain in the
array are public and not abstract.
methods - the methods array to scanremoveDuplicateVirtualMethods(Method[])public static void removeDuplicateVirtualMethods(Method[] methods)
Removes duplicate virtual methods defined in several classes. Also removes abstract methods since they cannot be invoked.
The algorithm assumes that methods declared in a given class
occur before methods defined in a super class. This is in fact
the order provided by getPublicMethods.
In particular, the given methods array object is unchanged but
some of its array slots may be set to null.
methods - the methods array to scanacceptJPFMethods(Method[])
public static boolean isDuplicate(Method method1,
Method method2)
Returns true if the two methods have the same signature.
method1 - method 1 to comparemethod2 - method 2 to compareisDuplicateParameterList(Method, Method)
public static boolean isDuplicateParameterList(Method method1,
Method method2)
Returns true if the two methods have the same parameter list types in the same order.
Helper method for isDuplicate.
method1 - method 1 to comparemethod2 - method 2 to compareisDuplicate(Method, Method)public static String className(Class c)
Returns the unqualified name of the given Class.
Returns "null" if the given Class is
null.
Note: The Java method call c.getName() returns what
is called the fully qualified name, that is, the name with the
sequence of package names separated by periods placed in front.
This method returns just the name.
c - the class to querypublic static String classQualifier(Class c)
Returns the qualifier of the given Class.
Returns "null" if the given Class is
null.
Note: The Java method call c.getName() returns what
is called the fully qualified name, that is, the name with the
sequence of package names separated by periods placed in front.
This method returns just the qualifier.
c - the class to querypublic static String simpleName(String name)
Returns the substring of the given string that corresponds to a simple name, that is, one with all qualifiers removed.
Finds that last index of the period character and returns the substring that begins after that character.
Returns the name unchanged if it is null or has
no period character.
public static String nameQualifier(String name)
Returns the substring of the given string that corresponds to the qualifier of a qualified name.
Finds that last index of the period character and returns the substring that begins before that character.
Returns an empty string if the name has no period character or if the last period is in position 0.
Returns null if the name is null.
public static String getMethodToolTip(Method method)
Returns a tool tip appropriate for the given method.
method - the method to express as a tool tipgetParameterNames(Method)public static String getParameterNames(Method method)
Returns a String representing the parameters of the method.
Helper method for getMethodToolTip.
method - the method to express as a tool tipgetMethodToolTip(Method)
public static String getAdaptedExceptionTrace(Throwable exception,
Method method)
Returns an adapted exception trace string for an exception that is thrown in the execution of a JPF method with the given method name.
The adaption to the exception trace is to remove reference to the use of reflection in JPF from the tail of the exception trace. Header info is also prepended to the trace to increase clarity.
exception - the exception being thrownmethod - the method being executed
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||