| From | Sent On | Attachments |
|---|---|---|
| Bob Brown | Dec 28, 2008 11:04 pm | |
| Roshan Dawrani | Dec 28, 2008 11:15 pm | |
| Roshan Dawrani | Dec 28, 2008 11:43 pm | |
| Paul King | Dec 29, 2008 1:29 am | |
| Paul King | Dec 29, 2008 1:38 am | |
| Paul King | Dec 29, 2008 1:50 am | |
| Roshan Dawrani | Dec 29, 2008 2:14 am | |
| Bob Brown | Dec 29, 2008 3:29 am | |
| Jochen Theodorou | Dec 29, 2008 6:38 am | |
| Paul King | Dec 29, 2008 2:02 pm | |
| Bob Brown | Dec 29, 2008 2:19 pm | |
| Paul King | Dec 31, 2008 10:12 pm | |
| Bob Brown | Dec 31, 2008 10:20 pm | |
| Bob Brown | Jan 6, 2009 5:00 pm |
| Subject: | Re: [groovy-user] metaclass and curry() gives MissingMethodException | |
|---|---|---|
| From: | Roshan Dawrani (rosh...@gmail.com) | |
| Date: | Dec 28, 2008 11:43:56 pm | |
| List: | org.codehaus.groovy.user | |
Oh, oh..I missed the 2nd thing that you tried in the exception details.
I tried your first piece of code on 1.5.6 and mailed back. So it may be 1.6-RC-1 specific. I will try it on that version and get back if I find something.
Sorry.
On Mon, Dec 29, 2008 at 12:46 PM, Roshan Dawrani <rosh...@gmail.com>wrote:
Hi,
You can do it as below:
============================ def nonCurryClosure = {delim, expected -> def buffer = [] try { StringTokenizer st = new StringTokenizer(delegate, delim); for (int i = 0; i < expected; i++) buffer[i] = st.nextToken(); return buffer.toArray(); } catch (NoSuchElementException e) { throw new NoSuchElementException("Could not successfully split line:'" + line + "' into " + expected + " items delimited by '" + delim + "'"); } }
String.metaClass.fastSplit = nonCurryClosure
println "this,is,a,test".fastSplit(",", 4)
String.metaClass.fastSplitComma4 = nonCurryClosure.curry(",", 4)
println "this,is,a,test".fastSplitComma4() ===============================
Hope it helps. Roshan
On Mon, Dec 29, 2008 at 12:35 PM, Bob Brown <bo...@transentia.com.au> wrote:
To me, the following is unexpected (this is probably my inexperience shining out, so please be gentle!). I couldn't find anything pointing me in the right direction on the list archives.
I have the following test:
=== package au.com.transentia.utils.test
public class FastSplitTest extends GroovyTestCase {
void setUp() { String.metaClass.fastSplit = {delim, expected -> def buffer = [] try { StringTokenizer st = new StringTokenizer(delegate, delim); for (int i = 0; i < expected; i++) buffer[i] = st.nextToken(); return buffer.toArray(); } catch (NoSuchElementException e) { throw new NoSuchElementException("Could not successfully split line: '" + line + "' into " + expected + " items delimited by '" + delim + "'"); } }
String.metaClass.fastSplitComma4 = String.metaClass.fastSplit.curry(",", 4) }
void testSplit() { assertArrayEquals(['this', 'is', 'a', 'test'].toArray(), "this,is,a,test".fastSplit(",", 4)) }
void testCurried() { assertArrayEquals(['this', 'is', 'a', 'test'].toArray(), "this,is,a,test".fastSplitComma4()) } } ===
This gives: === "C:\Program Files\Java\jdk1.6.0_11\bin\java" -Didea.launcher.port=7551 "-Didea.launcher.bin.path=C:\Program Files\JetBrains\IntelliJ IDEA 8.0.1\bin" -Dfile.encoding=windows-1252 -classpath "C:\DEVTOOLS\groovy-1.6-RC-1\embeddable\groovy-all-1.6-RC-1.jar;C:\Program Files\Java\jdk1.6.0_11\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.6.0_11\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.6.0_11\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.6.0_11\jre\lib\jce.jar;C:\Program Files\Java\jdk1.6.0_11\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.6.0_11\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.6.0_11\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.6.0_11\jre\lib\resources.jar;C:\Program Files\Java\jdk1.6.0_11\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_11\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.6.0_11\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.6.0_11\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.6.0_11\jre\lib\ext\sunmscapi.jar;C:\Program
Files\Java\jdk1.6.0_11\jre\lib\ext\sunpkcs11.jar;C:\DEVELOPMENT\IntelliJ\FB\
out\production\FB;C:\DEVTOOLS\commons-lang-2.4\commons-lang-2.4.jar;C:\DEVTO OLS\groovy-1.6-RC-1\lib\junit-3.8.2.jar;C:\Program Files\JetBrains\IntelliJ IDEA 8.0.1\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 au.com.transentia.utils.test.FastSplitTest
groovy.lang.MissingMethodException: No signature of method: groovy.lang.ExpandoMetaClass$ExpandoMetaProperty.curry() is applicable for argument types: (java.lang.String, java.lang.Integer) values: {,, 4} at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapt er.java:54) at
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSit e.java:51) at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray .java:43) at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite. java:116) at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite. java:128) at au.com.transentia.utils.test.FastSplitTest.setUp(FastSplitTest.groovy:21) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39 ) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:25) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
groovy.lang.MissingMethodException: No signature of method: groovy.lang.ExpandoMetaClass$ExpandoMetaProperty.curry() is applicable for argument types: (java.lang.String, java.lang.Integer) values: {,, 4} at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapt er.java:54) at
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSit e.java:51) at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite. java:128) at au.com.transentia.utils.test.FastSplitTest.setUp(FastSplitTest.groovy:21) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39 ) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:25) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Process finished with exit code -1 ===
I also tried:
=== void setUp() {
def fastSplit = {delim, expected -> def buffer = [] try { StringTokenizer st = new StringTokenizer(delegate, delim); for (int i = 0; i < expected; i++) buffer[i] = st.nextToken(); return buffer.toArray(); } catch (NoSuchElementException e) { throw new NoSuchElementException("Could not successfully split line: '" + line + "' into " + expected + " items delimited by '" + delim + "'"); } }
String.metaClass.fastSplit = fastSplit String.metaClass.fastSplitComma4 = fastSplit.curry(",", 4) } ===
But...as expected...delegate gets set to FastSplitTest class and so once gets:
=== groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.util.StringTokenizer(au.com.transentia.utils.test.FastSplitTest, java.lang.String) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1465) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1381) at
org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructo r(MetaClassConstructorSite.java:38) at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(Ca llSiteArray.java:55) at
org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap NoCoerce.callConstructor(ConstructorSite.java:108) at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(Abstra ctCallSite.java:203) at
au.com.transentia.utils.test.FastSplitTest$_setUp_closure1.doCall(FastSplitT est.groovy:26) [...more elided...] ===
Is there a way of doing what I need here?
Comments/suggestions gratefully received.
Cheers,
BOB
--------------------------------------------------------------------- To unsubscribe from this list, please visit:





