use of org.python.pydev.navigator.elements.PythonResource in project Pydev by fabioz.
the class PythonModelProvider method convertToPythonElementsUpdateOrRefresh.
/**
* Converts elements to the python model -- but only creates it if it's parent is found in the python model
*/
protected boolean convertToPythonElementsUpdateOrRefresh(Set<Object> currentChildren) {
final Map<PythonNature, Set<String>> natureToSourcePathSet = new HashMap<>();
LinkedHashSet<Object> convertedChildren = new LinkedHashSet<>();
for (Iterator<Object> childrenItr = currentChildren.iterator(); childrenItr.hasNext(); ) {
Object child = childrenItr.next();
if (child == null) {
// only case when a child is removed and another one is not added (null)
childrenItr.remove();
continue;
}
if (child instanceof IResource && !(child instanceof IWrappedResource)) {
IResource res = (IResource) child;
Object resourceInPythonModel = getResourceInPythonModel(res, true);
if (resourceInPythonModel != null) {
// if it is in the python model, just go on
childrenItr.remove();
convertedChildren.add(resourceInPythonModel);
} else {
// now, if it's not but its parent is, go on and create it
IContainer p = res.getParent();
if (p == null) {
continue;
}
Object pythonParent = getResourceInPythonModel(p, true);
if (pythonParent instanceof IWrappedResource) {
IWrappedResource parent = (IWrappedResource) pythonParent;
if (res instanceof IProject) {
throw new RuntimeException("A project's parent should never be an IWrappedResource!");
} else if (res instanceof IFolder) {
childrenItr.remove();
convertedChildren.add(new PythonFolder(parent, (IFolder) res, parent.getSourceFolder()));
} else if (res instanceof IFile) {
childrenItr.remove();
convertedChildren.add(new PythonFile(parent, (IFile) res, parent.getSourceFolder()));
} else if (child instanceof IResource) {
childrenItr.remove();
convertedChildren.add(new PythonResource(parent, (IResource) child, parent.getSourceFolder()));
}
} else if (res instanceof IFolder) {
// ok, still not in the model... could it be a PythonSourceFolder
IFolder folder = (IFolder) res;
IProject project = folder.getProject();
if (project == null) {
continue;
}
PythonNature nature = PythonNature.getPythonNature(project);
if (nature == null) {
continue;
}
Set<String> sourcePathSet = this.getSourcePathSet(natureToSourcePathSet, nature);
PythonSourceFolder wrapped = tryWrapSourceFolder(p, folder, sourcePathSet);
if (wrapped != null) {
childrenItr.remove();
convertedChildren.add(wrapped);
}
}
}
}
}
if (!convertedChildren.isEmpty()) {
currentChildren.addAll(convertedChildren);
return true;
}
return false;
}
Aggregations