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(); } }
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); }
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); }