[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/model ItemPointer.java,1.1,1.2 AbstractNode
Brought to you by:
fabioz
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14105/src/org/python/pydev/editor/model Modified Files: ItemPointer.java AbstractNode.java ModelUtils.java NameEqualsMainNode.java Scope.java ModuleNode.java ModelMaker.java Log Message: Lots of minor changes: double-clicking, more hyperlink navigation, making editor more useable. Moved some files here from debug, and pruned some obsolete ones. Index: NameEqualsMainNode.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/model/NameEqualsMainNode.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NameEqualsMainNode.java 15 Apr 2004 23:19:21 -0000 1.2 --- NameEqualsMainNode.java 22 Apr 2004 10:35:22 -0000 1.3 *************** *** 18,23 **** super(parent); this.astNode = astNode; ! this.setStart(new Location(astNode.beginLine, astNode.beginColumn-1)); ! this.setEnd(new Location(astNode.beginLine, astNode.beginColumn + 22)); } --- 18,23 ---- super(parent); this.astNode = astNode; ! this.setStart(new Location(astNode.beginLine-1, astNode.beginColumn-1)); ! this.setEnd(new Location(astNode.beginLine-1, astNode.beginColumn + 22)); } Index: ModelMaker.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/model/ModelMaker.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ModelMaker.java 15 Apr 2004 23:19:21 -0000 1.2 --- ModelMaker.java 22 Apr 2004 10:35:22 -0000 1.3 *************** *** 6,10 **** package org.python.pydev.editor.model; ! import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.text.BadLocationException; --- 6,10 ---- package org.python.pydev.editor.model; ! import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.text.BadLocationException; *************** *** 26,30 **** * */ ! public static ModuleNode createModel(SimpleNode root, IDocument doc, IFile file) { int lastLine = doc.getNumberOfLines(); int lineLength = 255; --- 26,30 ---- * */ ! public static ModuleNode createModel(SimpleNode root, IDocument doc, IPath file) { int lastLine = doc.getNumberOfLines(); int lineLength = 255; Index: ModelUtils.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/model/ModelUtils.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ModelUtils.java 15 Apr 2004 23:19:21 -0000 1.2 --- ModelUtils.java 22 Apr 2004 10:35:22 -0000 1.3 *************** *** 11,19 **** import java.util.Iterator; - import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.python.pydev.plugin.PydevPlugin; --- 11,19 ---- import java.util.Iterator; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; + import org.python.parser.ast.Name; import org.python.pydev.plugin.PydevPlugin; *************** *** 177,180 **** --- 177,189 ---- } + public static Scope findEnclosingClassScope(AbstractNode node) { + if (node == null) + return null; + Scope s = node.getScope(); + while (s != null && !(s.getStartNode() instanceof ClassNode)) + s = s.getParent(); + return s; + } + /** * Finds where the given node is defined. *************** *** 184,188 **** */ public static ArrayList findDefinition(AbstractNode node) { - IFile file; ArrayList retVal = new ArrayList(); // simple function calls --- 193,196 ---- *************** *** 198,211 **** for (Iterator i = funcCalls.iterator(); i.hasNext();) { FunctionNode funcNode = (FunctionNode)i.next(); ! retVal.add(new ItemPointer(funcNode.getFile(), funcNode.getStart(), funcNode.getEnd())); } ! } else if (node instanceof ImportAlias) { // imports: // import sys ! File myImport = node.getScope().findImport(node.getName(), node.getFile()); if (myImport != null) retVal.add(new ItemPointer(myImport)); ! }else if (node instanceof AttributeNode) { // method calls. ex: self.break_here() } return retVal; --- 206,240 ---- for (Iterator i = funcCalls.iterator(); i.hasNext();) { FunctionNode funcNode = (FunctionNode)i.next(); ! retVal.add(new ItemPointer(funcNode.getPath(), funcNode.getStart(), funcNode.getEnd())); } ! } else if (node instanceof ImportAlias || node instanceof ImportFromNode) { // imports: // import sys ! File myImport = node.getScope().findImport(node.getName(), node.getPath()); if (myImport != null) retVal.add(new ItemPointer(myImport)); ! } else if (node instanceof AttributeNode && ! node.parent instanceof FunctionCallNode && ! ((AttributeNode)node).astNode.value instanceof Name && ! ((Name)((AttributeNode)node).astNode.value).id.equals("self")) ! { ! // self. method calls // method calls. ex: self.break_here() + // Find the function calls in the containing class that + Scope s = node.getScope(); + s = s.findContainingClass(); + if (s != null) { + ArrayList funcCalls = s.findFunctionCalls( + node.getName(), false, + new Comparator() { + public int compare(Object token, Object funcCall) { + return ((String)token).compareTo(((AbstractNode)funcCall).getName()); + }} + ); + for (Iterator i = funcCalls.iterator(); i.hasNext();) { + FunctionNode funcNode = (FunctionNode)i.next(); + retVal.add(new ItemPointer(funcNode.getPath(), funcNode.getStart(), funcNode.getEnd())); + } + } } return retVal; Index: Scope.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/model/Scope.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Scope.java 15 Apr 2004 23:19:21 -0000 1.2 --- Scope.java 22 Apr 2004 10:35:22 -0000 1.3 *************** *** 11,15 **** import java.util.Iterator; - import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; import org.python.pydev.plugin.PydevPrefs; --- 11,14 ---- *************** *** 107,111 **** * @param name: function name * @param c: comparator to test for. ! * @return an ArrayList of ItemPointers to the function definitions. * each returned item will test as equal in c.compare(token, item); * null is never returned, there will be an empty array if none were found. --- 106,110 ---- * @param name: function name * @param c: comparator to test for. ! * @return an ArrayList of AbstractNode to the function/class definitions. * each returned item will test as equal in c.compare(token, item); * null is never returned, there will be an empty array if none were found. *************** *** 130,133 **** --- 129,135 ---- } } + if (start != null && start instanceof ClassNode) + // class name can also be a function call + retVal.add(start); // now traverse parents ArrayList ancestors = null; *************** *** 145,153 **** * @return an ordered ArrayList of File of all import paths for the project. */ ! private ArrayList getImportPaths(IFile startingPoint) { ArrayList retVal = new ArrayList(); // 1) the directory where the file is if (startingPoint != null) { ! IPath fileDir = startingPoint.getLocation().removeLastSegments(1); retVal.add(fileDir.toFile()); } --- 147,155 ---- * @return an ordered ArrayList of File of all import paths for the project. */ ! private ArrayList getImportPaths(IPath startingPoint) { ArrayList retVal = new ArrayList(); // 1) the directory where the file is if (startingPoint != null) { ! IPath fileDir = startingPoint.removeLastSegments(1); retVal.add(fileDir.toFile()); } *************** *** 165,169 **** * @return ArrayList of File objects that match. */ ! public File findImport(String name, IFile startAt) { ArrayList importPaths = getImportPaths(startAt); for (Iterator i= importPaths.iterator();i.hasNext();) { --- 167,171 ---- * @return ArrayList of File objects that match. */ ! public File findImport(String name, IPath startAt) { ArrayList importPaths = getImportPaths(startAt); for (Iterator i= importPaths.iterator();i.hasNext();) { *************** *** 175,177 **** --- 177,186 ---- return null; } + + public Scope findContainingClass() { + if (this.start instanceof ClassNode) + return this; + else + return parent != null ? parent.findContainingClass() : null; + } } Index: ItemPointer.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/model/ItemPointer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ItemPointer.java 15 Apr 2004 23:19:21 -0000 1.1 --- ItemPointer.java 22 Apr 2004 10:35:22 -0000 1.2 *************** *** 7,18 **** /** ! * ! * TODO Comment this class */ public class ItemPointer { ! ! public Object file; // IFile or File... ! public Location start; ! public Location end; public ItemPointer(Object file) { --- 7,20 ---- /** ! * Pointer points to a python resource inside a file system. ! * ! * You can create one of these, and use PyOpenAction to open the ! * right editor. */ public class ItemPointer { ! ! public Object file; // IFile or File object ! public Location start; // (first character) ! public Location end; // (last character) public ItemPointer(Object file) { *************** *** 25,28 **** this.end = end; } - } --- 27,29 ---- Index: ModuleNode.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/model/ModuleNode.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ModuleNode.java 15 Apr 2004 23:19:21 -0000 1.2 --- ModuleNode.java 22 Apr 2004 10:35:22 -0000 1.3 *************** *** 6,10 **** package org.python.pydev.editor.model; ! import org.eclipse.core.resources.IFile; /** --- 6,10 ---- package org.python.pydev.editor.model; ! import org.eclipse.core.runtime.IPath; /** *************** *** 16,22 **** Scope scope; ! IFile file; ! public ModuleNode(IFile file, int lines, int cols) { super(null); scope = new Scope(this); --- 16,22 ---- Scope scope; ! IPath file; ! public ModuleNode(IPath file, int lines, int cols) { super(null); scope = new Scope(this); *************** *** 28,36 **** public String getName() { ! // TODO module needs a name, probably a file it comes from ! return "module"; } ! public IFile getFile() { return file; } --- 28,35 ---- public String getName() { ! return (file != null) ? file.lastSegment() : "module"; } ! public IPath getPath() { return file; } Index: AbstractNode.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/model/AbstractNode.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AbstractNode.java 15 Apr 2004 23:19:21 -0000 1.2 --- AbstractNode.java 22 Apr 2004 10:35:22 -0000 1.3 *************** *** 8,12 **** import java.util.ArrayList; ! import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IStatus; import org.python.pydev.plugin.PydevPlugin; --- 8,12 ---- import java.util.ArrayList; ! import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.python.pydev.plugin.PydevPlugin; *************** *** 101,106 **** public abstract String getName(); ! public IFile getFile() { ! return parent.getFile(); } --- 101,106 ---- public abstract String getName(); ! public IPath getPath() { ! return parent.getPath(); } |