private void AssociateToProviderFunction(string providerFunctionName, IFunctionExpression factoryFunction) { var constructedFactoryType = factoryFunction.GetJsType(context, new JsCyclicFlowAccumulator()).GetConstructedType(JsUnresolvedTypeArray.NoList); var providerFunctionGlobalType = GetProviderFunctionGlobalType(providerFunctionName); var offset = context.GetDocumentStartOffset(factoryFunction); CreateAssignmentAssociation(providerFunctionGlobalType, constructedFactoryType, offset); }
private void AssociateToProviderGet(string providerFunctionName, IFunctionExpression providerGetFactoryFunction) { var serviceType = providerGetFactoryFunction.GetJsType(context, new JsCyclicFlowAccumulator()).GetReturnType(); var providerGetGlobalType = GetProviderGetGlobalType(providerFunctionName); var offset = context.GetDocumentStartOffset(providerGetFactoryFunction); CreateAssignmentAssociation(providerGetGlobalType, serviceType, offset); }
private object Act(IFunctionExpression expression, IFunctionParametersFiller functionParametersFiller = null, IFunctionHandlerResolver functionHandlerResolver = null) { var executor = new FunctionExpressionExecutor(functionParametersFiller ?? Substitute.For <IFunctionParametersFiller>(), functionHandlerResolver ?? Substitute.For <IFunctionHandlerResolver>()); return(executor.Execute(expression)); }
private ILiteralBinaryFunctionExpression <T, U> get <T, U>(IBinaryFunctionExpression <T, U> expression, IEvaluator ev, IContext context) { IFunctionExpression <T, U> ex = expression; while (!ex.IsLiteral) { ex = ex.Evaluate(this, context); } return(ex as ILiteralBinaryFunctionExpression <T, U>); }
private void ProcessServiceInjection(IExpressionOrSpread owner, IFunctionExpression factoryFunction) { var injectedServiceNames = GetInjectedServiceNames(owner, factoryFunction); for (var i = 0; i < factoryFunction.Parameters.Count; i++) { var parameter = factoryFunction.Parameters[i]; var serviceName = injectedServiceNames[i]; AssociateToParameter(serviceName, parameter); } }
private void ProcessModuleProviderRegistration(string serviceName, IFunctionExpression factoryFunction) { if (factoryFunction == null) { return; } // The function is likely to be anonymous, in which case, create a default name var providerName = factoryFunction.HasName ? factoryFunction.DeclaredName : serviceName + ProviderSuffix; AssociateToProviderGlobalType(serviceName, providerName, factoryFunction); AssociateToServiceGlobalType(serviceName, providerName, factoryFunction); }
private void ProcessModuleFactoryRegistration(string serviceName, IFunctionExpression factoryFunction) { if (factoryFunction == null) { return; } // The return type of the factory function var serviceType = factoryFunction.GetFunctionImplicitReturnType(context); var serviceOffset = context.GetDocumentStartOffset(factoryFunction); AssociateToServiceGlobalType(serviceName, serviceType, serviceOffset); }
private void ProcessModuleServiceRegistration(string serviceName, IFunctionExpression factoryFunction) { if (factoryFunction == null) { return; } // The factory function is a constructor, use the constructed type var serviceType = factoryFunction.GetJsType(context, new JsCyclicFlowAccumulator()).GetConstructedType(JsUnresolvedTypeArray.NoList); var serviceOffset = context.GetDocumentStartOffset(factoryFunction); AssociateToServiceGlobalType(serviceName, serviceType, serviceOffset); }
public object Execute(IFunctionExpression expression) { var functionType = expression.FunctionType; var functionDefinitionImplementation = functionType.GetGenericInterfaceDefinitionImplementation(typeof(IFunction <>)); var resultType = functionDefinitionImplementation.GetGenericArguments()[0]; try { return(_executeFunctionMethod.Value .MakeGenericMethod(functionType, resultType) .Invoke(this, new object[] { expression.ArgumentExpressions })); } catch (TargetInvocationException exception) { throw exception.InnerException; } }
private string[] GetInjectedServiceNames(IExpressionOrSpread owner, IFunctionExpression factoryFunction) { // TODO: Get the names from the $inject string literal array var injectedServiceNames = factoryFunction.Parameters.Select(p => p.GetDeclaredName()).ToArray(); var arrayLiteral = owner as IArrayLiteral; if (arrayLiteral != null) { for (int i = 0; i < injectedServiceNames.Length && i < arrayLiteral.ArrayElements.Count; i++) { var serviceName = arrayLiteral.ArrayElements[i].GetStringLiteralValue(); if (!string.IsNullOrEmpty(serviceName)) { injectedServiceNames[i] = serviceName; } } } return(injectedServiceNames); }
private void ProcessProviderFunctionDeclaration(string providerFunctionName, IFunctionExpression functionExpression) { if (!providerFunctionName.EndsWith(ProviderSuffix)) { return; } var block = functionExpression.Block; if (block == null) { return; } IFunctionExpression providerGetFactoryFunction = null; foreach (var statement in block.StatementsEnumerable.OfType <IExpressionStatement>()) { var assignment = statement.Expression.LastExpression as ISimpleAssignmentExpression; if (assignment == null) { continue; } if (IsAssignmentToGet(assignment)) { providerGetFactoryFunction = GetFactoryFunction(assignment.Source); if (providerGetFactoryFunction != null) { break; } } } if (providerGetFactoryFunction != null) { AssociateToProviderGet(providerFunctionName, providerGetFactoryFunction); } }
public override void VisitFunctionExpression(IFunctionExpression functionExpression) { ProcessProviderFunctionDeclaration(functionExpression); base.VisitFunctionExpression(functionExpression); }
private void AssociateToProviderGet(string providerFunctionName, IFunctionExpression providerGetFactoryFunction) { var serviceType = providerGetFactoryFunction.GetJsType(context).GetReturnType(); var providerGetGlobalType = GetProviderGetGlobalType(providerFunctionName); var offset = context.GetDocumentStartOffset(providerGetFactoryFunction); CreateAssignmentAssociation(providerGetGlobalType, serviceType, offset); }
private string[] GetInjectedServiceNames(IExpressionOrSpread owner, IFunctionExpression factoryFunction) { // TODO: Get the names from the $inject string literal array var injectedServiceNames = factoryFunction.Parameters.Select(p => p.GetDeclaredName()).ToArray(); var arrayLiteral = owner as IArrayLiteral; if (arrayLiteral != null) { for (int i = 0; i < injectedServiceNames.Length && i < arrayLiteral.ArrayElements.Count; i++) { var serviceName = arrayLiteral.ArrayElements[i].GetStringLiteralValue(); if (!string.IsNullOrEmpty(serviceName)) injectedServiceNames[i] = serviceName; } } return injectedServiceNames; }
// Built in services // Sets up the type for an injected factory function (type of the last parameter // to the array literal assigned to $get) // function $BrowserProvider() { // this.$get = [ '$window', '$log', ..., function($window, $log, ...) { ... private void ProcessProviderFunctionDeclaration(IFunctionExpression functionExpression) { ProcessProviderFunctionDeclaration(functionExpression.DeclaredName, functionExpression); }
private void ProcessModuleFactoryRegistration(string serviceName, IFunctionExpression factoryFunction) { if (factoryFunction == null) return; // The return type of the factory function var serviceType = factoryFunction.GetFunctionImplicitReturnType(context); var serviceOffset = context.GetDocumentStartOffset(factoryFunction); AssociateToServiceGlobalType(serviceName, serviceType, serviceOffset); }
private void ProcessModuleServiceRegistration(string serviceName, IFunctionExpression factoryFunction) { if (factoryFunction == null) return; // The factory function is a constructor, use the constructed type // TODO: Is this right? What invocation info should I use? var serviceType = factoryFunction.GetJsType(context).GetConstructedType(JsUnresolvedTypeArray.EmptyList); var serviceOffset = context.GetDocumentStartOffset(factoryFunction); AssociateToServiceGlobalType(serviceName, serviceType, serviceOffset); }
private void ProcessModuleProviderRegistration(string serviceName, IFunctionExpression factoryFunction) { if (factoryFunction == null) return; // The function is likely to be anonymous, in which case, create a default name var providerName = factoryFunction.HasName ? factoryFunction.DeclaredName : serviceName + ProviderSuffix; AssociateToProviderGlobalType(serviceName, providerName, factoryFunction); AssociateToServiceGlobalType(serviceName, providerName, factoryFunction); }
private void AssociateToProviderFunction(string providerFunctionName, IFunctionExpression factoryFunction) { var constructedFactoryType = factoryFunction.GetJsType(context).GetConstructedType(JsUnresolvedTypeArray.EmptyList); var providerFunctionGlobalType = GetProviderFunctionGlobalType(providerFunctionName); var offset = context.GetDocumentStartOffset(factoryFunction); CreateAssignmentAssociation(providerFunctionGlobalType, constructedFactoryType, offset); }
private void ProcessProviderFunctionDeclaration(string providerFunctionName, IFunctionExpression functionExpression) { if (!providerFunctionName.EndsWith(ProviderSuffix)) return; var block = functionExpression.Block; if (block == null) return; IFunctionExpression providerGetFactoryFunction = null; foreach (var statement in block.StatementsEnumerable.OfType<IExpressionStatement>()) { var assignment = statement.Expression.LastExpression as ISimpleAssignmentExpression; if (assignment == null) continue; if (IsAssignmentToGet(assignment)) { providerGetFactoryFunction = GetFactoryFunction(assignment.Source); if (providerGetFactoryFunction != null) break; } } if (providerGetFactoryFunction != null) AssociateToProviderGet(providerFunctionName, providerGetFactoryFunction); }