if (parent instanceof IContainer) {
IContainer parentContainer = (IContainer) parent;
Object pythonParent = getResourceInPythonModel(parentContainer, true);
if (pythonParent instanceof IWrappedResource) {
IWrappedResource parentResource = (IWrappedResource) pythonParent;
modification.setParent(parentResource);
wrapChildren(parentResource, parentResource.getSourceFolder(), modification.getChildren(), isAdd);
} else if (pythonParent == null) {
Object parentInWrap = parentContainer;
PythonSourceFolder sourceFolderInWrap = null;
//this may happen when a source folder is added or some element that still doesn't have it's parent in the model...
//so, we have to get the parent's parent until we actually 'know' that it is not in the model (or until we run
//out of parents to try)
//the case in which we reproduce this is Test 1 (described in the class)
FastStack<Object> found = new FastStack<Object>(20);
while (true) {
//add the current to the found
if (parentContainer == null) {
break;
}
found.push(parentContainer);
if (parentContainer instanceof IProject) {
//we got to the project without finding any part of a python model already there, so, let's see
//if any of the parts was actually a source folder (that was still not added)
tryCreateModelFromProject((IProject) parentContainer, found);
//and now, if it was created, try to convert it to the python model (without any further add)
convertToPythonElementsUpdateOrRefresh(modification.getChildren());
return;
}
Object p = getResourceInPythonModel(parentContainer, true);
if (p instanceof IWrappedResource) {
IWrappedResource wrappedResource = (IWrappedResource) p;
sourceFolderInWrap = wrappedResource.getSourceFolder();
while (found.size() > 0) {
Object f = found.pop();
if (f instanceof IResource) {
//no need to create it if it's already in the model!