edu.neu.ccs.jpf
Class JPFExtras

java.lang.Object
  extended byedu.neu.ccs.jpf.JPFExtras
All Implemented Interfaces:
JPTConstants, SwingConstants

public class JPFExtras
extends Object
implements JPTConstants

Provides some utility methods for use in the Java Power Framework or elsewhere in the Java Power Tools. These methods may be used to test if a class contains a required set of constructors and/or methods and may be used to provide interactive feedback to a user via a dialog box if desired.

Prior to 2.7.0, this class was named JPFBase and was a base class for JPF. With the introduction of JPFApplet, this design no longer made sense because an applet must derive from the Java Applet class. Therefore, the class was renamed JPFExtras and its important methods and internal classes were made public static.

In the following examples, Foo will represent the name of some class being tested. In all examples, a dialog will be shown if some required constructor or method is missing.

Example 1: To test if Foo declares certain constructors, use:

    return JPFExtras.declaresConstructors(Foo.class,
         new String[] {
             "public Foo()",
             "public Foo(int x)",
             "public Foo(int x, int y)" } );

Example 2: To test if Foo declares certain methods, use:

    return JPFExtras.declaresMethods(Foo.class,
         new String[] {
             "public void setX(int x)",
             "public int xValue()",
             "public void setY(int y)",
             "public int yValue()" } );

Example 3: To test if Foo declares certain constructors and methods, use:

    return JPFExtras.declaresConstructorsAndMethods(Foo.class,
         new String[] {
             "public Foo()",
             "public Foo(int x)",
             "public Foo(int x, int y)" },
         new String[] {
             "public void setX(int x)",
             "public int xValue()",
             "public void setY(int y)",
             "public int yValue()" } );

Example 4: To test if Foo or a super class provides certain constructors and methods, replaces "declares..." with "provides..." in Example 3.

Since:
2.2
Version:
2.7.0

Nested Class Summary
static class JPFExtras.ConstructorSignature
          Encapsulates constructor signature attributes.
static class JPFExtras.MemberSignature
          Encapsulates the member signature attributes for a class member.
static class JPFExtras.MethodSignature
          Encapsulates a method signature.
static class JPFExtras.ParametrizedSignature
          Encapsulates a parametrized member signature where the parameters are specified with both a type and an optional parameter name.
 
Field Summary
private static PaintAction CHECK_ACTION
          GUI component representing a green check mark.
private static PaintAction X_ACTION
          GUI component representing a red X mark.
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
JPFExtras()
           
 
Method Summary
static boolean declaresConstructor(Class c, String constructor)
          Returns true if the given class declares the constructor with the given signature, and, otherwise, shows a nonmodal dialog box containing the given constructor signature and an indication that the constructor is missing, and then returns false.
static boolean declaresConstructorNoDialog(Class c, String constructor)
          Returns true if the given class declares the constructor with the given signature, and returns false otherwise.
static boolean declaresConstructors(Class c, String[] constructors)
          Returns true if the given class declares all of the constructors with the given signatures, and, otherwise, shows a nonmodal dialog box containing a list of all of the given constructor signatures, and an indication of which constructors are missing, and then returns false.
static boolean declaresConstructorsAndMethods(Class c, String[] constructors, String[] methods)
          Returns true if the given class declares all of the constructors and methods with the given signatures, and, otherwise, shows a nonmodal dialog box containing a list of all of the given signatures and an indication of which signatures are missing, and then returns false.
static boolean declaresConstructorsAndMethodsNoDialog(Class c, String[] constructors, String[] methods)
          Returns true if the given class declares all of the constructors and methods with the given signatures, and otherwise returns false.
static boolean declaresConstructorsNoDialog(Class c, String[] constructors)
          Returns true if the given class declares all of the constructors with the given signatures, and returns false otherwise.
static boolean declaresMethod(Class c, String method)
          Returns true if the given class declares the method with the given signature, and, otherwise, shows a nonmodal dialog box containing the given method signature and an indication that the method is missing, and then returns false.
