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();
}
}
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);
}
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;
}
}
}
}
}
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());
}
}
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());
}
}
Aggregations