Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17496/src/org/python/pydev/editor/actions
Modified Files:
PyOrganizeImports.java
Log Message:
Created better utilities to handle imports.
Index: PyOrganizeImports.java
===================================================================
RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyOrganizeImports.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** PyOrganizeImports.java 4 Aug 2007 16:01:11 -0000 1.12
--- PyOrganizeImports.java 17 May 2008 14:26:52 -0000 1.13
***************
*** 19,25 ****
import org.eclipse.jface.text.IDocumentExtension4;
import org.python.pydev.core.ExtensionHelper;
! import org.python.pydev.core.docutils.PyDocIterator;
import org.python.pydev.core.docutils.PySelection;
- import org.python.pydev.core.docutils.WordUtils;
import org.python.pydev.editor.PyEdit;
import org.python.pydev.plugin.PydevPlugin;
--- 19,25 ----
import org.eclipse.jface.text.IDocumentExtension4;
import org.python.pydev.core.ExtensionHelper;
! import org.python.pydev.core.docutils.ImportHandle;
! import org.python.pydev.core.docutils.PyImportsHandling;
import org.python.pydev.core.docutils.PySelection;
import org.python.pydev.editor.PyEdit;
import org.python.pydev.plugin.PydevPlugin;
***************
*** 95,125 ****
ArrayList list = new ArrayList();
int firstImport = -1;
! PyDocIterator it = new PyDocIterator(doc, false, false, false, true);
! while(it.hasNext()){
! String str = it.next();
!
! if((str.startsWith("import ") || str.startsWith("from "))){
! int iToAdd = it.getLastReturnedLine();
! if(str.indexOf('(') != -1){ //we have something like from os import (pipe,\nfoo)
! while(it.hasNext() && str.indexOf(')') == -1){
! String str1 = it.next();
! str += endLineDelim+str1;
! }
! }
! if(WordUtils.endsWith(str, '\\')){
! while(it.hasNext() && WordUtils.endsWith(str, '\\')){
! //we have to get all until there are no more back-slashes
! String str1 = it.next();
! str += endLineDelim+str1;
! }
! }
! list.add( new Object[]{iToAdd, str} );
!
! if(firstImport == -1){
! firstImport = iToAdd;
! }
! }
! }
//check if we had any import
--- 95,109 ----
ArrayList list = new ArrayList();
+ //Gather imports in a structure we can work on.
+ PyImportsHandling pyImportsHandling = new PyImportsHandling(doc);
int firstImport = -1;
! for(ImportHandle imp:pyImportsHandling){
! list.add( new Object[]{imp.startFoundLine, imp.importFound} );
!
! if(firstImport == -1){
! firstImport = imp.startFoundLine;
! }
! }
!
//check if we had any import
|