static boolean declaresMethodNoDialog(Class c, String method)
          Returns true if the given class declares the method with the given signature, and returns false otherwise.
static boolean declaresMethods(Class c, String[] methods)
          Returns true if the given class declares all of the methods with the given signatures, and, otherwise, shows a nonmodal dialog box containing a list of all of the given method signatures and an indication of which methods are missing, and then returns false.
static boolean declaresMethodsNoDialog(Class c, String[] methods)
          Returns true if the given class declares all of the methods with the given signatures, and returns false otherwise.
private static boolean hasConstructorImpl(Class c, String constructor)
          Returns true if the given class declares the constructor with the given signature, or false otherwise.
private static boolean hasConstructorsAndMethods(Class c, String[] constructors, String[] methods, boolean recurse, boolean showDialog)
          Returns true if all of the given signatures represent methods and constructors declared in the given class, or if the recurse option is set, if all of the given signatures represent methods and constructors declared in the class and its superclasses, and returns false otherwise.
private static boolean hasMethodImpl(Class c, String method, boolean recurse)
          Returns true if the given class declares the method with the given signature, or false otherwise.
static boolean isConstructorModifier(String token)
          Returns true if the given String equals a constructor modifier keyword, or false otherwise.
static boolean isMethodModifier(String token)
          Returns true if the given String equals a method modifier keyword, or false otherwise.
static boolean providesConstructorsAndMethods(Class c, String[] constructors, String[] methods)
          Returns true if the given class or any of its superclass ancestors declares all of the constructors and methods with the given signatures, and, otherwise, shows a nonmodal dialog box containing a list of all of the given signatures and an indication of which signatures are missing, and then returns false.
static boolean providesConstructorsAndMethodsNoDialog(Class c, String[] constructors, String[] methods)
          Returns true if the given class or any of its superclass ancestors declares all of the constructors and methods with the given signatures, and otherwise returns false.
static boolean providesMethod(Class c, String method)
          Returns true if the given class or any of its superclass ancestors declares the method with the given signature, and, otherwise, shows a nonmodal dialog box containing the given method signature and an indication that the method is missing, and then returns false.
static boolean providesMethodNoDialog(Class c, String method)
          Returns true if the given class or any of its superclass ancestors declares the method with the given signature, and returns false otherwise.
static boolean providesMethods(Class c, String[] methods)
          Returns true if all of the given signatures represent methods declared in the given class or any of its superclass ancestors, and, otherwise, shows a nonmodal dialog box containing a list of all of the given method signatures, and an indication of which methods are missing, and then returns false.
static boolean providesMethodsNoDialog(Class c, String[] methods)
          Returns true if all of the given signatures represent methods declared in the given class or any of its superclass ancestors, and returns false otherwise.
static void report(Class c, String[] constructors, boolean[] isConstructorDeclared, String[] methods, boolean[] isMethodDeclared)
          Reports using a dialog whether or not the given class declares constructors and methods with each of the given signatures, where the each array of booleans represents whether or not each constructor or method is declared.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHECK_ACTION

private static final PaintAction CHECK_ACTION
GUI component representing a green check mark.


X_ACTION

private static final PaintAction X_ACTION
GUI component representing a red X mark.

Constructor Detail

JPFExtras

public JPFExtras()
Method Detail

declaresMethod

public static boolean declaresMethod(Class c,
                                     String method)
Returns true if the given class declares the method with the given signature, and, otherwise, shows a nonmodal dialog box containing the given method signature and an indication that the method is missing, and then returns false.

Parameters:
c - class to test
method - text signature of method
Throws:
JPTError - if the method signature is malformed

declaresMethodNoDialog

public static boolean declaresMethodNoDialog(Class c,
                                             String method)
Returns true if the given class declares the method with the given signature, and returns false otherwise.

