Created
November 16, 2010 10:29
-
-
Save kimukou/701668 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Intercepter sample test | |
// see http://d.hatena.ne.jp/funatti/20100717/1279390870 | |
class Tracer implements Interceptor{ | |
Object beforeInvoke(Object obj, String name, Object[] args){ | |
println "BEFORE: ${obj}.${name}" | |
} | |
boolean doInvoke(){ return true } | |
Object afterInvoke(Object obj, String name, Object[] args, Object result){ | |
println "AFTER: ${obj}.${name}" | |
return result | |
} | |
} | |
//== case 1 (before after correct ?)== | |
println "====start=====" | |
def tracer = new Tracer() | |
def proxy = ProxyMetaClass.getInstance(String) | |
proxy.interceptor = tracer | |
/* | |
BEFORE: hello.multiply | |
AFTER: hello.multiply | |
hellohellohello | |
*/ | |
proxy.use{ // intercept start | |
println "hello"*3 | |
} | |
//NG case | |
/* | |
hello | |
*/ | |
proxy.use{ | |
println "hello" | |
} | |
println "====end=====" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment