[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/refactoring PyRefactoring.java,1.4,1.5
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-09-20 19:09:36
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/refactoring In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11446/src/org/python/pydev/editor/refactoring Modified Files: PyRefactoring.java Log Message: Changed search for bicycle repair man search and added a refactor view to show which files are modified. Index: PyRefactoring.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/refactoring/PyRefactoring.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PyRefactoring.java 17 Sep 2004 19:22:04 -0000 1.4 --- PyRefactoring.java 20 Sep 2004 19:08:43 -0000 1.5 *************** *** 9,16 **** --- 9,23 ---- import java.io.IOException; import java.net.URLDecoder; + import java.util.ArrayList; + import java.util.Iterator; + import java.util.List; + import java.util.StringTokenizer; import org.eclipse.core.runtime.CoreException; + import org.eclipse.ui.IPropertyListener; import org.python.pydev.editor.actions.refactoring.PyRefactorAction.Operation; import org.python.pydev.editor.codecompletion.PythonShell; + import org.python.pydev.editor.model.ItemPointer; + import org.python.pydev.editor.model.Location; /** *************** *** 37,40 **** --- 44,51 ---- private static PyRefactoring pyRefactoring; + private List propChangeListeners = new ArrayList(); + + public static final int REFACTOR_RESULT = 1; + public synchronized static PyRefactoring getPyRefactoring(){ *************** *** 67,70 **** --- 78,85 ---- } + public void addPropertyListener(IPropertyListener l) { + propChangeListeners.add(l); + } + /** * This method can be used to write something to the server and get its answer. *************** *** 104,108 **** */ public String extract(File editorFile, int beginLine, int beginCol, int endLine, int endCol, String name, Operation operation) { ! String s = "@@REFACTOR"; s+= "extractMethod"; s+= " "+editorFile.getAbsolutePath(); --- 119,123 ---- */ public String extract(File editorFile, int beginLine, int beginCol, int endLine, int endCol, String name, Operation operation) { ! String s = "@@BIKE"; s+= "extractMethod"; s+= " "+editorFile.getAbsolutePath(); *************** *** 113,119 **** s+= " "+name; s+= "END@@"; ! System.out.println("Extract: "+s); String string = makeAction(s, operation); ! System.out.println("REFACTOR RESULT:"+string); return string; } --- 128,136 ---- s+= " "+name; s+= "END@@"; ! // System.out.println("Extract: "+s); String string = makeAction(s, operation); ! // System.out.println("REFACTOR RESULT:"+string); ! ! communicateRefactorResult(string); return string; } *************** *** 127,131 **** */ public String rename(File editorFile, int beginLine, int beginCol, String name, Operation operation) { ! String s = "@@REFACTOR"; s+= "renameByCoordinates"; s+= " "+editorFile.getAbsolutePath(); --- 144,148 ---- */ public String rename(File editorFile, int beginLine, int beginCol, String name, Operation operation) { ! String s = "@@BIKE"; s+= "renameByCoordinates"; s+= " "+editorFile.getAbsolutePath(); *************** *** 134,144 **** s+= " "+name; s+= "END@@"; ! System.out.println("Extract: "+s); String string = makeAction(s, operation); ! System.out.println("REFACTOR RESULT:"+string); return string; } /** * --- 151,237 ---- s+= " "+name; s+= "END@@"; ! // System.out.println("Extract: "+s); String string = makeAction(s, operation); ! ! // System.out.println("REFACTOR RESULT:"+string); ! communicateRefactorResult(string); return string; } + public List findDefinition(File editorFile, int beginLine, int beginCol, Operation operation) { + String s = "@@BIKE"; + s+= "findDefinition"; + s+= " "+editorFile.getAbsolutePath(); + s+= " "+beginLine; + s+= " "+beginCol; + s+= "END@@"; + + System.out.println("Find: "+s); + String string = makeAction(s, operation); + + System.out.println("REFACTOR RESULT:"+string); + List l = new ArrayList(); + + + if (string.startsWith("BIKE_OK:")){ + string = string.replaceFirst("BIKE_OK:", "").replaceAll("\\[","").replaceAll("'",""); + string = string.substring(0, string.lastIndexOf(']')); + + //now we should have something like: + //(file,line,col,confidence)(file,line,col,confidence)... + + string = string.replaceAll("\\(",""); + StringTokenizer tokenizer = new StringTokenizer(string, ")"); + while(tokenizer.hasMoreTokens()){ + String tok = tokenizer.nextToken(); + + String[] toks = tok.split(","); + if(toks.length == 4){ //4th position is the confidence + Location location = new Location(Integer.parseInt(toks[1])-1, Integer.parseInt(toks[2])); + l.add(new ItemPointer(new File(toks[0]), location, location)); + } + } + } + + + return l; + + } + + + /** + * @param string + */ + private void communicateRefactorResult(String string) { + + List l = refactorResultAsList(string); + + for (Iterator iter = this.propChangeListeners.iterator(); iter.hasNext();) { + IPropertyListener element = (IPropertyListener) iter.next(); + element.propertyChanged(new Object[]{this, l}, REFACTOR_RESULT); + } + } + + + /** + * @param string + * @return + */ + public List refactorResultAsList(String string) { + List l = new ArrayList(); + + if (string.startsWith("BIKE_OK:")){ + string = string.replaceFirst("BIKE_OK:", "").replaceAll("\\[","").replaceAll("'",""); + string = string.substring(0, string.lastIndexOf(']')); + StringTokenizer tokenizer = new StringTokenizer(string, ", "); + + while(tokenizer.hasMoreTokens()){ + l.add(tokenizer.nextToken()); + } + } + return l; + } + /** * |