Parameters:
c - class to test
method - text signature of method
Throws:
JPTError - if the method signature is malformed

providesMethod

public static boolean providesMethod(Class c,
                                     String method)
Returns true if the given class or any of its superclass ancestors declares the method with the given signature, and, otherwise, shows a nonmodal dialog box containing the given method signature and an indication that the method is missing, and then returns false.

Parameters:
c - class to test
method - text signature of method
Throws:
JPTError - if the method signature is malformed

providesMethodNoDialog

public static boolean providesMethodNoDialog(Class c,
                                             String method)
Returns true if the given class or any of its superclass ancestors declares the method with the given signature, and returns false otherwise.

Parameters:
c - class to test
method - text signature of method
Throws:
JPTError - if the method signature is malformed

declaresMethods

public static boolean declaresMethods(Class c,
                                      String[] methods)
Returns true if the given class declares all of the methods with the given signatures, and, otherwise, shows a nonmodal dialog box containing a list of all of the given method signatures and an indication of which methods are missing, and then returns false.

Parameters:
c - class to test
methods - text signatures of methods
Throws:
JPTError - if one of the method signatures is malformed

declaresMethodsNoDialog

public static boolean declaresMethodsNoDialog(Class c,
                                              String[] methods)
Returns true if the given class declares all of the methods with the given signatures, and returns false otherwise.

Parameters:
c - class to test
methods - text signatures of methods
Throws:
JPTError - if one of the method signatures is malformed

providesMethods

public static boolean providesMethods(Class c,
                                      String[] methods)
Returns true if all of the given signatures represent methods declared in the given class or any of its superclass ancestors, and, otherwise, shows a nonmodal dialog box containing a list of all of the given method signatures, and an indication of which methods are missing, and then returns false.

Parameters:
c - class to test
methods - text signatures of methods
Throws:
JPTError - if one of the method signatures is malformed

providesMethodsNoDialog

public static boolean providesMethodsNoDialog(Class c,
                                              String[] methods)
Returns true if all of the given signatures represent methods declared in the given class or any of its superclass ancestors, and returns false otherwise.

Parameters:
c - class to test
methods - text signatures of methods
Throws:
JPTError - if one of the method signatures is malformed

declaresConstructor

public static boolean declaresConstructor(Class c,
                                          String constructor)
Returns true if the given class declares the constructor with the given signature, and, otherwise, shows a nonmodal dialog box containing the given constructor signature and an indication that the constructor is missing, and then returns false.

Parameters:
c - class to test
constructor - text signature of constructor
Throws:
JPTError - if the constructor signature is malformed

declaresConstructorNoDialog

public static boolean declaresConstructorNoDialog(Class c,
                                                  String constructor)
Returns true if the given class declares the constructor with the given signature, and returns false otherwise.

Parameters:
c - class to test
constructor - text signature of constructor
Throws:
JPTError - if the constructor signature is malformed

declaresConstructors

public static boolean declaresConstructors(Class c,
                                           String[] constructors)
Returns true if the given class declares all of the constructors with the given signatures, and, otherwise, shows a nonmodal dialog box containing a list of all of the given constructor signatures, and an indication of which constructors are missing, and then returns false.

Parameters:
c - class to test
constructors - text signatures of constructors
Throws:
JPTError - if one of the constructor signatures is malformed

declaresConstructorsNoDialog

public static boolean declaresConstructorsNoDialog(Class c,
                                                   String[] constructors)
Returns true if the given class declares all of the constructors with the given signatures, and returns false otherwise.

Parameters:
c - class to test
constructors - text signatures of constructors
Throws:
JPTError - if one of the constructor signatures is malformed

declaresConstructorsAndMethods

public static boolean declaresConstructorsAndMethods(Class c,
                                                     String[] constructors,
                                                     String[] methods)
Returns true if the given class declares all of the constructors and methods with the given signatures, and, otherwise, shows a nonmodal dialog box containing a list of all of the given signatures and an indication of which signatures are missing, and then returns false.

