Tools__LintService.st
author vrany
Fri, 05 Aug 2011 13:11:54 +0200
changeset 10484 efc1f0809373
child 11227 3d57003855a7
permissions -rw-r--r--
initial checkin

"
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
              All Rights Reserved

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
"{ Package: 'stx:libtool' }"

"{ NameSpace: Tools }"

CodeViewService subclass:#LintService
	instanceVariableNames:'ruleHolderFromApp highlighter'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Lint'
!

!LintService class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
              All Rights Reserved

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
! !

!LintService class methodsFor:'accessing'!

label

    "Answers short label - for UI"

    ^'SmallLint Checker'

    "Created: / 05-08-2011 / 11:01:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LintService methodsFor:'accessing'!

syntaxHighlighter

    | app rules |

    ((app :=codeView application) respondsTo: #selectedLintRules) ifTrue:[
        rules := self ruleHolderFromApp value.
        rules isEmptyOrNil not ifTrue:[
            highlighter rules: rules.
            ^highlighter
        ]
    ].
    ^nil

    "Created: / 05-08-2011 / 10:59:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LintService methodsFor:'aspects'!

ruleHolderFromApp
    "return/create the 'ruleHolderFromApp' value holder (automatically generated)"

    ruleHolderFromApp isNil ifTrue:[
        ruleHolderFromApp := ValueHolder new.
        ruleHolderFromApp addDependent:self.
    ].
    ^ ruleHolderFromApp
!

ruleHolderFromApp:something
    "set the 'ruleHolderFromApp' value holder (automatically generated)"

    |oldValue newValue|

    ruleHolderFromApp notNil ifTrue:[
        oldValue := ruleHolderFromApp value.
        ruleHolderFromApp removeDependent:self.
    ].
    ruleHolderFromApp := something.
    ruleHolderFromApp notNil ifTrue:[
        ruleHolderFromApp addDependent:self.
    ].
    newValue := ruleHolderFromApp value.
    oldValue ~~ newValue ifTrue:[
        self update:#value with:newValue from:ruleHolderFromApp.
    ].
! !

!LintService methodsFor:'change & update'!

update: aspect with: param from: sender


    sender == ruleHolderFromApp ifTrue:[
        self syntaxHighlight: true
    ]

    "Created: / 05-08-2011 / 11:49:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LintService methodsFor:'initialization'!

initialize

    super initialize.

    highlighter := LintHighlighter new

    "Modified: / 03-09-2010 / 22:29:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Created: / 05-08-2011 / 11:53:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LintService methodsFor:'private'!

syntaxHighlight: delayed

    | service |
    service := self service: #'Tools::CodeHighlightingService'.
    service notNil ifTrue:[
        service syntaxHighlight: delayed
    ]

    "Created: / 05-08-2011 / 11:49:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LintService methodsFor:'registering'!

registerIn: aCodeView

    super registerIn: aCodeView.
    (self application respondsTo: #selectedLintRules) ifTrue:[
        self ruleHolderFromApp: self application selectedLintRules
    ].

    "Modified: / 17-06-2011 / 13:07:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Created: / 05-08-2011 / 11:47:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LintService class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libtool/Tools__LintService.st,v 1.1 2011-08-05 11:11:54 vrany Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libtool/Tools__LintService.st,v 1.1 2011-08-05 11:11:54 vrany Exp $'
! !