Tools__LintService.st
author Claus Gittinger <cg@exept.de>
Mon, 12 Mar 2012 19:20:05 +0100
changeset 11416 941e576b6f71
parent 11390 b5af6f49f10f
child 12401 4714b9640528
child 13099 f4f0761ca231
permissions -rw-r--r--
changed: #fetchLintRuleHolder

"
 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.
    app notNil ifTrue:[
        rules := self ruleHolderFromApp value.
        rules notEmptyOrNil ifTrue:[
            highlighter rules: rules.
            ^ highlighter
        ].
    ].
    ^nil

    "Created: / 05-08-2011 / 10:59:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-03-2012 / 01:23:48 / cg"
! !

!LintService methodsFor:'aspects'!

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

    |app|

    ruleHolderFromApp isNil ifTrue:[
        (app := self application) notNil ifTrue:[
            self fetchLintRuleHolder
            "/ ruleHolderFromApp := ValueHolder new.
            "/ ruleHolderFromApp addDependent:self.
        ].
    ].
    ^ ruleHolderFromApp

    "Modified: / 08-03-2012 / 01:17:15 / cg"
!

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
    aspect == #sizeOfView ifFalse:[
        sender == ruleHolderFromApp ifTrue:[
            self syntaxHighlight: true.
            ^ self.
        ]
    ].
    super update: aspect with: param from: sender.

    "Created: / 05-08-2011 / 11:49:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 07-03-2012 / 17:16:59 / cg"
! !

!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 process: delayed
    ]

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

!LintService methodsFor:'registering'!

fetchLintRuleHolder
    |app|

    app := self application.
    app notNil ifTrue:[
        "/ bad design; better idea would be to pass the lintRuleHolder back from the
        "/ application to me explicitely (in a postBuild method for some ruleCanvas of the app)
        (app respondsTo: #selectedLintRules) ifTrue:[
            self ruleHolderFromApp: app selectedLintRules
        ] ifFalse:[
            self breakPoint:#jv.
            "/ Transcript showCR:'LintService [info]: app does not provide a lintRuleHolder'
        ]
    ].

    "Created: / 08-03-2012 / 01:16:38 / cg"
!

registerIn: aCodeView
    super registerIn: aCodeView.
    self fetchLintRuleHolder.

    "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>"
    "Modified: / 08-03-2012 / 01:16:51 / cg"
! !

!LintService class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libtool/Tools__LintService.st,v 1.6 2012-03-12 18:20:05 cg Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libtool/Tools__LintService.st,v 1.6 2012-03-12 18:20:05 cg Exp $'
! !