Search in sources :

Example 1 with AdditionalSystemInterpreterInfo

use of com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo in project Pydev by fabioz.

the class GlobalsTwoPanelElementSelector2 method fillContentProvider.

/**
 * This is the place where we put all the info in the content provider. Note that here we must add
 * ALL the info -- later, we'll filter it based on the active working set.
 */
@Override
protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) throws CoreException {
    if (itemsFilter instanceof InfoFilter) {
        if (progressMonitor != null) {
            progressMonitor.beginTask("Searching...", this.additionalInfo.size());
        }
        for (AbstractAdditionalTokensInfo additionalInfo : this.additionalInfo) {
            if (progressMonitor != null) {
                if (progressMonitor.isCanceled()) {
                    return;
                } else {
                    progressMonitor.worked(1);
                }
            }
            // no duplicates
            Collection<IInfo> allTokens = new HashSet<IInfo>(additionalInfo.getAllTokens());
            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, modulesManager.getNature(), modulesKey.file != null ? modulesKey.file.toString() : null, 1, 1)), itemsFilter);
                }
            }
        }
    }
    if (progressMonitor != null) {
        progressMonitor.done();
    }
}
Also used : IPythonNature(org.python.pydev.core.IPythonNature) PythonNature(org.python.pydev.plugin.nature.PythonNature) IModulesManager(org.python.pydev.core.IModulesManager) IProject(org.eclipse.core.resources.IProject) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) AdditionalInfoAndIInfo(com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo) IInfo(org.python.pydev.core.IInfo) AdditionalProjectInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo) ICodeCompletionASTManager(org.python.pydev.core.ICodeCompletionASTManager) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) AdditionalInfoAndIInfo(com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo) ModulesKey(org.python.pydev.core.ModulesKey) AbstractAdditionalTokensInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo) ModInfo(com.python.pydev.analysis.additionalinfo.ModInfo) HashSet(java.util.HashSet)

Example 2 with AdditionalSystemInterpreterInfo

use of com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo in project Pydev by fabioz.

the class ModuleIInfoLabelProvider method getText.

@Override
public String getText(Object element) {
    if (element instanceof AdditionalInfoAndIInfo) {
        AdditionalInfoAndIInfo additional = (AdditionalInfoAndIInfo) element;
        element = additional.info;
        String suffix = null;
        try {
            if (additional.additionalInfo instanceof AdditionalProjectInterpreterInfo) {
                AdditionalProjectInterpreterInfo projectInterpreterInfo = (AdditionalProjectInterpreterInfo) additional.additionalInfo;
                suffix = projectInterpreterInfo.getProject().getName();
            } else if (additional.additionalInfo instanceof AdditionalSystemInterpreterInfo) {
                AdditionalSystemInterpreterInfo systemInterpreterInfo = (AdditionalSystemInterpreterInfo) additional.additionalInfo;
                suffix = systemInterpreterInfo.getManager().getDefaultInterpreterInfo(false).getName();
            }
        } catch (Throwable e) {
            Log.log(e);
        }
        String iInfoText = getIInfoText((IInfo) element, suffix);
        return iInfoText;
    }
    if (element instanceof String) {
        return (String) element;
    }
    return getIInfoText((IInfo) element, null);
}
Also used : AdditionalProjectInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo) AdditionalInfoAndIInfo(com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)

Example 3 with AdditionalSystemInterpreterInfo

use of com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo in project Pydev by fabioz.

the class PyGlobalsBrowser method doSelect.

/**
 * @param pythonNatures the natures from were we can get info
 * @param additionalInfo the additional informations
 * @param selectedText the text that should be initially set as a filter
 */
