[Pydev-cvs] org.python.pydev/src_navigator/org/python/pydev/navigator PythonModelProvider.java, 1.
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-05-10 16:29:33
|
Update of /cvsroot/pydev/org.python.pydev/src_navigator/org/python/pydev/navigator In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16453/src_navigator/org/python/pydev/navigator Modified Files: PythonModelProvider.java PythonBaseModelProvider.java Log Message: Pydev model provider for project explorer: Better handling of null objects when intercepting them / interaction with other models. Index: PythonModelProvider.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_navigator/org/python/pydev/navigator/PythonModelProvider.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** PythonModelProvider.java 9 May 2008 01:10:13 -0000 1.13 --- PythonModelProvider.java 10 May 2008 16:29:24 -0000 1.14 *************** *** 224,233 **** //add the current to the found - found.push(parentContainer); - parentContainer = parentContainer.getParent(); if(parentContainer == null){ break; } if(parentContainer instanceof IProject){ //we got to the project without finding any part of a python model already there, so, let's see --- 224,232 ---- //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 *************** *** 259,264 **** --- 258,265 ---- } + parentContainer = parentContainer.getParent(); } + wrapChildren(parentInWrap, sourceFolderInWrap, modification.getChildren(), isAdd); *************** *** 295,306 **** for(Iterator<Object> it = found.topDownIterator();it.hasNext();){ Object child = it.next(); ! if(child instanceof IFolder){ if(pythonSourceFolder == null){ ! pythonSourceFolder = tryWrapSourceFolder(currentParent, (IFolder) child, sourcePathSet); if(pythonSourceFolder != null){ currentParent = pythonSourceFolder; }else if(child instanceof IContainer){ currentParent = (IContainer) child; } //just go on (if we found the source folder or not, because if we found, that's ok, and if //we didn't, then the children will not be in the python model anyway) --- 296,311 ---- for(Iterator<Object> it = found.topDownIterator();it.hasNext();){ Object child = it.next(); ! if(child instanceof IFolder || child instanceof IProject){ if(pythonSourceFolder == null){ ! pythonSourceFolder = tryWrapSourceFolder(currentParent, (IContainer) child, sourcePathSet); ! if(pythonSourceFolder != null){ currentParent = pythonSourceFolder; + }else if(child instanceof IContainer){ currentParent = (IContainer) child; + } + //just go on (if we found the source folder or not, because if we found, that's ok, and if //we didn't, then the children will not be in the python model anyway) *************** *** 308,311 **** --- 313,318 ---- } } + + if(pythonSourceFolder != null){ IWrappedResource r = doWrap(currentParent, pythonSourceFolder, child); *************** *** 340,343 **** --- 347,356 ---- Object child = childrenItr.next(); + if(child == null){ + //only case when a child is removed and another one is not added (null) + childrenItr.remove(); + continue; + } + //yeap, it may be an object that's not an actual resource (created by some other plugin... just continue) if(!(child instanceof IResource)){ *************** *** 390,394 **** protected IWrappedResource doWrap(Object parent, PythonSourceFolder pythonSourceFolder, Object child) { if (child instanceof IProject){ ! //do nothing (because a project is never going to be an IWrappedResource) if(pythonSourceFolder == null && parent != null){ PythonSourceFolder f = doWrapPossibleSourceFolder(parent, (IProject)child); --- 403,407 ---- protected IWrappedResource doWrap(Object parent, PythonSourceFolder pythonSourceFolder, Object child) { if (child instanceof IProject){ ! //ok, let's see if the child is a source folder (as the default project can be the actual source folder) if(pythonSourceFolder == null && parent != null){ PythonSourceFolder f = doWrapPossibleSourceFolder(parent, (IProject)child); *************** *** 471,475 **** sourceFolder = new PythonProjectSourceFolder(parent, (IProject)container); }else{ ! throw new RuntimeException("Shouldn't get here: "+container.getClass()); } //System.out.println("Created source folder: "+ret[i]+" - "+folder.getProject()+" - "+folder.getProjectRelativePath()); --- 484,488 ---- sourceFolder = new PythonProjectSourceFolder(parent, (IProject)container); }else{ ! return null; //some other container we don't know how to treat! } //System.out.println("Created source folder: "+ret[i]+" - "+folder.getProject()+" - "+folder.getProjectRelativePath()); *************** *** 491,494 **** --- 504,514 ---- for (Iterator 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; *************** *** 510,522 **** if(pythonParent instanceof IWrappedResource){ IWrappedResource parent = (IWrappedResource) pythonParent; if (res instanceof IProject){ ! //do nothing (because a project is never going to be an IWrappedResource) ! throw new RuntimeException("Shouldn't be here..."); }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(); --- 530,545 ---- 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(); Index: PythonBaseModelProvider.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_navigator/org/python/pydev/navigator/PythonBaseModelProvider.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** PythonBaseModelProvider.java 27 Apr 2008 17:28:05 -0000 1.11 --- PythonBaseModelProvider.java 10 May 2008 16:29:24 -0000 1.12 *************** *** 309,313 **** //if we don't have a python nature in this project, there is no way we can have a PythonSourceFolder ! Object[] ret = new Object[childrenToReturn.length]; for (int i=0; i < childrenToReturn.length; i++) { PythonNature localNature = nature; --- 309,313 ---- //if we don't have a python nature in this project, there is no way we can have a PythonSourceFolder ! List<Object> ret = new ArrayList<Object>(childrenToReturn.length); for (int i=0; i < childrenToReturn.length; i++) { PythonNature localNature = nature; *************** *** 316,324 **** //now, first we have to try to get it (because it might already be created) Object child = childrenToReturn[i]; ! if(!(child instanceof IResource)){ continue; } child = getResourceInPythonModel((IResource) child); ! ret[i] = child; //if it is a folder (that is not already a PythonSourceFolder, it might be that we have to create a PythonSourceFolder) --- 316,339 ---- //now, first we have to try to get it (because it might already be created) Object child = childrenToReturn[i]; ! ! if(child == null){ ! continue; ! } ! ! //only add it if it wasn't null ! ret.add(child); ! ! if(!(child instanceof IResource)){ ! //not an element that we can treat in pydev (but still, it was already added) continue; } child = getResourceInPythonModel((IResource) child); ! ! if(child == null){ ! //ok, it was not in the python model (but it was already added with the original representation, so, that's ok) ! continue; ! }else{ ! ret.set(ret.size()-1, child); //replace the element added for the one in the python model ! } //if it is a folder (that is not already a PythonSourceFolder, it might be that we have to create a PythonSourceFolder) *************** *** 348,360 **** IPath fullPath = container.getFullPath(); if(sourcePathSet.contains(fullPath.toString())){ if(container instanceof IFolder){ ! ret[i] = new PythonSourceFolder(parentElement, (IFolder)container); }else if(container instanceof IProject){ ! ret[i] = new PythonProjectSourceFolder(parentElement, (IProject)container); }else{ throw new RuntimeException("Should not get here."); } Set<PythonSourceFolder> sourceFolders = getProjectSourceFolders(localProject); ! sourceFolders.add((PythonSourceFolder) ret[i]); } } catch (CoreException e) { --- 363,377 ---- IPath fullPath = container.getFullPath(); if(sourcePathSet.contains(fullPath.toString())){ + PythonSourceFolder createdSourceFolder; if(container instanceof IFolder){ ! createdSourceFolder = new PythonSourceFolder(parentElement, (IFolder)container); }else if(container instanceof IProject){ ! createdSourceFolder = new PythonProjectSourceFolder(parentElement, (IProject)container); }else{ throw new RuntimeException("Should not get here."); } + ret.set(ret.size()-1, createdSourceFolder); //replace the element added for the one in the python model Set<PythonSourceFolder> sourceFolders = getProjectSourceFolders(localProject); ! sourceFolders.add(createdSourceFolder); } } catch (CoreException e) { *************** *** 363,367 **** } } ! return ret; } --- 380,384 ---- } } ! return ret.toArray(); } *************** *** 456,486 **** */ protected Object[] wrapChildren(IWrappedResource parent, PythonSourceFolder pythonSourceFolder, Object[] children) { ! Object[] childrenToReturn; ! Object[] ret = new Object[children.length]; for (int i = 0; i < children.length; i++) { Object object = children[i]; ! Object existing = getResourceInPythonModel((IResource) object, true); ! if(existing == null){ ! if(object instanceof IFolder){ ! IFolder folder = (IFolder) object; ! ret[i] = new PythonFolder(parent, folder, pythonSourceFolder); ! ! }else if(object instanceof IFile){ ! IFile file = (IFile) object; ! ret[i] = new PythonFile(parent, file, pythonSourceFolder); ! ! }else if(object instanceof IResource){ ! ret[i] = new PythonResource(parent, (IResource) object, pythonSourceFolder); ! }else{ ! ret[i] = existing; } }else{ ! ret[i] = existing; } } ! childrenToReturn = ret; ! return childrenToReturn; } --- 473,507 ---- */ protected Object[] wrapChildren(IWrappedResource parent, PythonSourceFolder pythonSourceFolder, Object[] children) { ! List<Object> ret = new ArrayList<Object>(children.length); for (int i = 0; i < children.length; i++) { Object object = children[i]; ! ! if(object instanceof IResource){ ! Object existing = getResourceInPythonModel((IResource) object, true); ! if(existing == null){ ! if(object instanceof IFolder){ ! object = new PythonFolder(parent, ((IFolder) object), pythonSourceFolder); ! ! }else if(object instanceof IFile){ ! object = new PythonFile(parent, ((IFile) object), pythonSourceFolder); ! ! }else if(object instanceof IResource){ ! object = new PythonResource(parent, (IResource) object, pythonSourceFolder); ! } ! }else{ //existing != null ! object = existing; } + } + + if(object == null){ + continue; }else{ ! ret.add(object); } + } ! return ret.toArray(); } |