Exemplo n.º 1
0
        public static void ExtractChildren(this IPythonNode node, Statement statement)
        {
            if (statement is SuiteStatement suiteStatement)
            {
                foreach (Statement memberStatement in suiteStatement.Statements)
                {
                    switch (memberStatement)
                    {
                    case ClassDefinition classDefinition:
                        var pythonClass = PythonClass.Create(classDefinition);
                        node.Children[pythonClass.Name] = pythonClass;
                        break;

                    case FunctionDefinition functionDefinition:
                        var pythonFunction = PythonFunction.Create(functionDefinition);
                        node.Children[pythonFunction.Name] = pythonFunction;
                        break;
                    }
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Exemplo n.º 2
0
        public static PythonClass GetOrAddClass(this IPythonNode node, string className)
        {
            var pathParts = className.Split(".");

            foreach (string pathPart in pathParts)
            {
                if (!node.Children.TryGetValue(pathPart, out var childNode))
                {
                    childNode = PythonClass.Create(pathPart);
                    node.Children[pathPart] = childNode;
                }

                node = childNode;
            }

            return((PythonClass)node);
        }
Exemplo n.º 3
0
        public static PythonClass Create(ClassDefinition pythonDefinition)
        {
            var node     = new PythonClass(pythonDefinition.Name, pythonDefinition);
            var nodeType = new PythonType(node);

            node.ExtractChildren(pythonDefinition.Body);

            foreach (var child in node.Children.Values)
            {
                if (child is PythonFunction pythonFunction)
                {
                    pythonFunction.Parameters[0].Type = nodeType;
                }
            }

            return(node);
        }