public static void doSelect(List<IPythonNature> pythonNatures, List<AbstractAdditionalTokensInfo> additionalInfo, String selectedText) {
    SelectionDialog dialog = GlobalsDialogFactory.create(EditorUtils.getShell(), additionalInfo, selectedText);
    dialog.open();
    Object[] result = dialog.getResult();
    if (result != null && result.length > 0) {
        for (Object obj : result) {
            IInfo entry;
            if (obj instanceof AdditionalInfoAndIInfo) {
                AdditionalInfoAndIInfo additional = (AdditionalInfoAndIInfo) obj;
                try {
                    // all of the input natures).
                    if (additional.additionalInfo instanceof AdditionalProjectInterpreterInfo) {
                        AdditionalProjectInterpreterInfo projectInterpreterInfo = (AdditionalProjectInterpreterInfo) additional.additionalInfo;
                        IProject project = projectInterpreterInfo.getProject();
                        PythonNature pythonNature = PythonNature.getPythonNature(project);
                        if (pythonNature != null) {
                            pythonNatures = new ArrayList<IPythonNature>();
                            pythonNatures.add(pythonNature);
                        }
                    } else if (additional.additionalInfo instanceof AdditionalSystemInterpreterInfo) {
                        AdditionalSystemInterpreterInfo systemInterpreterInfo = (AdditionalSystemInterpreterInfo) additional.additionalInfo;
                        SystemPythonNature pythonNature = new SystemPythonNature(systemInterpreterInfo.getManager());
                        pythonNatures = new ArrayList<IPythonNature>();
                        pythonNatures.add(pythonNature);
                    }
                } catch (Throwable e) {
                    Log.log(e);
                }
                entry = additional.info;
            } else {
                entry = (IInfo) obj;
            }
            List<ItemPointer> pointers = new ArrayList<ItemPointer>();
            ICompletionState completionCache = new CompletionState();
            for (IPythonNature pythonNature : pythonNatures) {
                // try to find in one of the natures...
                ICodeCompletionASTManager astManager = pythonNature.getAstManager();
                if (astManager == null) {
                    continue;
                }
                AnalysisPlugin.getDefinitionFromIInfo(pointers, astManager, pythonNature, entry, completionCache, false, true);
                if (pointers.size() > 0) {
                    new PyOpenAction().run(pointers.get(0));
                    // don't check the other natures
                    break;
                }
            }
        }
    }
}
Also used : IPythonNature(org.python.pydev.core.IPythonNature) PythonNature(org.python.pydev.plugin.nature.PythonNature) SystemPythonNature(org.python.pydev.plugin.nature.SystemPythonNature) PyOpenAction(org.python.pydev.editor.actions.PyOpenAction) IPythonNature(org.python.pydev.core.IPythonNature) ArrayList(java.util.ArrayList) SystemPythonNature(org.python.pydev.plugin.nature.SystemPythonNature) ICompletionState(org.python.pydev.core.ICompletionState) CompletionState(org.python.pydev.ast.codecompletion.revisited.CompletionState) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) IProject(org.eclipse.core.resources.IProject) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInfo(org.python.pydev.core.IInfo) AdditionalInfoAndIInfo(com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo) AdditionalProjectInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo) ICodeCompletionASTManager(org.python.pydev.core.ICodeCompletionASTManager) AdditionalInfoAndIInfo(com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo) ICompletionState(org.python.pydev.core.ICompletionState) ItemPointer(org.python.pydev.ast.item_pointer.ItemPointer)

Example 4 with AdditionalSystemInterpreterInfo

use of com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo in project Pydev by fabioz.

the class SyncSystemModulesManagerTest method setupEnv.

private void setupEnv(boolean setupInitialInfoProperly) throws MisconfigurationException {
    Collection<String> pythonpath = new ArrayList<String>();
    pythonpath.add(libDir.toString());
    final InterpreterInfo info = new InterpreterInfo("2.6", TestDependent.PYTHON2_EXE, pythonpath);
    IEclipsePreferences preferences = createPreferenceStore();
    final PythonInterpreterManager manager = new PythonInterpreterManager(preferences);
    InterpreterManagersAPI.setPythonInterpreterManager(manager);
    manager.setInfos(new IInterpreterInfo[] { info }, null, null);
    AdditionalSystemInterpreterInfo additionalInfo = new AdditionalSystemInterpreterInfo(manager, info.getExecutableOrJar());
    AdditionalSystemInterpreterInfo.setAdditionalSystemInfo(manager, info.getExecutableOrJar(), additionalInfo);
    // Don't load it (otherwise it'll get the 'proper' info).
    if (setupInitialInfoProperly) {
        InterpreterInfo infoOnManager = manager.getInterpreterInfo(info.getExecutableOrJar(), null);
        assertEquals(infoOnManager.getPythonPath(), info.getPythonPath());
        NullProgressMonitor monitor = new NullProgressMonitor();
        info.restorePythonpath(monitor);
        AdditionalSystemInterpreterInfo.recreateAllInfo(manager, info.getExecutableOrJar(), monitor);
        final ISystemModulesManager modulesManager = info.getModulesManager();
        assertEquals(3, modulesManager.getSize(false));
        assertEquals(3, infoOnManager.getModulesManager().getSize(false));
        additionalInfo = (AdditionalSystemInterpreterInfo) AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(manager, info.getExecutableOrJar());
        Collection<IInfo> allTokens = additionalInfo.getAllTokens();
        assertEquals(3, additionalInfo.getAllTokens().size());
    } else {
        final ISystemModulesManager modulesManager = info.getModulesManager();
        assertEquals(0, modulesManager.getSize(false));
        assertEquals(0, additionalInfo.getAllTokens().size());
    }
}
Also used : IInfo(org.python.pydev.core.IInfo) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ISystemModulesManager(org.python.pydev.core.ISystemModulesManager) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) PythonInterpreterManager(org.python.pydev.ast.interpreter_managers.PythonInterpreterManager) ArrayList(java.util.ArrayList) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)

