private static IList <MethodDescription> TranslateStartEdgeToVirtualTransitionMethodDescriptions(Graph graph, Edge edge) { var virtualTransitionMethodDescriptions = new List <MethodDescription>(); var internalMethodName = String.Concat(edge.Connection.GetName(), StartConnectionTransitionInternalMethodNameSufix); var parameterPairs = edge.Connection.GetParameters(); var internalMethod = new MethodDescription() { Name = internalMethodName, ReturnType = TypeName.Void(), Accessibility = Accessibility.Protected, DeclarationModifiers = DeclarationModifiers.Virtual }; internalMethod.Parameters = parameterPairs.Select(ConvertToParameter).ToList(); virtualTransitionMethodDescriptions.Add(internalMethod); var method = new MethodDescription() { Name = edge.Connection.GetName(), ReturnType = TypeName.CreateTypeName(String.Concat(GetTransitionClassName(graph), ".", String.Concat("I", edge.End.Identifier))), Accessibility = Accessibility.Public, Parameters = internalMethod.Parameters }; method.StatementsBuilders.Add(syntaxGenerator => GenerateInvokeMethodSyntaxNode(syntaxGenerator, internalMethodName, internalMethod.Parameters.Select(parameter => parameter.Name))); method.StatementsBuilders.Add(syntaxGenerator => syntaxGenerator.ReturnStatement(syntaxGenerator.ThisExpression())); virtualTransitionMethodDescriptions.Add(method); return(virtualTransitionMethodDescriptions); }
private static Parameter ConvertToParameter(ParameterPair parameterPair) { return(new Parameter() { Type = TypeName.CreateTypeName(parameterPair.Type), Name = parameterPair.Name }); }
private static Code.Type CreateBuilderClass(Graph graph) { var name = graph.GetName(); var accessibility = graph.GetAccessibility(); var builderClass = new Code.Type() { Name = name, Accessibility = accessibility, }; var interfaces = GetInterfacesDictionary(graph); var virtualTransitionMethodsDescription = GetVirtualTransitionMethodsDescription(graph); foreach (var transitionMethod in virtualTransitionMethodsDescription) { builderClass.Methods.Add(transitionMethod); } foreach (var @interface in interfaces.Values) { builderClass.BaseTypes.Add(TypeName.CreateTypeName(String.Concat(GetTransitionClassName(graph), ".", @interface.Name))); foreach (var method in @interface.Methods) { MethodDescription methodDescription = null; if (method.IsEndStateTransition) { methodDescription = new MethodDescription() { Name = String.Concat(GetTransitionClassName(graph), ".", @interface.Name, ".", method.Name), ReturnType = TypeName.CreateTypeName(method.ReturnType.Name), Parameters = method.Parameters.ToList() }; methodDescription.StatementsBuilders.Add(syntaxGenerator => syntaxGenerator.ReturnStatement(GenerateInvokeMethodSyntaxNode(syntaxGenerator, method.Name, method.Parameters.Select(parameter => parameter.Name)))); } else { methodDescription = new MethodDescription() { Name = String.Concat(GetTransitionClassName(graph), ".", @interface.Name, ".", method.Name), ReturnType = TypeName.CreateTypeName(String.Concat(GetTransitionClassName(graph), ".", method.ReturnType.Name)), Parameters = method.Parameters.ToList() }; methodDescription.StatementsBuilders.Add(syntaxGenerator => GenerateInvokeMethodSyntaxNode(syntaxGenerator, method.Name, method.Parameters.Select(parameter => parameter.Name))); methodDescription.StatementsBuilders.Add(syntaxGenerator => syntaxGenerator.ReturnStatement(syntaxGenerator.ThisExpression())); } builderClass.Methods.Add(methodDescription); } } return(builderClass); }
private static MethodDescription GetInternalTransitionMethodDescription(Edge edge) { var method = new MethodDescription() { Name = edge.Connection.GetName(), ReturnType = TypeName.CreateTypeName(String.Concat("I", edge.End.Identifier)) }; var parameterPairs = edge.Connection.GetParameters(); method.Parameters = parameterPairs.Select(ConvertToParameter).ToList(); return(method); }
private static MethodDescription GetEndStateTransitionMethodDescription(Edge edge) { var method = new MethodDescription() { Name = edge.End.GetName(), ReturnType = TypeName.CreateTypeName(edge.End.GetReturn()), IsEndStateTransition = true }; var parameterPairs = edge.End.GetParameters(); method.Parameters = parameterPairs.Select(ConvertToParameter).ToList(); return(method); }
private static MethodDescription TranslateEndStateToVirtualTransitionMethodDescription(Node end) { var method = new MethodDescription() { Name = end.GetName(), ReturnType = TypeName.CreateTypeName(end.GetReturn()), Accessibility = Accessibility.Protected, DeclarationModifiers = DeclarationModifiers.Virtual, IsEndStateTransition = true }; var endParameterPairs = end.GetParameters(); method.Parameters = endParameterPairs.Select(ConvertToParameter).ToList(); method.StatementsBuilders.Add( (syntaxGenerator) => syntaxGenerator.ReturnStatement(syntaxGenerator.DefaultExpression(method.ReturnType.ToSyntaxNode(syntaxGenerator)))); return(method); }