SmallSense__CompletionEngine.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 04 Oct 2013 08:25:15 +0100
changeset 120 4fefce92f5bb
parent 118 88e6fd734a11
child 131 ea84eea5a3c4
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 }"

Object subclass:#CompletionEngine
	instanceVariableNames:'codeView result'
	classVariableNames:''
	poolDictionaries:''
	category:'SmallSense-Core'
!

!CompletionEngine class methodsFor:'testing'!

isAbstract
    ^ self == CompletionEngine

    "Created: / 02-10-2013 / 13:11:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CompletionEngine methodsFor:'completion'!

complete
    "Compute completion for `codeView`, taking all the information
     from it. Returns a CompletionResult with computed completions"        

    ^ self subclassResponsibility

    "Modified (comment): / 02-10-2013 / 13:33:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

completeFor: aCodeView2OrTextEditView
    "Compute completion for given codeView, taking all the information
     from it. Returns a CompletionResult with computed completions"

    codeView := aCodeView2OrTextEditView.
    result := CompletionResult new.

    ^ self complete.

    "Created: / 02-10-2013 / 13:24:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 03-10-2013 / 16:42:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CompletionEngine methodsFor:'completion-individual'!

addMethodsStartingWith: prefix
    ^ self addMethodsStartingWith: prefix filter: nil

    "Created: / 24-07-2013 / 13:10:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 03-10-2013 / 17:59:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

addMethodsStartingWith: prefix filter: filterOrNil
    | selectors filter |

    selectors := Dictionary new.
    filter := filterOrNil  isNil ifTrue:[ [:method | true ] ] ifFalse:[ filterOrNil  ].

    Smalltalk allClassesDo:[:class|
        class selectorsAndMethodsDo:[:selector :mthd |             
            ((selector startsWith: prefix) and:[filter value: mthd]) ifTrue:[
                | class skip |

                class := mthd mclass superclass.
                skip := false.
                [ skip not and:[class notNil] ] whileTrue:[
                    (class methodDictionary includesKey: selector) ifTrue:[
                        skip := true.
                    ].
                    class := class superclass.
                ].
                skip ifFalse:[
                    | classes |

                    classes := selectors at: selector ifAbsentPut:[ Set new ].
                    classes add: mthd mclass.
                ].
            ]
        ].
    ].

    selectors keysAndValuesDo: [:selector :classes|
        result add:(MethodPO 
                name:selector
                description:"met source"nil
                class:(classes size == 1 ifTrue:[classes anElement] ifFalse:[classes])).
    ]

    "Created: / 03-10-2013 / 17:56:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !