Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        private static Code.Type CreateTransitionsClass(Graph graph)
        {
            var accessibility = graph.GetAccessibility();

            var transitionsClass = new Code.Type()
            {
                Name          = GetTransitionClassName(graph),
                Accessibility = accessibility
            };

            var interfaces = GetInterfacesDictionary(graph);

            foreach (var @interface in interfaces.Values)
            {
                transitionsClass.InternalTypes.Add(@interface);
            }

            return(transitionsClass);
        }
Ejemplo n.º 3
0
        private static IList <Code.Type> GetReturnTypes(Graph graph)
        {
            var returnTypes = new Dictionary <string, Code.Type>();

            foreach (var edge in graph.Edges)
            {
                if (edge.End.IsEnd)
                {
                    if (!returnTypes.ContainsKey(edge.End.GetReturn()))
                    {
                        var returnType = new Code.Type()
                        {
                            Name          = edge.End.GetReturn(),
                            Accessibility = graph.GetAccessibility(),
                            IsPartial     = true
                        };

                        returnTypes.Add(returnType.Name, returnType);
                    }
                }
            }

            return(returnTypes.Values.ToList());
        }