private void visitWith(int visitType, final IResource resource, ICallback0<IDocument> document,
IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return; //it's already cancelled
}
IPythonNature nature = PythonNature.getPythonNature(resource);
if (nature == null) {
return;
}
if (!nature.startRequests()) {
return;
}
try {
try {
//we visit external because we must index them
if (!isResourceInPythonpathProjectSources(resource, nature, true)) {
return; // we only analyze resources that are in the pythonpath
}
} catch (Exception e1) {
Log.log(e1);
return; // we only analyze resources that are in the pythonpath
}
HashMap<String, Object> copyMemo = new HashMap<String, Object>(this.memo);
FastStringBuffer bufferToCommunicateProgress = new FastStringBuffer();
for (PyDevBuilderVisitor visitor : visitors) {
// some visitors cannot visit too many elements because they do a lot of processing
if (visitor.maxResourcesToVisit() == PyDevBuilderVisitor.MAX_TO_VISIT_INFINITE
|| visitor.maxResourcesToVisit() >= totalResources) {
visitor.memo = copyMemo; //setting the memo must be the first thing.
try {
//communicate progress for each visitor
PyDevBuilder.communicateProgress(monitor, totalResources, currentResourcesVisited, resource,
visitor, bufferToCommunicateProgress);
switch (visitType) {
case VISIT_ADD:
visitor.visitAddedResource(resource, document, monitor);
break;
case VISIT_CHANGE:
visitor.visitChangedResource(resource, document, monitor);
break;
case VISIT_REMOVE:
visitor.visitRemovedResource(resource, document, monitor);
break;
default:
throw new RuntimeException("Error: visit type not properly given!"); //$NON-NLS-1$
}
} catch (Exception e) {
Log.log(e);
}
}
}
} finally {
nature.endRequests();
}
}