Search in sources :

Example 71 with Closure

use of groovy.lang.Closure in project groovy-core by groovy.

the class GroovyTypeCheckingExtensionSupport method handleIncompatibleAssignment.

@Override
public boolean handleIncompatibleAssignment(final ClassNode lhsType, final ClassNode rhsType, final Expression assignmentExpression) {
    setHandled(false);
    List<Closure> list = eventHandlers.get("handleIncompatibleAssignment");
    if (list != null) {
        for (Closure closure : list) {
            safeCall(closure, lhsType, rhsType, assignmentExpression);
        }
    }
    return handled;
}
Also used : Closure(groovy.lang.Closure)

Example 72 with Closure

use of groovy.lang.Closure in project groovy-core by groovy.

the class GroovyTypeCheckingExtensionSupport method handleIncompatibleReturnType.

@Override
public boolean handleIncompatibleReturnType(final ReturnStatement returnStatement, ClassNode inferredReturnType) {
    setHandled(false);
    List<Closure> list = eventHandlers.get("handleIncompatibleReturnType");
    if (list != null) {
        for (Closure closure : list) {
            safeCall(closure, returnStatement, inferredReturnType);
        }
    }
    return handled;
}
Also used : Closure(groovy.lang.Closure)

Example 73 with Closure

use of groovy.lang.Closure in project groovy-core by groovy.

the class GroovyTypeCheckingExtensionSupport method handleAmbiguousMethods.

@Override
@SuppressWarnings("unchecked")
public List<MethodNode> handleAmbiguousMethods(final List<MethodNode> nodes, final Expression origin) {
    List<Closure> onMethodSelection = eventHandlers.get("handleAmbiguousMethods");
    List<MethodNode> methodList = nodes;
    if (onMethodSelection != null) {
        Iterator<Closure> iterator = onMethodSelection.iterator();
        while (methodList.size() > 1 && iterator.hasNext()) {
            final Closure closure = iterator.next();
            Object result = safeCall(closure, methodList, origin);
            if (result != null) {
                if (result instanceof MethodNode) {
                    methodList = Collections.singletonList((MethodNode) result);
                } else if (result instanceof Collection) {
                    methodList = new LinkedList<MethodNode>((Collection<? extends MethodNode>) result);
                } else {
                    throw new GroovyBugError("Type checking extension returned unexpected method list: " + result);
                }
            }
        }
    }
    return methodList;
}
Also used : Closure(groovy.lang.Closure) MethodNode(org.codehaus.groovy.ast.MethodNode) GroovyBugError(org.codehaus.groovy.GroovyBugError) Collection(java.util.Collection) LinkedList(java.util.LinkedList)

Example 74 with Closure

use of groovy.lang.Closure in project groovy-core by groovy.

the class GroovyTypeCheckingExtensionSupport method beforeMethodCall.

@Override
public boolean beforeMethodCall(final MethodCall call) {
    setHandled(false);
    List<Closure> onMethodSelection = eventHandlers.get("beforeMethodCall");
    if (onMethodSelection != null) {
        for (Closure closure : onMethodSelection) {
            safeCall(closure, call);
        }
    }
    return handled;
}
Also used : Closure(groovy.lang.Closure)

Example 75 with Closure

use of groovy.lang.Closure in project groovy-core by groovy.

the class ClosureJavaIntegrationTest method testEachMap.

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=Monkeys,v=3", "k=Giraffe,v=2", "k=Lions,v=5"), result);
}
Also used : BigInteger(java.math.BigInteger) Closure(groovy.lang.Closure) ArrayList(java.util.ArrayList)

Aggregations

Closure (groovy.lang.Closure)251 Map (java.util.Map)55 HashMap (java.util.HashMap)38 ArrayList (java.util.ArrayList)37 GroovyObject (groovy.lang.GroovyObject)33 List (java.util.List)33 Binding (groovy.lang.Binding)22 GString (groovy.lang.GString)21 LinkedHashMap (java.util.LinkedHashMap)20 LinkedList (java.util.LinkedList)19 Collection (java.util.Collection)17 GroovyShell (groovy.lang.GroovyShell)14 Test (org.junit.Test)14 MethodClosure (org.codehaus.groovy.runtime.MethodClosure)13 FileType (groovy.io.FileType)12 FileVisitResult (groovy.io.FileVisitResult)12 File (java.io.File)12 Iterator (java.util.Iterator)10 GroovyBugError (org.codehaus.groovy.GroovyBugError)10 IOException (java.io.IOException)9