--- a/Tools__LintHighlighter.st Wed Feb 05 19:57:45 2014 +0100
+++ b/Tools__LintHighlighter.st Wed Feb 05 19:57:47 2014 +0100
@@ -1,18 +1,48 @@
+"
+ COPYRIGHT (c) 2006 by eXept Software AG
+ All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice. This software may not
+ be provided or otherwise made available to, or used by, any
+ other person. No title to or ownership of the software is
+ hereby transferred.
+"
"{ Package: 'stx:libtool' }"
"{ NameSpace: Tools }"
Object subclass:#LintHighlighter
- instanceVariableNames:'rules formattingMethod emphasisError emphasisInformation
- emphasisWarning'
+ instanceVariableNames:'rules annotations formattingMethod emphasisError
+ emphasisInformation emphasisWarning'
classVariableNames:''
poolDictionaries:''
category:'Interface-Lint'
!
+!LintHighlighter class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 2006 by eXept Software AG
+ All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice. This software may not
+ be provided or otherwise made available to, or used by, any
+ other person. No title to or ownership of the software is
+ hereby transferred.
+"
+! !
!LintHighlighter methodsFor:'accessing'!
+annotations
+ ^ annotations
+!
+
rules
^ rules
!
@@ -31,7 +61,7 @@
emphasisError isNil ifTrue:[
warnColor := Color red.
emphasisError := Array
- with: #backgroundColor -> warnColor lightened lightened
+ "/with: #backgroundColor -> warnColor lightened lightened
with: #underwave
with: #underlineColor -> warnColor
].
@@ -39,6 +69,7 @@
"Created: / 05-08-2011 / 09:31:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 08-03-2012 / 03:00:51 / cg"
+ "Modified: / 20-04-2012 / 18:29:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
emphasisForInformation
@@ -47,7 +78,7 @@
emphasisInformation isNil ifTrue:[
warnColor := Color blue lighter.
emphasisInformation := Array
- with: #backgroundColor -> warnColor lightened lightened
+ "/with: #backgroundColor -> warnColor lightened lightened
with: #underwave
with: #underlineColor -> warnColor
].
@@ -55,6 +86,7 @@
"Created: / 05-08-2011 / 09:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 08-03-2012 / 03:01:22 / cg"
+ "Modified: / 20-04-2012 / 18:29:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
emphasisForSeverity: severity
@@ -73,7 +105,7 @@
emphasisWarning isNil ifTrue:[
warnColor := (Color redByte: 224 greenByte: 200 blueByte: 45).
emphasisWarning := Array
- with: #backgroundColor -> warnColor lightened lightened
+ "/with: #backgroundColor -> warnColor lightened lightened
with: #underwave
with: #underlineColor -> warnColor
].
@@ -81,6 +113,7 @@
"Created: / 05-08-2011 / 09:31:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 08-03-2012 / 03:00:19 / cg"
+ "Modified: / 20-04-2012 / 18:29:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!LintHighlighter methodsFor:'formatting'!
@@ -137,9 +170,9 @@
format: text
- rules ? #() do:[:rule|
- self format: text rule: rule
- ].
+ | tree |
+ tree := RBParser parseMethod: text string onError:[:error :pos| ^ text ].
+ self format: text tree: tree.
^text
"Created: / 04-08-2011 / 23:51:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -192,14 +225,90 @@
"Created: / 04-08-2011 / 23:55:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 07-03-2012 / 18:18:25 / cg"
+!
+
+format: text tree: tree
+
+ annotations := SortedCollection new.
+ rules ? #() do:[:rule|
+ self format: text tree: tree rule: rule
+ ].
+ ^text
+
+ "Created: / 02-02-2012 / 23:32:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+format: text tree: tree rule: rule
+
+ | string |
+
+ string := text string.
+ rule result isParseTreeEnvironment ifTrue:[
+ formattingMethod ifTrue:[
+ rule result selectionIntervalsForSource: string tree: tree do: [:interval|
+ interval notEmptyOrNil ifTrue:[
+ (interval first == 1 and:[interval last == text size]) ifTrue:[
+ (OperatingSystem getLoginName = 'jv') ifTrue:[
+ Transcript showCR:'>> no meaningful selection interval for ' , rule printString.
+ ].
+ ] ifFalse:[
+ self mark: text from: interval first to: interval last for: rule.
+ ]
+ ]
+ ].
+ ].
+ ] ifFalse: [
+ | searches |
+
+ searches := rule result searchStrings asSet.
+
+ searches do:[:search|
+ | i |
+ i := 1.
+ [
+ i := string findString: search startingAt: i.
+ i ~~ 0
+ ] whileTrue:[
+ self mark: text from: i to: (i + search size - 1) for: rule.
+ i := i + search size + 1.
+ ]
+
+
+ ]
+ ]
+
+ "Created: / 03-02-2012 / 10:39:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!LintHighlighter methodsFor:'initialization'!
+
+reset
+ annotations := OrderedCollection new.
+
+ "Created: / 18-02-2012 / 22:54:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 15-08-2013 / 12:40:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!LintHighlighter methodsFor:'markup'!
+
+mark: text from: start to: end for: rule
+ | emphasis |
+
+ emphasis := self emphasisForSeverity: rule severity.
+ text emphasisFrom: start to: end add: emphasis.
+ annotations add:
+ (LintAnnotation from: start to: end rule: rule)
+
+ "Created: / 30-01-2012 / 15:30:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!LintHighlighter class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.5 2012-03-08 03:16:18 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.6 2014-02-05 18:57:47 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.5 2012-03-08 03:16:18 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.6 2014-02-05 18:57:47 cg Exp $'
! !
+