Class OperationSignature

java.lang.Object
randoop.condition.specification.OperationSignature

public class OperationSignature extends Object
Represents the signature of a method or constructor for an OperationSpecification so that the java.lang.reflect.AccessibleObject can be loaded, which is done by SpecificationCollection.getAccessibleObject.

The JSON serialization of this class is used to read the specifications for an operation given using the --specifications command-line option. The JSON should include a JSON object labeled by the name of each field of this class, as in

   {
     "classname": "net.Connection",
     "name": "send",
     "parameterTypes": [
       "int"
     ]
   }
 

The classname must be the declaring class of the method. (For a constructor, the classname and operation name will be identical.) If named class is not the declaring class of the method, the method will not be found, and the enclosing specification will not be used.

  • Field Details

    • classname

      private final @ClassGetName String classname
      The fully-qualified binary name of the declaring class of this operation.
    • name

      private final String name
      The name of this operation. For a method, is its simple name. For a constructor, is the fully-qualified name of the class.
    • parameterTypes

      private final List<@ClassGetName String> parameterTypes
      The list of fully-qualified raw type names for the parameters of this operation.
  • Constructor Details

    • OperationSignature

      private OperationSignature()
      Gson serialization requires a default constructor.
    • OperationSignature

      private OperationSignature(@ClassGetName String classname, String name, List<@ClassGetName String> parameterTypes)
      Create an OperationSignature object given the names of the declaring class, method or constructor, and parameter types.
      Parameters:
      classname - the fully-qualified binary name of the declaring class
      name - the name of the method or constructor
      parameterTypes - the list of fully-qualified raw parameter type names
  • Method Details

    • forConstructorName

      public static OperationSignature forConstructorName(@ClassGetName String classname, String simpleName, List<@ClassGetName String> parameterTypes)
      Create a OperationSignature for the constructor of the class with the parameter types.
      Parameters:
      classname - the fully-qualified raw name of the declaring class
      simpleName - the simple name of the class (and of the constructor)
      parameterTypes - the list of fully-qualified parameter type names
      Returns:
      the OperationSignature for a constructor of the declaring class with the parameter types
    • forMethodName

      public static OperationSignature forMethodName(@ClassGetName String classname, String name, List<@ClassGetName String> parameterTypes)
      Create a OperationSignature for the method in the named class, with the method name and parameter types.
      Parameters:
      classname - the name of the declaring class
      name - the name of the method
      parameterTypes - the list of fully-qualified parameter type names
      Returns:
      the OperationSignature for the named method in the declaring class, with the parameter types
    • of

      public static OperationSignature of(Method method)
      Returns an OperationSignature for a method given as a java.lang.reflect.Method.
      Parameters:
      method - the Method for which operation is to be created
      Returns:
      the OperationSignature with the class, name and parameter types of method
    • of

      public static OperationSignature of(Constructor<?> constructor)
      Returns an OperationSignature for a constructor given as a java.lang.reflect.Constructor.

      Note: the name and classname of a constructor are equal

      Parameters:
      constructor - the Constructor for which an operation is to be created
      Returns:
      the OperationSignature with the class and parameter types of constructor
    • of

      public static OperationSignature of(AccessibleObject op)
      Returns an operation for a method or constructor given as a java.lang.reflect.AccessibleObject.
      Parameters:
      op - the method or constructor
      Returns:
      an OperationSignature if op is a constructor or method, null if field
    • getClassname

      public @ClassGetName String getClassname()
      Return the name of the declaring class of this OperationSignature.
      Returns:
      the name of the declaring class of this operation
    • getName

      public String getName()
      Return the name of this OperationSignature.
      Returns:
      the name of this operation
    • getParameterTypeNames

      public List<@ClassGetName String> getParameterTypeNames()
      Return the list of parameter type names for this OperationSignature.
      Returns:
      the list of parameter type names for this operation
    • isConstructor

      public boolean isConstructor()
      Indicates whether this OperationSignature represents a constructor.
      Returns:
      true if this OperationSignature represents a constructor, false otherwise
    • isValid

      public boolean isValid()
      Indicates whether this OperationSignature is a valid representation of a method or constructor.
      Returns:
      true if the class and operation names are both non-null, non-empty and the type name list is non-null.
    • getTypeNames

      private static List<@ClassGetName String> getTypeNames(Class<?>[] classes)
      Creates a list of fully-qualified type names from the array of Class<?> objects.
      Parameters:
      classes - the array of Class<?> objects
      Returns:
      the list of fully-qualified type names for the objects in classes
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object