org.unitils.mock.argumentmatcher
Class ArgumentMatcherPositionFinder

java.lang.Object
  extended by org.unitils.mock.argumentmatcher.ArgumentMatcherPositionFinder

public class ArgumentMatcherPositionFinder
extends Object

Utility class for locating argument matchers in method invocations.

Author:
Tim Ducheyne, Filip Neven, Kenny Claes

Nested Class Summary
protected static class ArgumentMatcherPositionFinder.ArgumentMatcherValue
          A value representing a found argument matcher invocation
protected static class ArgumentMatcherPositionFinder.MethodAnalyzer
          Analyzer that passes the line nrs to the given interpreter.
protected static class ArgumentMatcherPositionFinder.MethodInterpreter
          Interpreter that implements the argument matcher finder behavior.
 
Constructor Summary
ArgumentMatcherPositionFinder()
           
 
Method Summary
protected static List<Integer> findArgumentMatcherIndexes(org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.tree.MethodNode methodNode, Class<?> interpretedClass, String interpretedMethodName, Method invokedMethod, int fromLineNr, int toLineNr, int index)
          Locates the argument matchers for the method invocation on the given line.
static List<Integer> getArgumentMatcherIndexes(Class<?> clazz, String methodName, Method invokedMethod, int fromLineNr, int toLineNr, int index)
          Locates the argument matchers for the method invocation on the given line.
static List<Integer> getArgumentMatcherIndexes(ProxyInvocation proxyInvocation, int fromLineNr, int toLineNr, int index)
          Locates the argument matchers for the given proxy method invocation.
protected static org.objectweb.asm.tree.ClassNode readClass(Class<?> clazz)
          Uses ASM to read the byte code of the given class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArgumentMatcherPositionFinder

public ArgumentMatcherPositionFinder()
Method Detail

getArgumentMatcherIndexes

public static List<Integer> getArgumentMatcherIndexes(ProxyInvocation proxyInvocation,
                                                      int fromLineNr,
                                                      int toLineNr,
                                                      int index)
Locates the argument matchers for the given proxy method invocation.

Parameters:
proxyInvocation - The method invocation, not null
fromLineNr - The begin line-nr of the invocation
toLineNr - The end line-nr of the invocation (could be different from the begin line-nr if the invocation is written on more than 1 line)
index - The index of the matcher on that line, 1 for the first, 2 for the second etc
Returns:
The argument indexes, empty if there are no matchers

getArgumentMatcherIndexes

public static List<Integer> getArgumentMatcherIndexes(Class<?> clazz,
                                                      String methodName,
                                                      Method invokedMethod,
                                                      int fromLineNr,
                                                      int toLineNr,
                                                      int index)
Locates the argument matchers for the method invocation on the given line. An exception is raised when the given method cannot be found.

Parameters:
clazz - The class containing the method invocation, not null
methodName - The method containing the method invocation, not null
invokedMethod - The invocation to look for, not null
fromLineNr - The begin line-nr of the invocation
toLineNr - The end line-nr of the invocation (could be different from the begin line-nr if the invocation is written on more than 1 line)
index - The index of the matcher on that line, 1 for the first, 2 for the second etc
Returns:
The argument indexes, empty if there are no matchers

readClass

protected static org.objectweb.asm.tree.ClassNode readClass(Class<?> clazz)
Uses ASM to read the byte code of the given class. This will access the class file and create some sort of DOM tree for the structure of the bytecode.

Parameters:
clazz - The class to read, not null
Returns:
The structure of the class, not null

findArgumentMatcherIndexes

protected static List<Integer> findArgumentMatcherIndexes(org.objectweb.asm.tree.ClassNode classNode,
                                                          org.objectweb.asm.tree.MethodNode methodNode,
                                                          Class<?> interpretedClass,
                                                          String interpretedMethodName,
                                                          Method invokedMethod,
                                                          int fromLineNr,
                                                          int toLineNr,
                                                          int index)
Locates the argument matchers for the method invocation on the given line.

Parameters:
classNode - The class containing the method invocation, not null
methodNode - The method containing the method invocation, not null
interpretedClass - The current class, not null
interpretedMethodName - The current method name, not null
invokedMethod - The invocation to look for, not null
fromLineNr - The begin line-nr of the invocation
toLineNr - The end line-nr of the invocation (could be different from the begin line-nr if the invocation is written on more than 1 line)
index - The index of the matcher on that line, 1 for the first, 2 for the second etc
Returns:
The argument indexes, null if method was not found, empty if method found but there are no matchers


Copyright © 2011. All Rights Reserved.