Parameters:
c - class to test
constructors - text signatures of constructors
methods - text signatures of methods
Throws:
JPTError - if one of the signatures is malformed

declaresConstructorsAndMethodsNoDialog

public static boolean declaresConstructorsAndMethodsNoDialog(Class c,
                                                             String[] constructors,
                                                             String[] methods)
Returns true if the given class declares all of the constructors and methods with the given signatures, and otherwise returns false.

Parameters:
c - class to test
constructors - text signatures of constructors
methods - text signatures of methods
Throws:
JPTError - if one of the signatures is malformed

providesConstructorsAndMethods

public static boolean providesConstructorsAndMethods(Class c,
                                                     String[] constructors,
                                                     String[] methods)
Returns true if the given class or any of its superclass ancestors declares all of the constructors and methods with the given signatures, and, otherwise, shows a nonmodal dialog box containing a list of all of the given signatures and an indication of which signatures are missing, and then returns false.

Parameters:
c - class to test
constructors - text signatures of constructors
methods - text signatures of methods
Throws:
JPTError - if one of the signatures is malformed

providesConstructorsAndMethodsNoDialog

public static boolean providesConstructorsAndMethodsNoDialog(Class c,
                                                             String[] constructors,
                                                             String[] methods)
Returns true if the given class or any of its superclass ancestors declares all of the constructors and methods with the given signatures, and otherwise returns false.

Parameters:
c - class to test
constructors - text signatures of constructors
methods - text signatures of methods
Throws:
JPTError - if one of the signatures is malformed

report

public static void report(Class c,
                          String[] constructors,
                          boolean[] isConstructorDeclared,
                          String[] methods,
                          boolean[] isMethodDeclared)
Reports using a dialog whether or not the given class declares constructors and methods with each of the given signatures, where the each array of booleans represents whether or not each constructor or method is declared.

Parameters:
c - the class to contain required methods
constructors - text signatures of the required constructors
isConstructorDeclared - whether or not each required constructor is declared
methods - text signatures of the required methods
isMethodDeclared - whether or not each required method is declared

hasConstructorsAndMethods

private static boolean hasConstructorsAndMethods(Class c,
                                                 String[] constructors,
                                                 String[] methods,
                                                 boolean recurse,
                                                 boolean showDialog)
Returns true if all of the given signatures represent methods and constructors declared in the given class, or if the recurse option is set, if all of the given signatures represent methods and constructors declared in the class and its superclasses, and returns false otherwise. If the dialog option is set, as a side effect this method shows a nonmodal dialog box containing a list of all of the given method signatures, and an indication of which methods are missing.

Parameters:
c - class to test
methods - text signatures of methods
recurse - whether or not to search superclasses
Throws:
JPTError - if one of the method signatures is malformed

hasMethodImpl

private static boolean hasMethodImpl(Class c,
                                     String method,
                                     boolean recurse)
Returns true if the given class declares the method with the given signature, or false otherwise.

Parameters:
c - class to test
method - text signature of method
Throws:
JPTError - if the method signature is malformed

hasConstructorImpl

private static boolean hasConstructorImpl(Class c,
                                          String constructor)
Returns true if the given class declares the constructor with the given signature, or false otherwise.

Parameters:
c - class to test
constructor - text signature of constructor
Throws:
JPTError - if the method signature is malformed

isMethodModifier

public static boolean isMethodModifier(String token)

Returns true if the given String equals a method modifier keyword, or false otherwise.

The method modifier keywords are: public, protected, private, abstract, static, final, synchronized, native, strictfp.

Parameters:
token - possible method modifier keyword

isConstructorModifier

public static boolean isConstructorModifier(String token)

Returns true if the given String equals a constructor modifier keyword, or false otherwise.

The constructor modifier keywords are: public, protected, private.

Parameters:
token - possible constructor modifier keyword