[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/actions/navigation package.html,NONE,1.1 Py
Brought to you by:
fabioz
From: Aleksandar T. <at...@us...> - 2004-04-10 02:01:39
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/navigation In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv649/src/org/python/pydev/editor/actions/navigation Modified Files: PyPreviousMethod.java PyNextMethod.java PyMethodNavigation.java Added Files: package.html Log Message: Huge code rewrite. I've implemented a Python model. Model is based in AST tree, but should be simpler to use. No more visitor pattern. OutlineView and Navigation actions have been reworked to use new model, instead of traversing AST. Added Hyperlinking capability, but goto is not implemetned yet. Index: PyPreviousMethod.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/navigation/PyPreviousMethod.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PyPreviousMethod.java 5 Mar 2004 22:04:44 -0000 1.2 --- PyPreviousMethod.java 10 Apr 2004 01:48:13 -0000 1.3 *************** *** 7,24 **** package org.python.pydev.editor.actions.navigation; ! import org.python.pydev.outline.ParsedItem; ! import org.python.pydev.outline.SelectionPosition; /** * @author Fabio Zadrozny */ ! public class PyPreviousMethod extends PyMethodNavigation{ ! public SelectionPosition getSelect(Visitor v) { ! if (v.prevNode != null){ ! return ParsedItem.getPosition(v.prevNode); ! } ! return null; } - } --- 7,26 ---- package org.python.pydev.editor.actions.navigation; ! import org.python.pydev.editor.model.*; ! /** * @author Fabio Zadrozny */ ! public class PyPreviousMethod extends PyMethodNavigation { ! // me is the last node w ! public AbstractNode getSelect(AbstractNode me) { ! AbstractNode current = ModelUtils.getPreviousNode(me); ! while (current != null && ! !(current instanceof FunctionNode) && ! !(current instanceof ClassNode)) ! current = ModelUtils.getPreviousNode(current); ! return current; } } --- NEW FILE: package.html --- <body> Editor navigation actions. </body> Index: PyNextMethod.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/navigation/PyNextMethod.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PyNextMethod.java 5 Mar 2004 22:04:44 -0000 1.2 --- PyNextMethod.java 10 Apr 2004 01:48:13 -0000 1.3 *************** *** 7,23 **** package org.python.pydev.editor.actions.navigation; ! import org.python.pydev.outline.ParsedItem; ! import org.python.pydev.outline.SelectionPosition; /** ! * @author Fabio Zadrozny */ public class PyNextMethod extends PyMethodNavigation{ ! public SelectionPosition getSelect(Visitor v) { ! if (v.nextNode != null){ ! return ParsedItem.getPosition(v.nextNode); ! } ! return null; } } --- 7,27 ---- package org.python.pydev.editor.actions.navigation; ! import org.python.pydev.editor.model.*; /** ! * One-trick pony, finds the next method. */ public class PyNextMethod extends PyMethodNavigation{ ! /** ! * Gets the next method/class definition ! */ ! public AbstractNode getSelect(AbstractNode me ) { ! AbstractNode current = ModelUtils.getNextNode(me); ! while (current != null && ! !(current instanceof FunctionNode) && ! !(current instanceof ClassNode)) ! current = ModelUtils.getNextNode(current); ! return current; } } Index: PyMethodNavigation.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/navigation/PyMethodNavigation.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PyMethodNavigation.java 5 Mar 2004 22:07:04 -0000 1.3 --- PyMethodNavigation.java 10 Apr 2004 01:48:13 -0000 1.4 *************** *** 10,22 **** import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextSelection; - import org.python.parser.SimpleNode; - import org.python.parser.ast.ClassDef; - import org.python.parser.ast.FunctionDef; - import org.python.parser.ast.VisitorBase; import org.python.pydev.editor.PyEdit; import org.python.pydev.editor.actions.PyAction; ! import org.python.pydev.outline.ParsedItem; ! import org.python.pydev.outline.ParsedModel; ! import org.python.pydev.outline.SelectionPosition; /** --- 10,16 ---- import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextSelection; import org.python.pydev.editor.PyEdit; import org.python.pydev.editor.actions.PyAction; ! import org.python.pydev.editor.model.*; /** *************** *** 30,107 **** /** - * This class is interested in knowing where are we... - * - * @author Fabio Zadrozny - * - */ - class Visitor extends VisitorBase { - - /** - * The initial line starts in 0 - */ - public int initialLine; - - /** - * This is the previous node. - */ - public SimpleNode prevNode = null; - - /** - * This is the current node. (Its begin line - * starts at 1 and not 0). - */ - public SimpleNode currentNode = null; - - /** - * This is the next found node. - */ - public SimpleNode nextNode = null; - - /** - * We have to know the initialLine, so that we can know where we are. - * @param initialLine - */ - public Visitor(int initialLine) { - this.initialLine = initialLine; - } - - /** - * Marks the current, previous and next node... - * @param node - */ - private void mark(SimpleNode node) { - if (this.initialLine >= node.beginLine - 1) { - if (this.currentNode != null) { - this.prevNode = this.currentNode; - } - this.currentNode = node; - } else if (nextNode == null) { //only sets the next node once... - nextNode = node; - } - } - - public Object visitClassDef(ClassDef node) throws Exception { - // print("visiting...visitClassDef"); - mark(node); - node.traverse(this); - return null; - } - - public Object visitFunctionDef(FunctionDef node) throws Exception { - // print("visiting...visitFunctionDef"); - mark(node); - return null; - } - - protected Object unhandled_node(SimpleNode node) throws Exception { - return null; - } - - public void traverse(SimpleNode node) throws Exception { - } - - } - - /** * This method gets the parsed model, discovers where we are in the * document (through the visitor), and asks the implementing class --- 24,27 ---- *************** *** 110,154 **** public void run(IAction action) { PyEdit pyEdit = getPyEdit(); ! IDocument doc = ! pyEdit.getDocumentProvider().getDocument(pyEdit.getEditorInput()); ITextSelection selection = (ITextSelection) pyEdit.getSelectionProvider().getSelection(); - - ParsedModel model = new ParsedModel(null, pyEdit.getParser()); - ParsedItem item = (ParsedItem)model.getRoot(); - SimpleNode node = item.getToken(); - - if (node == null) - return; ! int startLine = selection.getStartLine(); ! Visitor v = whereAmI(startLine, node); ! ! // print (v.nextNode); ! SelectionPosition select = getSelect(v); ! // print("select = " + select); ! if (select != null) { ! pyEdit.setSelection(select); ! } ! model.dispose(); ! } ! ! /** ! * Returns a visitor that knows where we are and the nodes next to me... ! * ! * @param startLine ! * @param root ! * @return ! */ ! public Visitor whereAmI(int startLine, SimpleNode root) { ! Visitor v = new Visitor(startLine); ! try { ! synchronized (v) { ! root.traverse(v); ! } ! } catch (Exception e) { ! e.printStackTrace(); ! } ! return v; } --- 30,42 ---- public void run(IAction action) { PyEdit pyEdit = getPyEdit(); ! IDocument doc = pyEdit.getDocumentProvider().getDocument(pyEdit.getEditorInput()); ITextSelection selection = (ITextSelection) pyEdit.getSelectionProvider().getSelection(); ! Location loc = Location.offsetToLocation(doc, selection.getOffset()); ! AbstractNode closest = ModelUtils.getLessOrEqualNode(pyEdit.getPythonModel(),loc); ! ! AbstractNode goHere = getSelect(closest); ! pyEdit.revealModelNode(goHere); } *************** *** 159,165 **** * * @param v ! * @return */ ! public abstract SelectionPosition getSelect(Visitor v); } --- 47,53 ---- * * @param v ! * @return where we should go depending on visitor */ ! public abstract AbstractNode getSelect(AbstractNode v); } |