示例#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();
            }
        }
示例#2
0
        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 + "  ");
                }
            }
        }
示例#3
0
        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);
        }
示例#4
0
        private PythonType GetMemberType(IPythonNode memberNode)
        {
            switch (memberNode)
            {
            case PythonField field:
                return(field.Type);

            case PythonFunction function:
                return(new PythonType(function));

            default:
                return(PythonTypes.Unknown);
            }
        }
示例#5
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);
        }
示例#6
0
 public PythonType(IPythonNode node)
 {
     this.Node = node;
 }