SmallSense__AbstractJavaCompletionEngine.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 07 Aug 2014 10:30:23 +0100
changeset 267 b6fbf84b14ae
parent 252 feba6ee5c814
child 276 4844368a74bc
permissions -rw-r--r--
Temporary commit: More work on JavaCompletionEngine

"
stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE
Copyright (C) 2013-2014 Jan Vrany

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
"{ Package: 'stx:goodies/smallsense' }"

"{ NameSpace: SmallSense }"

CompletionEngine subclass:#AbstractJavaCompletionEngine
	instanceVariableNames:'class method'
	classVariableNames:''
	poolDictionaries:''
	category:'SmallSense-Java'
!

!AbstractJavaCompletionEngine class methodsFor:'documentation'!

copyright
"
stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE
Copyright (C) 2013-2014 Jan Vrany

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
! !

!AbstractJavaCompletionEngine class methodsFor:'queries'!

isAbstract
    "Return if this class is an abstract class.
     True is returned here for myself only; false for subclasses.
     Abstract subclasses must redefine again."

    ^ self == SmallSense::AbstractJavaCompletionEngine.
! !

!AbstractJavaCompletionEngine methodsFor:'completion-individual'!

addClassesStartingWith: prefix
    ^ self addClassesStartingWith: prefix fullName: false

    "Created: / 03-10-2013 / 11:16:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 15-05-2014 / 07:25:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

addClassesStartingWith: prefixArg fullName: matchFullName
    | prefix |

    prefix := prefixArg.
    matchFullName ifTrue:[
        prefix := prefix copyReplaceAll: $. with: $/.
    ].
    context environment allClassesDo: [:cls |
        cls isJavaClass ifTrue:[
            | name i |

            matchFullName ifTrue:[
                (cls binaryName startsWith: prefix) ifTrue:[
                    result add: ((PO forClas: cls) showPrefix: true; yourself).
                ].
            ] ifFalse:[
                name := cls lastName.
                i := name lastIndexOf: $/.
                ((name size >= (i + prefix size))
                    and:[(name at: i + 1) == prefix first
                    and:[(name at: i + prefix size) == prefix last
                    and:[(2 to: prefix size - 1) allSatisfy:[:o| (name at: i + o) == (prefix at: o)]]]])
                    ifTrue:[
                        result add: (PO forClass: cls).
                    ].
            ].
        ].
    ].

    "Created: / 15-05-2014 / 07:24:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

addConstructorsForClass: aJavaClass fullName: showFullName
    aJavaClass selectorsAndMethodsDo:[:selector :method |
        (selector first == $< and:[ selector startsWith: '<init>' ]) ifTrue:[
            result add: ((JavaConstructorPO new initializeWithClass: aJavaClass selector: selector) showPrefix: showFullName)
        ].
    ].

    "Created: / 15-05-2014 / 12:05:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

addFieldsForType: type
    | seen |

    type isUnknownType ifTrue:[ 
        ^ self.
    ].
    seen := Set new.
    type classesDo:[:initialCls |
        (seen includes: initialCls) ifFalse:[
            | cls |

            cls := initialCls.
            cls staticFields do:[:each | result add: (VariablePO classVariable: each name in: cls) ].
            [ cls ~~ JavaObject and:[ (seen includes: cls) not ] ] whileTrue:[
                seen add: cls.
                cls fields do:[:each | result add: (VariablePO instanceVariable: each name in: cls) ].
                cls := cls superclass.
            ].
        ]
    ].

    "Created: / 17-05-2014 / 20:37:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 22-05-2014 / 17:36:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

addImportsStartingWith: prefix
    | packages |

    packages := Set new.

    "/ Class imports...
    context environment allClassesDo: [:cls |
        cls isJavaClass ifTrue:[
            | name |

            name := cls javaName.
            (cls isPublic and:[name startsWith: prefix]) ifTrue:[
                result add: (JavaImportPO new import: name; klass: cls; yourself).
                packages add: cls javaPackage.
            ].
        ]
    ].
    "/ Package imports...
    packages do:[:each |
        result add: (JavaImportPO new import: (each , '.*'))
    ].

    "Created: / 19-10-2013 / 17:54:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 14-05-2014 / 12:48:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

addMethodsStartingWith: prefix
    ^ self addMethodsStartingWith: prefix stripOff: nil filter: [:m | m isJavaMethod ]

    "Created: / 03-10-2013 / 18:01:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-04-2014 / 21:37:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!AbstractJavaCompletionEngine class methodsFor:'documentation'!

version_HG

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