Package groovy.lang

Examples of groovy.lang.Closure$WritableClosure


                    public CachedClass getDeclaringClass() {
                        return ReflectionCache.getCachedClass(declaringClass);
                    }

                    public Object invoke(Object object, Object[] arguments) {
                        Closure cloned = (Closure) closure.clone();
                        cloned.setDelegate(object);
                        arguments = coerceArgumentsToClasses(arguments);
                        return InvokerHelper.invokeMethod(cloned, "call", arguments);
                    }
                };
                res.add(adjustParamTypesForStdMethods(metaMethod, name));
View Full Code Here


    }

    public Object invokeCustom(Object proxy, Method method, Object[] args)
            throws Throwable {
        Map m = (Map) getDelegate();
        Closure cl = (Closure) m.get(method.getName());
        if (cl == null) {
            throw new UnsupportedOperationException();
        }
        return cl.call(args);
    }
View Full Code Here

        assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX3);
    }

    public void testObjectSupportNameHandlingWitnClosureValues() {
        final Tt1cgo obj = new Tt1cgo()// Test subclass of GroovyObjectSupport
        final Closure newX = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x";
            }
        };
        final Closure newX1 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x1";
            }
        };
        final Closure newX2 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x2";
            }
        };
        final Closure newX3 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x3";
            }
        };

        assertTrue(((Closure) obj.getProperty("x")).call() == obj.getX().call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == obj.x.call());
        assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());

        obj.setProperty("x", newX);
        obj.getMetaClass().setAttribute(obj, "x", newX1);

        assertTrue(((Closure) obj.getProperty("x")).call() == newX.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX1.call());

        obj.setX(newX2);
        obj.x = newX3;

        assertTrue(((Closure) obj.getProperty("x")).call() == newX2.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
    }
View Full Code Here

    }

    public void testObjectSupportNameHandlingWitnClosureValuesi() {
        final Tt1cgo obj = new Tt1cgo() {
        }// repeat test with subclass
        final Closure newX = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x";
            }
        };
        final Closure newX1 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x1";
            }
        };
        final Closure newX2 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x2";
            }
        };
        final Closure newX3 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x3";
            }
        };

        assertTrue(((Closure) obj.getProperty("x")).call() == obj.getX().call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == obj.x.call());
        assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());

        obj.setProperty("x", newX);
        obj.getMetaClass().setAttribute(obj, "x", newX1);

        assertTrue(((Closure) obj.getProperty("x")).call() == newX.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX1.call());

        obj.setX(newX2);
        obj.x = newX3;

        assertTrue(((Closure) obj.getProperty("x")).call() == newX2.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
    }
View Full Code Here

        assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX3);
    }

    public void testMetaClassNameHandlingWithClosures() {
        final Tt1cgi obj = new Tt1cgi()// Test class implementing GroovyObject
        final Closure newX = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x";
            }
        };
        final Closure newX1 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x1";
            }
        };
        final Closure newX2 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x2";
            }
        };
        final Closure newX3 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x3";
            }
        };

        assertTrue(((Closure) obj.getProperty("x")).call() == obj.getX().call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == obj.x.call());
        assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());

        obj.setProperty("x", newX);
        obj.getMetaClass().setAttribute(obj, "x", newX1);

        assertTrue(((Closure) obj.getProperty("x")).call() == newX.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX1.call());

        obj.setX(newX2);
        obj.x = newX3;

        assertTrue(((Closure) obj.getProperty("x")).call() == newX2.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
    }
View Full Code Here

    }

    public void testMetaClassNameHandlingWithClosures1() {
        final Tt1cgi obj = new Tt1cgi() {
        }// repeat test with subclass
        final Closure newX = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x";
            }
        };
        final Closure newX1 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x1";
            }
        };
        final Closure newX2 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x2";
            }
        };
        final Closure newX3 = new Closure(null) {
            public Object doCall(final Object params) {
                return "new x3";
            }
        };

        assertTrue(((Closure) obj.getProperty("x")).call() == obj.getX().call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == obj.x.call());
        assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());

        obj.setProperty("x", newX);
        obj.getMetaClass().setAttribute(obj, "x", newX1);

        assertTrue(((Closure) obj.getProperty("x")).call() == newX.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX1.call());

        obj.setX(newX2);
        obj.x = newX3;

        assertTrue(((Closure) obj.getProperty("x")).call() == newX2.call());
        assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
    }
View Full Code Here

        appendNode(newValue);
        return this;
    }
   
    public Object plus(final Object newValue) {
        this.replaceNode(new Closure(this) {
            public void doCall(Object[] args) {
            final GroovyObject delegate = (GroovyObject)getDelegate();
            
                delegate.getProperty("mkp");
                delegate.invokeMethod("yield", args);
View Full Code Here

    public boolean isEmpty() {
        return size() == 0;
    }
   
    public Closure getBody() {
        return new Closure(this.parent(),this) {
            public void doCall(Object[] args) {
                final GroovyObject delegate = (GroovyObject)getDelegate();
                final GPathResult thisObject = (GPathResult)getThisObject();

                Node node = (Node)thisObject.getAt(0);
View Full Code Here

        Closure handler;

        public EventTriggerFullBinding(final SourceBinding sourceBinding, TargetBinding targetBinding) {
            setSourceBinding(sourceBinding);
            setTargetBinding(targetBinding);
            handler = new Closure(triggerBean) {
                public Object call(Object[] params) {
                    if (sourceBinding instanceof ClosureSourceBinding) {
                        ((ClosureSourceBinding)sourceBinding).setClosureArguments(params);
                    }
                    update();
View Full Code Here

        final ServletBinding binding = new ServletBinding(request, response, servletContext);
        setVariables(binding);

        // Run the script
        try {
            Closure closure = new Closure(gse) {

                public Object call() {
                    try {
                        return ((GroovyScriptEngine) getDelegate()).run(scriptUri, binding);
                    } catch (ResourceException e) {
View Full Code Here

TOP

Related Classes of groovy.lang.Closure$WritableClosure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.