Optimization in JavaLintService: cache language of the code view in an instvar.
"
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:libjava/tools' }"
Tools::CodeViewService subclass:#JavaLintService
instanceVariableNames:'highlighter showingJava'
classVariableNames:'Debugging'
poolDictionaries:''
category:'Languages-Java-Tools-Editor-Lint'
!
!JavaLintService 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.
"
! !
!JavaLintService class methodsFor:'initialization'!
initialize
"
| map |
map := Screen current keyboardMap.
map bindValue:#CodeCompletion to: #'Ctrl '.
map bindValue:#CodeCompletion to: #'Ctrlspace'.
"
Smalltalk isInitialized ifTrue:[
Smalltalk addStartBlock:[
Screen current notNil ifTrue:[
| map |
map := Screen current keyboardMap.
(map keyAtValue:#CodeCompletion) isNil ifTrue:[
map bindValue:#CodeCompletion to: #'Ctrl '.
map bindValue:#CodeCompletion to: #'Ctrlspace'.
].
]
]
]
"Modified: / 15-08-2013 / 15:19:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintService class methodsFor:'accessing'!
debugging
^Debugging == true
"Created: / 17-02-2012 / 00:48:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
debugging: aBoolean
Debugging := aBoolean
"Created: / 16-02-2012 / 16:22:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
label
"Answers short label - for UI"
^'Java - Static Checking'
"Created: / 07-03-2010 / 14:00:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 16-09-2013 / 10:01:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
priority
"Answers a priority of the service. Services with higher priority
will get the event notification before ones with lower priority.
Therefore, a lower-priority service might not get the event if high
priority service processes it"
^ 10
"Created: / 01-02-2012 / 10:29:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintService class methodsFor:'queries'!
isUsefulFor:aCodeView
"this filters useful services.
must be redefined to return true in subclasses (but each class must do it only
for itself - not for subclasses"
^ self == JavaLintService
"Created: / 24-07-2013 / 11:35:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 16-09-2013 / 09:56:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintService class methodsFor:'testing'!
isAvailable
^UserPreferences current smallSenseEnabled
"Created: / 04-02-2012 / 22:20:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintService methodsFor:'accessing'!
syntaxHighlighter
"Returns a syntax highligter class or nil. The highlighting
process gather all syntaxHighlighterClasses from all services
and then use them one by one to highlight the text. Individual
services may override this method to provide additional
highliging of the source code"
| lang |
JavaCompiler isNil ifTrue: [
^ nil
].
lang := codeView language.
^ (lang notNil and: [ lang isJava "and:[ self problems notEmptyOrNil ]"])
ifTrue: [ highlighter ]
ifFalse: [ nil ]
"Created: / 05-08-2011 / 10:59:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 04-10-2013 / 10:41:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintService methodsFor:'change & update'!
update:something with:aParameter from:changedObject
"Invoked when an object that I depend upon sends a change notification."
changedObject == codeView ifTrue:[
(#(methodHolder classHolder languageHolder) includes: something) ifTrue:[
aParameter key removeDependent: self.
aParameter value addDependent: self.
].
].
(changedObject == codeView languageHolder
or:[changedObject == codeView classHolder
or:[changedObject == codeView methodHolder]]) ifTrue:[
| lang |
lang := codeView language.
showingJava := lang notNil and:[lang isJava].
^ self
].
super update:something with:aParameter from:changedObject
"Modified (format): / 21-10-2013 / 15:11:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintService methodsFor:'event handling'!
buttonPress:button x:x y:y in:view
|lineNr|
showingJava ifFalse:[ ^ false ].
view == gutterView ifTrue:[
button == 1 ifTrue:[
lineNr := textView yVisibleToLineNr:y.
lineNr notNil ifTrue:[
^ self showInfoWindowForLine: lineNr
].
^ false.
].
].
^ false
"Created: / 30-01-2012 / 21:04:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 21-10-2013 / 15:12:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintService methodsFor:'initialization'!
initialize
super initialize.
highlighter := JavaLintHighlighter new.
showingJava := false.
"Created: / 05-08-2011 / 11:53:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 21-10-2013 / 15:11:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintService methodsFor:'private'!
annotationAtLine: lineNo
| annotations |
(annotations := highlighter annotations) isEmptyOrNil ifTrue:[ ^ nil ].
annotations do:[:a|
| line |
line := a line.
line > lineNo ifTrue:[ ^ nil ].
line == lineNo ifTrue:[ ^ a ].
].
^nil
"Created: / 30-01-2012 / 21:06:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 16-09-2013 / 13:38:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
showInfoWindowForLine: lineNo
| ann |
ann := self annotationAtLine: lineNo.
ann isNil ifTrue: [
^ false
].
(JavaLintPopupWindow new)
problem: ann problem;
codeView: codeView;
allButOpen;
openWindowAt: (Screen current pointerPosition - (20 @ 20)).
^ true
"Created: / 30-01-2012 / 21:04:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 16-09-2013 / 13:40:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintService methodsFor:'redrawing'!
drawLine:lineNo in:view atX:x y:y width:w height:h from:startCol to:endColOrNil with:fg and:bg
"Called by both gutterView and textView (well, not yet) to
allow services to draw custom things on text view.
Ask JV what the args means if unsure (I'm lazy to document
them, now it is just an experiment...)"
| annotation |
showingJava ifFalse:[ ^ self ].
annotation := self annotationAtLine: lineNo.
annotation notNil ifTrue:[
self drawAnnotationIcon: (ToolbarIconLibrary smalllintWarning16x16)
atX: x y: y width: w height: h.
].
"Created: / 30-01-2012 / 15:11:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 21-10-2013 / 15:12:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintService methodsFor:'registering'!
registerIn: aCodeView
super registerIn: aCodeView.
aCodeView languageHolder addDependent: self.
aCodeView classHolder addDependent: self.
aCodeView methodHolder addDependent: self.
"Created: / 17-09-2013 / 00:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintService class methodsFor:'documentation'!
version_HG
^ '$Changeset: <not expanded> $'
! !
JavaLintService initialize!