Exemple #1
0
 /**
  * This function creates a module and resolves the module name (use this function if only the file
  * is available).
  *
  * @throws MisconfigurationException
  */
 public static IModule createModuleFromDoc(File file, IDocument doc, IPythonNature pythonNature)
     throws MisconfigurationException {
   IModulesManager projModulesManager = pythonNature.getAstManager().getModulesManager();
   String moduleName = null;
   if (file != null) {
     moduleName = projModulesManager.resolveModule(FileUtils.getFileAbsolutePath(file));
   }
   if (moduleName == null) {
     moduleName = MODULE_NAME_WHEN_FILE_IS_UNDEFINED;
   }
   IModule module = createModuleFromDoc(moduleName, file, doc, pythonNature, false);
   return module;
 }
Exemple #2
0
 public static ModuleAdapter createModuleAdapter(
     PythonModuleManager pythonModuleManager, File file, IDocument doc, IPythonNature nature)
     throws Throwable {
   if (file != null && file.exists()) {
     if (pythonModuleManager != null) {
       IModulesManager modulesManager = pythonModuleManager.getIModuleManager();
       if (modulesManager != null) {
         String modName = modulesManager.resolveModule(REF.getFileAbsolutePath(file));
         if (modName != null) {
           IModule module = modulesManager.getModule(modName, nature, true);
           if (module instanceof ISourceModule) {
             SourceModule iSourceModule = (SourceModule) module;
             if (iSourceModule.parseError != null) {
               throw iSourceModule.parseError;
             }
             return new ModuleAdapter(pythonModuleManager, ((ISourceModule) module), nature, doc);
           }
         }
       }
     }
   }
   return new ModuleAdapter(pythonModuleManager, file, doc, getRootNode(doc), nature);
 }