initial checkin
authorvrany
Fri, 05 Aug 2011 13:13:08 +0200
changeset 10485 abd25bbd5625
parent 10484 efc1f0809373
child 10486 ecf02903122f
initial checkin
Tools__LintHighlighter.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Tools__LintHighlighter.st	Fri Aug 05 13:13:08 2011 +0200
@@ -0,0 +1,180 @@
+"{ Package: 'stx:libtool' }"
+
+"{ NameSpace: Tools }"
+
+Object subclass:#LintHighlighter
+	instanceVariableNames:'rules formattingMethod emphasisError emphasisInformation
+		emphasisWarning'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Interface-Lint'
+!
+
+
+!LintHighlighter methodsFor:'accessing'!
+
+rules
+    ^ rules
+!
+
+rules:something
+    rules := something.
+! !
+
+!LintHighlighter methodsFor:'accessing-emphasis'!
+
+emphasisForError
+
+    emphasisError isNil ifTrue:[
+        emphasisError := Array 
+            with: #underwave 
+            with: #underlineColor -> Color red                    
+    ].
+    ^emphasisError
+
+    "Created: / 05-08-2011 / 09:31:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+emphasisForInformation
+
+    emphasisInformation isNil ifTrue:[
+        emphasisInformation := Array 
+            with: #underwave 
+            with: #underlineColor -> Color blue lighter                    
+    ].
+    ^emphasisInformation
+
+    "Created: / 05-08-2011 / 09:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+emphasisForSeverity: severity
+
+    severity == #error ifTrue:[^self emphasisForError].
+    severity == #information ifTrue:[^self emphasisForInformation].
+
+    ^self emphasisForWarning
+
+    "Created: / 05-08-2011 / 09:31:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+emphasisForWarning
+
+    emphasisWarning isNil ifTrue:[
+        emphasisWarning := Array 
+            with: #underwave 
+            with: #underlineColor -> Color yellow darker                  
+    ].
+    ^emphasisWarning
+
+    "Created: / 05-08-2011 / 09:31:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!LintHighlighter methodsFor:'formatting'!
+
+formatClassDefinition:source in:class
+
+    formattingMethod := false.
+    ^ self format: source
+
+    "Created: / 04-08-2011 / 23:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+formatClassDefinition:source in:class elementsInto: elements
+
+    formattingMethod := false.
+    ^ self format: source
+
+    "Created: / 04-08-2011 / 23:44:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+formatExpression:source in:class
+
+    formattingMethod := false.
+    ^ self format: source
+
+    "Created: / 04-08-2011 / 23:45:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+formatExpression:source in:class elementsInto: elements
+
+    formattingMethod := false.
+    ^ self format: source
+
+    "Created: / 04-08-2011 / 23:43:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+formatMethod:mth source:source in:class using: preferences
+
+    formattingMethod := true.
+    ^ self format: source
+
+    "Created: / 04-08-2011 / 23:45:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+formatMethod:mth source:source in:class using: preferences elementsInto: elements
+
+    formattingMethod := true.
+    ^ self format: source
+
+    "Created: / 04-08-2011 / 23:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!LintHighlighter methodsFor:'formatting-private'!
+
+format: text
+
+    rules ? #() do:[:rule|
+        self format: text rule: rule
+    ].
+    ^text
+
+    "Created: / 04-08-2011 / 23:51:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+format: text rule: rule
+
+    | string emphasis |
+
+    string := text asString.
+    emphasis := self emphasisForSeverity: rule severity.
+
+    rule result isParseTreeEnvironment ifTrue:[
+        formattingMethod ifTrue:[
+            | interval |
+            interval := rule result selectionIntervalFor: string.
+            text emphasisFrom: interval first to: interval last 
+                     add: emphasis.            
+        ].
+    ] ifFalse:[
+        | searches |
+
+        searches := rule result searchStrings asSet.
+
+        searches do:[:search|
+            | i |
+            i := 1.
+            [ 
+                i := string findString: search startingAt: i.
+                i ~~ 0
+            ] whileTrue:[
+                text emphasisFrom: i to: i + search size - 1 
+                     add: emphasis.
+                i := i + search size + 1.
+            ]
+            
+
+        ]
+    ]
+
+    "Created: / 04-08-2011 / 23:55:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!LintHighlighter class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.1 2011-08-05 11:13:08 vrany Exp $'
+!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.1 2011-08-05 11:13:08 vrany Exp $'
+! !