Added source line number to JavaSourceRef. development
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 10 Sep 2013 05:04:41 +0100
branchdevelopment
changeset 2721 ceb9ed115183
parent 2720 d55ab9c66bb3
child 2722 1527fdb0c92f
Added source line number to JavaSourceRef. Used for scrolling to the method header, skipping the Javadoc.
tools/JavaSourceDocument.st
tools/JavaSourceRef.st
--- a/tools/JavaSourceDocument.st	Mon Sep 09 13:25:14 2013 +0100
+++ b/tools/JavaSourceDocument.st	Tue Sep 10 05:04:41 2013 +0100
@@ -107,6 +107,33 @@
     "Created: / 08-09-2013 / 10:52:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+sourceOffsetToLine: offset
+
+    |low    "{ Class: SmallInteger}"
+     high   "{ Class: SmallInteger}"
+     middle "{ Class: SmallInteger}"
+     element|
+
+    "
+     we can of course use a binary search - since the elements are sorted
+    "
+    low := 1.
+    high := sourceLineEnds size.
+    [low > high] whileFalse:[
+        middle := (low + high) // 2.
+        element := sourceLineEnds at:middle.
+        element < offset ifTrue:[
+            "middleelement is smaller than object"
+            low := middle + 1
+        ] ifFalse:[
+            high := middle - 1
+        ]
+    ].
+    ^ low
+
+    "Created: / 10-09-2013 / 03:40:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 sourceText
     ^ sourceText
 !
@@ -245,11 +272,15 @@
                         ].
                     ].
                     methodNode notNil ifTrue: [
+                        | line |
+
+                        line := (self sourceOffsetToLine: methodNode sourceStart) -
+                                (self sourceOffsetToLine: methodNode declarationSourceStart) + 1.
+
                         source := JavaSourceRef new.
                         source offset: methodNode declarationSourceStart.
-                        source 
-                            length: methodNode declarationSourceEnd - methodNode declarationSourceStart 
-                                    + 1.
+                        source length: methodNode declarationSourceEnd - methodNode declarationSourceStart + 1.
+                        source line: line.
                         method setSource: source.
                     ] ifFalse: [
                         self error: 'Cannot determine method!!'.
@@ -259,7 +290,7 @@
         ]
 
     "Created: / 07-09-2013 / 01:43:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 09-09-2013 / 10:28:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 10-09-2013 / 03:56:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 initializeSourceTree
--- a/tools/JavaSourceRef.st	Mon Sep 09 13:25:14 2013 +0100
+++ b/tools/JavaSourceRef.st	Tue Sep 10 05:04:41 2013 +0100
@@ -70,24 +70,24 @@
     ^ length
 !
 
-length:something
-    length := something.
+length:anInteger
+    length := anInteger.
 !
 
 line
     ^ line
 !
 
-line:something
-    line := something.
+line:anInteger
+    line := anInteger.
 !
 
 offset
     ^ offset
 !
 
-offset:something
-    offset := something.
+offset:anInteger
+    offset := anInteger.
 ! !
 
 !JavaSourceRef methodsFor:'reading'!