use of com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo 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.AdditionalProjectInterpreterInfo in project Pydev by fabioz.
the class RefactorerFindReferences method findPossibleReferences.
/**
* Find the references that may have the text we're looking for.
*
* @param request the request with the info for the find
* @return an array of IFile with the files that may have the references we're
* interested about (note that those may not actually contain the matches we're
* interested in -- it is just a helper to refine our search).
*/
public List<Tuple<List<ModulesKey>, IPythonNature>> findPossibleReferences(RefactoringRequest request) throws OperationCanceledException {
String initialName = request.qualifier;
List<Tuple<List<ModulesKey>, IPythonNature>> ret = request.getPossibleReferences(initialName);
if (ret != null) {
return ret;
}
if (FORCED_RETURN != null) {
ret = new ArrayList<Tuple<List<ModulesKey>, IPythonNature>>();
for (Tuple<List<ModulesKey>, IPythonNature> f : FORCED_RETURN) {
// only for testing purposes
for (ModulesKey k : f.o1) {
String object = FileUtils.getFileContents(k.file);
if (object.indexOf(request.qualifier) != -1) {
ret.add(new Tuple<List<ModulesKey>, IPythonNature>(Arrays.asList(k), f.o2));
}
}
}
return ret;
}
ret = new ArrayList<Tuple<List<ModulesKey>, IPythonNature>>();
try {
try {
IProject project = request.nature.getProject();
List<Tuple<AbstractAdditionalTokensInfo, IPythonNature>> infoAndNature = null;
if (project == null) {
if (request.nature instanceof SystemPythonNature) {
SystemPythonNature systemPythonNature = (SystemPythonNature) request.nature;
int interpreterType = systemPythonNature.getInterpreterType();
List<IPythonNature> naturesRelatedTo = PythonNature.getPythonNaturesRelatedTo(interpreterType);
infoAndNature = new ArrayList<Tuple<AbstractAdditionalTokensInfo, IPythonNature>>();
for (IPythonNature iPythonNature : naturesRelatedTo) {
if (iPythonNature.getProject() != null && iPythonNature.getProject().isAccessible()) {
AbstractAdditionalTokensInfo o1 = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(iPythonNature);
if (o1 != null) {
infoAndNature.add(new Tuple<AbstractAdditionalTokensInfo, IPythonNature>(o1, iPythonNature));
}
}
}
}
} else {
infoAndNature = AdditionalProjectInterpreterInfo.getAdditionalInfoAndNature(request.nature, false, true, true);
}
if (infoAndNature == null || infoAndNature.size() == 0) {
return ret;
}
// long initial = System.currentTimeMillis();
request.getMonitor().beginTask("Find possible references", infoAndNature.size());
request.getMonitor().setTaskName("Find possible references");
try {
for (Tuple<AbstractAdditionalTokensInfo, IPythonNature> tuple : infoAndNature) {
try {
SubProgressMonitor sub = new SubProgressMonitor(request.getMonitor(), 1);
request.pushMonitor(sub);
if (tuple.o1 instanceof AdditionalProjectInterpreterInfo && tuple.o2 != null) {
AdditionalProjectInterpreterInfo info = (AdditionalProjectInterpreterInfo) tuple.o1;
List<ModulesKey> modulesWithToken = info.getModulesWithToken(initialName, sub);
if (sub.isCanceled()) {
break;
}
ret.add(new Tuple<List<ModulesKey>, IPythonNature>(modulesWithToken, tuple.o2));
}
} finally {
request.popMonitor().done();
}
}
} finally {
request.getMonitor().done();
}
// System.out.println("Total: " + ((System.currentTimeMillis() - initial) / 1000.));
} catch (MisconfigurationException e) {
throw new RuntimeException(e);
}
} catch (OperationCanceledException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
request.setPossibleReferences(initialName, ret);
return ret;
}
use of com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo in project Pydev by fabioz.
the class RefactorerFinds method findLikelyModulesWithChildren.
private HashSet<SourceModule> findLikelyModulesWithChildren(RefactoringRequest request, HierarchyNodeModel model, List<AbstractAdditionalDependencyInfo> infoForProject) {
// get the modules that are most likely to have that declaration.
HashSet<SourceModule> modulesToAnalyze = new HashSet<SourceModule>();
for (AbstractAdditionalDependencyInfo additionalInfo : infoForProject) {
IProgressMonitor monitor = request.getMonitor();
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("Find likely modules with children", 100);
monitor.setTaskName("Searching: " + model.name);
try {
List<ModulesKey> modules;
try {
request.pushMonitor(new SubProgressMonitor(monitor, 90));
if (additionalInfo instanceof AdditionalProjectInterpreterInfo) {
AdditionalProjectInterpreterInfo additionalProjectInterpreterInfo = (AdditionalProjectInterpreterInfo) additionalInfo;
modules = additionalProjectInterpreterInfo.getModulesWithToken(model.name, monitor);
} else {
continue;
}
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
} finally {
request.popMonitor().done();
}
try {
request.pushMonitor(new SubProgressMonitor(monitor, 10));
request.getMonitor().beginTask("Find likely modules with children", modules.size());
for (ModulesKey declaringModuleName : modules) {
if (DEBUG) {
System.out.println("findLikelyModulesWithChildren: " + declaringModuleName);
}
IModule module = null;
IPythonNature pythonNature = null;
if (additionalInfo instanceof AdditionalProjectInterpreterInfo) {
AdditionalProjectInterpreterInfo projectInterpreterInfo = (AdditionalProjectInterpreterInfo) additionalInfo;
pythonNature = PythonNature.getPythonNature(projectInterpreterInfo.getProject());
}
if (pythonNature == null) {
pythonNature = request.nature;
}
BaseModuleRequest moduleRequest = new BaseModuleRequest(request.acceptTypeshed);
module = pythonNature.getAstManager().getModule(declaringModuleName.name, pythonNature, false, moduleRequest);
if (module == null && pythonNature != request.nature) {
module = request.nature.getAstManager().getModule(declaringModuleName.name, request.nature, false, moduleRequest);
}
if (module instanceof SourceModule) {
modulesToAnalyze.add((SourceModule) module);
}
request.getMonitor().worked(1);
}
} finally {
request.popMonitor().done();
}
} finally {
monitor.done();
}
}
return modulesToAnalyze;
}
use of com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo 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.AdditionalProjectInterpreterInfo 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;
}
}
}
}
}
Aggregations