Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/refactoring
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25438/src/org/python/pydev/editor/refactoring
Modified Files:
PyRefactoring.java
Log Message:
Making refactoring.
Index: PyRefactoring.java
===================================================================
RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/refactoring/PyRefactoring.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PyRefactoring.java 14 Sep 2004 17:42:15 -0000 1.1
--- PyRefactoring.java 15 Sep 2004 17:36:08 -0000 1.2
***************
*** 6,9 ****
--- 6,15 ----
package org.python.pydev.editor.refactoring;
+ import java.io.File;
+ import java.io.IOException;
+
+ import org.eclipse.core.runtime.CoreException;
+ import org.python.pydev.editor.codecompletion.PythonShell;
+
/**
* This class is used to make the refactorings.
***************
*** 18,21 ****
--- 24,133 ----
*/
public class PyRefactoring {
+
+ /**
+ * Reference to a 'global python shell'
+ */
+ private static PythonShell pytonShell;
+
+ /**
+ * Instead of making all static, let's use a singleton... it may be useful...
+ */
+ private static PyRefactoring pyRefactoring;
+
+
+ private PyRefactoring(){
+
+ }
+
+ public static PyRefactoring getPyRefactoring(){
+ if (pyRefactoring == null){
+ pyRefactoring = new PyRefactoring();
+ }
+ return pyRefactoring;
+ }
+
+ /**
+ * @return
+ * @throws CoreException
+ * @throws IOException
+ *
+ */
+ private PythonShell getServerShell() throws IOException, CoreException {
+ if(pytonShell == null){
+ pytonShell = new PythonShell();
+ pytonShell.startIt();
+ }
+ return pytonShell;
+ }
+
+ /**
+ * This method can be used to write something to the server and get its answer.
+ *
+ * @param str
+ * @return
+ */
+ private String makeAction(String str){
+ PythonShell pytonShell;
+ try {
+ pytonShell = getServerShell();
+ try {
+ pytonShell.write(str);
+
+ return pytonShell.read();
+ } catch (Exception e) {
+ e.printStackTrace();
+
+ pytonShell.restartShell();
+ }
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ return null;
+ }
+
+
+ /**
+ * @param editorFile
+ * @param beginLine
+ * @param beginCol
+ * @param endLine
+ * @param endCol
+ * @param name
+ */
+ public void extract(File editorFile, int beginLine, int beginCol, int endLine, int endCol, String name) {
+ String s = "@@REFACTOR";
+ s+= "extractMethod";
+ s+= " "+editorFile.getAbsolutePath();
+ s+= " "+beginLine;
+ s+= " "+beginCol;
+ s+= " "+endLine;
+ s+= " "+endCol;
+ s+= " "+name;
+ s+= "END@@";
+ System.out.println("Extract: "+s);
+ String string = makeAction(s);
+ System.out.println("REFACTOR RESULT:"+string);
+
+ }
+
+ /**
+ * @param editorFile
+ * @param beginLine
+ * @param beginCol
+ * @param name
+ */
+ public void rename(File editorFile, int beginLine, int beginCol, String name) {
+ String s = "@@REFACTOR";
+ s+= "renameByCoordinates";
+ s+= " "+editorFile.getAbsolutePath();
+ s+= " "+beginLine;
+ s+= " "+beginCol;
+ s+= " "+name;
+ s+= "END@@";
+ System.out.println("Extract: "+s);
+ String string = makeAction(s);
+ System.out.println("REFACTOR RESULT:"+string);
+
+ }
}
|