Package org.python.pydev.core

Examples of org.python.pydev.core.IModulesManager


                if (nature != null) {
                    ICodeCompletionASTManager astManager = nature.getAstManager();
                    //the nature may still not be completely restored...
                    if (astManager != null) {
                        IModulesManager modulesManager = astManager.getModulesManager();

                        if (modulesManager instanceof IProjectModulesManager) {
                            IProjectModulesManager projectModulesManager = (IProjectModulesManager) modulesManager;
                            String moduleName = projectModulesManager.resolveModuleInDirectManager(file
                                    .getActualObject());
View Full Code Here


    public static void recreateAllInfo(IPythonNature nature, IProgressMonitor monitor) {
        try {
            synchronized (additionalNatureInfoLock) {
                //Note: at this point we're 100% certain that the ast manager is there.
                IModulesManager m = nature.getAstManager().getModulesManager();
                IProject project = nature.getProject();

                AbstractAdditionalDependencyInfo currInfo = AdditionalProjectInterpreterInfo
                        .getAdditionalInfoForProject(nature);
                if (currInfo != null) {
View Full Code Here

                for (IInfo iInfo : allTokens) {
                    contentProvider.add(new AdditionalInfoAndIInfo(additionalInfo, iInfo), itemsFilter);
                }

                //Also show to the user the modules available as globals (2.2.3)
                IModulesManager modulesManager = null;
                try {
                    if (additionalInfo instanceof AdditionalProjectInterpreterInfo) {
                        AdditionalProjectInterpreterInfo projectInterpreterInfo = (AdditionalProjectInterpreterInfo) additionalInfo;
                        IProject project = projectInterpreterInfo.getProject();
                        PythonNature nature = PythonNature.getPythonNature(project);
                        if (nature != null) {
                            ICodeCompletionASTManager astManager = nature.getAstManager();
                            if (astManager != null) {
                                modulesManager = astManager.getModulesManager();
                            }

                        }
                    } else if (additionalInfo instanceof AdditionalSystemInterpreterInfo) {
                        AdditionalSystemInterpreterInfo systemInterpreterInfo = (AdditionalSystemInterpreterInfo) additionalInfo;
                        IInterpreterInfo defaultInterpreterInfo = systemInterpreterInfo.getManager()
                                .getDefaultInterpreterInfo(false);
                        modulesManager = defaultInterpreterInfo.getModulesManager();
                    }
                } catch (Throwable e) {
                    Log.log(e);
                }

                if (modulesManager != null) {
                    SortedMap<ModulesKey, ModulesKey> allDirectModulesStartingWith = modulesManager
                            .getAllDirectModulesStartingWith("");
                    Collection<ModulesKey> values = allDirectModulesStartingWith.values();
                    for (ModulesKey modulesKey : values) {
                        contentProvider.add(new AdditionalInfoAndIInfo(additionalInfo, new ModInfo(modulesKey.name)),
                                itemsFilter);
View Full Code Here

        ImageCache imageCache = PydevPlugin.getImageCache();
        Image packageImage = null;
        if (imageCache != null) { //making tests
            packageImage = imageCache.get(UIConstants.COMPLETION_PACKAGE_ICON);
        }
        IModulesManager projectModulesManager = astManager.getModulesManager();
        Set<String> allModules = projectModulesManager.getAllModuleNames(true, markerContents.toLowerCase());

        //when an undefined variable is found, we can:
        // - add an auto import (if it is a class or a method or some global attribute)
        // - declare it as a local or global variable
        // - change its name to some other global or local (mistyped)
View Full Code Here

        if (astManager == null) {
            addLeaf("AST manager == null (should happen only in the plugin initialization) -- skipping other checks.");
            return;
        }

        IModulesManager projectModulesManager = astManager.getModulesManager();
        if (projectModulesManager == null) {
            addLeaf("Modules manager == null (should happen only in the plugin initialization) -- skipping other checks.");
            return;
        }

        PythonPathHelper pythonPathHelper = (PythonPathHelper) projectModulesManager.getPythonPathHelper();
        if (pythonPathHelper == null) {
            addLeaf("PythonPathHelper == null (should happen only in the plugin initialization) -- skipping other checks.");
            return;
        }
        List<String> pythonpath = pythonPathHelper.getPythonpath();
        for (String s : pythonpath) {
            addLeaf("PYTHONPATH: " + s);
        }

        HashSet<ModulesKey> expectedModuleNames = new HashSet<ModulesKey>();
        for (String string : pythonpath) {
            File file = new File(string);
            if (file.isDirectory()) { //TODO: Handle zip file modules!
                Collection<PyFileInfo> modulesBelow = pythonPathHelper.getModulesBelow(file, new NullProgressMonitor())
                        .getFoundPyFileInfos();
                for (PyFileInfo fileInfo : modulesBelow) {
                    File moduleFile = fileInfo.getFile();
                    String modName = pythonPathHelper.resolveModule(FileUtils.getFileAbsolutePath(moduleFile), true);
                    if (modName != null) {
                        expectedModuleNames.add(new ModulesKey(modName, moduleFile));
                    } else {
                        if (PythonPathHelper.isValidModuleLastPart(StringUtils.stripExtension((moduleFile.getName())))) {
                            addLeaf(com.aptana.shared_core.string.StringUtils.format("Unable to resolve module: %s (gotten null module name)",
                                    moduleFile));
                        }
                    }
                }
            } else {
                if (!file.exists()) {
                    addLeaf(com.aptana.shared_core.string.StringUtils.format("File %s is referenced in the pythonpath but does not exist.", file));
                } else {
                    addLeaf(com.aptana.shared_core.string.StringUtils
                            .format("File %s not handled (TODO: Fix zip files support in the viewer).", file));
                }
            }
        }

        IntegrityInfo info = new IntegrityInfo();
        info.nature = nature;

        ModulesKey[] onlyDirectModules = projectModulesManager.getOnlyDirectModules();
        TreeSet<ModulesKey> inModulesManager = new TreeSet<ModulesKey>(Arrays.asList(onlyDirectModules));

        Set<String> allAdditionalInfoModuleNames = new TreeSet<String>();
        List<Tuple<AbstractAdditionalTokensInfo, IPythonNature>> additionalInfoAndNature = AdditionalProjectInterpreterInfo
                .getAdditionalInfoAndNature(nature, false, false, false);
        AbstractAdditionalTokensInfo additionalProjectInfo;
        if (additionalInfoAndNature.size() == 0) {
            addChild(new LeafElement(this, "No additional infos found (1 expected) -- skipping other checks."));
            return;

        } else {
            if (additionalInfoAndNature.size() > 1) {
                addChild(new LeafElement(this, com.aptana.shared_core.string.StringUtils.format(
                        "%s additional infos found (only 1 expected) -- continuing checks but analysis may be wrong.",
                        additionalInfoAndNature.size())));
            }
            additionalProjectInfo = additionalInfoAndNature.get(0).o1;
            allAdditionalInfoModuleNames.addAll(additionalProjectInfo.getAllModulesWithTokens());
        }

        for (ModulesKey key : inModulesManager) {
            if (!expectedModuleNames.contains(key)) {
                info.modulesNotInDisk.add(key);
                addChild(new LeafElement(this, com.aptana.shared_core.string.StringUtils.format("%s exists in memory but not in the disk.", key)));
            }
        }

        ModulesKey tempKey = new ModulesKey(null, null);
        for (String s : allAdditionalInfoModuleNames) {
            tempKey.name = s;
            if (!expectedModuleNames.contains(tempKey)) {
                info.additionalModulesNotInDisk.add(s);
                addChild(new LeafElement(this, com.aptana.shared_core.string.StringUtils.format(
                        "%s exists in the additional info but not in the disk.", s)));
            }
        }

        for (ModulesKey key : expectedModuleNames) {
            boolean isInModulesManager = inModulesManager.contains(key);
            if (!isInModulesManager) {
                info.modulesNotInMemory.add(key);
                addChild(new LeafElement(this, com.aptana.shared_core.string.StringUtils.format("%s exists in the disk but not in memory.", key)));
            }
            if (!allAdditionalInfoModuleNames.contains(key.name)) {
                try {
                    AbstractModule mod = AbstractModule.createModule(key.name, key.file, info.nature, true);
                    if (!(mod instanceof SourceModule)) {
                        continue;
                    }
                    SourceModule module = (SourceModule) mod;
                    if (module == null || module.getAst() == null) {
                        addChild(new LeafElement(this, com.aptana.shared_core.string.StringUtils.format(
                                "Warning: cannot parse: %s - %s (so, it's ok not having additional info on it)",
                                key.name, key.file)));
                    } else {
                        try {
                            Iterator<ASTEntry> innerEntriesForAST = AbstractAdditionalDependencyInfo
                                    .getInnerEntriesForAST(module.getAst()).o2;
                            if (innerEntriesForAST.hasNext()) {
                                info.moduleNotInAdditionalInfo.add(module);
                                addChild(new LeafElement(this, com.aptana.shared_core.string.StringUtils.format(
                                        "The additional info index of the module: %s is not updated.", key.name)));
                            }
                        } catch (Exception e) {
                            addChild(new LeafElement(this, com.aptana.shared_core.string.StringUtils.format(
                                    "Unexpected error happened on: %s - %s: %s", key.name, key.file, e.getMessage())));
                        }
                    }
                } catch (IOException e) {
                    //OK, it cannot be parsed, so, we cannot generate its info
                    addChild(new LeafElement(this, com.aptana.shared_core.string.StringUtils.format(
                            "Warning: cannot parse: %s - %s (so, it's ok not having additional info on it)", key.name,
                            key.file)));
                }
            }
        }

        //modules manager
        if (info.modulesNotInDisk.size() > 0) {
            for (ModulesKey m : info.modulesNotInDisk) {
                addChild(new LeafElement(this, com.aptana.shared_core.string.StringUtils.format("FIX: Removing from modules manager: %s", m)));
            }
            projectModulesManager.removeModules(info.modulesNotInDisk);
        }

        for (ModulesKey key : info.modulesNotInMemory) {
            addChild(new LeafElement(this, "FIX: Adding to modules manager: " + key));
            projectModulesManager.addModule(key);
        }

        //additional info
        for (String s : info.additionalModulesNotInDisk) {
            addChild(new LeafElement(this, com.aptana.shared_core.string.StringUtils.format("FIX: Removing from additional info: %s", s)));
View Full Code Here

     */
    public String resolveModuleOnlyInProjectSources(String fileAbsolutePath, boolean addExternal) throws CoreException {
        String moduleName = null;

        if (astManager != null) {
            IModulesManager modulesManager = astManager.getModulesManager();
            if (modulesManager instanceof ProjectModulesManager) {
                moduleName = ((ProjectModulesManager) modulesManager).resolveModuleOnlyInProjectSources(
                        fileAbsolutePath, addExternal);
            }
        }
View Full Code Here

    protected ModuleAdapter createModuleAdapterFromDataSource(String version) throws Throwable {
        codeCompletionTestsBase.restorePythonPath(FileUtils.getFileAbsolutePath(data.file.getParentFile()), true);
        PythonModuleManager pythonModuleManager = new PythonModuleManager(CodeCompletionTestsBase.nature);
        if (version != null) {
            //As the files will be found in the system, we need to set the system modules manager info.
            IModulesManager modulesManager = pythonModuleManager.getIModuleManager();
            SystemModulesManager systemModulesManager = (SystemModulesManager) modulesManager.getSystemModulesManager();
            systemModulesManager.setInfo(new InterpreterInfo(version, "", new ArrayList<String>()));

            CodeCompletionTestsBase.nature.setVersion(version, null);
        }
        ModuleAdapter module = VisitorFactory.createModuleAdapter(pythonModuleManager, data.file, new Document(
View Full Code Here

     *
     * This includes the pythonpath for the project, all the referenced projects and the
     * system.
     */
    public List<String> getCompleteProjectPythonPath(IInterpreterInfo interpreter, IInterpreterManager manager) {
        IModulesManager projectModulesManager = getProjectModulesManager();
        if (projectModulesManager == null) {
            if (!waited) {
                waited = true;
                for (int i = 0; i < 10 && projectModulesManager == null; i++) {
                    //We may get into a race condition, so, try to see if we can get it.
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        //OK
                    }
                    projectModulesManager = getProjectModulesManager();
                }
            }
        }
        if (projectModulesManager == null) {
            return null;
        }
        return projectModulesManager.getCompletePythonPath(interpreter, manager);
    }
View Full Code Here

        try {
            IPythonNature pythonNature = this.getPythonNature();
            if (pythonNature != null) {
                ICodeCompletionASTManager astManager = pythonNature.getAstManager();
                if (astManager != null) {
                    IModulesManager modulesManager = astManager.getModulesManager();
                    if (modulesManager != null) {
                        File editorFile = this.getEditorFile();
                        if (editorFile != null) {
                            String moduleName = pythonNature.resolveModule(editorFile);
                            if (moduleName != null) {
                                synchronized (lockHandle) {
                                    releaseCurrentHandle();
                                    int modHandle = modulesManager.pushTemporaryModule(moduleName, new SourceModule(
                                            moduleName, editorFile, ast, null));

                                    this.handle = new Tuple3<Integer, IModulesManager, String>(modHandle,
                                            modulesManager, moduleName);
                                }
View Full Code Here

    public boolean startRequests() {
        ICodeCompletionASTManager astManager = this.getAstManager();
        if (astManager == null) {
            return false;
        }
        IModulesManager modulesManager = astManager.getModulesManager();
        if (modulesManager == null) {
            return false;
        }
        synchronized (modulesManagerStackLock) {
            modulesManagerStack.push(modulesManager);
            return modulesManager.startCompletionCache();
        }
    }
View Full Code Here

TOP

Related Classes of org.python.pydev.core.IModulesManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.