Package groovy.lang

Examples of groovy.lang.Closure$WritableClosure


     */
    public int hashCode() {
        Object method = getProperties().get("hashCode");
        if (method != null && method instanceof Closure) {
            // invoke overridden hashCode closure method
            Closure closure = (Closure) method;
            closure.setDelegate(this);
            Integer ret = (Integer) closure.call();
            return ret.intValue();
        } else {
            return super.hashCode();
        }
    }
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

        }
    }

    public void testDownto() {
        final int[] count = new int[]{0};
        final Closure closure = new Closure(null) {
            public Object doCall(final Object params) {
                count[0]++;
                return null;
            }
        };
View Full Code Here

        assertEquals(join(animals, ", "), "ant, bear, camel");
    }

    public void testEachList() {
        final List<Integer> result = new ArrayList<Integer>();
        each(animals, new Closure(null) {
            public void doCall(String arg) {
                result.add(arg.length());
            }
        });
        assertEquals(Arrays.asList(3, 4, 5), result);
View Full Code Here

        assertEquals(Arrays.asList(3, 4, 5), result);
    }

    public void testEachMap() {
        final List<String> result = new ArrayList<String>();
        each(zoo, new Closure(null) {
            public void doCall(String k, Integer v) {
                result.add("k=" + k + ",v=" + v);
            }
        });
        assertEquals(Arrays.asList("k=Lions,v=5", "k=Monkeys,v=3", "k=Giraffe,v=2"), result);
View Full Code Here

    }

    public void testMethodWhichCallsTheFailingMethodInsideAClosure() {
        MockGroovyObject object = new MockGroovyObject();
        try {
            object.invokeMethod("callClosure", new Closure(this) {
                protected Object doCall(GroovyObject object) {
                    return object.invokeMethod("nonExistentMethod", "hello");
                }
            });
View Full Code Here

        List list = new ArrayList();
        list.add("abc");
        list.add("def");

        InvokerHelper.invokeMethod(list, "each", new Closure(this) {
            protected Object doCall(Object arguments) {
                buffer.append(arguments.toString());
                return null;
            }
        });
View Full Code Here

        Object answer = super.doInvokeMethod(s, name, args);
        List list = InvokerHelper.asList(args);
        if (!list.isEmpty()) {
            Object o = list.get(list.size() - 1);
            if (o instanceof Closure) {
                Closure closure = (Closure) o;
                closure.setDelegate(answer);
            }
        }
        return answer;
    }
View Full Code Here

        Object answer = super.doInvokeMethod(s, name, args);
        List list = InvokerHelper.asList(args);
        if (!list.isEmpty()) {
            Object o = list.get(list.size() - 1);
            if (o instanceof Closure) {
                Closure closure = (Closure) o;
                closure.setDelegate(answer);
            }
        }
        return answer;
    }
View Full Code Here

    }

    public void replaceNode(final Closure replacementClosure, final GPathResult result) {
        this.replacementNodeStack.push(new ReplacementNode() {
            public void build(final GroovyObject builder, final Map namespaceMap, final Map<String, String> namespaceTagHints) {
                final Closure c = (Closure) replacementClosure.clone();
                Node.this.replacementNodeStack.pop(); // disable the replacement whilst the closure is being executed
                c.setDelegate(builder);
                c.call(new Object[]{result});
                Node.this.replacementNodeStack.push(this);
            }
        });
    }
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.