/** * Stores the inferred return type of a closure or a method. We are using a separate key to store * inferred return type because the inferred type of a closure is {@link Closure}, which is different * from the inferred type of the code of the closure. * * @param node a {@link ClosureExpression} or a {@link MethodNode} * @param type the inferred return type of the code * @return the old value of the inferred type */ protected ClassNode storeInferredReturnType(final ASTNode node, final ClassNode type) { if (!(node instanceof ClosureExpression)) { throw new IllegalArgumentException("Storing inferred return type is only allowed on closures but found " + node.getClass()); } return (ClassNode) node.putNodeMetaData(StaticTypesMarker.INFERRED_RETURN_TYPE, type); }
/** * 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); }
Variable targetVariable = findTargetVariable((VariableExpression) leftExpression); if (targetVariable instanceof ASTNode) { ((ASTNode) targetVariable).putNodeMetaData( StaticTypesMarker.CLOSURE_ARGUMENTS, ((Expression) ((VariableExpression) rightExpression).getAccessedVariable()).getNodeMetaData(StaticTypesMarker.CLOSURE_ARGUMENTS));