Tools__LintService.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 05 Sep 2013 12:46:11 +0200
changeset 13498 b8d845e42988
parent 13202 dd6ea03d2edd
child 13530 2269bce1636d
child 14052 ebcdddd89b02
permissions -rw-r--r--
Added `environment` instance variable to Tools__NewSystemBrowser and components it uses. The environment is by default initialized to Smalltalk. This allow for displaying limited subset of classes in the browser. The classes displayed does not even have to be classes and does not have to be installed in Smalltalk dictionary.

"
 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 a short label - for UI"

    ^'SmallLint Checker'

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

!LintService class methodsFor:'testing'!

isUsefulFor:aCodeView
    "this filters useful services.
     Redefined to return true for myself - not for subclasses"

    ^ self == Tools::LintService

    "Created: / 22-07-2013 / 14:01:38 / cg"
! !

!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.9 2013-09-05 10:46:11 vrany Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libtool/Tools__LintService.st,v 1.9 2013-09-05 10:46:11 vrany Exp $'
! !