SmallSense__MethodPO.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 04 Oct 2013 08:25:15 +0100
changeset 120 4fefce92f5bb
parent 115 254c4f5dc963
child 122 a0d62e942364
permissions -rw-r--r--
Initial support for Java/Groovy completion and for mixed-language completion. For now, completion for Java & Groovy is rather naive, based on a lexical structure of the line.

"{ Package: 'jv:smallsense' }"

"{ NameSpace: SmallSense }"

PO subclass:#MethodPO
	instanceVariableNames:'class'
	classVariableNames:''
	poolDictionaries:''
	category:'SmallSense-Core-Interface-PO'
!


!MethodPO class methodsFor:'Instance creation'!

name:name description:description class:class 
    ^ (self new)
        name:name;
        description:description;
        class:class.

    "Created: / 06-04-2011 / 16:50:05 / Jakub <zelenja7@fel.cvut.cz>"
! !

!MethodPO methodsFor:'accessing'!

class:something
    class := something.

    "Created: / 06-04-2011 / 16:51:42 / Jakub <zelenja7@fel.cvut.cz>"
!

cursorColumnAfterComplete

    | idx |
    idx := name indexOf: $:.
    ^idx == 0 ifTrue:[name size + 1] ifFalse:[idx + 1].

    "Created: / 05-04-2011 / 17:08:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

cursorColumnAfterCompleteForLanguage: language
    | stringToComplete idx |

    stringToComplete := self stringToCompleteForLanguage: language.
    language  isSmalltalk  ifTrue:[
        idx := stringToComplete indexOf: $:.
        ^idx == 0 ifTrue:[stringToComplete size + 1] ifFalse:[idx + 1].
    ].
    language isJava ifTrue:[
        ^ (stringToComplete at: stringToComplete size - 1) isSeparator
            ifTrue:[stringToComplete size- 2]
            ifFalse:[stringToComplete size]
    ].

    ^ stringToComplete size + 1.

    "Created: / 03-10-2013 / 16:50:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 03-10-2013 / 18:09:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

label

    label isNil ifTrue:[
        | someClass |

        someClass := class isBehavior ifTrue:[class] ifFalse:[class anElement].
        label := name.
        someClass programmingLanguage isSmalltalk ifFalse:[
            label := (someClass compiledMethodAt: name) printStringForBrowserWithSelector: name.
        ]
    ].
    ^ label

    "Created: / 07-04-2011 / 09:56:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-10-2013 / 02:28:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

stringToComplete

    ^String 
        fromStringCollection: (name tokensBasedOn: $:)
        separatedBy: ':  '.

    "Created: / 05-04-2011 / 16:51:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

stringToCompleteForLanguage: language
    | someClass |

    someClass := class isBehavior ifTrue:[class] ifFalse:[class anElement].
    someClass isJavaClass ifTrue:[
        | method |

        method := someClass compiledMethodAt: name.
        language isSmalltalk  ifTrue:[          
            ^  method selector upTo: $(
        ].
        language isJava ifTrue:[
            ^ (method selector upTo: $() , (method numArgs == 0 ifTrue:['()'] ifFalse:['(  )']).
        ].
    ].
    ^ super stringToCompleteForLanguage: language

    "Created: / 02-10-2013 / 02:33:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 03-10-2013 / 18:07:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!MethodPO methodsFor:'displaying'!

displayLabel:aLabel h:lH on:aGC x:x y:y h:h
    | lw cn cnw fg y0 |

    super displayLabel:aLabel h:lH on:aGC x:x y:y h:h.

    lw :=  x + IconWidth + (self label widthOn: aGC).
    class isCollection ifTrue:[
        cn := (class collect:[:each | each nameWithoutPrefix ]) asArray asStringWith:' , '.
    ] ifFalse:[
        cn := class nameWithoutPrefix.
    ].
    cnw := aGC widthOfString: cn.
    y0 := y - (lH + 1 - h // 2).
    y0 := y0 + (cn ascentOn:aGC).  

    (aGC width > (lw + cnw + 5)) ifTrue:
        [fg := aGC paint.
        aGC paint: Color gray .
        aGC displayString: cn x: aGC width - cnw - 5 y: y0.
        aGC paint: fg.
    ]

    "Created: / 18-09-2013 / 00:19:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-10-2013 / 02:17:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

displayOn:aGC x:x y:y opaque:opaque

    | lw cn cnw fg |

    super displayOn:aGC x:x y:y opaque:opaque.
    lw :=  x + 16 + (self label widthOn: aGC).
    cn := class nameWithoutPrefix.
    cnw := aGC widthOfString: cn.

    (aGC width > (lw + cnw + 5)) ifTrue:
        [fg := aGC paint.
        aGC paint: Color gray .
        aGC displayString: cn x: aGC width - cnw - 5 y: y.
        aGC paint: fg.
        ]

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

!MethodPO methodsFor:'testing'!

isSmallSenseMethodPO
    ^ true
! !

!MethodPO class methodsFor:'documentation'!

version_HG

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

version_SVN
    ^ '$Id: SmallSenseMethod.st 7825 2011-11-26 18:32:31Z vranyj1 $'
! !