Utilities/ClassBrowsers/rbclbr.py

branch
Py2 comp.
changeset 2791
a9577f248f04
parent 2525
8b507a9a2d40
parent 2769
8cbebde7a984
child 3057
10516539f238
diff -r 6686a3326df8 -r a9577f248f04 Utilities/ClassBrowsers/rbclbr.py
--- a/Utilities/ClassBrowsers/rbclbr.py	Mon Jul 08 21:47:26 2013 +0200
+++ b/Utilities/ClassBrowsers/rbclbr.py	Mon Jul 08 22:36:10 2013 +0200
@@ -283,6 +283,8 @@
         return dict
 
     lineno, last_lineno_pos = 1, 0
+    cur_obj = None
+    lastGlobalEntry = None
     i = 0
     while True:
         m = _getnext(src, i)
@@ -309,6 +311,9 @@
             # close all classes/modules indented at least as much
             while classstack and \
                   classstack[-1][1] >= thisindent:
+                if classstack[-1][0] is not None:
+                    # record the end line
+                    classstack[-1][0].setEndLine(lineno - 1)
                 del classstack[-1]
             while acstack and \
                   acstack[-1][1] >= thisindent:
@@ -343,6 +348,13 @@
                 else:
                     dict_counts[meth_name] = 0
                 dict[meth_name] = f
+            if not classstack:
+                if lastGlobalEntry:
+                    lastGlobalEntry.setEndLine(lineno - 1)
+                lastGlobalEntry = f
+            if cur_obj and isinstance(cur_obj, Function):
+                cur_obj.setEndLine(lineno - 1)
+            cur_obj = f
             classstack.append((f, thisindent))  # Marker for nested fns
 
         elif m.start("String") >= 0:
@@ -358,12 +370,15 @@
             # we found a class definition
             thisindent = indent
             indent += 1
+            lineno = lineno + src.count('\n', last_lineno_pos, start)
+            last_lineno_pos = start
             # close all classes/modules indented at least as much
             while classstack and \
                   classstack[-1][1] >= thisindent:
+                if classstack[-1][0] is not None:
+                    # record the end line
+                    classstack[-1][0].setEndLine(lineno - 1)
                 del classstack[-1]
-            lineno = lineno + src.count('\n', last_lineno_pos, start)
-            last_lineno_pos = start
             class_name = m.group("ClassName") or m.group("ClassName2")
             inherit = m.group("ClassSupers")
             if inherit:
@@ -386,6 +401,11 @@
                     cur_class = cls
                 else:
                     cls._addclass(class_name, cur_class)
+            if not classstack:
+                if lastGlobalEntry:
+                    lastGlobalEntry.setEndLine(lineno - 1)
+                lastGlobalEntry = cur_class
+            cur_obj = cur_class
             classstack.append((cur_class, thisindent))
             while acstack and \
                   acstack[-1][1] >= thisindent:
@@ -396,12 +416,15 @@
             # we found a module definition
             thisindent = indent
             indent += 1
+            lineno = lineno + src.count('\n', last_lineno_pos, start)
+            last_lineno_pos = start
             # close all classes/modules indented at least as much
             while classstack and \
                   classstack[-1][1] >= thisindent:
+                if classstack[-1][0] is not None:
+                    # record the end line
+                    classstack[-1][0].setEndLine(lineno - 1)
                 del classstack[-1]
-            lineno = lineno + src.count('\n', last_lineno_pos, start)
-            last_lineno_pos = start
             module_name = m.group("ModuleName")
             # remember this class
             cur_class = Module(module, module_name, file, lineno)
@@ -418,6 +441,11 @@
                     cur_class = cls
                 else:
                     cls._addclass(module_name, cur_class)
+            if not classstack:
+                if lastGlobalEntry:
+                    lastGlobalEntry.setEndLine(lineno - 1)
+                lastGlobalEntry = cur_class
+            cur_obj = cur_class
             classstack.append((cur_class, thisindent))
             while acstack and \
                   acstack[-1][1] >= thisindent:
@@ -474,6 +502,9 @@
                     break
                 else:
                     index -= 1
+                    if lastGlobalEntry:
+                        lastGlobalEntry.setEndLine(lineno - 1)
+                    lastGlobalEntry = None
 
         elif m.start("Attr") >= 0:
             lineno = lineno + src.count('\n', last_lineno_pos, start)

eric ide

mercurial