LintHighlighter/.LintService refactored to show multiple rules at line...
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 15 Dec 2014 21:27:23 +0100
changeset 15030 c8d7085ee271
parent 15029 5dccdad68e3a
child 15031 fd2c24c7f230
LintHighlighter/.LintService refactored to show multiple rules at line... ...not only first-found.
Tools__LintService.st
--- a/Tools__LintService.st	Mon Dec 15 21:27:18 2014 +0100
+++ b/Tools__LintService.st	Mon Dec 15 21:27:23 2014 +0100
@@ -28,7 +28,8 @@
 "{ NameSpace: Tools }"
 
 CodeViewService subclass:#LintService
-	instanceVariableNames:'ruleHolderFromApp highlighter'
+	instanceVariableNames:'ruleHolderFromApp highlighter annotations
+		annotationsSequenceNumber'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Interface-Lint'
@@ -87,6 +88,51 @@
 
 !LintService methodsFor:'accessing'!
 
+annotationAtLine: lineNo
+    | anns |
+
+    (anns := self annotations) notNil ifTrue:[ 
+        anns do:[:annotation | annotation line = lineNo ifTrue:[ ^ annotation ] ]
+    ].
+    ^ nil
+
+    "Created: / 30-01-2012 / 21:06:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 15-12-2014 / 15:40:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+annotations
+    
+    (highlighter notNil and:[ highlighter sequenceNumber ~~ annotationsSequenceNumber ]) ifTrue:[
+        | rulesToIntervalsMap annotationsPerLineMap |
+
+        rulesToIntervalsMap := highlighter rulesToIntervalsMap.
+        rulesToIntervalsMap notNil ifTrue:[ 
+            annotationsPerLineMap := Dictionary new.
+            rulesToIntervalsMap keysAndValuesDo:[ :rule :intervals |
+                intervals do:[:interval | 
+                    | line annotation |
+
+                    line := codeView lineOfCharacterPosition: interval first.
+                    annotation := annotationsPerLineMap at: line ifAbsentPut:[ LintAnnotation new line: line ].
+                    annotation rule notNil ifTrue:[ 
+                        annotation rule isComposite 
+                            ifTrue: [ annotation rule rules add: rule ]
+                            ifFalse:[ annotation rule: (RBCompositeLintRule rules: (Array with: annotation rule with: rule))]
+                    ] ifFalse:[ 
+                        annotation rule: rule
+                    ].
+                ].
+            ].
+            annotations := annotationsPerLineMap values sort:[ :a :b | a line < b line ].
+            annotationsSequenceNumber := highlighter sequenceNumber.
+        ]
+    ].
+    ^annotations
+
+    "Created: / 15-12-2014 / 15:29:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 15-12-2014 / 18:41:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 syntaxHighlighter
     | app rules |
 
@@ -94,6 +140,7 @@
     app notNil ifTrue:[
         rules := self ruleHolderFromApp value.
         rules notEmptyOrNil ifTrue:[
+            annotations := nil.
             highlighter rules: rules.
             ^ highlighter
         ].
@@ -102,6 +149,7 @@
 
     "Created: / 05-08-2011 / 10:59:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 08-03-2012 / 01:23:48 / cg"
+    "Modified: / 15-12-2014 / 20:22:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !LintService methodsFor:'aspects'!
@@ -195,25 +243,6 @@
 
 !LintService methodsFor:'private'!
 
-annotationAtLine: lineNo
-    | annotations |        
-
-    (annotations := highlighter annotations) isEmptyOrNil ifTrue:[ ^ nil ].
-    annotations do:[:annotation|
-        | line |
-
-        (line := annotation line) isNil ifTrue:[
-            line := codeView lineOfCharacterPosition: annotation startPosition.
-            annotation line: line.
-        ].
-        line > lineNo ifTrue:[ ^ nil ].
-        line == lineNo ifTrue:[ ^ annotation ].
-    ].
-    ^nil
-
-    "Created: / 30-01-2012 / 21:06:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
 syntaxHighlight: delayed
 
     | service |
@@ -280,10 +309,10 @@
 !LintService class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__LintService.st,v 1.11 2014-12-03 10:25:53 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__LintService.st,v 1.12 2014-12-15 20:27:23 vrany Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__LintService.st,v 1.11 2014-12-03 10:25:53 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__LintService.st,v 1.12 2014-12-15 20:27:23 vrany Exp $'
 ! !