ClassNode[] inferred = candidates.get(0); if (closureParams.length == 0 && inferred.length == 1) { expression.putNodeMetaData(StaticTypesMarker.CLOSURE_ARGUMENTS, inferred); } else { final int length = closureParams.length;
/** * Used to instruct the type checker that the call is a dynamic method call. * Calling this method automatically sets the handled flag to true. * @param call the method call which is a dynamic method call * @param returnType the expected return type of the dynamic call * @return a virtual method node with the same name as the expected call */ public MethodNode makeDynamic(MethodCall call, ClassNode returnType) { TypeCheckingContext.EnclosingClosure enclosingClosure = context.getEnclosingClosure(); MethodNode enclosingMethod = context.getEnclosingMethod(); ((ASTNode)call).putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, returnType); if (enclosingClosure!=null) { enclosingClosure.getClosureExpression().putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, Boolean.TRUE); } else { enclosingMethod.putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, Boolean.TRUE); } setHandled(true); if (debug) { LOG.info("Turning "+call.getText()+" into a dynamic method call returning "+returnType.toString(false)); } return new MethodNode(call.getMethodAsString(), 0, returnType, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, EmptyStatement.INSTANCE); }
/** * @param callArguments * @param receiver * @deprecated this method is unused, replaced with {@link DelegatesTo} inference. */ @Deprecated protected void checkClosureParameters(final Expression callArguments, final ClassNode receiver) { if (callArguments instanceof ArgumentListExpression) { ArgumentListExpression argList = (ArgumentListExpression) callArguments; ClosureExpression closure = (ClosureExpression) argList.getExpression(0); Parameter[] parameters = closure.getParameters(); if (parameters.length > 1) { addStaticTypeError("Unexpected number of parameters for a with call", argList); } else if (parameters.length == 1) { Parameter param = parameters[0]; if (!param.isDynamicTyped() && !isAssignableTo(receiver, param.getType().redirect())) { addStaticTypeError("Expected parameter type: " + receiver.toString(false) + " but was: " + param.getType().redirect().toString(false), param); } } closure.putNodeMetaData(StaticTypesMarker.DELEGATION_METADATA, new DelegationMetadata( receiver, Closure.DELEGATE_FIRST, typeCheckingContext.delegationMetadata )); } }
blockParameterTypes[i] = resolvedParameter; openBlock.putNodeMetaData(StaticTypesMarker.CLOSURE_ARGUMENTS, blockParameterTypes);
public void transformClosureExpression(ClassNode classNode, ClosureExpression closureExpression) { if (closureExpression.getNodeMetaData(TRANSFORMED_MARKER) != null) return; ClassNode previousClassNode = this.currentClassNode; try { this.currentClassNode = classNode; List<String> propertyNames = AstPropertyResolveUtils.getPropertyNames(classNode); Statement code = closureExpression.getCode(); BlockStatement newCode = new BlockStatement(); boolean addAll = false; if (code instanceof BlockStatement) { BlockStatement bs = (BlockStatement) code; addBlockStatementToNewQuery(bs, newCode, addAll, propertyNames, closureExpression.getVariableScope()); newCode.setVariableScope(bs.getVariableScope()); } if (!newCode.getStatements().isEmpty()) { closureExpression.putNodeMetaData(TRANSFORMED_MARKER, Boolean.TRUE); closureExpression.setCode(newCode); } } finally { this.currentClassNode = previousClassNode; } }