tools/JavaCompilerProblemService.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 06 Sep 2013 00:16:38 +0100
branchdevelopment
changeset 2711 a00302fe5083
parent 2671 8f41105bb931
child 2731 13f5be2bf83b
permissions -rw-r--r--
Added version_CVS to all classes and build files regenerated & cleaned. This is necessary step before updating CVS.

"{ Package: 'stx:libjava/tools' }"

Tools::CodeViewService subclass:#JavaCompilerProblemService
	instanceVariableNames:'problems'
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Java-Tools-Editor'
!


!JavaCompilerProblemService class methodsFor:'image specs'!

javaCompilerError16x16
    "This resource specification was automatically generated
     by the ImageEditor of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the ImageEditor may not be able to read the specification."

    "
     self javaCompilerError16x16 inspect
     ImageEditor openOnClass:self andSelector:#javaCompilerError16x16
     Icon flushCachedIcons
    "

    <resource: #image>

    ^Icon
        constantNamed:'JavaCompilerProblemService javaCompilerError16x16'
        ifAbsentPut:[(Depth8Image new) width: 16; height: 16; photometric:(#palette); bitsPerSample:(#(8)); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'
K"8.K"8.K"8.K"8.K"8.K"8.K"4-KR4-K"8.K"8.K"8.K"4&J20+I"4.K"8.K"8.K"8)JBL#H2\*KR8.K"8.K"8.IA,_F1<[IR4.K"8.K"8.K"DTE1TWD2H-
KR4-KR8.K"8 DQ@RD@@@@@@@@@@.K"8.G!!$OKP<@@ TAAPH@K"8.K"4ZGB4]@@T-AB4E@B8.K"8.KQXFF@@AAB4D@P@.K"8.K"4LKP @@PP-A@D@K"8.K"8-
C \J@@T-AB4E@B8.K"8.KP4IB0@BAPDE@0@.K"8.K"8-KR4@@@@@@@@@K"8.K"8.K"8.KR4-KR4-KR8.K"8.K"8.K"8.K"8.K"8.K @@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@a') ; colorMapFromArray:#[216 66 79 221 91 102 227 119 128 231 136 144 232 144 151 236 160 167 199 213 238 175 182 194 81 106 139 75 96 121 92 112 135 175 185 196 133 172 208 179 192 204 132 163 188 249 246 194 253 252 236 248 242 175 253 251 228 251 238 178 251 239 178 252 242 196 186 173 121 252 242 198 181 167 115 239 199 71 253 224 127 252 233 175 250 209 100 251 211 101 248 220 142 253 232 174 238 186 57 239 184 63 237 183 63 255 231 181 237 176 63 236 175 63 239 189 97 243 191 99 242 191 99 241 190 102 241 191 102 236 170 64 236 172 67 255 255 255 255 255 255]; mask:((ImageMask new) width: 16; height: 16; photometric:(#blackIs0); bitsPerSample:(#[1]); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@_@C>@O<@?0C?<O?0??C?<G?0_?A?<G?0O?@G<@@@b') ; yourself); yourself]
!

javaCompilerWarning16x16
    "This resource specification was automatically generated
     by the ImageEditor of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the ImageEditor may not be able to read the specification."

    "
     self javaCompilerWarning16x16 inspect
     ImageEditor openOnClass:self andSelector:#javaCompilerWarning16x16
     Icon flushCachedIcons
    "

    <resource: #image>

    ^Icon
        constantNamed:'JavaCompilerProblemService javaCompilerWarning16x16'
        ifAbsentPut:[(Depth8Image new) width: 16; height: 16; photometric:(#palette); bitsPerSample:(#(8)); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'
PDA@PDA@PDA@PDA@PDA@PDA@PC<?O3<?PDA@PDA@PDA@PC</MSX5K3=@PDA@PDA@PD@2LR,+J3@3O4A@PDA@PDA@KA !!FBDXKS=@PDA@PDA@PBXOD!!@RC"\?
O3=@PDA@PD@"B0(MB ,#OC =O4A@PDA@GQTIO0$VG# LNC=@PDA@PC<WFS<$D30\O!!0<O4A@PDA@O1D@EC<8GC8\NC=@PDA@PC<FO0H;JA0.GB$:PDA@PD@?
B@DDNA,4O#PZNDA@PDA@O0\CAS\_HB( IS]@PDA@PD@?O3<9M3\7M3\9PDA@PDA@PDA@O3<?O3<?O4A@PDA@PDA@PDA@PDA@PDA@P@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@a') ; colorMapFromArray:#[199 213 238 175 182 194 81 106 139 75 96 121 92 112 135 198 205 213 133 172 208 179 192 204 132 163 188 249 246 194 253 252 236 248 242 175 255 252 211 253 251 228 251 238 178 251 239 178 252 242 196 186 173 121 252 242 198 253 226 129 181 167 115 239 199 71 239 200 71 253 224 127 252 233 175 250 209 100 253 221 130 253 222 130 248 216 128 248 220 142 248 221 143 254 227 150 240 216 144 253 232 174 238 186 57 238 187 58 247 203 90 255 226 150 239 184 63 237 183 63 237 192 96 237 191 96 181 148 82 255 231 181 237 176 63 236 175 63 210 157 62 239 189 97 243 191 99 242 191 99 241 190 102 241 191 102 237 194 116 236 170 64 236 172 67 198 133 46 225 165 85 229 199 160 226 179 120 225 179 120 234 192 141 234 201 159 80 40 0 255 255 255 255 255 255]; mask:((ImageMask new) width: 16; height: 16; photometric:(#blackIs0); bitsPerSample:(#[1]); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@_@C>@O<@?0C?0O? ?>C?<G?0_?A?<G?0O?@G<@@@b') ; yourself); yourself]
! !

!JavaCompilerProblemService 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 == JavaCompilerProblemService

    "Created: / 04-08-2013 / 14:19:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaCompilerProblemService 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]) 
        ifTrue:[JavaCompilerProblemHighlighter new]
        ifFalse:[nil]

    "Created: / 15-04-2013 / 23:35:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 04-08-2013 / 14:26:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaCompilerProblemService methodsFor:'change & update'!

update: aspect with: param from: sender

    "Get updated whenever something changes in the code view.
     Subclasses may override this"

    | cls method |

    sender == codeView ifTrue:[
        (#(methodHolder classHolder languageHolder) includes: aspect) ifTrue:[
            param key removeDependent: self.
            param value addDependent: self.                         
        ]
    ].    

    (sender == codeView languageHolder
        or:[sender == codeView classHolder
        or:[sender == codeView methodHolder]]) 
        ifTrue:[
        method := codeView method.
        cls := method notNil ifTrue:[method mclass] ifFalse:[codeView classHolder value].
        self updateProblems: cls
    ].

    (aspect == #problems) ifTrue:[
        method := codeView method.
        cls := method notNil ifTrue:[method mclass] ifFalse:[codeView classHolder value].
        cls == param ifTrue:[
            self updateProblems: cls
        ]
    ].

    "Created: / 06-08-2013 / 10:37:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 09-08-2013 / 00:51:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

updateProblems: class
    problems := JavaCompilerProblemRegistry problemsFor: class.
    self rehighlight: true.
    gutterView invalidate.

    "Created: / 06-08-2013 / 20:18:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-08-2013 / 00:19:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaCompilerProblemService methodsFor:'drawing'!

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...)"

    | problem |        

    problems isEmptyOrNil ifTrue:[ ^ self ].
    problem :=  self problemAtLine: lineNo.
    problem notNil ifTrue:[
        self 
            drawAnnotationIcon: (problem isError 
                                    ifTrue:[self class javaCompilerError16x16] 
                                    ifFalse:[self class javaCompilerWarning16x16])
            atX: x y: y  width: w height: h.
    ].

    "Created: / 06-08-2013 / 21:29:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 06-08-2013 / 23:30:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaCompilerProblemService methodsFor:'event handling'!

buttonPress:button x:x y:y in:view 
    |lineNr|

    problems isEmptyOrNil ifTrue:[
        ^ false
    ].
    view == gutterView ifTrue:[
        button == 1 ifTrue:[
            lineNr := textView yVisibleToLineNr:y.
            lineNr notNil ifTrue:[ 
                ^ self showProblemAtLine: lineNr 
            ].
            ^ false.
        ].
    ].
    ^ false

    "Created: / 07-08-2013 / 00:00:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaCompilerProblemService methodsFor:'private'!

problemAtLine: lineNr
    ^ problems detect:[:p | p getSourceLineNumber == lineNr ] ifNone:[nil].

    "Created: / 06-08-2013 / 23:28:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

rehighlight: delayed

    | service |
    service := self service: #'SmallSense::SyntaxHighlightingService'.
    service isNil ifTrue:[
        service := self service: Tools::CodeHighlightingService name
    ].
    service notNil ifTrue:[
        service sourceChanged: true.
    ]

    "Created: / 27-01-2012 / 17:06:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 06-08-2013 / 10:32:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

showProblemAtLine: lineNr
    | p |

    p := self problemAtLine: lineNr.
    p isNil ifTrue:[ ^ false ].
    JavaCompilerProblemPopup new
        problem: p;
        codeView: codeView;
        allButOpen;
        openWindowAt: (Screen current pointerPosition - (20@20)).

    ^ true

    "Created: / 07-08-2013 / 00:00:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaCompilerProblemService methodsFor:'registering'!

registerIn: aCodeView

    "Installs myself in aCodeView"

    super registerIn: aCodeView.
    JavaCompilerProblemRegistry instance addDependent: self.
    codeView languageHolder addDependent: self.
    codeView classHolder addDependent: self.
    codeView methodHolder addDependent: self.

    "Created: / 06-08-2013 / 10:33:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 09-08-2013 / 00:38:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

unregister

    "Uninstall myself from my codeView"

    JavaCompilerProblemRegistry instance addDependent: self.
    codeView languageHolder removeDependent: self.
    codeView classHolder removeDependent: self.
    codeView methodHolder removeDependent: self.

    "Created: / 09-08-2013 / 00:38:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaCompilerProblemService class methodsFor:'documentation'!

version_CVS
    ^ '$Header$'
!

version_HG

    ^ '$Changeset: <not expanded> $'
! !