sofya.mutator.selectors
Class MethodMutationSelector

java.lang.Object
  extended by sofya.mutator.selectors.MethodMutationSelector
All Implemented Interfaces:
MutationSelector
Direct Known Subclasses:
RandomMethodMutationSelector

public class MethodMutationSelector
extends java.lang.Object
implements MutationSelector

Mutation selector that selects by method name and signature.

This selector will only select mutations of the MethodMutation type. It parses method name and signature information extracted from source code by a certain method diffing tool, and uses that information to compare against method names and signatures supplied by BCEL to implement the selection.

Version:
05/12/2006
Author:
Alex Kinneer

Nested Class Summary
protected static class MethodMutationSelector.TypeSignature
          Data class that records signature information about a selected method.
 
Field Summary
protected  java.util.Map nameSigTable
          Map that stores dot-concatenated class name and method names as keys to TypeSignature values recording the formal argument and return types.
 
Constructor Summary
protected MethodMutationSelector()
           
  MethodMutationSelector(java.util.Collection methodNames)
          Creates a new mutation selector.
  MethodMutationSelector(java.lang.String[] methodNames)
          Creates a new mutation selector.
 
Method Summary
protected  void addMethod(java.lang.String methodDesc)
          Adds a selected method.
 Mutation.Variant getVariant(Mutation mutation)
          Gets the selected variant.
 boolean isSelected(Mutation mutation)
          Reports whether a mutation is selected..
static void main(java.lang.String[] argv)
          Test driver to verify the textual method parsing and comparison function.
 void setMutationCount(int mutationCount)
          Sets the total number of mutations that may be passed to this selector (typically the number of mutations in a mutation table).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nameSigTable

protected java.util.Map nameSigTable
Map that stores dot-concatenated class name and method names as keys to TypeSignature values recording the formal argument and return types. The keys are the nearest 'meeting point' between the format supplied by the diff tool and that supplied by BCEL, allowing the fastest initial lookup to determine if the mutation is selected before applying the more costly signature comparison.

Constructor Detail

MethodMutationSelector

protected MethodMutationSelector()

MethodMutationSelector

public MethodMutationSelector(java.lang.String[] methodNames)
Creates a new mutation selector.

Parameters:
methodNames - Array of method descriptions supplied by the diffing tool. Mutations occurring in the selected methods will be selected.

MethodMutationSelector

public MethodMutationSelector(java.util.Collection methodNames)
Creates a new mutation selector.

Parameters:
methodNames - Collection of method descriptions supplied by the diffing tool, as strings. Mutations occurring in the selected methods will be selected.
Method Detail

isSelected

public boolean isSelected(Mutation mutation)
Reports whether a mutation is selected..

Argument and return types are compared using an ends-with test against the string conversion of the types retrieved from the mutation. This is because the method description format it is being compared against (apparently) originates from source code where fully qualified type names are rarely used (only if disambiguation is required). Note that this approach is NOT implemented commutatively, since we know that BCEL will always return the fully qualified type string (thus an unqualified class name is considered a separate type from one with package qualifiers, a distinction permitted by the Java type system as a consequence of the implicit namespaces created by Java packages). The safety of this approach is guaranteed by the requirement that ambiguous type names be fully qualified in the source code, as mentioned above.

Specified by:
isSelected in interface MutationSelector
Parameters:
mutation - Mutation to be checked for selection.
Returns:
true if this selector implements a selection criteria that the given mutation meets, false otherwise.

getVariant

public Mutation.Variant getVariant(Mutation mutation)
Description copied from interface: MutationSelector
Gets the selected variant.

Some mutation operators, such as the arithmetic operator change (AOP), generate multiple variants at a single location.

Specified by:
getVariant in interface MutationSelector
Parameters:
mutation - Mutation for which to retrieve the selected variant.
Returns:
The selected mutation variant.

setMutationCount

public void setMutationCount(int mutationCount)
Description copied from interface: MutationSelector
Sets the total number of mutations that may be passed to this selector (typically the number of mutations in a mutation table).

This is useful for some selectors, such as those that implement random selection criteria.

Specified by:
setMutationCount in interface MutationSelector
Parameters:
mutationCount - Total number of mutations from which this selector may select.

addMethod

protected void addMethod(java.lang.String methodDesc)
Adds a selected method.

This method is responsible for parsing a textual method description received from the diffing tool.


main

public static void main(java.lang.String[] argv)
Test driver to verify the textual method parsing and comparison function.