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 void LogNode(IPythonNode node, string prefix) { switch (node) { case PythonModule pythonModule: Logger.Log($"{prefix}Module: {pythonModule.Name}", LogLevel.Info); break; case PythonClass pythonClass: Logger.Log($"{prefix}Class: {pythonClass}", LogLevel.Info); break; case PythonField pythonField: Logger.Log($"{prefix}Field: {pythonField}", LogLevel.Info); break; case PythonProperty pythonProperty: Logger.Log($"{prefix}Property: {pythonProperty}", LogLevel.Info); break; case PythonFunction pythonFunction: Logger.Log($"{prefix}Function: {pythonFunction}", LogLevel.Info); break; } if (node.Children != null) { foreach (var child in node.Children) { LogNode(child.Value, prefix + " "); } } }
public static IPythonNode GetDescendent(this IPythonNode node, string path) { var pathParts = path.Split("."); foreach (string pathPart in pathParts) { if (!node.Children.TryGetValue(pathPart, out node)) { return(null); } } return(node); }
private PythonType GetMemberType(IPythonNode memberNode) { switch (memberNode) { case PythonField field: return(field.Type); case PythonFunction function: return(new PythonType(function)); default: return(PythonTypes.Unknown); } }
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 PythonType(IPythonNode node) { this.Node = node; }