last minute change because console was broken: allow converted closure to be limited to a single method only if needed.

git-svn-id: http://svn.codehaus.org/groovy/tags/GROOVY_1_1_BETA_1@6240 a5544e8c-8a19-0410-ba12-f9af4593a198
diff --git a/groovy/groovy-core/src/main/groovy/lang/MetaClassImpl.java b/groovy/groovy-core/src/main/groovy/lang/MetaClassImpl.java
index 845fafd..a187367 100644
--- a/groovy/groovy-core/src/main/groovy/lang/MetaClassImpl.java
+++ b/groovy/groovy-core/src/main/groovy/lang/MetaClassImpl.java
@@ -54,6 +54,7 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
 import java.net.URL;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -1465,8 +1466,10 @@
                 newValue instanceof Closure) 
            {
                // lets create a dynamic proxy
-               Object proxy =
-                   DefaultGroovyMethods.asType((Closure) newValue, method.getParameterTypes()[0]);
+               Object proxy = Proxy.newProxyInstance(
+                       theClass.getClassLoader(),
+                       new Class[]{method.getParameterTypes()[0]},
+                       new ConvertedClosure((Closure) newValue,name));
                arguments = new Object[] { proxy };
                newValue = proxy;
                usesProxy = true;
diff --git a/groovy/groovy-core/src/main/org/codehaus/groovy/runtime/ConvertedClosure.java b/groovy/groovy-core/src/main/org/codehaus/groovy/runtime/ConvertedClosure.java
index 5a4ce58..72b1373 100644
--- a/groovy/groovy-core/src/main/org/codehaus/groovy/runtime/ConvertedClosure.java
+++ b/groovy/groovy-core/src/main/org/codehaus/groovy/runtime/ConvertedClosure.java
@@ -11,17 +11,24 @@
  * Jul 27, 2006 3:50:51 PM

  */

 public class ConvertedClosure extends ConversionHandler {

+    private String methodName;

     

     /**

      * to create a ConvertedClosure object.

      * @param closure the closure object.

      */

-    protected ConvertedClosure(Closure closure) {

+    public ConvertedClosure(Closure closure, String method) {

         super(closure);

+        this.methodName = method;

+    }

+    

+    public ConvertedClosure(Closure closure) {

+        this(closure,null);

     }

     

     public Object invokeCustom(Object proxy, Method method, Object[] args)

     throws Throwable {

+        if (methodName!=null && !methodName.equals(method.getName())) return null;

         return ((Closure) getDelegate()).call(args);

     }

 }