use of com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo in project Pydev by fabioz.
the class AnalysisBuilderRunnableForRemove method removeInfoForModule.
/**
* @param moduleName this is the module name
* @param nature this is the nature
*/
public static void removeInfoForModule(String moduleName, IPythonNature nature, boolean isFullBuild) {
if (moduleName != null && nature != null) {
AbstractAdditionalDependencyInfo info;
try {
info = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
} catch (MisconfigurationException e) {
Log.log(e);
return;
}
boolean generateDelta;
if (isFullBuild) {
generateDelta = false;
} else {
generateDelta = true;
}
info.removeInfoFromModule(moduleName, generateDelta);
} else {
if (DebugSettings.DEBUG_ANALYSIS_REQUESTS) {
org.python.pydev.shared_core.log.ToLogFile.toLogFile("Unable to remove info. name: " + moduleName + " or nature:" + nature + " is null.", AnalysisBuilderRunnableForRemove.class);
}
}
}
use of com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo in project Pydev by fabioz.
the class PyGlobalsBrowser method getFromManagerAndRelatedNatures.
/**
* Gets it using all the natures that match a given interpreter manager.
* @throws MisconfigurationException
*/
private static void getFromManagerAndRelatedNatures(String selectedText, IInterpreterManager useManager) {
AbstractAdditionalTokensInfo additionalSystemInfo;
try {
additionalSystemInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(useManager, useManager.getDefaultInterpreterInfo(true).getExecutableOrJar());
} catch (MisconfigurationException e) {
MessageDialog.openError(EditorUtils.getShell(), "Error", "Additional info is not available (default interpreter not configured).");
handle(e);
return;
}
List<AbstractAdditionalTokensInfo> additionalInfo = new ArrayList<AbstractAdditionalTokensInfo>();
additionalInfo.add(additionalSystemInfo);
List<IPythonNature> natures = PythonNature.getPythonNaturesRelatedTo(useManager.getInterpreterType());
for (IPythonNature nature : natures) {
AbstractAdditionalDependencyInfo info;
try {
info = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
if (info != null) {
additionalInfo.add(info);
}
} catch (MisconfigurationException e) {
// just go on to the next nature if one is not properly configured.
handle(e);
}
}
doSelect(natures, additionalInfo, selectedText);
}
use of com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo in project Pydev by fabioz.
the class RefactorerFinds method findChildren.
private void findChildren(RefactoringRequest request, HierarchyNodeModel initialModel, HashMap<HierarchyNodeModel, HierarchyNodeModel> allFound) {
try {
request.getMonitor().beginTask("Find children", 100);
// and now the children...
List<AbstractAdditionalDependencyInfo> infoForProject;
try {
infoForProject = AdditionalProjectInterpreterInfo.getAdditionalInfoForProjectAndReferencing(request.nature);
} catch (MisconfigurationException e) {
Log.log(e);
return;
}
HashSet<HierarchyNodeModel> foundOnRound = new HashSet<HierarchyNodeModel>();
foundOnRound.add(initialModel);
int totalWork = 1000;
while (foundOnRound.size() > 0) {
HashSet<HierarchyNodeModel> nextRound = new HashSet<HierarchyNodeModel>(foundOnRound);
foundOnRound.clear();
for (HierarchyNodeModel toFindOnRound : nextRound) {
HashSet<SourceModule> modulesToAnalyze;
int work = totalWork / 250;
if (work <= 0) {
work = 1;
totalWork = 0;
}
totalWork -= work;
try {
request.pushMonitor(new SubProgressMonitor(request.getMonitor(), work));
modulesToAnalyze = findLikelyModulesWithChildren(request, toFindOnRound, infoForProject);
} finally {
request.popMonitor().done();
}
request.communicateWork("Likely modules with matches:" + modulesToAnalyze.size());
findChildrenOnModules(request, allFound, foundOnRound, toFindOnRound, modulesToAnalyze);
}
}
} finally {
request.getMonitor().done();
}
}
use of com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo in project Pydev by fabioz.
the class PySearchIndexQuery method run.
@Override
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
SearchIndexResult searchResult = (SearchIndexResult) getSearchResult();
// Remove all so that we don't get duplicates on a search refresh.
searchResult.removeAll();
StringMatcherWithIndexSemantics stringMatcher = createStringMatcher();
Set<String> moduleNamesFilter = scopeAndData.getModuleNamesFilter();
OrderedMap<String, Set<String>> fieldNameToValues = new OrderedMap<>();
if (moduleNamesFilter != null && !moduleNamesFilter.isEmpty()) {
fieldNameToValues.put(IReferenceSearches.FIELD_MODULE_NAME, moduleNamesFilter);
}
Set<String> split = makeTextFieldPatternsToSearchFromText();
fieldNameToValues.put(IReferenceSearches.FIELD_CONTENTS, split);
final List<IPythonNature> pythonNatures = PyScopeAndData.getPythonNatures(scopeAndData);
monitor.beginTask("Search indexes", pythonNatures.size());
try {
for (IPythonNature nature : pythonNatures) {
AbstractAdditionalDependencyInfo info;
try {
info = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
} catch (MisconfigurationException e) {
Log.log(e);
continue;
}
IReferenceSearches referenceSearches = info.getReferenceSearches();
List<ModulesKey> search = referenceSearches.search(nature.getProject(), fieldNameToValues, new SubProgressMonitor(monitor, 1));
IFile workspaceFile;
for (ModulesKey modulesKey : search) {
File file = modulesKey.file;
if (file == null || !file.exists()) {
Log.logInfo(StringUtils.format("Ignoring: %s. File no longer exists.", file));
}
workspaceFile = FindWorkspaceFiles.getWorkspaceFile(file, nature.getProject());
if (workspaceFile == null) {
Log.logInfo(StringUtils.format("Ignoring: %s. Unable to resolve to a file in the Eclipse workspace.", file));
continue;
}
IDocument doc = FileUtilsFileBuffer.getDocFromResource(workspaceFile);
String text = doc.get();
createMatches(doc, text, stringMatcher, workspaceFile, searchResult, modulesKey);
}
}
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
use of com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo in project Pydev by fabioz.
the class AnalysisTestsBase method restoreSystemPythonPath.
// ---------------------------------------------------------------------- additional info
@Override
protected boolean restoreSystemPythonPath(boolean force, String path) {
boolean restored = super.restoreSystemPythonPath(force, path);
if (restored) {
IProgressMonitor monitor = new NullProgressMonitor();
// try to load it from previous session
IInterpreterManager interpreterManager = getInterpreterManager();
try {
String defaultInterpreter = interpreterManager.getDefaultInterpreterInfo(false).getExecutableOrJar();
boolean recreate = forceAdditionalInfoRecreation;
if (!recreate) {
// one last check: if TestCase is not found, recreate it!
AbstractAdditionalDependencyInfo additionalSystemInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(interpreterManager, defaultInterpreter);
Collection<IInfo> tokensStartingWith = additionalSystemInfo.getTokensStartingWith("TestCase", AbstractAdditionalTokensInfo.TOP_LEVEL);
recreate = true;
for (IInfo info : tokensStartingWith) {
if (info.getName().equals("TestCase")) {
if (info.getDeclaringModuleName().equals("unittest")) {
recreate = false;
break;
}
}
}
}
if (recreate) {
// Commented out some noise on the build
// System.out.println("Recreating: " + this.getClass() + " - "
// + interpreterManager.getInterpreterInfo(defaultInterpreter, null));
observer.notifyDefaultPythonpathRestored(interpreterManager, defaultInterpreter, monitor);
}
} catch (MisconfigurationException e) {
throw new RuntimeException(e);
}
}
return restored;
}
Aggregations