Example 5 with AdditionalSystemInterpreterInfo

use of com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo in project Pydev by fabioz.

the class SyncSystemModulesManagerTest method testUpdateWhenEggIsAdded.

public void testUpdateWhenEggIsAdded() throws Exception {
    setupEnv(true);
    SyncSystemModulesManager synchManager = new SyncSystemModulesManager();
    final DataAndImageTreeNode root = new DataAndImageTreeNode(null, null, null);
    Map<IInterpreterManager, Map<String, IInterpreterInfo>> managerToNameToInfoMap = InterpreterManagersAPI.getInterpreterManagerToInterpreterNameToInfo();
    ManagerInfoToUpdate managerToNameToInfo = new ManagerInfoToUpdate(managerToNameToInfoMap);
    checkUpdateStructures(synchManager, root, managerToNameToInfo);
    checkSynchronize(synchManager, root, managerToNameToInfo);
    root.clear();
    managerToNameToInfo = new ManagerInfoToUpdate(InterpreterManagersAPI.getInterpreterManagerToInterpreterNameToInfo());
    synchManager.updateStructures(null, root, managerToNameToInfo, new SyncSystemModulesManager.CreateInterpreterInfoCallback() {

        @Override
        public IInterpreterInfo createInterpreterInfo(IInterpreterManager manager, String executable, IProgressMonitor monitor) {
            Collection<String> pythonpath = new ArrayList<String>();
            pythonpath.add(libDir.toString());
            pythonpath.add(libZipFile.toString());
            final InterpreterInfo info = new InterpreterInfo("2.6", TestDependent.PYTHON2_EXE, pythonpath);
            return info;
        }
    });
    assertTrue(root.hasChildren());
    List<TreeNode> selectElements = new ArrayList<>();
    selectElements.addAll(root.flattenChildren());
    synchManager.applySelectedChangesToInterpreterInfosPythonpath(root, selectElements, null);
    List<IInterpreterInfo> allInterpreterInfos = InterpreterManagersAPI.getAllInterpreterInfos();
    for (IInterpreterInfo interpreterInfo : allInterpreterInfos) {
        assertEquals(4, interpreterInfo.getModulesManager().getSize(false));
        AdditionalSystemInterpreterInfo additionalInfo = (AdditionalSystemInterpreterInfo) AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(interpreterInfo.getModulesManager().getInterpreterManager(), interpreterInfo.getExecutableOrJar());
        Collection<IInfo> allTokens = additionalInfo.getAllTokens();
        assertEquals(4, additionalInfo.getAllTokens().size());
    }
}
Also used : ArrayList(java.util.ArrayList) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) IInterpreterManager(org.python.pydev.core.IInterpreterManager) SyncSystemModulesManager(org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInfo(org.python.pydev.core.IInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) TreeNode(org.python.pydev.shared_core.structure.TreeNode) Collection(java.util.Collection) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) HashMap(java.util.HashMap) Map(java.util.Map) ManagerInfoToUpdate(org.python.pydev.ast.codecompletion.revisited.ManagerInfoToUpdate)

Aggregations

AdditionalSystemInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)6 IInfo (org.python.pydev.core.IInfo)5 ArrayList (java.util.ArrayList)4 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)4 AdditionalInfoAndIInfo (com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo)3 AdditionalProjectInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo)3 InterpreterInfo (org.python.pydev.ast.interpreter_managers.InterpreterInfo)3 IProject (org.eclipse.core.resources.IProject)2 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)2 PythonInterpreterManager (org.python.pydev.ast.interpreter_managers.PythonInterpreterManager)2 ICodeCompletionASTManager (org.python.pydev.core.ICodeCompletionASTManager)2 IPythonNature (org.python.pydev.core.IPythonNature)2 ISystemModulesManager (org.python.pydev.core.ISystemModulesManager)2 PythonNature (org.python.pydev.plugin.nature.PythonNature)2 AbstractAdditionalDependencyInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo)1 AbstractAdditionalTokensInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo)1 ModInfo (com.python.pydev.analysis.additionalinfo.ModInfo)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1