bineanzhou / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

method name matcher #164

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It would be useful to be able to match methods for interception based on
method name (and/or param list).

Original issue reported on code.google.com by AaronJWh...@gmail.com on 14 Nov 2007 at 2:11

GoogleCodeExporter commented 9 years ago
additional: this allows one to match methods like toString(), finalize(), 
wait(),
whatever, etc.. in say the default java.lang.Object class without having to 
apply
annotations everywhere..

Original comment by AaronJWh...@gmail.com on 14 Nov 2007 at 2:22

GoogleCodeExporter commented 9 years ago
public class MethodCalledMatcher
extends AbstractMatcher<Method>
{
    public static Matcher<Method> methodCalled(String methodName)
    {
        return new MethodCalledMatcher(methodName);
    }

    private String methodName;

    public MethodCalledMatcher(String methodName)
    {
        Objects.nonNull(methodName, "method name");        
        this.methodName = methodName;
    }

    @Override
    public boolean matches(Method method) {
        return method.getName().equals(methodName);
    }

    @Override
    public String toString() {
        return "methodCalled(" + methodName + ")";
    }
}

Original comment by AaronJWh...@gmail.com on 19 Nov 2007 at 4:40

GoogleCodeExporter commented 9 years ago
Anyone interested in this can use the code above. We won't add this 
functionality to core Guice for the reasons 
crazybob describes here:
http://groups.google.com/group/google-guice/browse_frm/thread/1330ed84618d57b4/c
40843d874a4833c?
#c40843d874a4833c

Original comment by limpbizkit on 16 May 2008 at 4:31