Tools__LintHighlighter.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 03 Feb 2012 10:54:40 +0000
branchjv
changeset 12141 f95099b6b5f7
parent 12128 a7ff7d66ee85
child 12170 6c9c4b7981ee
permissions -rw-r--r--
(none)

"
 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 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
!

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 redByte: 224 greenByte: 200 blueByte: 45)                  
    ].
    ^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

    | 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>"
!

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 notNil ifTrue:[
                    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:'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
    ^ '$Id: Tools__LintHighlighter.st 7868 2012-02-03 10:54:40Z vranyj1 $'
!

version_CVS
    ^ '§Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.3 2012/01/27 21:18:06 vrany Exp §'
!

version_SVN
    ^ '$Id: Tools__LintHighlighter.st 7868 2012-02-03 10:54:40Z vranyj1 $'
! !