pydev-cvs Mailing List for PyDev for Eclipse (Page 302)
Brought to you by:
fabioz
You can subscribe to this list here.
2004 |
Jan
|
Feb
(4) |
Mar
(48) |
Apr
(56) |
May
(64) |
Jun
(27) |
Jul
(66) |
Aug
(81) |
Sep
(148) |
Oct
(194) |
Nov
(78) |
Dec
(46) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(125) |
Feb
(126) |
Mar
(163) |
Apr
(133) |
May
(115) |
Jun
(307) |
Jul
(387) |
Aug
(417) |
Sep
(283) |
Oct
(148) |
Nov
(45) |
Dec
(53) |
2006 |
Jan
(240) |
Feb
(200) |
Mar
(267) |
Apr
(231) |
May
(245) |
Jun
(361) |
Jul
(142) |
Aug
(12) |
Sep
(210) |
Oct
(99) |
Nov
(7) |
Dec
(30) |
2007 |
Jan
(161) |
Feb
(511) |
Mar
(265) |
Apr
(74) |
May
(147) |
Jun
(151) |
Jul
(94) |
Aug
(68) |
Sep
(98) |
Oct
(144) |
Nov
(26) |
Dec
(36) |
2008 |
Jan
(98) |
Feb
(107) |
Mar
(199) |
Apr
(113) |
May
(119) |
Jun
(112) |
Jul
(92) |
Aug
(71) |
Sep
(101) |
Oct
(16) |
Nov
|
Dec
|
From: Fabio Z. <fa...@us...> - 2004-09-20 19:09:36
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/refactoring In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11446/src/org/python/pydev/editor/actions/refactoring Modified Files: PyExtractMethod.java PyRefactorAction.java PyRename.java Log Message: Changed search for bicycle repair man search and added a refactor view to show which files are modified. Index: PyRename.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/refactoring/PyRename.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PyRename.java 16 Sep 2004 15:33:32 -0000 1.2 --- PyRename.java 20 Sep 2004 19:08:42 -0000 1.3 *************** *** 31,36 **** if(name.equals("") == false){ res = PyRefactoring.getPyRefactoring().rename(editorFile, beginLine, beginCol, name, operation); - - refreshEditors(getPyEdit()); } return res; --- 31,34 ---- Index: PyExtractMethod.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/refactoring/PyExtractMethod.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PyExtractMethod.java 16 Sep 2004 15:33:32 -0000 1.2 --- PyExtractMethod.java 20 Sep 2004 19:08:42 -0000 1.3 *************** *** 42,47 **** if(name.equals("") == false){ res = PyRefactoring.getPyRefactoring().extract(editorFile, beginLine, beginCol, endLine, endCol, name, operation); - - refreshEditors(getPyEdit()); } return res; --- 42,45 ---- Index: PyRefactorAction.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/refactoring/PyRefactorAction.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PyRefactorAction.java 16 Sep 2004 15:33:32 -0000 1.2 --- PyRefactorAction.java 20 Sep 2004 19:08:42 -0000 1.3 *************** *** 22,26 **** --- 22,28 ---- import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorReference; + import org.eclipse.ui.IViewReference; import org.eclipse.ui.IWorkbenchPage; + import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; *************** *** 32,35 **** --- 34,38 ---- import org.python.pydev.editor.refactoring.PyRefactoring; import org.python.pydev.plugin.PydevPlugin; + import org.python.pydev.views.PyRefactorView; /** *************** *** 38,42 **** public abstract class PyRefactorAction extends PyAction { ! private IWorkbenchWindow workbenchWindow; public final class Operation extends WorkspaceModifyOperation { --- 41,45 ---- public abstract class PyRefactorAction extends PyAction { ! protected IWorkbenchWindow workbenchWindow; public final class Operation extends WorkspaceModifyOperation { *************** *** 104,117 **** .getEditorReferences(); for (int j = 0; j < editorReferences.length; j++) { ! if (editorReferences[j] instanceof PyEdit) { ! PyEdit e = (PyEdit) editorReferences[j]; if (e != edit) { - System.out.println("REFRESHING OTHER"); refreshEditor(e); } } } } } --- 107,134 ---- .getEditorReferences(); + IViewReference[] viewReferences = pages[i].getViewReferences(); + for (int j = 0; j < editorReferences.length; j++) { ! IEditorPart ed = editorReferences[j].getEditor(false); ! if (ed instanceof PyEdit) { ! PyEdit e = (PyEdit) ed; if (e != edit) { refreshEditor(e); } } } + + + for (int j = 0; j < viewReferences.length; j++) { + IWorkbenchPart view = viewReferences[j].getPart(false); + if(view instanceof PyRefactorView){ + view = viewReferences[j].getPart(true); + PyRefactorView e = (PyRefactorView) view; + e.refresh(); + } + } + } + } *************** *** 207,210 **** --- 224,232 ---- e.printStackTrace(); } + try { + refreshEditors(getPyEdit()); + } catch (CoreException e1) { + e1.printStackTrace(); + } if (operation.statusOfOperation.startsWith("ERROR:")) { |
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; + } + /** * |
From: Fabio Z. <fa...@us...> - 2004-09-20 19:09:35
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codefolding In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11446/src/org/python/pydev/editor/codefolding Modified Files: CodeFoldingSetter.java Log Message: Changed search for bicycle repair man search and added a refactor view to show which files are modified. Index: CodeFoldingSetter.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codefolding/CodeFoldingSetter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CodeFoldingSetter.java 19 Aug 2004 17:50:46 -0000 1.6 --- CodeFoldingSetter.java 20 Sep 2004 19:08:43 -0000 1.7 *************** *** 133,152 **** private void addMarks(ArrayList nodes, ProjectionAnnotationModel model, ArrayList collapsed) { int i=0; ! ! IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); ! ! for (Iterator iter = nodes.iterator(); iter.hasNext();++i) { ! AbstractNode element = (AbstractNode) iter.next(); ! int end = findEnd(element, nodes, i, doc); ! int start = element.getStart().line; ! if (end == -1){ ! end = start; ! } ! try { ! addFoldingMark(element, start, end, model, collapsed); ! } catch (BadLocationException e) { ! e.printStackTrace(); } } } --- 133,155 ---- private void addMarks(ArrayList nodes, ProjectionAnnotationModel model, ArrayList collapsed) { int i=0; ! ! try { ! IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); ! for (Iterator iter = nodes.iterator(); iter.hasNext();++i) { ! ! AbstractNode element = (AbstractNode) iter.next(); ! int end = findEnd(element, nodes, i, doc); ! int start = element.getStart().line; ! if (end == -1){ ! end = start; ! } ! try { ! addFoldingMark(element, start, end, model, collapsed); ! } catch (BadLocationException e) { ! e.printStackTrace(); ! } } + } catch (NullPointerException e) { } } |
From: Fabio Z. <fa...@us...> - 2004-09-20 19:09:04
|
Update of /cvsroot/pydev/org.python.pydev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11446 Modified Files: plugin.xml Log Message: Changed search for bicycle repair man search and added a refactor view to show which files are modified. Index: plugin.xml =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/plugin.xml,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** plugin.xml 17 Sep 2004 19:22:06 -0000 1.38 --- plugin.xml 20 Sep 2004 19:08:43 -0000 1.39 *************** *** 4,8 **** id="org.python.pydev" name="Pydev - Python Development Environment" ! version="0.5.9.6a" provider-name="AleksTotic" class="org.python.pydev.plugin.PydevPlugin"> --- 4,8 ---- id="org.python.pydev" name="Pydev - Python Development Environment" ! version="0.5.9.7" provider-name="AleksTotic" class="org.python.pydev.plugin.PydevPlugin"> *************** *** 720,723 **** --- 720,745 ---- </template> </extension> + <extension + point="org.eclipse.ui.views"> + <category + name="Pydev" + id="org.python.pydev"/> + <view + class="org.python.pydev.views.PyRefactorView" + icon="icons/sample.gif" + category="org.python.pydev" + name="Refactor Results View" + id="org.python.pydev.views.PyRefactorView"/> + </extension> + <extension + point="org.eclipse.ui.perspectiveExtensions"> + <perspectiveExtension targetID="org.eclipse.ui.resourcePerspective"> + <view + ratio="0.5" + relationship="right" + relative="org.eclipse.ui.views.TaskList" + id="org.python.pydev.views.PyRefactorView"/> + </perspectiveExtension> + </extension> </plugin> |
From: Fabio Z. <fa...@us...> - 2004-09-20 19:09:02
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11446/src/org/python/pydev/editor/actions Modified Files: PyGoToDefinition.java PyOpenAction.java Log Message: Changed search for bicycle repair man search and added a refactor view to show which files are modified. Index: PyOpenAction.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyOpenAction.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PyOpenAction.java 7 May 2004 21:48:58 -0000 1.5 --- PyOpenAction.java 20 Sep 2004 19:08:42 -0000 1.6 *************** *** 63,67 **** editor = PydevPlugin.doOpenEditor(path, true); } ! if (editor instanceof ITextEditor) { showInEditor((ITextEditor)editor, p.start, p.end); } --- 63,67 ---- editor = PydevPlugin.doOpenEditor(path, true); } ! if (editor instanceof ITextEditor && p.start.line >= 0 && p.end.line >= 0) { showInEditor((ITextEditor)editor, p.start, p.end); } Index: PyGoToDefinition.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyGoToDefinition.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyGoToDefinition.java 21 May 2004 18:12:32 -0000 1.1 --- PyGoToDefinition.java 20 Sep 2004 19:08:42 -0000 1.2 *************** *** 5,9 **** package org.python.pydev.editor.actions; ! import java.util.ArrayList; import org.eclipse.jface.action.IAction; --- 5,9 ---- package org.python.pydev.editor.actions; ! import java.util.List; import org.eclipse.jface.action.IAction; *************** *** 12,53 **** import org.eclipse.ui.PlatformUI; import org.python.pydev.editor.PyEdit; import org.python.pydev.editor.model.AbstractNode; import org.python.pydev.editor.model.ItemPointer; import org.python.pydev.editor.model.Location; import org.python.pydev.editor.model.ModelUtils; /** * @author Fabio Zadrozny ! * */ ! public class PyGoToDefinition extends PyAction{ ! /* (non-Javadoc) ! * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) ! */ ! public void run(IAction action) { ! try{ ! PyEdit pyEdit = getPyEdit(); ! IDocument doc = pyEdit.getDocumentProvider().getDocument(pyEdit.getEditorInput()); ! ITextSelection selection = ! (ITextSelection) pyEdit.getSelectionProvider().getSelection(); ! Location loc = Location.offsetToLocation(doc, selection.getOffset()); ! AbstractNode node = ModelUtils.getElement(pyEdit.getPythonModel(),loc, AbstractNode.PROP_CLICKABLE); ! ! if(node == null) ! return; ! ! PyOpenAction openAction = (PyOpenAction)pyEdit.getAction(PyEdit.ACTION_OPEN); ! ArrayList where = ModelUtils.findDefinition(node); ! if (where.size() > 0) ! openAction.run((ItemPointer)where.get(0)); ! else ! PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay().beep(); ! }catch (Exception e) { ! e.printStackTrace(); ! } ! } ! } --- 12,100 ---- import org.eclipse.ui.PlatformUI; import org.python.pydev.editor.PyEdit; + import org.python.pydev.editor.actions.refactoring.PyRefactorAction; import org.python.pydev.editor.model.AbstractNode; import org.python.pydev.editor.model.ItemPointer; import org.python.pydev.editor.model.Location; import org.python.pydev.editor.model.ModelUtils; + import org.python.pydev.editor.refactoring.PyRefactoring; /** * @author Fabio Zadrozny ! * */ ! public class PyGoToDefinition extends PyRefactorAction { ! protected boolean areRefactorPreconditionsOK(PyEdit edit) { ! ! if(edit.isDirty()) ! edit.doSave(null); ! ! return true; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) ! */ ! public void run(IAction action) { ! try { ! ! ps = new PySelection(getTextEditor(), false); ! PyEdit pyEdit = getPyEdit(); ! areRefactorPreconditionsOK(pyEdit); ! ! PyOpenAction openAction = (PyOpenAction) pyEdit ! .getAction(PyEdit.ACTION_OPEN); ! ! List where = findDefinition(pyEdit); ! ! if (where == null) { ! return; ! } ! ! if (where.size() > 0) ! openAction.run((ItemPointer) where.get(0)); ! else ! PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ! .getDisplay().beep(); ! } catch (Exception e) { ! e.printStackTrace(); ! } ! } ! ! /** ! * @param node ! * @return ! */ ! private List findDefinition(PyEdit pyEdit) { ! if(true){ ! PyRefactoring pyRefactoring = PyRefactoring.getPyRefactoring(); ! return pyRefactoring.findDefinition(pyEdit.getEditorFile(), getStartLine(), getStartCol(), null); ! ! }else{ //kept earlier version (may be useful). ! IDocument doc = pyEdit.getDocumentProvider().getDocument( ! pyEdit.getEditorInput()); ! ITextSelection selection = (ITextSelection) pyEdit ! .getSelectionProvider().getSelection(); ! Location loc = Location.offsetToLocation(doc, selection.getOffset()); ! AbstractNode node = ModelUtils.getElement(pyEdit.getPythonModel(), loc, ! AbstractNode.PROP_CLICKABLE); ! if (node == null) ! return null; ! return ModelUtils.findDefinition(node); ! } ! } ! protected String perform(IAction action, String name, Operation operation) ! throws Exception { ! return null; ! } ! ! protected String getInputMessage() { ! return null; ! } ! ! } \ No newline at end of file |
From: Fabio Z. <fa...@us...> - 2004-09-20 19:09:01
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/views In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11446/src/org/python/pydev/views Added Files: PyRefactorView.java Log Message: Changed search for bicycle repair man search and added a refactor view to show which files are modified. --- NEW FILE: PyRefactorView.java --- package org.python.pydev.views; import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.eclipse.jface.action.Action; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IPropertyListener; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; import org.python.pydev.editor.actions.PyOpenAction; import org.python.pydev.editor.model.ItemPointer; import org.python.pydev.editor.model.Location; import org.python.pydev.editor.refactoring.PyRefactoring; /** * This sample class demonstrates how to plug-in a new workbench view. The view * shows data obtained from the model. The sample creates a dummy model on the * fly, but a real implementation would connect to the model available either in * this or another plug-in (e.g. the workspace). The view is connected to the * model using a content provider. * <p> * The view uses a label provider to define how model objects should be * presented in the view. Each view can present the same model objects using * different labels and icons, if needed. Alternatively, a single label provider * can be shared between views in order to ensure that objects of the same type * are presented in the same way everywhere. * <p> */ public class PyRefactorView extends ViewPart implements IPropertyListener, IStructuredContentProvider{ private TableViewer viewer; private Action doubleClickAction; /* * The content provider class is responsible for providing objects to the * view. It can wrap existing objects in adapters or simply return objects * as-is. These objects may be sensitive to the current input of the view, * or ignore it and always show the same content (like Task List, for * example). */ class ViewLabelProvider extends LabelProvider implements ITableLabelProvider { public String getColumnText(Object obj, int index) { return getText(obj); } public Image getColumnImage(Object obj, int index) { return getImage(obj); } public Image getImage(Object obj) { return PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJ_ELEMENT); } } class NameSorter extends ViewerSorter { } /** * The constructor. */ public PyRefactorView() { } public void refresh() { viewer.refresh(); getSite().getPage().bringToTop(this); } /** * This is a callback that will allow us to create the viewer and initialize * it. */ public void createPartControl(Composite parent) { viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); viewer.setContentProvider(this); viewer.setLabelProvider(new ViewLabelProvider()); viewer.setSorter(new NameSorter()); viewer.setInput(getViewSite()); hookDoubleClickAction(); PyRefactoring.getPyRefactoring().addPropertyListener(this); } private void hookDoubleClickAction() { doubleClickAction = new Action() { public void run() { ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection) selection) .getFirstElement(); File realFile = new File(obj.toString()); if (realFile.exists()) { ItemPointer p = new ItemPointer(realFile, new Location(-1, -1), null); new PyOpenAction().run(p); } } }; viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { doubleClickAction.run(); } }); } /** * Passing the focus request to the viewer's control. */ public void setFocus() { viewer.getControl().setFocus(); } public void propertyChanged(Object source, int propId) { Object[] sources = (Object[]) source; if (sources[0] == PyRefactoring.getPyRefactoring() && propId == PyRefactoring.REFACTOR_RESULT) { elements.clear(); elements.addAll((Collection) sources[1]); } } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } public Object[] getElements(Object parent) { return elements.toArray(); } private List elements = new ArrayList(); } |
From: Fabio Z. <fa...@us...> - 2004-09-20 19:08:41
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/views In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11381/src/org/python/pydev/views Log Message: Directory /cvsroot/pydev/org.python.pydev/src/org/python/pydev/views added to the repository |
From: Fabio Z. <fa...@us...> - 2004-09-20 13:20:49
|
Update of /cvsroot/pydev/org.python.pydev.debug In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32528 Modified Files: plugin.xml Log Message: Version changed. Index: plugin.xml =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/plugin.xml,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** plugin.xml 20 Sep 2004 13:19:42 -0000 1.15 --- plugin.xml 20 Sep 2004 13:20:39 -0000 1.16 *************** *** 4,8 **** id="org.python.pydev.debug" name="Pydev debug" ! version="0.5.3a" provider-name="Aleks Totic" class="org.python.pydev.debug.core.PydevDebugPlugin"> --- 4,8 ---- id="org.python.pydev.debug" name="Pydev debug" ! version="0.5.3.1" provider-name="Aleks Totic" class="org.python.pydev.debug.core.PydevDebugPlugin"> |
From: Fabio Z. <fa...@us...> - 2004-09-20 13:19:53
|
Update of /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32211/src/org/python/pydev/debug/ui/actions Added Files: PythonTestActionDelegate.java Log Message: Grig contribution (unittest). --- NEW FILE: PythonTestActionDelegate.java --- /* * Author: ggheorghiu * Created: Sept. 10, 2004 * License: Common Public License v1.0 */ package org.python.pydev.debug.ui.actions; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.actions.ActionDelegate; import org.python.pydev.plugin.PydevPrefs; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; /** * Implements "pyUnit Test..." extension for org.eclipse.ui.popupMenus. * * <p>Launches python process and runs pyUnit's unittest * */ public class PythonTestActionDelegate extends ActionDelegate implements IObjectActionDelegate { private IFile selectedFile; private IWorkbenchPart part; public void run(IAction action) { if (part != null && selectedFile != null) { try { Process p = Runtime.getRuntime().exec(new String[]{PydevPrefs.getDefaultInterpreter()}); //we have the process... OutputStreamWriter writer = new OutputStreamWriter(p.getOutputStream()); int bufsize = 64; // small bufsize so that we can see the progress BufferedReader in = new BufferedReader(new InputStreamReader(p .getInputStream()), bufsize); BufferedReader eIn = new BufferedReader(new InputStreamReader( p.getErrorStream()), bufsize); // get the location of the workspace root IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot wsRoot = workspace.getRoot(); IPath wsRootPath = wsRoot.getLocation(); String wsRootDir = wsRootPath.toString(); // get the location of the selected file relative to the workspace IPath fullPath = selectedFile.getFullPath(); int segmentCount = fullPath.segmentCount(); // get the test module name and path so that we can import it in Python IPath noextPath = fullPath.removeFileExtension(); String moduleName = noextPath.lastSegment(); IPath modulePath = fullPath.uptoSegment(segmentCount-1); String moduleDir = modulePath.toString(); writer.write("import sys, os, unittest\n"); writer.write("os.chdir('" + wsRootDir + moduleDir + "')\n"); String arg = "sys.path.append('" + wsRootDir + moduleDir + "')\n"; writer.write(arg); arg = "unittest.TestProgram('" + moduleName + "', argv=['" + moduleName + "', '--verbose'])\n"; //arg = "unittest.TestProgram('" + moduleName + "')\n"; writer.write(arg); writer.flush(); writer.close(); String str; while ((str = eIn.readLine()) != null) { //System.out.println("STDERR: " + str); System.out.println(str); } eIn.close(); while ((str = in.readLine()) != null) { //System.out.println("STDOUT: " + str); System.out.println(str); } in.close(); p.waitFor(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } } public void selectionChanged(IAction action, ISelection selection) { selectedFile = null; if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; if (structuredSelection.size() == 1) { Object selectedResource = structuredSelection.getFirstElement(); if (selectedResource instanceof IFile) selectedFile = (IFile) selectedResource; } } } public void setActivePart(IAction action, IWorkbenchPart targetPart) { this.part = targetPart; } } |
From: Fabio Z. <fa...@us...> - 2004-09-20 13:19:52
|
Update of /cvsroot/pydev/org.python.pydev.debug In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32211 Modified Files: plugin.xml Log Message: Grig contribution (unittest). Index: plugin.xml =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/plugin.xml,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** plugin.xml 25 Jul 2004 13:53:51 -0000 1.14 --- plugin.xml 20 Sep 2004 13:19:42 -0000 1.15 *************** *** 4,8 **** id="org.python.pydev.debug" name="Pydev debug" ! version="0.5.3" provider-name="Aleks Totic" class="org.python.pydev.debug.core.PydevDebugPlugin"> --- 4,8 ---- id="org.python.pydev.debug" name="Pydev debug" ! version="0.5.3a" provider-name="Aleks Totic" class="org.python.pydev.debug.core.PydevDebugPlugin"> *************** *** 101,104 **** --- 101,112 ---- id="org.python.pydev.debug.RunPythonAction"> </action> + <action + enablesFor="1" + label="pyUnit Test..." + tooltip="Test a python script with pyUnit" + icon="icons/python.gif" + class="org.python.pydev.debug.ui.actions.PythonTestActionDelegate" + menubarPath="org.python.pydev.debug.WorkspaceMenu/group1" + id="org.python.pydev.debug.TestPythonAction"/> </objectContribution> </extension> |
From: Fabio Z. <fa...@us...> - 2004-09-20 13:19:52
|
Update of /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32211/src/org/python/pydev/debug/ui/launching Modified Files: LaunchShortcut.java Log Message: Grig contribution (unittest). Index: LaunchShortcut.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching/LaunchShortcut.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** LaunchShortcut.java 5 May 2004 02:01:58 -0000 1.5 --- LaunchShortcut.java 20 Sep 2004 13:19:42 -0000 1.6 *************** *** 155,159 **** String baseDirectory = file.getRawLocation().removeLastSegments(1).toString(); String arguments = ""; ! String interpreter = PydevPrefs.getInterpreters()[0]; workingCopy.setAttribute(Constants.ATTR_LOCATION,location); workingCopy.setAttribute(Constants.ATTR_WORKING_DIRECTORY,baseDirectory); --- 155,159 ---- String baseDirectory = file.getRawLocation().removeLastSegments(1).toString(); String arguments = ""; ! String interpreter = PydevPrefs.getDefaultInterpreter(); workingCopy.setAttribute(Constants.ATTR_LOCATION,location); workingCopy.setAttribute(Constants.ATTR_WORKING_DIRECTORY,baseDirectory); |
From: Fabio Z. <fa...@us...> - 2004-09-20 13:18:14
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31827/src/org/python/pydev/editor/codecompletion Modified Files: PythonShell.java PyCodeCompletion.java Log Message: Using pydev preferences to know which python interpreter to use. Index: PythonShell.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PythonShell.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PythonShell.java 17 Sep 2004 19:22:04 -0000 1.7 --- PythonShell.java 20 Sep 2004 13:18:05 -0000 1.8 *************** *** 18,21 **** --- 18,22 ---- import org.eclipse.core.runtime.CoreException; import org.python.pydev.editor.actions.refactoring.PyRefactorAction.Operation; + import org.python.pydev.plugin.PydevPrefs; import org.python.pydev.plugin.SocketUtil; *************** *** 135,139 **** if(process != null) endIt(); ! process = Runtime.getRuntime().exec("python "+serverFile.getAbsolutePath()+" "+pWrite+" "+pRead); boolean connected = false; --- 136,140 ---- if(process != null) endIt(); ! process = Runtime.getRuntime().exec(PydevPrefs.getDefaultInterpreter()+" "+serverFile.getAbsolutePath()+" "+pWrite+" "+pRead); boolean connected = false; *************** *** 249,253 **** public String read() throws IOException { String r = read(null); ! System.out.println("RETURNING:"+r); return r; } --- 250,254 ---- public String read() throws IOException { String r = read(null); ! // System.out.println("RETURNING:"+r); return r; } *************** *** 259,263 **** */ public void write(String str) throws IOException { ! System.out.println("WRITING:"+str); this.socketToWrite.getOutputStream().write(str.getBytes()); } --- 260,264 ---- */ public void write(String str) throws IOException { ! // System.out.println("WRITING:"+str); this.socketToWrite.getOutputStream().write(str.getBytes()); } Index: PyCodeCompletion.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PyCodeCompletion.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PyCodeCompletion.java 17 Sep 2004 19:22:04 -0000 1.7 --- PyCodeCompletion.java 20 Sep 2004 13:18:05 -0000 1.8 *************** *** 105,112 **** .getPythonModel(), loc); ! Scope scope = closest.getScope().findContainingClass(); ! String token = scope.getStartNode().getName(); ! completions = serverShell ! .getClassCompletions(token, docToParse); } else { completions = serverShell.getTokenCompletions(trimmed, --- 105,117 ---- .getPythonModel(), loc); ! if(closest == null){ ! completions = serverShell.getTokenCompletions(trimmed, ! docToParse); ! }else{ ! Scope scope = closest.getScope().findContainingClass(); ! String token = scope.getStartNode().getName(); ! completions = serverShell ! .getClassCompletions(token, docToParse); ! } } else { completions = serverShell.getTokenCompletions(trimmed, *************** *** 206,210 **** e1.printStackTrace(); } ! return newDoc; } --- 211,215 ---- e1.printStackTrace(); } ! return "\n"+newDoc; } *************** *** 294,299 **** return " "; } ! if(str.lastIndexOf(' ') != -1){ ! return str.substring(str.lastIndexOf(' '), str.length()); } return str; --- 299,309 ---- return " "; } ! ! int lastSpaceIndex = str.lastIndexOf(' '); ! int lastParIndex = str.lastIndexOf('('); ! ! if(lastParIndex != -1 || lastSpaceIndex != -1){ ! int lastIndex = lastSpaceIndex > lastParIndex ? lastSpaceIndex : lastParIndex; ! return str.substring(lastIndex+1, str.length()); } return str; |
From: Fabio Z. <fa...@us...> - 2004-09-20 13:18:14
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31827/src/org/python/pydev/plugin Modified Files: PydevPrefs.java Log Message: Using pydev preferences to know which python interpreter to use. Index: PydevPrefs.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/PydevPrefs.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** PydevPrefs.java 25 Jul 2004 13:51:39 -0000 1.11 --- PydevPrefs.java 20 Sep 2004 13:18:04 -0000 1.12 *************** *** 87,90 **** --- 87,94 ---- } + public static String getDefaultInterpreter() { + return getInterpreters()[0]; + } + public void init(IWorkbench workbench) { } |
From: Fabio Z. <fa...@us...> - 2004-09-20 12:46:17
|
Update of /cvsroot/pydev/org.python.pydev/PySrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24733/PySrc Modified Files: simpleinspect.py simpleTipper.py test_simpleTipper.py Log Message: Bug fix. Index: test_simpleTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/test_simpleTipper.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** test_simpleTipper.py 17 Sep 2004 19:22:04 -0000 1.5 --- test_simpleTipper.py 20 Sep 2004 12:46:07 -0000 1.6 *************** *** 3,7 **** ''' ! import unittest import simpleTipper import importsTipper --- 3,7 ---- ''' ! from coilib import unittest import simpleTipper import importsTipper *************** *** 95,103 **** - def getDoc3(self): - pass def testImports(self): ! print importsTipper.GenerateTip('qt.') importsTipper.GenerateTip('scbr.') importsTipper.GenerateImportsTip(['scbr']) --- 95,101 ---- def testImports(self): ! importsTipper.GenerateTip('qt.') importsTipper.GenerateTip('scbr.') importsTipper.GenerateImportsTip(['scbr']) *************** *** 110,116 **** --- 108,149 ---- + def testEnv3(self): + comps = simpleTipper.GenerateTip(self.getDoc3(), None, False) + def getDoc3(self): + s= \ + ''' + import sys + + class TestLocals(object): + + sys.path + ''' + return s + + def testEnv4(self): + comps = simpleTipper.GenerateTip(self.getDoc4(), None, False) + + def getDoc4(self): + s = \ + '''import test + + + class KKKK(object): + pass + + f = KKKK() + + d = test.LL() + d.vv() + ''' + return s + if __name__ == '__main__': + + from coilib import unittest + # unittest.TestMethod(Test, 'Test.testEnv3') unittest.main() + Index: simpleinspect.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/simpleinspect.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** simpleinspect.py 13 Sep 2004 19:47:54 -0000 1.2 --- simpleinspect.py 20 Sep 2004 12:46:07 -0000 1.3 *************** *** 1,9 **** ''' - Do not pollute this namespace! @author Fabio Zadrozny ''' ! def GenerateTip (__eraseThisV, __eraseThisToken): ! ! exec(__eraseThisV) --- 1,10 ---- ''' @author Fabio Zadrozny ''' ! def GenerateTip (__eraseThisV): ! d = dict() ! d['__eraseThisTips'] = [] ! exec __eraseThisV in d ! return d['__eraseThisTips'] Index: simpleTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/simpleTipper.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** simpleTipper.py 17 Sep 2004 17:35:55 -0000 1.5 --- simpleTipper.py 20 Sep 2004 12:46:07 -0000 1.6 *************** *** 3,7 **** ''' import compiler ! import sys __eraseThisCurrDirModule = None --- 3,7 ---- ''' import compiler ! __eraseThisCurrDirModule = None *************** *** 12,15 **** --- 12,16 ---- we are completing is located. ''' + import sys global __eraseThisCurrDirModule if __eraseThisCurrDirModule is not None: *************** *** 18,24 **** sys.path.insert(0, dir) ! def GenerateImportsTip(theDoc): ! pass ! def ReloadModules(): ''' --- 19,23 ---- sys.path.insert(0, dir) ! def ReloadModules(): ''' *************** *** 76,83 **** __eraseThisMsg += 'Compiled' ! simpleinspect.__eraseThisTips = [] ! simpleinspect.GenerateTip (__eraseThis, token) ! toReturn = simpleinspect.__eraseThisTips ! simpleinspect.__eraseThisTips = [] __eraseThisMsg += 'Getting self variables \n%s\n' % originalDoc --- 75,79 ---- __eraseThisMsg += 'Compiled' ! toReturn = simpleinspect.GenerateTip (__eraseThis) __eraseThisMsg += 'Getting self variables \n%s\n' % originalDoc *************** *** 94,98 **** def visitClass(self, node): - # print node.name if node.name == self.classToVisit: for n in node.getChildNodes(): --- 90,93 ---- |
From: Fabio Z. <fa...@us...> - 2004-09-17 19:22:47
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/refactoring In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2281/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.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PyRefactoring.java 16 Sep 2004 15:33:33 -0000 1.3 --- PyRefactoring.java 17 Sep 2004 19:22:04 -0000 1.4 *************** *** 8,11 **** --- 8,12 ---- import java.io.File; import java.io.IOException; + import java.net.URLDecoder; import org.eclipse.core.runtime.CoreException; *************** *** 80,84 **** pytonShell.write(str); ! return pytonShell.read(operation); } catch (Exception e) { e.printStackTrace(); --- 81,85 ---- pytonShell.write(str); ! return URLDecoder.decode(pytonShell.read(operation)); } catch (Exception e) { e.printStackTrace(); |
From: Fabio Z. <fa...@us...> - 2004-09-17 19:22:47
|
Update of /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/codecompletion In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2281/tests/org/python/pydev/editor/codecompletion Modified Files: PythonShellTest.java Added Files: GeneralTests.java Log Message: Making refactoring. Index: PythonShellTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/codecompletion/PythonShellTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PythonShellTest.java 13 Sep 2004 19:47:54 -0000 1.2 --- PythonShellTest.java 17 Sep 2004 19:22:03 -0000 1.3 *************** *** 50,116 **** for (Iterator iter = list.iterator(); iter.hasNext();) { Object[] element = (Object[]) iter.next(); ! assertEquals("math",element[0]); ! assertEquals("This module is always available. It provides access to the\n"+ ! "mathematical functions defined by the C standard.",element[1]); ! } ! } public void testGetTokenCompletions() throws IOException, CoreException { String str = "\n\n\n\n\nimport math\n\n\n#testetestse\n\n\n\n\n"; ! List list = shell.getTokenCompletions("math",str); assertEquals(29, list.size()); ! // for (Iterator iter = list.iterator(); iter.hasNext();) { ! // Object[] element = (Object[]) iter.next(); ! // System.out.println(element[0]); ! // System.out.println(element[1]); ! // } ! } ! public void testErrorOnCompletions() throws IOException, CoreException { String str = "import math; class C dsdfas d not valid\n"; ! List list = shell.getTokenCompletions("math",str); assertEquals(1, list.size()); Object object[] = (Object[]) list.get(0); ! assertEquals("ERROR_COMPLETING",object[0]); ! } ! ! public void testOther(){ ! String str = getTestStr(); ! ! List list = shell.getClassCompletions("C",str); ! assertEquals(18, list.size()); ! list = shell.getTokenCompletions("C",str); ! assertEquals(17, list.size()); ! // for (Iterator iter = list.iterator(); iter.hasNext();) { ! // Object[] element = (Object[]) iter.next(); ! // System.out.println(element[0]); ! // System.out.println(element[1]); ! // } ! ! } ! /** ! * @return ! */ ! private String getTestStr() { ! String str = ! "class C(object): \n"+ ! " \n"+ ! " def __init__(self): \n"+ ! " print dir(self) \n"+ ! " \n"+ ! " def a(self): \n"+ ! " pass \n"+ ! " \n"+ ! " \n"+ ! " def b(self): \n"+ ! " self.c=1 \n"+ ! " pass \n"; ! return str; ! } ! } --- 50,109 ---- for (Iterator iter = list.iterator(); iter.hasNext();) { Object[] element = (Object[]) iter.next(); ! assertEquals("math", element[0]); ! assertEquals( ! "This module is always available. It provides access to the\n" ! + "mathematical functions defined by the C standard.", ! element[1]); ! } ! } public void testGetTokenCompletions() throws IOException, CoreException { String str = "\n\n\n\n\nimport math\n\n\n#testetestse\n\n\n\n\n"; ! List list = shell.getTokenCompletions("math", str); assertEquals(29, list.size()); ! // for (Iterator iter = list.iterator(); iter.hasNext();) { ! // Object[] element = (Object[]) iter.next(); ! // System.out.println(element[0]); ! // System.out.println(element[1]); ! // } ! } public void testErrorOnCompletions() throws IOException, CoreException { String str = "import math; class C dsdfas d not valid\n"; ! List list = shell.getTokenCompletions("math", str); assertEquals(1, list.size()); Object object[] = (Object[]) list.get(0); ! assertEquals("ERROR_COMPLETING", object[0]); ! } ! public void testOther() { ! String str = getTestStr(); + List list = shell.getClassCompletions("C", str); + assertEquals(18, list.size()); ! list = shell.getTokenCompletions("C", str); ! assertEquals(17, list.size()); ! // for (Iterator iter = list.iterator(); iter.hasNext();) { ! // Object[] element = (Object[]) iter.next(); ! // System.out.println(element[0]); ! // System.out.println(element[1]); ! // } ! } ! ! /** ! * @return ! */ ! private String getTestStr() { ! String str = "class C(object): \n" ! + " \n" + " def __init__(self): \n" ! + " print dir(self) \n" + " \n" ! + " def a(self): \n" + " pass \n" ! + " \n" + " \n" ! + " def b(self): \n" + " self.c=1 \n" ! + " pass \n"; ! return str; ! } ! } \ No newline at end of file --- NEW FILE: GeneralTests.java --- /* * Created on Sep 17, 2004 * * @author Fabio Zadrozny */ package org.python.pydev.editor.codecompletion; import junit.framework.TestCase; /** * @author Fabio Zadrozny */ public class GeneralTests extends TestCase{ public void testIt() { String string = "from scbr import ddd #tetet"; System.out.println(string.replaceAll("#.*", "")); } public static void main(String[] args) { junit.textui.TestRunner.run(GeneralTests.class); } } |
From: Fabio Z. <fa...@us...> - 2004-09-17 19:22:46
|
Update of /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/query In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2281/PySrc/ThirdParty/brm/bike/query Modified Files: common.py getTypeOf.py Log Message: Making refactoring. Index: getTypeOf.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/query/getTypeOf.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** getTypeOf.py 14 Sep 2004 17:42:08 -0000 1.1 --- getTypeOf.py 17 Sep 2004 19:22:03 -0000 1.2 *************** *** 25,28 **** --- 25,29 ---- def getTypeOf(scope, fqn): if isinstance(scope, Root): + return getModuleOrPackageUsingFQN(fqn) assert False, "Can't use getTypeOf to resolve from Root. Use getModuleOrPackageUsingFQN instead" Index: common.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/brm/bike/query/common.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** common.py 16 Sep 2004 15:32:44 -0000 1.2 --- common.py 17 Sep 2004 19:22:02 -0000 1.3 *************** *** 59,62 **** --- 59,63 ---- except : print >> log.warning , 'Error parsing: %s' % doctoredline + print >> log.warning , 'Params: \n--%s\n--%s\n--%s\n--%s' % (sourcenode,scope,matchFinder,targetname) raise scope = getScopeForLine(sourcenode, lineno) |
From: Fabio Z. <fa...@us...> - 2004-09-17 19:22:15
|
Update of /cvsroot/pydev/org.python.pydev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2281 Modified Files: plugin.xml Log Message: Making refactoring. Index: plugin.xml =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/plugin.xml,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** plugin.xml 16 Sep 2004 15:33:34 -0000 1.37 --- plugin.xml 17 Sep 2004 19:22:06 -0000 1.38 *************** *** 4,8 **** id="org.python.pydev" name="Pydev - Python Development Environment" ! version="0.5.9.5b" provider-name="AleksTotic" class="org.python.pydev.plugin.PydevPlugin"> --- 4,8 ---- id="org.python.pydev" name="Pydev - Python Development Environment" ! version="0.5.9.6a" provider-name="AleksTotic" class="org.python.pydev.plugin.PydevPlugin"> |
From: Fabio Z. <fa...@us...> - 2004-09-17 19:22:14
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2281/src/org/python/pydev/editor/codecompletion Modified Files: PythonShell.java PyCodeCompletion.java Log Message: Making refactoring. Index: PythonShell.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PythonShell.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PythonShell.java 16 Sep 2004 15:33:33 -0000 1.6 --- PythonShell.java 17 Sep 2004 19:22:04 -0000 1.7 *************** *** 10,13 **** --- 10,15 ---- import java.net.ServerSocket; import java.net.Socket; + import java.net.URLDecoder; + import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; *************** *** 205,208 **** --- 207,211 ---- s = s.replaceAll("END@@", ""); j = 0; + s = URLDecoder.decode(s); if(s.trim().equals("") == false){ communicateWork("Processing: "+s, operation); *************** *** 230,234 **** //remove END@@ try { ! return str.substring(0, str.lastIndexOf("END@@")); } catch (RuntimeException e) { System.out.println("ERROR WITH STRING:"+str); --- 233,238 ---- //remove END@@ try { ! str = str.substring(0, str.lastIndexOf("END@@")); ! return str; } catch (RuntimeException e) { System.out.println("ERROR WITH STRING:"+str); *************** *** 244,248 **** */ public String read() throws IOException { ! return read(null); } --- 248,254 ---- */ public String read() throws IOException { ! String r = read(null); ! System.out.println("RETURNING:"+r); ! return r; } *************** *** 253,256 **** --- 259,263 ---- */ public void write(String str) throws IOException { + System.out.println("WRITING:"+str); this.socketToWrite.getOutputStream().write(str.getBytes()); } *************** *** 328,332 **** file = file.getParentFile(); } ! this.write("@@CHANGE_DIR:"+file.getAbsolutePath()+"END@@"); String ok = this.read(); //this should be the ok message... --- 335,342 ---- file = file.getParentFile(); } ! ! String str = file.getAbsolutePath(); ! str = URLEncoder.encode(str); ! this.write("@@CHANGE_DIR:"+str+"END@@"); String ok = this.read(); //this should be the ok message... *************** *** 351,354 **** --- 361,365 ---- */ public List getGlobalCompletions(String str) { + str = URLEncoder.encode(str); return this.getTheCompletions("@@GLOBALS:"+str+"\nEND@@"); } *************** *** 359,362 **** --- 370,375 ---- */ public List getTokenCompletions(String token, String str) { + token = URLEncoder.encode(token); + str = URLEncoder.encode(str); String s = "@@TOKEN_GLOBALS("+token+"):"+str+"\nEND@@"; return this.getTheCompletions(s); *************** *** 369,376 **** --- 382,400 ---- */ public List getClassCompletions(String token, String str) { + token = URLEncoder.encode(token); + str = URLEncoder.encode(str); String s = "@@CLASS_GLOBALS("+token+"):"+str+"\nEND@@"; return this.getTheCompletions(s); } + /** + * @param importsTipper + * @return + */ + public List getImportCompletions(String str) { + str = URLEncoder.encode(str); + return this.getTheCompletions("@@IMPORTS:"+str+"\nEND@@"); + } + private List getTheCompletions(String str){ try { *************** *** 422,427 **** while(tokenizer.hasMoreTokens()){ ! String token = tokenizer.nextToken(); ! String description = tokenizer.nextToken(); list.add(new String[]{token, description}); } --- 446,453 ---- while(tokenizer.hasMoreTokens()){ ! String token = URLDecoder.decode(tokenizer.nextToken()); ! String description = URLDecoder.decode(tokenizer.nextToken()); ! ! list.add(new String[]{token, description}); } *************** *** 432,434 **** --- 458,462 ---- + + } \ No newline at end of file Index: PyCodeCompletion.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PyCodeCompletion.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PyCodeCompletion.java 14 Sep 2004 17:42:14 -0000 1.6 --- PyCodeCompletion.java 17 Sep 2004 19:22:04 -0000 1.7 *************** *** 33,44 **** */ public class PyCodeCompletion { ! ! int docBoundary = -1; // the document prior to the activation token private PythonShell pytonShell; /** ! * @param theDoc: the whole document as a string. ! * @param documentOffset: the cursor position */ String partialDocument(String theDoc, int documentOffset) { --- 33,46 ---- */ public class PyCodeCompletion { ! int docBoundary = -1; // the document prior to the activation token + private PythonShell pytonShell; /** ! * @param theDoc: ! * the whole document as a string. ! * @param documentOffset: ! * the cursor position */ String partialDocument(String theDoc, int documentOffset) { *************** *** 46,52 **** calcDocBoundary(theDoc, documentOffset); } ! if(this.docBoundary != -1){ ! String before = theDoc.substring(0, this.docBoundary); ! return before; } return ""; --- 48,54 ---- calcDocBoundary(theDoc, documentOffset); } ! if (this.docBoundary != -1) { ! String before = theDoc.substring(0, this.docBoundary); ! return before; } return ""; *************** *** 56,59 **** --- 58,62 ---- /** * Returns a list with the tokens to use for autocompletion. + * * @param edit * @param doc *************** *** 68,72 **** } - /** * @param edit --- 71,74 ---- *************** *** 74,78 **** * @param documentOffset */ ! private List serverCompletion(String theActivationToken, PyEdit edit, IDocument doc, int documentOffset) { List theList = new ArrayList(); PythonShell serverShell = null; --- 76,81 ---- * @param documentOffset */ ! private List serverCompletion(String theActivationToken, PyEdit edit, ! IDocument doc, int documentOffset) { List theList = new ArrayList(); PythonShell serverShell = null; *************** *** 83,113 **** } - String docToParse = getDocToParse(doc, documentOffset); ! String trimmed = theActivationToken.replace('.',' ').trim(); ! if (trimmed.equals("") == false && theActivationToken.indexOf('.') != -1){ ! List completions; ! if (trimmed.equals("self")){ Location loc = Location.offsetToLocation(doc, documentOffset); ! AbstractNode closest = ModelUtils.getLessOrEqualNode(edit.getPythonModel(),loc); Scope scope = closest.getScope().findContainingClass(); String token = scope.getStartNode().getName(); ! completions = serverShell.getClassCompletions(token, docToParse); ! }else{ ! completions = serverShell.getTokenCompletions(trimmed, docToParse); } theList.addAll(completions); ! ! } ! else{ //go to globals List completions = serverShell.getGlobalCompletions(docToParse); theList.addAll(completions); ! } return theList; } --- 86,175 ---- } String docToParse = getDocToParse(doc, documentOffset); ! String trimmed = theActivationToken.replace('.', ' ').trim(); ! ! String importsTipper = useImportsTipper(theActivationToken, edit, doc, documentOffset); ! if (importsTipper.length()!=0) { //may be space. ! ! List completions = serverShell.getImportCompletions(importsTipper); ! theList.addAll(completions); ! ! } else if (trimmed.equals("") == false ! && theActivationToken.indexOf('.') != -1) { ! List completions; ! if (trimmed.equals("self")) { Location loc = Location.offsetToLocation(doc, documentOffset); ! AbstractNode closest = ModelUtils.getLessOrEqualNode(edit ! .getPythonModel(), loc); Scope scope = closest.getScope().findContainingClass(); String token = scope.getStartNode().getName(); ! completions = serverShell ! .getClassCompletions(token, docToParse); ! } else { ! completions = serverShell.getTokenCompletions(trimmed, ! docToParse); } theList.addAll(completions); ! ! } else { //go to globals List completions = serverShell.getGlobalCompletions(docToParse); theList.addAll(completions); ! } return theList; + + } + + /** + * @param theActivationToken + * @param edit + * @param doc + * @param documentOffset + * @return + */ + private String useImportsTipper(String theActivationToken, PyEdit edit, + IDocument doc, int documentOffset) { + String importMsg = ""; + try { + + IRegion region = doc.getLineInformationOfOffset(documentOffset); + String string = doc.get(region.getOffset(), documentOffset-region.getOffset()); + int fromIndex = string.indexOf("from"); + int importIndex = string.indexOf("import"); + if(fromIndex != -1 || importIndex != -1){ + string = string.replaceAll("#.*", ""); //remove comments + String[] strings = string.split(" "); + + for (int i = 0; i < strings.length; i++) { + if(strings[i].equals("from")==false && strings[i].equals("import")==false){ + if(importMsg.length() != 0){ + importMsg += '.'; + } + importMsg += strings[i]; + } + } + + if(fromIndex != -1 && importIndex != -1){ + if(strings.length == 3){ + importMsg += '.'; + } + } + }else{ + return ""; + } + } catch (BadLocationException e) { + e.printStackTrace(); + } + if (importMsg.indexOf(".") == -1){ + return " "; + } + if (importMsg.length() > 0 && importMsg.endsWith(".") == false ){ + importMsg = importMsg.substring(0, importMsg.lastIndexOf('.')); + } + return importMsg; } *************** *** 123,142 **** int lineOfOffset = doc.getLineOfOffset(documentOffset); IRegion lineInformation = doc.getLineInformation(lineOfOffset); ! int docLength = doc.getLength(); ! String src = doc.get(lineInformation.getOffset(), documentOffset-lineInformation.getOffset()); ! ! String spaces=""; for (int i = 0; i < src.length(); i++) { ! if(src.charAt(i) != ' '){ break; } spaces += ' '; } ! newDoc = wholeDoc.substring(0, lineInformation.getOffset()); ! newDoc += spaces+"pass\n"; ! newDoc += wholeDoc.substring(lineInformation.getOffset() + lineInformation.getLength(), docLength); ! } catch (BadLocationException e1) { e1.printStackTrace(); --- 185,206 ---- int lineOfOffset = doc.getLineOfOffset(documentOffset); IRegion lineInformation = doc.getLineInformation(lineOfOffset); ! int docLength = doc.getLength(); ! String src = doc.get(lineInformation.getOffset(), documentOffset ! - lineInformation.getOffset()); ! ! String spaces = ""; for (int i = 0; i < src.length(); i++) { ! if (src.charAt(i) != ' ') { break; } spaces += ' '; } ! newDoc = wholeDoc.substring(0, lineInformation.getOffset()); ! newDoc += spaces + "pass\n"; ! newDoc += wholeDoc.substring(lineInformation.getOffset() ! + lineInformation.getLength(), docLength); ! } catch (BadLocationException e1) { e1.printStackTrace(); *************** *** 145,150 **** } - - /** * --- 209,212 ---- *************** *** 164,168 **** * @throws CoreException */ ! public static File getScriptWithinPySrc(String targetExec) throws CoreException { IPath relative = new Path("PySrc").addTrailingSeparator().append( --- 226,231 ---- * @throws CoreException */ ! public static File getScriptWithinPySrc(String targetExec) ! throws CoreException { IPath relative = new Path("PySrc").addTrailingSeparator().append( *************** *** 186,191 **** public static File getImageWithinIcons(String icon) throws CoreException { ! IPath relative = new Path("icons").addTrailingSeparator().append( ! icon); Bundle bundle = PydevPlugin.getDefault().getBundle(); --- 249,253 ---- public static File getImageWithinIcons(String icon) throws CoreException { ! IPath relative = new Path("icons").addTrailingSeparator().append(icon); Bundle bundle = PydevPlugin.getDefault().getBundle(); *************** *** 205,210 **** /** ! * The docBoundary should get until the last line before the one ! * we are editing. * * @param qualifier --- 267,272 ---- /** ! * The docBoundary should get until the last line before the one we are ! * editing. * * @param qualifier *************** *** 216,220 **** .lastIndexOf('\n'); } ! /** * Returns the activation token. --- 278,282 ---- .lastIndexOf('\n'); } ! /** * Returns the activation token. *************** *** 229,237 **** } String str = theDoc.substring(this.docBoundary + 1, documentOffset); ! if (str.endsWith(" ")){ ! str = " "; } return str; } ! } --- 291,302 ---- } String str = theDoc.substring(this.docBoundary + 1, documentOffset); ! if (str.endsWith(" ")) { ! return " "; ! } ! if(str.lastIndexOf(' ') != -1){ ! return str.substring(str.lastIndexOf(' '), str.length()); } return str; } ! } \ No newline at end of file |
From: Fabio Z. <fa...@us...> - 2004-09-17 19:22:14
|
Update of /cvsroot/pydev/org.python.pydev/PySrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2281/PySrc Modified Files: importsTipper.py pycompletionserver.py refactoring.py test_simpleTipper.py Log Message: Making refactoring. Index: test_simpleTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/test_simpleTipper.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_simpleTipper.py 17 Sep 2004 17:35:55 -0000 1.4 --- test_simpleTipper.py 17 Sep 2004 19:22:04 -0000 1.5 *************** *** 99,103 **** def testImports(self): ! importsTipper.GenerateTip('qt.') importsTipper.GenerateTip('scbr.') importsTipper.GenerateImportsTip(['scbr']) --- 99,103 ---- def testImports(self): ! print importsTipper.GenerateTip('qt.') importsTipper.GenerateTip('scbr.') importsTipper.GenerateImportsTip(['scbr']) Index: pycompletionserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/pycompletionserver.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** pycompletionserver.py 17 Sep 2004 17:35:55 -0000 1.9 --- pycompletionserver.py 17 Sep 2004 19:22:04 -0000 1.10 *************** *** 41,45 **** if self.processMsgFunc != None: ! s = MSG_PROCESSING_PROGRESS % self.processMsgFunc() self.socket.send(s) else: --- 41,45 ---- if self.processMsgFunc != None: ! s = MSG_PROCESSING_PROGRESS % urllib.quote_plus(self.processMsgFunc()) self.socket.send(s) else: Index: importsTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/importsTipper.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** importsTipper.py 17 Sep 2004 17:35:55 -0000 1.2 --- importsTipper.py 17 Sep 2004 19:22:04 -0000 1.3 *************** *** 56,60 **** splitted = data.split('.') - print splitted return GenerateImportsTip(splitted) --- 56,59 ---- *************** *** 69,73 **** mods += ParseDir(d) - print mods if len(tokenList) == 0: return mods --- 68,71 ---- *************** *** 91,94 **** --- 89,96 ---- elif os.path.isdir(mod[1]): return GenerateImportsTip(newTokenList, [mod[1]], completeModule) + + else: + mod = myImport(completeModule) + return GenerateImportsTipForModule(newTokenList, mod) raise RuntimeError('Unable to complete.') Index: refactoring.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/refactoring.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** refactoring.py 17 Sep 2004 17:35:55 -0000 1.4 --- refactoring.py 17 Sep 2004 19:22:04 -0000 1.5 *************** *** 30,34 **** msg = '' i -= 1 ! return urllib.quote(msg) def getLastProgressMsgs(self, v): --- 30,34 ---- msg = '' i -= 1 ! return msg def getLastProgressMsgs(self, v): *************** *** 42,46 **** pass i -= 1 ! return urllib.quote(msg) def init(self): --- 42,46 ---- pass i -= 1 ! return msg def init(self): *************** *** 114,118 **** f = func(*msgSplit) releaseRefactorerBuffers() ! s = urllib.quote(f) return 'REFACTOR_OK:%s\nEND@@'%(s) except: --- 114,118 ---- f = func(*msgSplit) releaseRefactorerBuffers() ! s = urllib.quote_plus(f) return 'REFACTOR_OK:%s\nEND@@'%(s) except: *************** *** 134,138 **** releaseRefactorerBuffers() restartRefactorer() ! s = urllib.quote(s.getvalue()) return 'ERROR:%s\nEND@@'%(s) --- 134,138 ---- releaseRefactorerBuffers() restartRefactorer() ! s = urllib.quote_plus(s.getvalue()) return 'ERROR:%s\nEND@@'%(s) |
From: Fabio Z. <fa...@us...> - 2004-09-17 17:36:06
|
Update of /cvsroot/pydev/org.python.pydev/PySrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13035/PySrc Modified Files: test_pyserver.py simpleTipper.py importsTipper.py pycompletionserver.py refactoring.py test_simpleTipper.py Log Message: testing... Index: pycompletionserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/pycompletionserver.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** pycompletionserver.py 16 Sep 2004 15:27:25 -0000 1.8 --- pycompletionserver.py 17 Sep 2004 17:35:55 -0000 1.9 *************** *** 7,10 **** --- 7,12 ---- import refactoring import sys + import urllib + import importsTipper HOST = '127.0.0.1' # Symbolic name meaning the local host *************** *** 23,26 **** --- 25,29 ---- MSG_PROCESSING = '@@PROCESSING_END@@' MSG_PROCESSING_PROGRESS = '@@PROCESSING:%sEND@@' + MSG_IMPORTS = '@@IMPORTS:' BUFFER_SIZE = 1024 *************** *** 64,68 **** def removeInvalidChars(self, msg): if msg: ! return msg.replace(',','').replace('(','').replace(')','') return ' ' --- 67,71 ---- def removeInvalidChars(self, msg): if msg: ! return urllib.quote_plus(msg) return ' ' *************** *** 130,174 **** try: ! if MSG_KILL_SERVER in data: ! #break if we received kill message. ! break; ! ! keepAliveThread.start() ! ! if MSG_RELOAD_MODULES in data: ! simpleTipper.ReloadModules() ! returnMsg = MSG_OK ! ! else: ! data = data[:data.rfind(MSG_END)] ! ! if data.startswith(MSG_GLOBALS): ! data = data.replace(MSG_GLOBALS, '') ! comps = simpleTipper.GenerateTip(data, None, False) ! returnMsg = self.getCompletionsMessage(comps) ! ! elif data.startswith(MSG_TOKEN_GLOBALS ): ! data = data.replace(MSG_TOKEN_GLOBALS, '') ! token, data = self.getTokenAndData(data) ! comps = simpleTipper.GenerateTip(data, token, False) ! returnMsg = self.getCompletionsMessage(comps) ! elif data.startswith(MSG_CLASS_GLOBALS ): ! data = data.replace(MSG_CLASS_GLOBALS, '') ! token, data = self.getTokenAndData(data) ! comps = simpleTipper.GenerateTip(data, token, True) ! returnMsg = self.getCompletionsMessage(comps) ! elif data.startswith(MSG_CHANGE_DIR ): ! data = data.replace(MSG_CHANGE_DIR, '') ! simpleTipper.CompleteFromDir(data) returnMsg = MSG_OK ! elif data.startswith(MSG_REFACTOR): ! data = data.replace(MSG_REFACTOR, '') ! returnMsg = refactoring.HandleRefactorMessage(data, keepAliveThread) ! else: ! returnMsg = MSG_INVALID_REQUEST finally: keepAliveThread.lastMsg = returnMsg --- 133,200 ---- try: ! try: ! if MSG_KILL_SERVER in data: ! #break if we received kill message. ! break; ! keepAliveThread.start() ! if MSG_RELOAD_MODULES in data: ! simpleTipper.ReloadModules() returnMsg = MSG_OK + + else: + data = data[:data.rfind(MSG_END)] + + if data.startswith(MSG_GLOBALS): + data = data.replace(MSG_GLOBALS, '') + data = urllib.unquote_plus(data) + comps = simpleTipper.GenerateTip(data, None, False) + returnMsg = self.getCompletionsMessage(comps) ! elif data.startswith(MSG_TOKEN_GLOBALS ): ! data = data.replace(MSG_TOKEN_GLOBALS, '') ! data = urllib.unquote_plus(data) ! token, data = self.getTokenAndData(data) ! comps = simpleTipper.GenerateTip(data, token, False) ! returnMsg = self.getCompletionsMessage(comps) ! ! elif data.startswith(MSG_CLASS_GLOBALS ): ! data = data.replace(MSG_CLASS_GLOBALS, '') ! data = urllib.unquote_plus(data) ! token, data = self.getTokenAndData(data) ! comps = simpleTipper.GenerateTip(data, token, True) ! returnMsg = self.getCompletionsMessage(comps) ! elif data.startswith(MSG_IMPORTS ): ! data = data.replace(MSG_IMPORTS, '') ! data = urllib.unquote_plus(data) ! comps = importsTipper.GenerateTip(data) ! returnMsg = self.getCompletionsMessage(comps) ! ! elif data.startswith(MSG_CHANGE_DIR ): ! data = data.replace(MSG_CHANGE_DIR, '') ! data = urllib.unquote_plus(data) ! simpleTipper.CompleteFromDir(data) ! returnMsg = MSG_OK ! ! elif data.startswith(MSG_REFACTOR): ! data = data.replace(MSG_REFACTOR, '') ! data = urllib.unquote_plus(data) ! returnMsg = refactoring.HandleRefactorMessage(data, keepAliveThread) ! ! else: ! returnMsg = MSG_INVALID_REQUEST ! except : ! import sys ! import traceback ! import StringIO ! ! s = StringIO.StringIO() ! exc_info = sys.exc_info() ! ! traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], limit=None, file = s) ! returnMsg = self.getCompletionsMessage([('ERROR:','%s'%(s.getvalue()))]) ! finally: keepAliveThread.lastMsg = returnMsg *************** *** 179,183 **** if __name__ == '__main__': #let's log this!! ! out = open('c:/temp/pydev.log', 'w') sys.stdout = out sys.stderr = out --- 205,216 ---- if __name__ == '__main__': #let's log this!! ! import os ! f = 'c:/temp/pydev.log' ! i=0 ! while os.path.exists(f): ! f = 'c:/temp/pydev%s.log' % i ! i+=1 ! ! out = open(f, 'w') sys.stdout = out sys.stderr = out Index: simpleTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/simpleTipper.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** simpleTipper.py 14 Sep 2004 17:42:07 -0000 1.4 --- simpleTipper.py 17 Sep 2004 17:35:55 -0000 1.5 *************** *** 71,93 **** import simpleinspect __eraseThisMsg = '' ! try: ! __eraseThisMsg += 'Compiling \n%s\n'%theDoc ! __eraseThis = compiler.compile(theDoc, 'temporary_file_completion.py', 'exec') ! __eraseThisMsg += 'Compiled' ! ! simpleinspect.__eraseThisTips = [] ! simpleinspect.GenerateTip (__eraseThis, token) ! toReturn = simpleinspect.__eraseThisTips ! simpleinspect.__eraseThisTips = [] ! ! __eraseThisMsg += 'Getting self variables \n%s\n' % originalDoc ! if checkForSelf: ! toReturn += GetSelfVariables(originalDoc, token) ! ! return toReturn ! except : ! import sys ! s = str(sys.exc_info()[1]) ! return [('ERROR_COMPLETING','%s\nerror tracing:\n%s'%(s,__eraseThisMsg))] class Visitor(compiler.visitor.ASTVisitor): --- 71,89 ---- import simpleinspect __eraseThisMsg = '' ! ! __eraseThisMsg += 'Compiling \n%s\n'%theDoc ! __eraseThis = compiler.compile(theDoc, 'temporary_file_completion.py', 'exec') ! __eraseThisMsg += 'Compiled' ! ! simpleinspect.__eraseThisTips = [] ! simpleinspect.GenerateTip (__eraseThis, token) ! toReturn = simpleinspect.__eraseThisTips ! simpleinspect.__eraseThisTips = [] ! ! __eraseThisMsg += 'Getting self variables \n%s\n' % originalDoc ! if checkForSelf: ! toReturn += GetSelfVariables(originalDoc, token) ! ! return toReturn class Visitor(compiler.visitor.ASTVisitor): Index: test_pyserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/test_pyserver.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** test_pyserver.py 16 Sep 2004 15:27:25 -0000 1.6 --- test_pyserver.py 17 Sep 2004 17:35:55 -0000 1.7 *************** *** 7,10 **** --- 7,13 ---- import socket import os + import urllib + + class Test(unittest.TestCase): *************** *** 32,36 **** l.append(('De,f)2','de,s,c,ription2')) msg = t.formatCompletionMessage(l) ! self.assertEquals('@@COMPLETIONS((Def,description),(Def1,description1),(Def2,description2))END@@', msg) def createConnections(self, p1 = 50002,p2 = 50003): --- 35,39 ---- l.append(('De,f)2','de,s,c,ription2')) msg = t.formatCompletionMessage(l) ! self.assertEquals('@@COMPLETIONS((Def,desc%2C%2Cr%2C%2Ci%28%29ption),(Def%281,descriptio%28n1),(De%2Cf%292,de%2Cs%2Cc%2Cription2))END@@', msg) def createConnections(self, p1 = 50002,p2 = 50003): *************** *** 68,82 **** #now that we have the connections all set up, check the code completion messages. ! sToWrite.send('@@GLOBALS:import math\nEND@@') #only 1 global should be returned: math itself. completions = self.readMsg() ! self.assertEquals('@@COMPLETIONS((math,This module is always available. It provides access to the\n'\ ! 'mathematical functions defined by the C standard.))END@@', completions) #check token msg. ! sToWrite.send('@@TOKEN_GLOBALS(math):import math\nEND@@') completions = self.readMsg() self.assert_('@@COMPLETIONS' in completions) --- 71,91 ---- #now that we have the connections all set up, check the code completion messages. ! msg = urllib.quote('import math\n') ! sToWrite.send('@@GLOBALS:%sEND@@'%msg) #only 1 global should be returned: math itself. completions = self.readMsg() ! ! msg = urllib.quote('This module is always available. It provides access to the\n'\ ! 'mathematical functions defined by the C standard.') ! self.assertEquals('@@COMPLETIONS((math,%s))END@@'%msg, completions) + msg1 = urllib.quote('math') + msg2 = urllib.quote('import math\n') #check token msg. ! sToWrite.send('@@TOKEN_GLOBALS(%s):%sEND@@' % (msg1, msg2)) completions = self.readMsg() + self.assert_('@@COMPLETIONS' in completions) *************** *** 100,103 **** --- 109,113 ---- pass ''' + msg = urllib.quote(s) sToWrite.send('@@TOKEN_GLOBALS(C):%s\nEND@@'%s) *************** *** 127,135 **** self.assert_(newDir != None) sToWrite.send('@@CHANGE_DIR:%sEND@@'%newDir) ok = self.readMsg() self.assertEquals('@@MSG_OK_END@@' , ok) ! sToWrite.send('@@TOKEN_GLOBALS(math acos):import math\nEND@@') completions = self.readMsg() self.sendKillMsg(sToWrite) --- 137,157 ---- self.assert_(newDir != None) + newDir = urllib.quote(newDir) sToWrite.send('@@CHANGE_DIR:%sEND@@'%newDir) ok = self.readMsg() self.assertEquals('@@MSG_OK_END@@' , ok) ! ! msg1 = urllib.quote('math.acos') #with point ! msg2 = urllib.quote('import math\n') ! sToWrite.send('@@TOKEN_GLOBALS(%s):%sEND@@' %(msg1, msg2)) completions = self.readMsg() + self.assert_('@@COMPLETIONS' in completions) + self.assert_('END@@' in completions) + + msg1 = urllib.quote('math acos') #with space + msg2 = urllib.quote('import math\n') + sToWrite.send('@@TOKEN_GLOBALS(%s):%sEND@@' %(msg1, msg2)) + completions2 = self.readMsg() + self.assertEquals(completions, completions2) self.sendKillMsg(sToWrite) Index: refactoring.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/refactoring.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** refactoring.py 16 Sep 2004 15:27:25 -0000 1.3 --- refactoring.py 17 Sep 2004 17:35:55 -0000 1.4 *************** *** 5,9 **** import traceback import StringIO ! sys.path.insert(1, os.path.join(os.path.dirname(sys.argv[0]), --- 5,9 ---- import traceback import StringIO ! import urllib sys.path.insert(1, os.path.join(os.path.dirname(sys.argv[0]), *************** *** 30,34 **** msg = '' i -= 1 ! return msg def getLastProgressMsgs(self, v): --- 30,34 ---- msg = '' i -= 1 ! return urllib.quote(msg) def getLastProgressMsgs(self, v): *************** *** 42,46 **** pass i -= 1 ! return msg def init(self): --- 42,46 ---- pass i -= 1 ! return urllib.quote(msg) def init(self): *************** *** 112,118 **** try: ! f = func(*msgSplit)+'END@@' releaseRefactorerBuffers() ! return f except: import sys --- 112,119 ---- try: ! f = func(*msgSplit) releaseRefactorerBuffers() ! s = urllib.quote(f) ! return 'REFACTOR_OK:%s\nEND@@'%(s) except: import sys *************** *** 133,137 **** releaseRefactorerBuffers() restartRefactorer() ! return 'ERROR:%s\nEND@@'%(s.getvalue().replace('END@@','')) --- 134,139 ---- releaseRefactorerBuffers() restartRefactorer() ! s = urllib.quote(s.getvalue()) ! return 'ERROR:%s\nEND@@'%(s) Index: test_simpleTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/test_simpleTipper.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_simpleTipper.py 14 Sep 2004 17:42:07 -0000 1.3 --- test_simpleTipper.py 17 Sep 2004 17:35:55 -0000 1.4 *************** *** 93,97 **** checkedA = True self.assert_(checkedA) - # self.assert_(('a',' ') in comps) --- 93,96 ---- *************** *** 100,106 **** def testImports(self): ! raise RuntimeError('not implemented') ! importsTipper.GenerateImportsTip(0) ! --- 99,111 ---- def testImports(self): ! importsTipper.GenerateTip('qt.') ! importsTipper.GenerateTip('scbr.') ! importsTipper.GenerateImportsTip(['scbr']) ! importsTipper.GenerateImportsTip([ ] ) ! importsTipper.GenerateImportsTip(['os']) ! importsTipper.GenerateImportsTip(['os','path']) ! importsTipper.GenerateImportsTip(['unittest']) ! importsTipper.GenerateImportsTip(['scbr', 'app', 'actions', 'db']) ! importsTipper.GenerateImportsTip(['scbr', 'app', 'actions', 'db', 'EditCont']) Index: importsTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/importsTipper.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** importsTipper.py 14 Sep 2004 17:42:07 -0000 1.1 --- importsTipper.py 17 Sep 2004 17:35:55 -0000 1.2 *************** *** 1,3 **** ! def GenerateImportsTip(theDoc): ! pass --- 1,116 ---- + import copy + import os + import sys + import os.path + import inspect ! _accessibleModules = {} ! ! def isModuleWithinList(mod, lis, dbg = False): ! for l in lis: ! if l[0] == mod: ! if dbg: ! print 'returning', l ! return l ! return None ! ! def ParseDir(d): ! ret = [] ! if os.path.exists(d) and os.path.isdir(d): ! contents = os.listdir(d) ! ! for f in contents: ! absolute = os.path.join(d, f) ! ! if os.path.isfile(absolute): ! m = None ! ! #if it is a file, just check if it is a valid module. ! if f.endswith('.py'): ! m = stripExtension(f, ret, '.py') ! ! if f.endswith('.pyc'): ! m = stripExtension(f, ret, '.pyc') ! ! if m is not None and isModuleWithinList(m, ret) is None: ! ret.append((m,absolute)) ! ! elif os.path.isdir(absolute): ! contents2 = os.listdir(absolute) ! ! if '__init__.py' in contents2 or '__init__.pyc' in contents2: ! ret.append((f,absolute)) ! ! return ret ! ! def stripExtension(f, ret, ext): ! return f[0:-len(ext)] ! ! def GenerateTip(data): ! data = data.replace('\n','') ! if data.endswith('.'): ! data = data.rstrip('.') ! ! if data.strip() == '': ! return GenerateImportsTip([]) ! ! splitted = data.split('.') ! print splitted ! return GenerateImportsTip(splitted) ! ! ! def GenerateImportsTip(tokenList, pth = sys.path, completeModule = ''): ! pythonPath = pth ! ! #first, just get the root modules ! mods = [] ! for d in pythonPath: ! if _accessibleModules.get(d, None) == None: ! mods += ParseDir(d) ! ! print mods ! if len(tokenList) == 0: ! return mods ! ! else: ! token = tokenList[0] ! if len(completeModule) > 0: ! completeModule += '.' ! completeModule += token ! ! ! newTokenList = tokenList[1:] ! mod = isModuleWithinList(token , mods) ! ! if mod is not None: ! ! if os.path.isfile(mod[1]): ! mod = myImport(completeModule) ! return GenerateImportsTipForModule(newTokenList, mod) ! ! elif os.path.isdir(mod[1]): ! return GenerateImportsTip(newTokenList, [mod[1]], completeModule) ! ! raise RuntimeError('Unable to complete.') ! ! def myImport(name): ! mod = __import__(name) ! components = name.split('.') ! for comp in components[1:]: ! mod = getattr(mod, comp) ! return mod ! ! ! def GenerateImportsTipForModule(tokenList, mod): ! ret = [] ! ! while len(tokenList) > 0: ! mod = getattr(mod, tokenList.pop(0)) ! ! for d in dir(mod): ! ret.append([d,inspect.getdoc(getattr(mod, d))]) ! return ret ! ! ! ! \ No newline at end of file |
From: Fabio Z. <fa...@us...> - 2004-09-16 15:33:45
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/refactoring In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26116/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.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PyRefactoring.java 15 Sep 2004 17:36:08 -0000 1.2 --- PyRefactoring.java 16 Sep 2004 15:33:33 -0000 1.3 *************** *** 10,13 **** --- 10,14 ---- import org.eclipse.core.runtime.CoreException; + import org.python.pydev.editor.actions.refactoring.PyRefactorAction.Operation; import org.python.pydev.editor.codecompletion.PythonShell; *************** *** 36,44 **** ! private PyRefactoring(){ ! ! } ! ! public static PyRefactoring getPyRefactoring(){ if (pyRefactoring == null){ pyRefactoring = new PyRefactoring(); --- 37,41 ---- ! public synchronized static PyRefactoring getPyRefactoring(){ if (pyRefactoring == null){ pyRefactoring = new PyRefactoring(); *************** *** 47,50 **** --- 44,55 ---- } + private PyRefactoring(){ + try { + getServerShell(); //when we initialize, initialize the server. + } catch (Exception e) { + e.printStackTrace(); + } + } + /** * @return *************** *** 53,57 **** * */ ! private PythonShell getServerShell() throws IOException, CoreException { if(pytonShell == null){ pytonShell = new PythonShell(); --- 58,62 ---- * */ ! private synchronized PythonShell getServerShell() throws IOException, CoreException { if(pytonShell == null){ pytonShell = new PythonShell(); *************** *** 65,71 **** * * @param str * @return */ ! private String makeAction(String str){ PythonShell pytonShell; try { --- 70,77 ---- * * @param str + * @param operation * @return */ ! private String makeAction(String str, Operation operation){ PythonShell pytonShell; try { *************** *** 74,78 **** pytonShell.write(str); ! return pytonShell.read(); } catch (Exception e) { e.printStackTrace(); --- 80,84 ---- pytonShell.write(str); ! return pytonShell.read(operation); } catch (Exception e) { e.printStackTrace(); *************** *** 94,99 **** * @param endCol * @param name */ ! public void extract(File editorFile, int beginLine, int beginCol, int endLine, int endCol, String name) { String s = "@@REFACTOR"; s+= "extractMethod"; --- 100,106 ---- * @param endCol * @param name + * @param operation */ ! public String extract(File editorFile, int beginLine, int beginCol, int endLine, int endCol, String name, Operation operation) { String s = "@@REFACTOR"; s+= "extractMethod"; *************** *** 106,112 **** s+= "END@@"; System.out.println("Extract: "+s); ! String string = makeAction(s); System.out.println("REFACTOR RESULT:"+string); ! } --- 113,119 ---- s+= "END@@"; System.out.println("Extract: "+s); ! String string = makeAction(s, operation); System.out.println("REFACTOR RESULT:"+string); ! return string; } *************** *** 116,121 **** * @param beginCol * @param name */ ! public void rename(File editorFile, int beginLine, int beginCol, String name) { String s = "@@REFACTOR"; s+= "renameByCoordinates"; --- 123,129 ---- * @param beginCol * @param name + * @param operation */ ! public String rename(File editorFile, int beginLine, int beginCol, String name, Operation operation) { String s = "@@REFACTOR"; s+= "renameByCoordinates"; *************** *** 126,133 **** s+= "END@@"; System.out.println("Extract: "+s); ! String string = makeAction(s); System.out.println("REFACTOR RESULT:"+string); } } --- 134,155 ---- s+= "END@@"; System.out.println("Extract: "+s); ! String string = makeAction(s, operation); System.out.println("REFACTOR RESULT:"+string); + return string; } + /** + * + */ + public void restartShell() { + try { + getServerShell().restartShell(); + } catch (IOException e) { + e.printStackTrace(); + } catch (CoreException e) { + e.printStackTrace(); + } + } + } |
From: Fabio Z. <fa...@us...> - 2004-09-16 15:33:45
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/refactoring In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26116/src/org/python/pydev/editor/actions/refactoring Modified Files: PyExtractMethod.java PyRefactorAction.java PyRename.java Log Message: Making refactoring. Index: PyRename.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/refactoring/PyRename.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyRename.java 15 Sep 2004 17:36:08 -0000 1.1 --- PyRename.java 16 Sep 2004 15:33:32 -0000 1.2 *************** *** 21,25 **** * renameByCoordinates(filename, line, column, newname) */ ! protected void perform(IAction action) throws Exception { File editorFile = getPyEdit().getEditorFile(); --- 21,25 ---- * renameByCoordinates(filename, line, column, newname) */ ! protected String perform(IAction action, String name, Operation operation) throws Exception { File editorFile = getPyEdit().getEditorFile(); *************** *** 28,41 **** int beginCol = getStartCol(); ! String name = getInput(getPyEdit(),"Please inform the new name."); ! if(name.equals("") == false){ ! PyRefactoring.getPyRefactoring().rename(editorFile, beginLine, beginCol, name); ! refreshEditor(getPyEdit()); } ! } } --- 28,46 ---- int beginCol = getStartCol(); ! String res = ""; if(name.equals("") == false){ ! res = PyRefactoring.getPyRefactoring().rename(editorFile, beginLine, beginCol, name, operation); ! refreshEditors(getPyEdit()); } ! return res; ! } ! ! protected String getInputMessage() { ! return "Please inform the new name."; } + + } Index: PyExtractMethod.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/refactoring/PyExtractMethod.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyExtractMethod.java 15 Sep 2004 17:36:08 -0000 1.1 --- PyExtractMethod.java 16 Sep 2004 15:33:32 -0000 1.2 *************** *** 29,33 **** * @throws CoreException */ ! protected void perform(IAction action) throws BadLocationException, CoreException { File editorFile = getPyEdit().getEditorFile(); --- 29,33 ---- * @throws CoreException */ ! protected String perform(IAction action, String name, Operation operation) throws BadLocationException, CoreException { File editorFile = getPyEdit().getEditorFile(); *************** *** 39,53 **** int endCol = getEndCol(); ! String name = getInput(getPyEdit(),"Please inform the new name."); ! if(name.equals("") == false){ ! PyRefactoring.getPyRefactoring().extract(editorFile, beginLine, beginCol, endLine, endCol, name); ! refreshEditor(getPyEdit()); } } ! --- 39,56 ---- int endCol = getEndCol(); ! String res = ""; if(name.equals("") == false){ ! res = PyRefactoring.getPyRefactoring().extract(editorFile, beginLine, beginCol, endLine, endCol, name, operation); ! refreshEditors(getPyEdit()); } + return res; } ! protected String getInputMessage() { ! return "Please inform the new name."; ! } ! Index: PyRefactorAction.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/refactoring/PyRefactorAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyRefactorAction.java 15 Sep 2004 17:36:08 -0000 1.1 --- PyRefactorAction.java 16 Sep 2004 15:33:32 -0000 1.2 *************** *** 6,22 **** --- 6,35 ---- package org.python.pydev.editor.actions.refactoring; + import java.lang.reflect.InvocationTargetException; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; + import org.eclipse.core.runtime.IProgressMonitor; + import org.eclipse.core.runtime.IStatus; + import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.IAction; + import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.dialogs.MessageDialog; + import org.eclipse.jface.dialogs.ProgressMonitorDialog; + import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorPart; + import org.eclipse.ui.IEditorReference; + import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; + import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.eclipse.ui.part.FileEditorInput; import org.python.pydev.editor.PyEdit; import org.python.pydev.editor.actions.PyAction; import org.python.pydev.editor.actions.PySelection; + import org.python.pydev.editor.refactoring.PyRefactoring; + import org.python.pydev.plugin.PydevPlugin; /** *************** *** 25,28 **** --- 38,73 ---- public abstract class PyRefactorAction extends PyAction { + private IWorkbenchWindow workbenchWindow; + + public final class Operation extends WorkspaceModifyOperation { + public String statusOfOperation; + + private final String nameUsed; + + private final IAction action; + + public IProgressMonitor monitor; + + public Operation(String nameUsed, IAction action) { + super(); + this.nameUsed = nameUsed; + this.action = action; + } + + protected void execute(IProgressMonitor monitor) throws CoreException, + InvocationTargetException, InterruptedException { + + try { + this.monitor = monitor; + monitor.beginTask("Refactor", 500); + this.statusOfOperation = perform(action, nameUsed, this); + monitor.done(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + } + /** * @param edit *************** *** 30,36 **** */ protected String getInput(PyEdit edit, String msg) { ! InputDialog d = new InputDialog(edit.getSite().getShell(),"Refactoring", msg,"",null); int retCode = d.open(); ! if(retCode == InputDialog.OK){ return d.getValue(); } --- 75,82 ---- */ protected String getInput(PyEdit edit, String msg) { ! InputDialog d = new InputDialog(getPyEditShell(), "Refactoring", msg, ! "", null); int retCode = d.open(); ! if (retCode == InputDialog.OK) { return d.getValue(); } *************** *** 38,48 **** } /** * @param edit * @throws CoreException */ ! protected void refreshEditor(PyEdit edit) throws CoreException { ! IFile file = (IFile) ((FileEditorInput)edit.getEditorInput()).getAdapter(IFile.class); ! file.refreshLocal(IResource.DEPTH_INFINITE, null); } --- 84,117 ---- } + private void refreshEditor(PyEdit edit) throws CoreException { + IFile file = (IFile) ((FileEditorInput) edit.getEditorInput()) + .getAdapter(IFile.class); + file.refreshLocal(IResource.DEPTH_INFINITE, null); + } + /** * @param edit * @throws CoreException */ ! protected void refreshEditors(PyEdit edit) throws CoreException { ! refreshEditor(edit); ! ! ! ! IWorkbenchPage[] pages = workbenchWindow.getPages(); ! for (int i = 0; i < pages.length; i++) { ! IEditorReference[] editorReferences = pages[i] ! .getEditorReferences(); ! ! for (int j = 0; j < editorReferences.length; j++) { ! if (editorReferences[j] instanceof PyEdit) { ! PyEdit e = (PyEdit) editorReferences[j]; ! if (e != edit) { ! System.out.println("REFRESHING OTHER"); ! refreshEditor(e); ! } ! } ! } ! } } *************** *** 51,68 **** */ protected boolean areRefactorPreconditionsOK(PyEdit edit) { ! IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); ! IEditorPart[] dirtyEditors = workbenchWindow.getActivePage().getDirtyEditors(); ! boolean saveEditors = false; ! if(dirtyEditors.length > 0){ ! saveEditors = MessageDialog.openQuestion(edit.getSite().getShell(), "Save All?", "All the editors must be saved to make this operation.\nIs it ok to save them?"); ! if(saveEditors==false){ return false; } ! } ! ! if(saveEditors){ ! boolean editorsSaved = workbenchWindow.getActivePage().saveAllEditors(false); ! if (!editorsSaved){ return false; } --- 120,142 ---- */ protected boolean areRefactorPreconditionsOK(PyEdit edit) { ! workbenchWindow = PlatformUI.getWorkbench() ! .getActiveWorkbenchWindow(); ! IEditorPart[] dirtyEditors = workbenchWindow.getActivePage() ! .getDirtyEditors(); ! boolean saveEditors = false; ! if (dirtyEditors.length > 0) { ! saveEditors = MessageDialog ! .openQuestion(getPyEditShell(), "Save All?", ! "All the editors must be saved to make this operation.\nIs it ok to save them?"); ! if (saveEditors == false) { return false; } ! } ! ! if (saveEditors) { ! boolean editorsSaved = workbenchWindow.getActivePage() ! .saveAllEditors(false); ! if (!editorsSaved) { return false; } *************** *** 84,88 **** */ protected int getEndLine() { ! return ps.endLineIndex+1; } --- 158,162 ---- */ protected int getEndLine() { ! return ps.endLineIndex + 1; } *************** *** 98,135 **** */ protected int getStartLine() { ! return ps.startLineIndex+1; } ! /* (non-Javadoc) * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ ! public void run(IAction action) { ! System.out.println("PyExtractMethod "); ! try ! { ! // Select from text editor ! ps = new PySelection ( getTextEditor ( ), false ); ! ! if(areRefactorPreconditionsOK(getPyEdit())==false){ ! return; ! } ! // Perform the action ! perform ( action ); ! // Put cursor at the first area of the selection ! getTextEditor ( ).selectAndReveal ( ps.endLine.getOffset ( ), 0 ); ! } ! catch ( Exception e ) ! { ! beep ( e ); ! } } /** * @param action */ ! protected abstract void perform(IAction action) throws Exception; ! } --- 172,266 ---- */ protected int getStartLine() { ! return ps.startLineIndex + 1; } ! /* ! * (non-Javadoc) ! * * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ ! public void run(final IAction action) { ! // Select from text editor ! ps = new PySelection(getTextEditor(), false); ! if (areRefactorPreconditionsOK(getPyEdit()) == false) { ! return; ! } ! String msg = getInputMessage(); ! String name = ""; ! if (msg != null) ! name = getInput(getPyEdit(), msg); ! ! final String nameUsed = name; ! Operation operation = new Operation(nameUsed, action); ! ! ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog( ! getPyEditShell()); ! monitorDialog.setBlockOnOpen(false); ! try { ! monitorDialog.run(true, false, operation); ! // Perform the action ! } catch (InvocationTargetException e) { ! e.printStackTrace(); ! } catch (InterruptedException e) { ! e.printStackTrace(); ! } ! ! if (operation.statusOfOperation.startsWith("ERROR:")) { ! restartRefactorShell(); ! String[] strings = operation.statusOfOperation.split("DETAILS:"); ! if (strings.length == 2) { ! IStatus status = new Status(IStatus.ERROR, PydevPlugin ! .getPluginID(), 0, strings[0], ! new Exception(strings[0])); ! ErrorDialog.openError(getPyEditShell(), "ERROR", strings[0], ! status); ! } else { ! MessageDialog.openError(getPyEditShell(), "ERROR", ! operation.statusOfOperation); ! } ! throw new RuntimeException(strings[1]); ! } ! ! // Put cursor at the first area of the selection ! getTextEditor().selectAndReveal(ps.endLine.getOffset(), 0); ! ! } ! ! /** ! * ! */ ! private void restartRefactorShell() { ! new Thread() { ! public void run() { ! PyRefactoring.getPyRefactoring().restartShell(); ! } ! }.start(); } /** + * @return + */ + protected Shell getPyEditShell() { + return getPyEdit().getSite().getShell(); + } + + /** + * * @param action + * @param name + * @param operation + * @return the status returned by the server for the refactoring. + * @throws Exception */ ! protected abstract String perform(IAction action, String name, ! Operation operation) throws Exception; ! /** ! * ! * @return null if no input message is needed. ! */ ! protected abstract String getInputMessage(); ! } \ No newline at end of file |
From: Fabio Z. <fa...@us...> - 2004-09-16 15:33:45
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26116/src/org/python/pydev/editor/codecompletion Modified Files: PythonShell.java Log Message: Making refactoring. Index: PythonShell.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PythonShell.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PythonShell.java 15 Sep 2004 17:36:09 -0000 1.5 --- PythonShell.java 16 Sep 2004 15:33:33 -0000 1.6 *************** *** 15,18 **** --- 15,19 ---- import org.eclipse.core.runtime.CoreException; + import org.python.pydev.editor.actions.refactoring.PyRefactorAction.Operation; import org.python.pydev.plugin.SocketUtil; *************** *** 34,38 **** * */ ! public static PythonShell getServerShell() throws IOException, CoreException { if(pytonShell == null){ pytonShell = new PythonShell(); --- 35,39 ---- * */ ! public synchronized static PythonShell getServerShell() throws IOException, CoreException { if(pytonShell == null){ pytonShell = new PythonShell(); *************** *** 121,127 **** * can talk with the server. * * @throws IOException is some error happens creating the sockets - the process is terminated. */ ! public void startIt() throws IOException{ try { --- 122,129 ---- * can talk with the server. * + * @param milisSleep: time to wait after creating the process. * @throws IOException is some error happens creating the sockets - the process is terminated. */ ! public void startIt(int milisSleep) throws IOException{ try { *************** *** 137,141 **** while(!connected && attempts < 20){ attempts += 1; ! sleepALittle(); try { socketToWrite = new Socket("127.0.0.1",pWrite); //we should write in this port --- 139,143 ---- while(!connected && attempts < 20){ attempts += 1; ! sleepALittle(milisSleep); try { socketToWrite = new Socket("127.0.0.1",pWrite); //we should write in this port *************** *** 144,148 **** connected = true; } catch (IOException e1) { ! e1.printStackTrace(); } } --- 146,150 ---- connected = true; } catch (IOException e1) { ! //e1.printStackTrace(); } } *************** *** 153,167 **** } process = null; ! e.printStackTrace(); throw e; } } /** ! * @return s string with the contents read. * @throws IOException */ ! public String read() throws IOException { String str = ""; --- 155,187 ---- } process = null; ! //e.printStackTrace(); throw e; } } + + /** + * This method creates the python server process and starts the sockets, so that we + * can talk with the server. + * + * @throws IOException is some error happens creating the sockets - the process is terminated. + */ + public void startIt() throws IOException{ + this.startIt(25); + } + private void communicateWork(String desc, Operation operation){ + if(operation != null){ + operation.monitor.setTaskName(desc); + operation.monitor.worked(1); + } + } + /** ! * @param operation ! * @return * @throws IOException */ ! public String read(Operation operation) throws IOException { String str = ""; *************** *** 170,192 **** byte[] b = new byte[PythonShell.BUFFER_SIZE]; - // System.out.println("WILL READ"); this.socketToRead.getInputStream().read(b); - // System.out.println("READ"); String s = new String(b); if(s.indexOf("@@PROCESSING_END@@") != -1){ //each time we get a processing message, reset j to 0. s = s.replaceAll("@@PROCESSING_END@@", ""); j = 0; ! // System.out.println("Processing msg received."); } s = s.replaceAll((char)0+"",""); //python sends this char as payload. - System.out.println("RECEIVED:"+s); str += s; if(str.indexOf("END@@") != -1){ - // System.out.println("WILL BREAK"); break; }else{ - // System.out.println("WILL SLEEP"); j++; sleepALittle(10); --- 190,223 ---- byte[] b = new byte[PythonShell.BUFFER_SIZE]; this.socketToRead.getInputStream().read(b); String s = new String(b); + if(s.indexOf("@@PROCESSING_END@@") != -1){ //each time we get a processing message, reset j to 0. s = s.replaceAll("@@PROCESSING_END@@", ""); j = 0; ! communicateWork("Processing...", operation); ! } ! ! ! if(s.indexOf("@@PROCESSING:") != -1){ //each time we get a processing message, reset j to 0. ! s = s.replaceAll("@@PROCESSING:", ""); ! s = s.replaceAll("END@@", ""); ! j = 0; ! if(s.trim().equals("") == false){ ! communicateWork("Processing: "+s, operation); ! }else{ ! communicateWork("Processing...", operation); ! } ! s = ""; } + + s = s.replaceAll((char)0+"",""); //python sends this char as payload. str += s; if(str.indexOf("END@@") != -1){ break; }else{ j++; sleepALittle(10); *************** *** 194,211 **** } - // System.out.println("OUT"); //remove @@COMPLETIONS str = str.replaceFirst("@@COMPLETIONS",""); //remove END@@ - try { return str.substring(0, str.lastIndexOf("END@@")); } catch (RuntimeException e) { ! System.out.println("ERROR WIT STRING:"+str); e.printStackTrace(); return ""; } } --- 225,249 ---- } //remove @@COMPLETIONS str = str.replaceFirst("@@COMPLETIONS",""); //remove END@@ try { return str.substring(0, str.lastIndexOf("END@@")); } catch (RuntimeException e) { ! System.out.println("ERROR WITH STRING:"+str); e.printStackTrace(); return ""; } } + + + /** + * @return s string with the contents read. + * @throws IOException + */ + public String read() throws IOException { + return read(null); + } *************** *** 393,395 **** --- 431,434 ---- + } \ No newline at end of file |
From: Fabio Z. <fa...@us...> - 2004-09-16 15:33:45
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26116/src/org/python/pydev/editor Modified Files: PyEdit.java Log Message: Making refactoring. Index: PyEdit.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/PyEdit.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** PyEdit.java 14 Sep 2004 17:42:17 -0000 1.22 --- PyEdit.java 16 Sep 2004 15:33:33 -0000 1.23 *************** *** 44,47 **** --- 44,48 ---- import org.python.parser.TokenMgrError; import org.python.pydev.editor.actions.PyOpenAction; + import org.python.pydev.editor.codecompletion.PythonShell; import org.python.pydev.editor.codefolding.CodeFoldingSetter; import org.python.pydev.editor.codefolding.PyEditProjection; *************** *** 50,53 **** --- 51,55 ---- import org.python.pydev.editor.model.Location; import org.python.pydev.editor.model.ModelMaker; + import org.python.pydev.editor.refactoring.PyRefactoring; import org.python.pydev.outline.PyOutlinePage; import org.python.pydev.parser.PyParser; *************** *** 110,113 **** --- 112,136 ---- this.addModelListener(codeFoldingSetter); this.addPropertyListener(codeFoldingSetter); + + //we also want to initialize our shells... + //we use 2: one for refactoring and one for code completion. + new Thread(){ + public void run(){ + try { + try { + PyRefactoring.getPyRefactoring(); + } catch (RuntimeException e1) { + } + try { + PythonShell.getServerShell(); + } catch (RuntimeException e1) { + } + } catch (Exception e) { + } + + + } + }.start(); + } |