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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations