Exemplo n.º 1
0
        public override bool Walk(FromImportStatement node)
        {
            PythonFromImport import = new PythonFromImport(compilationUnit.ProjectContent, node);

            compilationUnit.UsingScope.Usings.Add(import);
            return(false);
        }
		public void Init()
		{
			string python = "from math import *";
			
			DefaultProjectContent projectContent = new DefaultProjectContent();
			PythonParser parser = new PythonParser();
			compilationUnit = parser.Parse(projectContent, @"C:\test.py", python);
			import = compilationUnit.UsingScope.Usings[0] as PythonFromImport;
		}
 /// <summary>
 /// Looks for the module name where the specified identifier is imported from.
 /// </summary>
 public string GetModuleForImportedName(string name)
 {
     foreach (IUsing u in compilationUnit.UsingScope.Usings)
     {
         PythonFromImport pythonFromImport = u as PythonFromImport;
         if (pythonFromImport != null)
         {
             if (pythonFromImport.IsImportedName(name))
             {
                 return(pythonFromImport.Module);
             }
         }
     }
     return(null);
 }
 /// <summary>
 /// Converts a name into the correct identifier name based on any from import as statements.
 /// </summary>
 public string UnaliasImportedName(string name)
 {
     foreach (IUsing u in compilationUnit.UsingScope.Usings)
     {
         PythonFromImport pythonFromImport = u as PythonFromImport;
         if (pythonFromImport != null)
         {
             string actualName = pythonFromImport.GetOriginalNameForAlias(name);
             if (actualName != null)
             {
                 return(actualName);
             }
         }
     }
     return(name);
 }
        public string[] GetModulesThatImportEverything()
        {
            List <string> modules = new List <string>();

            foreach (IUsing u in compilationUnit.UsingScope.Usings)
            {
                PythonFromImport pythonFromImport = u as PythonFromImport;
                if (pythonFromImport != null)
                {
                    if (pythonFromImport.ImportsEverything)
                    {
                        modules.Add(pythonFromImport.Module);
                    }
                }
            }
            return(modules.ToArray());
        }
		public override bool Walk(FromImportStatement node)
		{
			PythonFromImport import = new PythonFromImport(compilationUnit.ProjectContent, node);
			compilationUnit.UsingScope.Usings.Add(import);
			return false;
		}